Enlightenment CVS committal Author : kwo Project : e16 Module : e
Dir : e16/e/src Modified Files: events.c events.h session.c session.h Log Message: Add registration of file descriptors to be handled in main event loop. =================================================================== RCS file: /cvs/e/e16/e/src/events.c,v retrieving revision 1.142 retrieving revision 1.143 diff -u -3 -r1.142 -r1.143 --- events.c 3 Nov 2007 10:25:11 -0000 1.142 +++ events.c 2 Dec 2007 18:39:16 -0000 1.143 @@ -25,7 +25,6 @@ #include "aclass.h" #include "emodule.h" #include "events.h" -#include "session.h" #include "timers.h" #include "tooltips.h" #include "xwin.h" @@ -53,6 +52,10 @@ static const char *EventName(unsigned int type); #endif +/* + * Server extension handling + */ + typedef struct { int event_base, error_base; @@ -199,6 +202,41 @@ ext->init(available); } +/* + * File descriptor handling + */ + +struct _EventFdDesc +{ + const char *name; + int fd; + void (*handler) (void); +}; + +static int nfds = 0; +static EventFdDesc *pfds = NULL; + +EventFdDesc * +EventFdRegister(int fd, EventFdHandler * handler) +{ + nfds++; + pfds = EREALLOC(EventFdDesc, pfds, nfds); + pfds[nfds - 1].fd = fd; + pfds[nfds - 1].handler = handler; + + return pfds + (nfds - 1); +} + +void +EventFdUnregister(EventFdDesc * efd) +{ + efd->fd = -1; +} + +/* + * Event handling + */ + #define DOUBLE_CLICK_TIME 250 /* Milliseconds */ void @@ -219,6 +257,8 @@ ExtData[XEXT_COMPOSITE].minor >= 2)) Mode.server.extensions |= 1 << XEXT_CM_ALL; #endif + + EventFdRegister(ConnectionNumber(disp), NULL); } static void @@ -647,8 +687,7 @@ struct timeval tval; double time1, time2, dt; int count, pfetch; - int fdsize; - int xfd, smfd; + int fdsize, fd, i; time1 = GetTime(); @@ -691,12 +730,17 @@ continue; FD_ZERO(&fdset); - xfd = ConnectionNumber(disp); - FD_SET(xfd, &fdset); - smfd = GetSMfd(); - if (smfd >= 0) - FD_SET(smfd, &fdset); - fdsize = MAX(xfd, smfd) + 1; + fdsize = -1; + for (i = 0; i < nfds; i++) + { + fd = pfds[i].fd; + if (fd < 0) + continue; + if (fdsize < fd) + fdsize = fd; + FD_SET(fd, &fdset); + } + fdsize++; if (time2 > 0.) { @@ -711,9 +755,8 @@ if (EDebug(EDBUG_TYPE_EVENTS)) Eprintf - ("EventsMain - count=%d xfd=%d:%d smfd=%d:%d dt=%lf time2=%lf\n", - count, xfd, FD_ISSET(xfd, &fdset), smfd, - (smfd >= 0) ? FD_ISSET(smfd, &fdset) : 0, dt, time2); + ("EventsMain - count=%d xfd=%d:%d dt=%lf time2=%lf\n", + count, pfds[0].fd, FD_ISSET(pfds[0].fd, &fdset), dt, time2); if (count == 0) { @@ -722,11 +765,16 @@ } else if (count > 0) { - if ((smfd >= 0) && (FD_ISSET(smfd, &fdset))) + /* Excluding X fd */ + for (i = 1; i < nfds; i++) { - if (EDebug(EDBUG_TYPE_EVENTS)) - Eprintf("EventsMain - ICE\n"); - ProcessICEMSGS(); + fd = pfds[i].fd; + if ((fd >= 0) && (FD_ISSET(fd, &fdset))) + { + if (EDebug(EDBUG_TYPE_EVENTS)) + Eprintf("Event fd %d\n", i); + pfds[i].handler(); + } } } } =================================================================== RCS file: /cvs/e/e16/e/src/events.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -3 -r1.3 -r1.4 --- events.h 11 Jul 2007 08:32:23 -0000 1.3 +++ events.h 2 Dec 2007 18:39:17 -0000 1.4 @@ -39,4 +39,9 @@ void EventsMain(void); void EventShow(const XEvent * ev); +typedef struct _EventFdDesc EventFdDesc; +typedef void (EventFdHandler) (void); +EventFdDesc *EventFdRegister(int fd, EventFdHandler * handler); +void EventFdUnregister(EventFdDesc * efd); + #endif /* _EVENTS_H_ */ =================================================================== RCS file: /cvs/e/e16/e/src/session.c,v retrieving revision 1.145 retrieving revision 1.146 diff -u -3 -r1.145 -r1.146 --- session.c 18 Jul 2007 11:18:50 -0000 1.145 +++ session.c 2 Dec 2007 18:39:17 -0000 1.146 @@ -25,6 +25,7 @@ #include "dialog.h" #include "e16-ecore_hints.h" #include "emodule.h" +#include "events.h" #include "ewins.h" #include "hints.h" #include "session.h" @@ -54,8 +55,6 @@ #endif #endif -static int sm_fd = -1; - /* True if we are saving state for a doExit("restart") */ static int restarting = False; @@ -71,6 +70,8 @@ static char *sm_client_id = NULL; static SmcConn sm_conn = NULL; +static EventFdDesc *sm_efd = NULL; + static void set_save_props(SmcConn smc_conn, int master_flag) { @@ -321,24 +322,49 @@ * exit(1) instead of closing the losing connection. */ } -#endif /* USE_SM */ +static void +ice_exit(void) +{ + SmcCloseConnection(sm_conn, 0, NULL); + sm_conn = NULL; + EventFdUnregister(sm_efd); +} -void -SessionInit(void) +static void +ice_msgs_process(void) +{ + IceProcessMessagesStatus status; + + status = IceProcessMessages(ice_conn, NULL, NULL); + if (status == IceProcessMessagesIOError) + { + /* Less of the hope.... E survives */ + DialogAlert(_("ERROR!\n" "\n" + "Lost the Session Manager that was there?\n" + "Here here session manager... come here... want a bone?\n" + "Oh come now! Stop sulking! Bugger. Oh well. " + "Will continue without\n" "a session manager.\n" "\n" + "I'll survive somehow.\n" "\n" "\n" "... I hope.\n")); + ice_exit(); + } +} + +static void +ice_init(void) { -#if USE_SM static SmPointer context; SmcCallbacks callbacks; -#endif + char error_string_ret[4096]; + char *client_id; + char style[2]; + SmPropValue styleVal; + SmProp styleProp; + SmProp *props[1]; + int sm_fd; - if (Mode.wm.window) + if (!getenv("SESSION_MANAGER")) return; -#if USE_SM -#if 0 /* Unused */ - atom_sm_client_id = XInternAtom(disp, "SM_CLIENT_ID", False); -#endif - IceSetIOErrorHandler(ice_io_error_handler); callbacks.save_yourself.callback = callback_save_yourself; @@ -349,54 +375,64 @@ callbacks.save_yourself.client_data = callbacks.die.client_data = callbacks.save_complete.client_data = callbacks.shutdown_cancelled.client_data = (SmPointer) NULL; - if (getenv("SESSION_MANAGER")) - { - char error_string_ret[4096] = ""; - char *client_id = NULL; - if (sm_client_id) - client_id = Estrdup(sm_client_id); - sm_conn = - SmcOpenConnection(NULL, &context, SmProtoMajor, SmProtoMinor, - SmcSaveYourselfProcMask | SmcDieProcMask | - SmcSaveCompleteProcMask | - SmcShutdownCancelledProcMask, &callbacks, - client_id, &sm_client_id, 4096, error_string_ret); - if (client_id) - Efree(client_id); - - if (error_string_ret[0]) - Eprintf("While connecting to session manager: %s.", - error_string_ret); - } - if (sm_conn) - { - char style[2]; - SmPropValue styleVal; - SmProp styleProp; - SmProp *props[1]; - - style[0] = SmRestartIfRunning; - style[1] = 0; - - styleVal.length = 1; - styleVal.value = style; - - styleProp.name = (char *)SmRestartStyleHint; - styleProp.type = (char *)SmCARD8; - styleProp.num_vals = 1; - styleProp.vals = &styleVal; - - props[0] = &styleProp; - - ice_conn = SmcGetIceConnection(sm_conn); - sm_fd = IceConnectionNumber(ice_conn); - /* Just in case we are a copy of E created by a doExit("restart") */ - SmcSetProperties(sm_conn, 1, props); - fcntl(sm_fd, F_SETFD, fcntl(sm_fd, F_GETFD, 0) | FD_CLOEXEC); - } + client_id = Estrdup(sm_client_id); + + error_string_ret[0] = '\0'; + + sm_conn = + SmcOpenConnection(NULL, &context, SmProtoMajor, SmProtoMinor, + SmcSaveYourselfProcMask | SmcDieProcMask | + SmcSaveCompleteProcMask | + SmcShutdownCancelledProcMask, &callbacks, + client_id, &sm_client_id, 4096, error_string_ret); + if (client_id) + Efree(client_id); + + if (error_string_ret[0]) + Eprintf("While connecting to session manager: %s.", error_string_ret); + + if (!sm_conn) + return; + + style[0] = SmRestartIfRunning; + style[1] = 0; + + styleVal.length = 1; + styleVal.value = style; + + styleProp.name = (char *)SmRestartStyleHint; + styleProp.type = (char *)SmCARD8; + styleProp.num_vals = 1; + styleProp.vals = &styleVal; + + props[0] = &styleProp; + + ice_conn = SmcGetIceConnection(sm_conn); + sm_fd = IceConnectionNumber(ice_conn); + /* Just in case we are a copy of E created by a doExit("restart") */ + SmcSetProperties(sm_conn, 1, props); + fcntl(sm_fd, F_SETFD, fcntl(sm_fd, F_GETFD, 0) | FD_CLOEXEC); + + sm_efd = EventFdRegister(sm_fd, ice_msgs_process); +} + #endif /* USE_SM */ +void +SessionInit(void) +{ + if (Mode.wm.window) + return; + +#if 0 /* Unused */ + atom_sm_client_id = XInternAtom(disp, "SM_CLIENT_ID", False); +#endif + +#if USE_SM + ice_init(); +#endif + if (!Conf.session.script) Conf.session.script = Estrdup("$EROOT/scripts/session.sh"); if (!Conf.session.cmd_reboot) @@ -406,37 +442,6 @@ } void -ProcessICEMSGS(void) -{ -#if USE_SM - IceProcessMessagesStatus status; - - if (sm_fd < 0) - return; - status = IceProcessMessages(ice_conn, NULL, NULL); - if (status == IceProcessMessagesIOError) - { - /* Less of the hope.... E survives */ - DialogAlert(_("ERROR!\n" "\n" - "Lost the Session Manager that was there?\n" - "Here here session manager... come here... want a bone?\n" - "Oh come now! Stop sulking! Bugger. Oh well. " - "Will continue without\n" "a session manager.\n" "\n" - "I'll survive somehow.\n" "\n" "\n" "... I hope.\n")); - SmcCloseConnection(sm_conn, 0, NULL); - sm_conn = NULL; - sm_fd = -1; - } -#endif /* USE_SM */ -} - -int -GetSMfd(void) -{ - return sm_fd; -} - -void SessionGetInfo(EWin * ewin) { #if 0 /* Unused */ @@ -465,21 +470,17 @@ #endif /* USE_SM */ } -void +static void SessionSave(int shutdown) { if (EDebug(EDBUG_TYPE_SESSION)) Eprintf("SessionSave(%d)\n", shutdown); - /* dont' need anymore */ - /* autosave(); */ + Real_SaveSnapInfo(0, NULL); + #if USE_SM if (shutdown && sm_conn) - { - SmcCloseConnection(sm_conn, 0, NULL); - sm_conn = NULL; - sm_fd = -1; - } + ice_exit(); #endif /* USE_SM */ } @@ -504,9 +505,7 @@ restarting = True; - if (!params) - SessionSave(1); - Real_SaveSnapInfo(0, NULL); + SessionSave(1); if (mode != EEXIT_THEME && mode != EEXIT_RESTART) SessionHelper(ESESSION_STOP); =================================================================== RCS file: /cvs/e/e16/e/src/session.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -3 -r1.3 -r1.4 --- session.h 13 Jan 2007 19:14:28 -0000 1.3 +++ session.h 2 Dec 2007 18:39:17 -0000 1.4 @@ -38,11 +38,8 @@ #define ESESSION_STOP 2 void SessionInit(void); -void SessionSave(int shutdown); void SessionExit(int mode, const char *params); void SessionHelper(int when); -void ProcessICEMSGS(void); -int GetSMfd(void); void SetSMID(const char *smid); void SettingsSession(void); ------------------------------------------------------------------------- SF.Net email is sponsored by: The Future of Linux Business White Paper from Novell. From the desktop to the data center, Linux is going mainstream. Let it simplify your IT future. http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4 _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs