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