2 * test utility for LoginHelper client API and services.
4 * Copyright Sun Microsystems 2004
10 #include <login-helper/Accessibility_LoginHelper.h>
12 gint main (int argc, char **argv)
14 Bonobo_ServerInfoList *server_list;
15 Accessibility_LoginHelper *helper_list = NULL;
18 Accessibility_LoginHelper_WindowList *windows;
21 CORBA_exception_init (&ev);
22 if (!bonobo_init (&argc, argv))
24 g_error ("Can't initialize Bonobo");
27 /* bonobo-activation query lists existing instances */
28 server_list = bonobo_activation_query (
29 "(repo_ids.has('IDL:Accessibility/LoginHelper:1.0')) AND _active",
34 bonobo_debug_shutdown ();
35 g_error ("LoginHelper query failed : %s",
36 bonobo_exception_get_text (&ev));
37 /* not reached (below) because g_error exits */
38 CORBA_exception_free (&ev);
41 g_message ("%d LoginHelpers are running.",
42 server_list ? server_list->_length : 0);
44 helper_list = g_new0 (Accessibility_LoginHelper, server_list->_length);
46 /* for each instance... */
47 for (i = 0; i < server_list->_length; i++)
49 Accessibility_LoginHelper helper;
50 Bonobo_Unknown server;
51 Bonobo_ServerInfo info = server_list->_buffer[i];
53 server = bonobo_activation_activate_from_id (
54 info.iid, Bonobo_ACTIVATION_FLAG_EXISTING_ONLY, NULL, &ev);
58 g_warning ("Error activating server %d: %s", i, bonobo_exception_get_text (&ev));
59 CORBA_exception_free (&ev);
62 else if (server == CORBA_OBJECT_NIL)
64 g_warning ("Activated server %d is NIL!", i);
70 helper = Bonobo_Unknown_queryInterface (
72 "IDL:Accessibility/LoginHelper:1.0",
77 g_warning ("Error performing interface query: %s", bonobo_exception_get_text (&ev));
78 CORBA_exception_free (&ev);
81 else if (helper == CORBA_OBJECT_NIL)
83 g_warning ("Activated an object which advertised LoginHelper but does not implement it!");
86 helper_list[i] = helper;
87 bonobo_object_release_unref (server, &ev);
89 if (helper && !BONOBO_EX (&ev))
91 /* ask the helper to go into safe mode */
92 safe = Accessibility_LoginHelper_setSafe (helper, TRUE, &ev);
95 g_warning ("setSafe(TRUE) failed: %s",
96 bonobo_exception_get_text (&ev));
97 CORBA_exception_free (&ev);
99 /* get the raise window list (if the program went into safe mode) */
103 gboolean needs_windows_raised = FALSE;
104 Accessibility_LoginHelper_DeviceReqList *list;
108 /* does this helper need to have windows raised? */
109 list = Accessibility_LoginHelper_getDeviceReqs (helper, &ev);
111 if (BONOBO_EX (&ev)) {
112 g_warning ("Bonobo exception getting Device Requirements: %s",
113 bonobo_exception_get_text (&ev));
114 CORBA_exception_free (&ev);
118 g_message ("LoginHelper device requirements: ");
119 if (list->_length == 0)
120 g_message ("\tNone.");
122 for (j = 0; j < list->_length; j++)
124 switch (list->_buffer[j])
126 case Accessibility_LoginHelper_GUI_EVENTS:
127 g_message ("\tNeeds access to the GUI event subsystem (e.g. Xserver)");
129 case Accessibility_LoginHelper_EXT_INPUT:
130 g_message ("\tReads XInput extended input devices");
132 case Accessibility_LoginHelper_POST_WINDOWS:
133 g_message ("\tPosts windows");
134 needs_windows_raised = TRUE;
136 case Accessibility_LoginHelper_AUDIO_OUT:
137 g_message ("\tWrites to audio device");
139 case Accessibility_LoginHelper_AUDIO_IN:
140 g_message ("\tReads from audio device");
142 case Accessibility_LoginHelper_LOCALHOST:
143 g_message ("\tNeeds LOCALHOST network connection");
145 case Accessibility_LoginHelper_SERIAL_OUT:
146 g_message ("\tNeeds to write to one or more serial ports");
154 if (needs_windows_raised)
156 /* don't raise in this test, but do something with each wid */
157 windows = Accessibility_LoginHelper_getRaiseWindows (helper, &ev);
160 g_warning ("getRaiseWindows failed: %s",
161 bonobo_exception_get_text (&ev));
162 CORBA_exception_free (&ev);
164 g_message ("%d windows need raising", windows->_length);
165 for (j = 0; j < windows->_length; j++)
168 wid = windows->_buffer[j].winID;
169 g_message ("Window ID = %ld", (long) wid);
175 g_warning ("LoginHelper %d did not go into safe mode", i);
182 g_warning ("Error activating %s: %s",
183 info.iid, bonobo_exception_get_text (&ev));
184 CORBA_exception_free (&ev);
188 g_warning ("no active instance of %s found", info.iid);
194 * In an actual login/authentication setting, login/authentication
195 * would take place here, and code below would be executed after
196 * authentication was complete.
199 /* now tell the apps they can resume their normal activities */
200 for (i = 0; i < server_list->_length; i++)
202 Accessibility_LoginHelper helper = helper_list[i];
203 /* really no need to check the return value this time */
204 Accessibility_LoginHelper_setSafe (helper, FALSE, &ev);
207 g_warning ("setSafe(FALSE) failed: %s",
208 bonobo_exception_get_text (&ev));
209 CORBA_exception_free (&ev);
211 CORBA_Object_release (helper, &ev);
213 CORBA_free (server_list);
215 return bonobo_debug_shutdown (); /* see if we leaked stuff */