comparison src/session.c @ 5211:0241d6b6702d

[gaim-migrate @ 5581] Wrote a new debugging API, and of course core/ui split it. Debug statements can now have debug levels and categories, for future filtering of stuff, and color highlighting. It's nifty, m'kay? committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Sat, 26 Apr 2003 06:46:08 +0000
parents 96a2a6c9affc
children b07aa997ddd8
comparison
equal deleted inserted replaced
5210:39bb2a35f8d9 5211:0241d6b6702d
54 54
55 /* please don't block... please! */ 55 /* please don't block... please! */
56 status = IceProcessMessages(connection, NULL, NULL); 56 status = IceProcessMessages(connection, NULL, NULL);
57 57
58 if (status == IceProcessMessagesIOError) { 58 if (status == IceProcessMessagesIOError) {
59 debug_printf("Session Management: ICE IO error, closing connection... "); 59 gaim_debug(GAIM_DEBUG_INFO, "Session Management",
60 "ICE IO error, closing connection... ");
60 61
61 /* IO error, please disconnect */ 62 /* IO error, please disconnect */
62 IceSetShutdownNegotiation(connection, False); 63 IceSetShutdownNegotiation(connection, False);
63 IceCloseConnection(connection); 64 IceCloseConnection(connection);
64 65
65 debug_printf("done\n"); 66 gaim_debug(GAIM_DEBUG_INFO, NULL, "done.\n");
66 67
67 /* cancel the handler */ 68 /* cancel the handler */
68 return FALSE; 69 return FALSE;
69 } 70 }
70 71
77 guint input_id; 78 guint input_id;
78 79
79 if (opening) { 80 if (opening) {
80 GIOChannel *channel; 81 GIOChannel *channel;
81 82
82 debug_printf("Session Management: handling new ICE connection... "); 83 gaim_debug(GAIM_DEBUG_INFO, "Session Management",
84 "Handling new ICE connection... ");
83 85
84 /* ensure ICE connection is not passed to child processes */ 86 /* ensure ICE connection is not passed to child processes */
85 fcntl(IceConnectionNumber(connection), F_SETFD, FD_CLOEXEC); 87 fcntl(IceConnectionNumber(connection), F_SETFD, FD_CLOEXEC);
86 88
87 /* get glib to watch the connection for us */ 89 /* get glib to watch the connection for us */
91 g_io_channel_unref(channel); 93 g_io_channel_unref(channel);
92 94
93 /* store the input ID as a pointer for when it closes */ 95 /* store the input ID as a pointer for when it closes */
94 *watch_data = (IcePointer)GUINT_TO_POINTER(input_id); 96 *watch_data = (IcePointer)GUINT_TO_POINTER(input_id);
95 } else { 97 } else {
96 debug_printf("Session Management: handling closed ICE connection... "); 98 gaim_debug(GAIM_DEBUG_INFO, "Session Management",
99 "Handling closed ICE connection... ");
97 100
98 /* get the input ID back and stop watching it */ 101 /* get the input ID back and stop watching it */
99 input_id = GPOINTER_TO_UINT((gpointer) *watch_data); 102 input_id = GPOINTER_TO_UINT((gpointer) *watch_data);
100 g_source_remove(input_id); 103 g_source_remove(input_id);
101 } 104 }
102 105
103 debug_printf("done\n"); 106 gaim_debug(GAIM_DEBUG_INFO, NULL, "done.\n");
104 } 107 }
105 108
106 /* We call any handler installed before (or after) ice_init but 109 /* We call any handler installed before (or after) ice_init but
107 * avoid calling the default libICE handler which does an exit(). 110 * avoid calling the default libICE handler which does an exit().
108 * 111 *
109 * This means we do nothing by default, which is probably correct, 112 * This means we do nothing by default, which is probably correct,
110 * the connection will get closed by libICE 113 * the connection will get closed by libICE
111 */ 114 */
112 115
113 static void ice_io_error_handler(IceConn connection) { 116 static void ice_io_error_handler(IceConn connection) {
114 debug_printf("Session Management: handling ICE IO error... "); 117 gaim_debug(GAIM_DEBUG_INFO, "Session Management",
118 "Handling ICE IO error... ");
115 119
116 if (ice_installed_io_error_handler) 120 if (ice_installed_io_error_handler)
117 (*ice_installed_io_error_handler)(connection); 121 (*ice_installed_io_error_handler)(connection);
118 122
119 debug_printf("done\n"); 123 gaim_debug(GAIM_DEBUG_INFO, NULL, "done.\n");
120 } 124 }
121 125
122 static void ice_init() { 126 static void ice_init() {
123 IceIOErrorHandler default_handler; 127 IceIOErrorHandler default_handler;
124 128
128 if (ice_installed_io_error_handler == default_handler) 132 if (ice_installed_io_error_handler == default_handler)
129 ice_installed_io_error_handler = NULL; 133 ice_installed_io_error_handler = NULL;
130 134
131 IceAddConnectionWatch(ice_connection_watch, NULL); 135 IceAddConnectionWatch(ice_connection_watch, NULL);
132 136
133 debug_printf("Session Management: ICE initialised\n"); 137 gaim_debug(GAIM_DEBUG_INFO, "Session Management",
138 "ICE initialized.\n");
134 } 139 }
135 140
136 /* my magic utility function */ 141 /* my magic utility function */
137 142
138 static gchar **session_make_command(gchar *client_id) { 143 static gchar **session_make_command(gchar *client_id) {
167 Bool shutdown, int interact_style, Bool fast) { 172 Bool shutdown, int interact_style, Bool fast) {
168 if (had_first_save == FALSE && save_type == SmSaveLocal && 173 if (had_first_save == FALSE && save_type == SmSaveLocal &&
169 interact_style == SmInteractStyleNone && !shutdown && 174 interact_style == SmInteractStyleNone && !shutdown &&
170 !fast) { 175 !fast) {
171 /* this is just a dry run, spit it back */ 176 /* this is just a dry run, spit it back */
172 debug_printf("Session Management: received first save_yourself\n"); 177 gaim_debug(GAIM_DEBUG_INFO, "Session Management",
178 "Received first save_yourself\n");
173 SmcSaveYourselfDone(conn, True); 179 SmcSaveYourselfDone(conn, True);
174 had_first_save = TRUE; 180 had_first_save = TRUE;
175 return; 181 return;
176 } 182 }
177 183
178 /* tum ti tum... don't add anything else here without * 184 /* tum ti tum... don't add anything else here without *
179 * reading SMlib.PS from an X.org ftp server near you */ 185 * reading SMlib.PS from an X.org ftp server near you */
180 186
181 debug_printf("Session Management: received save_yourself\n"); 187 gaim_debug(GAIM_DEBUG_INFO, "Session Management",
188 "Received save_yourself\n");
182 189
183 if (save_type == SmSaveGlobal || save_type == SmSaveBoth) { 190 if (save_type == SmSaveGlobal || save_type == SmSaveBoth) {
184 /* may as well do something ... */ 191 /* may as well do something ... */
185 save_prefs(); 192 save_prefs();
186 } 193 }
187 194
188 SmcSaveYourselfDone(conn, True); 195 SmcSaveYourselfDone(conn, True);
189 } 196 }
190 197
191 void session_die(SmcConn conn, SmPointer data) { 198 void session_die(SmcConn conn, SmPointer data) {
192 debug_printf("Session Management: received die\n"); 199 gaim_debug(GAIM_DEBUG_INFO, "Session Management",
200 "Received die\n");
193 do_quit(); 201 do_quit();
194 } 202 }
195 203
196 void session_save_complete(SmcConn conn, SmPointer data) { 204 void session_save_complete(SmcConn conn, SmPointer data) {
197 debug_printf("Session Management: received save_complete\n"); 205 gaim_debug(GAIM_DEBUG_INFO, "Session Management",
206 "Received save_complete\n");
198 } 207 }
199 208
200 void session_shutdown_cancelled(SmcConn conn, SmPointer data) { 209 void session_shutdown_cancelled(SmcConn conn, SmPointer data) {
201 debug_printf("Session Management: received shutdown_cancelled\n"); 210 gaim_debug(GAIM_DEBUG_INFO, "Session Management",
211 "Received shutdown_cancelled\n");
202 } 212 }
203 213
204 /* utility functions stolen from Gnome-client */ 214 /* utility functions stolen from Gnome-client */
205 215
206 static void session_set_value(SmcConn conn, gchar *name, char *type, 216 static void session_set_value(SmcConn conn, gchar *name, char *type,
277 gchar *tmp = NULL; 287 gchar *tmp = NULL;
278 gchar **cmd = NULL; 288 gchar **cmd = NULL;
279 289
280 if (session != NULL) { 290 if (session != NULL) {
281 /* session is already established, what the hell is going on? */ 291 /* session is already established, what the hell is going on? */
282 debug_printf("Session Management: duplicated call to session_init!\n"); 292 gaim_debug(GAIM_DEBUG_WARNING, "Session Management",
293 "Duplicated call to session_init!\n");
283 return; 294 return;
284 } 295 }
285 296
286 if (g_getenv("SESSION_MANAGER") == NULL) { 297 if (g_getenv("SESSION_MANAGER") == NULL) {
287 debug_printf("Session Management: no SESSION_MANAGER found, aborting\n"); 298 gaim_debug(GAIM_DEBUG_ERROR, "Session Management",
299 "No SESSION_MANAGER found, aborting.\n");
288 return; 300 return;
289 } 301 }
290 302
291 ice_init(); 303 ice_init();
292 304
299 callbacks.die.client_data = NULL; 311 callbacks.die.client_data = NULL;
300 callbacks.save_complete.client_data = NULL; 312 callbacks.save_complete.client_data = NULL;
301 callbacks.shutdown_cancelled.client_data = NULL; 313 callbacks.shutdown_cancelled.client_data = NULL;
302 314
303 if (previous_id) { 315 if (previous_id) {
304 debug_printf("Session Management: connecting with previous ID %s\n", previous_id); 316 gaim_debug(GAIM_DEBUG_INFO, "Session Management",
317 "Connecting with previous ID %s\n", previous_id);
305 } else { 318 } else {
306 debug_printf("Session Management: connecting with no previous ID\n"); 319 gaim_debug(GAIM_DEBUG_INFO, "Session Management",
320 "Connecting with no previous ID\n");
307 } 321 }
308 322
309 session = SmcOpenConnection(NULL, "session", SmProtoMajor, SmProtoMinor, SmcSaveYourselfProcMask | 323 session = SmcOpenConnection(NULL, "session", SmProtoMajor, SmProtoMinor, SmcSaveYourselfProcMask |
310 SmcDieProcMask | SmcSaveCompleteProcMask | SmcShutdownCancelledProcMask, 324 SmcDieProcMask | SmcSaveCompleteProcMask | SmcShutdownCancelledProcMask,
311 &callbacks, previous_id, &client_id, ERROR_LENGTH, error); 325 &callbacks, previous_id, &client_id, ERROR_LENGTH, error);
312 326
313 if (session == NULL) { 327 if (session == NULL) {
314 if (error[0] != '\0') { 328 if (error[0] != '\0') {
315 debug_printf("Session Management: connection failed with error: %s\n", error); 329 gaim_debug(GAIM_DEBUG_ERROR, "Session Management",
330 "Connection failed with error: %s\n", error);
316 } else { 331 } else {
317 debug_printf("Session Management: connection failed with unknown error\n"); 332 gaim_debug(GAIM_DEBUG_ERROR, "Session Management",
333 "Connetion failed with unknown error.\n");
318 } 334 }
319 return; 335 return;
320 } 336 }
321 337
322 tmp = SmcVendor(session); 338 tmp = SmcVendor(session);
323 debug_printf("Session Management: connected to manager (%s) with client ID %s\n", tmp, client_id); 339 gaim_debug(GAIM_DEBUG_INFO, "Session Management",
340 "Connected to manager (%s) with client ID %s\n",
341 tmp, client_id);
324 g_free(tmp); 342 g_free(tmp);
325 343
326 session_managed = TRUE; 344 session_managed = TRUE;
327 gdk_set_sm_client_id(client_id); 345 gdk_set_sm_client_id(client_id);
328 346
340 358
341 session_set_gchar(session, SmRestartStyleHint, (gchar) SmRestartIfRunning); 359 session_set_gchar(session, SmRestartStyleHint, (gchar) SmRestartIfRunning);
342 session_set_string(session, SmProgram, g_get_prgname()); 360 session_set_string(session, SmProgram, g_get_prgname());
343 361
344 myself = g_strdup(argv0); 362 myself = g_strdup(argv0);
345 debug_printf("Session Management: using %s as command\n", myself); 363 gaim_debug(GAIM_DEBUG_MISC, "Session Management",
364 "Using %s as command\n", myself);
346 365
347 cmd = session_make_command(NULL); 366 cmd = session_make_command(NULL);
348 session_set_array(session, SmCloneCommand, cmd); 367 session_set_array(session, SmCloneCommand, cmd);
349 g_strfreev(cmd); 368 g_strfreev(cmd);
350 369
370 if (session == NULL) /* no session to close */ 389 if (session == NULL) /* no session to close */
371 return; 390 return;
372 391
373 SmcCloseConnection(session, 0, NULL); 392 SmcCloseConnection(session, 0, NULL);
374 393
375 debug_printf("Session Management: connection closed\n"); 394 gaim_debug(GAIM_DEBUG_INFO, "Session Management",
395 "Connection closed.\n");
376 #endif /* USE_SM */ 396 #endif /* USE_SM */
377 } 397 }