Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • zephyr.c

    rcd28517 rf203cad  
    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;
     
    10491019{
    10501020#ifdef HAVE_LIBZEPHYR
    1051   char *exposure, *eset;
    1052   Code_t ret;
    1053 
    10541021  ZResetAuthentication();
    10551022
    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));
     1023  /* ZSetLocation, and store the default value as the current value */
     1024  owl_global_set_exposure(&g, owl_global_get_default_exposure(&g));
    10661025#endif
    10671026}
     
    11841143  ZInitLocationInfo(zstr(host), zstr(val));
    11851144#endif
     1145}
     1146
     1147const 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
     1158int 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
     1176const 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
     1191int 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;
    11861207}
    11871208 
     
    14491470}
    14501471
    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) {
     1472void owl_zephyr_process_events(const owl_io_dispatch *d, void *data)
     1473{
    14821474  _owl_zephyr_process_events();
    1483   return TRUE;
    1484 }
     1475}
     1476
     1477int owl_zephyr_pre_select_action(owl_ps_action *a, void *p)
     1478{
     1479  return _owl_zephyr_process_events();
     1480}
Note: See TracChangeset for help on using the changeset viewer.