1 /* 2 * Copyright (c) 1988 Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are permitted 6 * provided that this notice is preserved and that due credit is given 7 * to the University of California at Berkeley. The name of the University 8 * may not be used to endorse or promote products derived from this 9 * software without specific prior written permission. This software 10 * is provided ``as is'' without express or implied warranty. 11 */ 12 13 #ifndef lint 14 char copyright[] = 15 "@(#) Copyright (c) 1988 Regents of the University of California.\n\ 16 All rights reserved.\n"; 17 #endif /* not lint */ 18 19 #ifndef lint 20 static char sccsid[] = "@(#)test.c 4.1 (Berkeley) 12/04/88"; 21 #endif /* not lint */ 22 23 #include <stdio.h> 24 25 #include "../api/api.h" 26 #include "apilib.h" 27 #include "../ctlr/oia.h" 28 29 static char mybuffer[2000]; 30 31 api_perror(string) 32 char *string; 33 { 34 fprintf(stderr, "Error: [0x%x/0x%x:0x%x/0x%x] from %s.\n", 35 api_sup_fcn_id, api_sup_errno, 36 api_fcn_fcn_id, api_fcn_errno, string); 37 } 38 39 40 char * 41 session_type(type) 42 int type; 43 { 44 switch (type) { 45 case TYPE_WSCTL: 46 return "work station control"; 47 case TYPE_DFT: 48 return "distributed function terminal"; 49 case TYPE_CUT: 50 return "control unit terminal"; 51 case TYPE_NOTEPAD: 52 return "notepad"; 53 case TYPE_PC: 54 return "personal computer"; 55 default: 56 return "(UNKNOWN)"; 57 } 58 } 59 60 61 main() 62 { 63 register int i; 64 int session_id; 65 OIA oia; 66 QuerySessionIdParms id; 67 QuerySessionParametersParms pa; 68 QuerySessionCursorParms cu; 69 ConnectToKeyboardParms conn; 70 DisconnectFromKeyboardParms disc; 71 WriteKeystrokeParms wr; 72 DisableInputParms disable; 73 EnableInputParms enable; 74 CopyStringParms copy; 75 ReadOiaGroupParms re; 76 NameArray namearray; 77 78 if (api_init() == 0) { 79 fprintf(stderr, "API function not available.\n"); 80 return 1; 81 } 82 83 id.rc = 0; 84 id.function_id = 0; 85 id.option_code = ID_OPTION_BY_NAME; 86 id.data_code = 'E'; 87 id.name_array = &namearray; 88 namearray.length = sizeof namearray; 89 if (api_query_session_id(&id)) { 90 api_perror("api_query_session_id"); 91 } else if (namearray.number_matching_session == 0) { 92 fprintf(stderr, "query_session_id: No matching sessions!\n"); 93 } else { 94 printf("Session short name 0x%x, type is ", 95 namearray.name_array_element.short_name); 96 printf("%s", session_type(namearray.name_array_element.type)); 97 printf(", session ID is: 0x%x\n", 98 namearray.name_array_element.session_id); 99 } 100 session_id = namearray.name_array_element.session_id; 101 102 pa.rc = pa.function_id = 0; 103 pa.session_id = session_id; 104 if (api_query_session_parameters(&pa) == -1) { 105 api_perror("api_query_session_parameters"); 106 } else { 107 printf("Session type %s, ", session_type(pa.session_type)); 108 if (pa.session_characteristics&CHARACTERISTIC_EAB) { 109 printf(" has EAB, "); 110 } 111 if (pa.session_characteristics&CHARACTERISTIC_PSS) { 112 printf(" has PSS, "); 113 } 114 printf("%d rows, %d columns ", pa.rows, pa.columns); 115 if (pa.presentation_space) { 116 printf("presentation space at 0x%x:0x%x.\n", 117 FP_SEG(pa.presentation_space), FP_OFF(pa.presentation_space)); 118 } else { 119 printf("(no direct presentation space access).\n"); 120 } 121 } 122 123 cu.rc = cu.function_id = 0; 124 cu.session_id = session_id; 125 if (api_query_session_cursor(&cu) == -1) { 126 api_perror("api_query_session_cursor"); 127 } else { 128 printf("cursor"); 129 if (cu.cursor_type&CURSOR_INHIBITED_AUTOSCROLL) { 130 printf(" inhibited autoscroll"); 131 } 132 if (cu.cursor_type&CURSOR_INHIBITED) { 133 printf(" inhibited"); 134 } 135 if (cu.cursor_type&CURSOR_BLINKING) { 136 printf(" blinking"); 137 } else { 138 printf(" not blinking"); 139 } 140 if (cu.cursor_type&CURSOR_BOX) { 141 printf(" box "); 142 } else { 143 printf(" not box "); 144 } 145 printf("at row %d, column %d.\n", cu.row_address, cu.column_address); 146 } 147 148 re.rc = re.function_id = 0; 149 re.session_id = session_id; 150 re.oia_buffer = (char far *) &oia; 151 re.oia_group_number = API_OIA_ALL_GROUPS; 152 if (api_read_oia_group(&re) == -1) { 153 api_perror("api_read_oia_group"); 154 } else { 155 if (IsOiaReady3274(&oia)) { 156 printf("3274 ready, "); 157 } 158 if (IsOiaMyJob(&oia)) { 159 printf("my job, "); 160 } 161 if (IsOiaInsert(&oia)) { 162 printf("insert mode, "); 163 } 164 if (IsOiaSystemLocked(&oia)) { 165 printf("system locked, "); 166 } 167 if (IsOiaTWait(&oia)) { 168 printf("terminal wait, "); 169 } 170 printf("are some bits from the OIA.\n"); 171 } 172 173 conn.rc = conn.function_id = 0; 174 conn.session_id = session_id; 175 conn.event_queue_id = conn.input_queue_id = 0; 176 conn.intercept_options = 0; 177 if (api_connect_to_keyboard(&conn) == -1) { 178 api_perror("api_connect_to_keyboard"); 179 } else { 180 if (conn.first_connection_identifier) { 181 printf("First keyboard connection.\n"); 182 } else { 183 printf("Not first keyboard connection.\n"); 184 } 185 } 186 187 disable.rc = disable.function_id = 0; 188 disable.session_id = session_id; 189 disable.connectors_task_id = 0; 190 if (api_disable_input(&disable) == -1) { 191 api_perror("api_disable_input"); 192 } else { 193 printf("Disabled.\n"); 194 } 195 196 wr.rc = wr.function_id = 0; 197 wr.session_id = session_id; 198 wr.connectors_task_id = 0; 199 wr.options = OPTION_SINGLE_KEYSTROKE; 200 wr.number_of_keys_sent = 0; 201 wr.keystroke_specifier.keystroke_entry.scancode = 0x3a; 202 wr.keystroke_specifier.keystroke_entry.shift_state = 0; 203 if (api_write_keystroke(&wr) == -1) { 204 api_perror("api_write_keystroke"); 205 } else { 206 if (wr.number_of_keys_sent != 1) { 207 fprintf(stderr, 208 "write_keystroke claims to have sent %d keystrokes.\n", 209 wr.number_of_keys_sent); 210 } else { 211 printf("Keystroke sent.\n"); 212 } 213 } 214 215 enable.rc = enable.function_id = 0; 216 enable.session_id = session_id; 217 enable.connectors_task_id = 0; 218 if (api_enable_input(&enable) == -1) { 219 api_perror("api_enable"); 220 } else { 221 printf("Enabled.\n"); 222 } 223 224 disc.rc = disc.function_id = 0; 225 disc.session_id = session_id; 226 disc.connectors_task_id = 0; 227 if (api_disconnect_from_keyboard(&disc) == -1) { 228 api_perror("api_disconnect_from_keyboard"); 229 } else { 230 printf("Disconnected from keyboard.\n"); 231 } 232 /* Time copy services */ 233 234 for (i = 0; i < 100; i++) { 235 copy.copy_mode = 0; 236 copy.rc = copy.function_id = 0; 237 copy.source.session_id = session_id; 238 copy.source.characteristics = 0; 239 copy.source.session_type = TYPE_DFT; 240 copy.source.begin = 0; 241 242 copy.source_end = 1920; 243 244 copy.target.session_id = 0; 245 copy.target.buffer = mybuffer; 246 copy.target.characteristics = 0; 247 copy.target.session_type = TYPE_DFT; 248 249 if (api_copy_string(©) == -1) { 250 api_perror("api_copy_string"); 251 break; 252 } 253 } 254 printf("Copied data out.\n"); 255 256 (void) api_finish(); 257 258 return 0; 259 } 260