Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • zephyr.c

    rf203cad rcd28517  
    77#include "owl.h"
    88
     9static GSource *owl_zephyr_event_source_new(int fd);
     10
     11static gboolean owl_zephyr_event_prepare(GSource *source, int *timeout);
     12static gboolean owl_zephyr_event_check(GSource *source);
     13static gboolean owl_zephyr_event_dispatch(GSource *source, GSourceFunc callback, gpointer user_data);
     14
    915#ifdef HAVE_LIBZEPHYR
    1016static GList *deferred_subs = NULL;
     
    1622
    1723Code_t ZResetAuthentication(void);
     24
     25static GSourceFuncs zephyr_event_funcs = {
     26  owl_zephyr_event_prepare,
     27  owl_zephyr_event_check,
     28  owl_zephyr_event_dispatch,
     29  NULL
     30};
    1831#endif
    1932
     
    8497  Code_t code;
    8598  char *perl;
     99  GSource *event_source;
    86100
    87101  owl_select_remove_io_dispatch(d);
     
    99113  }
    100114
    101   owl_select_add_io_dispatch(ZGetFD(), OWL_IO_READ|OWL_IO_EXCEPT, &owl_zephyr_process_events, NULL, NULL);
     115  event_source = owl_zephyr_event_source_new(ZGetFD());
     116  g_source_attach(event_source, NULL);
     117  g_source_unref(event_source);
    102118
    103119  owl_global_set_havezephyr(&g);
     
    127143  perl = owl_perlconfig_execute("BarnOwl::Zephyr::_zephyr_startup()");
    128144  g_free(perl);
    129 
    130   owl_select_add_pre_select_action(owl_zephyr_pre_select_action, NULL, NULL);
    131145}
    132146
     
    180194    if((code = ZPending()) < 0) {
    181195      owl_function_debugmsg("Error (%s) in ZPending()\n",
     196                            error_message(code));
     197      return 0;
     198    }
     199    return code;
     200  }
     201#endif
     202  return 0;
     203}
     204
     205int owl_zephyr_zqlength(void)
     206{
     207#ifdef HAVE_LIBZEPHYR
     208  Code_t code;
     209  if(owl_global_is_havezephyr(&g)) {
     210    if((code = ZQLength()) < 0) {
     211      owl_function_debugmsg("Error (%s) in ZQLength()\n",
    182212                            error_message(code));
    183213      return 0;
     
    10191049{
    10201050#ifdef HAVE_LIBZEPHYR
     1051  char *exposure, *eset;
     1052  Code_t ret;
     1053
    10211054  ZResetAuthentication();
    10221055
    1023   /* ZSetLocation, and store the default value as the current value */
    1024   owl_global_set_exposure(&g, owl_global_get_default_exposure(&g));
     1056  eset = EXPOSE_REALMVIS;
     1057  exposure = ZGetVariable(zstr("exposure"));
     1058  if (exposure)
     1059    exposure = ZParseExposureLevel(exposure);
     1060  if (exposure)
     1061    eset = exposure;
     1062   
     1063  ret = ZSetLocation(eset);
     1064  if (ret != ZERR_NONE)
     1065    owl_function_error("Error setting location: %s", error_message(ret));
    10251066#endif
    10261067}
     
    11431184  ZInitLocationInfo(zstr(host), zstr(val));
    11441185#endif
    1145 }
    1146 
    1147 const char *owl_zephyr_normalize_exposure(const char *exposure)
    1148 {
    1149   if (exposure == NULL)
    1150     return NULL;
    1151 #ifdef HAVE_LIBZEPHYR
    1152   return ZParseExposureLevel(zstr(exposure));
    1153 #else
    1154   return exposure;
    1155 #endif
    1156 }
    1157 
    1158 int owl_zephyr_set_default_exposure(const char *exposure)
    1159 {
    1160 #ifdef HAVE_LIBZEPHYR
    1161   Code_t ret;
    1162   if (exposure == NULL)
    1163     return -1;
    1164   exposure = ZParseExposureLevel(zstr(exposure));
    1165   if (exposure == NULL)
    1166     return -1;
    1167   ret = ZSetVariable(zstr("exposure"), zstr(exposure)); /* ZSetVariable does file I/O */
    1168   if (ret != ZERR_NONE) {
    1169     owl_function_error("Unable to set default exposure location: %s", error_message(ret));
    1170     return -1;
    1171   }
    1172 #endif
    1173   return 0;
    1174 }
    1175 
    1176 const char *owl_zephyr_get_default_exposure(void)
    1177 {
    1178 #ifdef HAVE_LIBZEPHYR
    1179   const char *exposure = ZGetVariable(zstr("exposure")); /* ZGetVariable does file I/O */
    1180   if (exposure == NULL)
    1181     return EXPOSE_REALMVIS;
    1182   exposure = ZParseExposureLevel(zstr(exposure));
    1183   if (exposure == NULL) /* The user manually entered an invalid value in ~/.zephyr.vars, or something weird happened. */
    1184     return EXPOSE_REALMVIS;
    1185   return exposure;
    1186 #else
    1187   return "";
    1188 #endif
    1189 }
    1190 
    1191 int owl_zephyr_set_exposure(const char *exposure)
    1192 {
    1193 #ifdef HAVE_LIBZEPHYR
    1194   Code_t ret;
    1195   if (exposure == NULL)
    1196     return -1;
    1197   exposure = ZParseExposureLevel(zstr(exposure));
    1198   if (exposure == NULL)
    1199     return -1;
    1200   ret = ZSetLocation(zstr(exposure));
    1201   if (ret != ZERR_NONE) {
    1202     owl_function_error("Unable to set exposure level: %s.", error_message(ret));
    1203     return -1;
    1204   }
    1205 #endif
    1206   return 0;
    12071186}
    12081187 
     
    14701449}
    14711450
    1472 void owl_zephyr_process_events(const owl_io_dispatch *d, void *data)
    1473 {
     1451typedef struct { /*noproto*/
     1452  GSource source;
     1453  GPollFD poll_fd;
     1454} owl_zephyr_event_source;
     1455
     1456static GSource *owl_zephyr_event_source_new(int fd) {
     1457  GSource *source;
     1458  owl_zephyr_event_source *event_source;
     1459
     1460  source = g_source_new(&zephyr_event_funcs, sizeof(owl_zephyr_event_source));
     1461  event_source = (owl_zephyr_event_source*) source;
     1462  event_source->poll_fd.fd = fd;
     1463  event_source->poll_fd.events = G_IO_IN | G_IO_HUP | G_IO_PRI | G_IO_ERR;
     1464  g_source_add_poll(source, &event_source->poll_fd);
     1465
     1466  return source;
     1467}
     1468
     1469static gboolean owl_zephyr_event_prepare(GSource *source, int *timeout) {
     1470  *timeout = -1;
     1471  return owl_zephyr_zqlength() > 0;
     1472}
     1473
     1474static gboolean owl_zephyr_event_check(GSource *source) {
     1475  owl_zephyr_event_source *event_source = (owl_zephyr_event_source*)source;
     1476  if (event_source->poll_fd.revents & event_source->poll_fd.events)
     1477    return owl_zephyr_zpending() > 0;
     1478  return FALSE;
     1479}
     1480
     1481static gboolean owl_zephyr_event_dispatch(GSource *source, GSourceFunc callback, gpointer user_data) {
    14741482  _owl_zephyr_process_events();
    1475 }
    1476 
    1477 int owl_zephyr_pre_select_action(owl_ps_action *a, void *p)
    1478 {
    1479   return _owl_zephyr_process_events();
    1480 }
     1483  return TRUE;
     1484}
Note: See TracChangeset for help on using the changeset viewer.