Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • zephyr.c

    r959cb85 r3b8a563  
    77#include "owl.h"
    88
    9 static GSource *owl_zephyr_event_source_new(int fd);
    10 
    11 static gboolean owl_zephyr_event_prepare(GSource *source, int *timeout);
    12 static gboolean owl_zephyr_event_check(GSource *source);
    13 static gboolean owl_zephyr_event_dispatch(GSource *source, GSourceFunc callback, gpointer user_data);
    14 
    159#ifdef HAVE_LIBZEPHYR
    1610static GList *deferred_subs = NULL;
     
    2216
    2317Code_t ZResetAuthentication(void);
    24 
    25 static GSourceFuncs zephyr_event_funcs = {
    26   owl_zephyr_event_prepare,
    27   owl_zephyr_event_check,
    28   owl_zephyr_event_dispatch,
    29   NULL
    30 };
    3118#endif
    3219
     
    9784  Code_t code;
    9885  char *perl;
    99   GSource *event_source;
    10086
    10187  owl_select_remove_io_dispatch(d);
     
    11399  }
    114100
    115   event_source = owl_zephyr_event_source_new(ZGetFD());
    116   g_source_attach(event_source, NULL);
    117   g_source_unref(event_source);
     101  owl_select_add_io_dispatch(ZGetFD(), OWL_IO_READ|OWL_IO_EXCEPT, &owl_zephyr_process_events, NULL, NULL);
    118102
    119103  owl_global_set_havezephyr(&g);
     
    143127  perl = owl_perlconfig_execute("BarnOwl::Zephyr::_zephyr_startup()");
    144128  g_free(perl);
     129
     130  owl_select_add_pre_select_action(owl_zephyr_pre_select_action, NULL, NULL);
    145131}
    146132
     
    194180    if((code = ZPending()) < 0) {
    195181      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 
    205 int 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",
    212182                            error_message(code));
    213183      return 0;
     
    447417    return 0;
    448418  }
    449   if (buffer)
    450     g_free(buffer);
     419  g_free(buffer);
    451420
    452421  return owl_zephyr_loadsubs_helper(subs, count);
     
    10491018{
    10501019#ifdef HAVE_LIBZEPHYR
    1051   char *exposure, *eset;
    1052   Code_t ret;
    1053 
    10541020  ZResetAuthentication();
    10551021
    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));
     1022  /* ZSetLocation, and store the default value as the current value */
     1023  owl_global_set_exposure(&g, owl_global_get_default_exposure(&g));
    10661024#endif
    10671025}
     
    11841142  ZInitLocationInfo(zstr(host), zstr(val));
    11851143#endif
     1144}
     1145
     1146const char *owl_zephyr_normalize_exposure(const char *exposure)
     1147{
     1148  if (exposure == NULL)
     1149    return NULL;
     1150#ifdef HAVE_LIBZEPHYR
     1151  return ZParseExposureLevel(zstr(exposure));
     1152#else
     1153  return exposure;
     1154#endif
     1155}
     1156
     1157int owl_zephyr_set_default_exposure(const char *exposure)
     1158{
     1159#ifdef HAVE_LIBZEPHYR
     1160  Code_t ret;
     1161  if (exposure == NULL)
     1162    return -1;
     1163  exposure = ZParseExposureLevel(zstr(exposure));
     1164  if (exposure == NULL)
     1165    return -1;
     1166  ret = ZSetVariable(zstr("exposure"), zstr(exposure)); /* ZSetVariable does file I/O */
     1167  if (ret != ZERR_NONE) {
     1168    owl_function_error("Unable to set default exposure location: %s", error_message(ret));
     1169    return -1;
     1170  }
     1171#endif
     1172  return 0;
     1173}
     1174
     1175const char *owl_zephyr_get_default_exposure(void)
     1176{
     1177#ifdef HAVE_LIBZEPHYR
     1178  const char *exposure = ZGetVariable(zstr("exposure")); /* ZGetVariable does file I/O */
     1179  if (exposure == NULL)
     1180    return EXPOSE_REALMVIS;
     1181  exposure = ZParseExposureLevel(zstr(exposure));
     1182  if (exposure == NULL) /* The user manually entered an invalid value in ~/.zephyr.vars, or something weird happened. */
     1183    return EXPOSE_REALMVIS;
     1184  return exposure;
     1185#else
     1186  return "";
     1187#endif
     1188}
     1189
     1190int owl_zephyr_set_exposure(const char *exposure)
     1191{
     1192#ifdef HAVE_LIBZEPHYR
     1193  Code_t ret;
     1194  if (exposure == NULL)
     1195    return -1;
     1196  exposure = ZParseExposureLevel(zstr(exposure));
     1197  if (exposure == NULL)
     1198    return -1;
     1199  ret = ZSetLocation(zstr(exposure));
     1200  if (ret != ZERR_NONE) {
     1201    owl_function_error("Unable to set exposure level: %s.", error_message(ret));
     1202    return -1;
     1203  }
     1204#endif
     1205  return 0;
    11861206}
    11871207 
     
    14491469}
    14501470
    1451 typedef struct { /*noproto*/
    1452   GSource source;
    1453   GPollFD poll_fd;
    1454 } owl_zephyr_event_source;
    1455 
    1456 static 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 
    1469 static gboolean owl_zephyr_event_prepare(GSource *source, int *timeout) {
    1470   *timeout = -1;
    1471   return owl_zephyr_zqlength() > 0;
    1472 }
    1473 
    1474 static 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 
    1481 static gboolean owl_zephyr_event_dispatch(GSource *source, GSourceFunc callback, gpointer user_data) {
     1471void owl_zephyr_process_events(const owl_io_dispatch *d, void *data)
     1472{
    14821473  _owl_zephyr_process_events();
    1483   return TRUE;
    1484 }
     1474}
     1475
     1476int owl_zephyr_pre_select_action(owl_ps_action *a, void *p)
     1477{
     1478  return _owl_zephyr_process_events();
     1479}
Note: See TracChangeset for help on using the changeset viewer.