Changes in zephyr.c [f203cad:cd28517]
Legend:
- Unmodified
- Added
- Removed
-
zephyr.c
rf203cad rcd28517 7 7 #include "owl.h" 8 8 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 9 15 #ifdef HAVE_LIBZEPHYR 10 16 static GList *deferred_subs = NULL; … … 16 22 17 23 Code_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 }; 18 31 #endif 19 32 … … 84 97 Code_t code; 85 98 char *perl; 99 GSource *event_source; 86 100 87 101 owl_select_remove_io_dispatch(d); … … 99 113 } 100 114 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); 102 118 103 119 owl_global_set_havezephyr(&g); … … 127 143 perl = owl_perlconfig_execute("BarnOwl::Zephyr::_zephyr_startup()"); 128 144 g_free(perl); 129 130 owl_select_add_pre_select_action(owl_zephyr_pre_select_action, NULL, NULL);131 145 } 132 146 … … 180 194 if((code = ZPending()) < 0) { 181 195 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", 182 212 error_message(code)); 183 213 return 0; … … 1019 1049 { 1020 1050 #ifdef HAVE_LIBZEPHYR 1051 char *exposure, *eset; 1052 Code_t ret; 1053 1021 1054 ZResetAuthentication(); 1022 1055 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)); 1025 1066 #endif 1026 1067 } … … 1143 1184 ZInitLocationInfo(zstr(host), zstr(val)); 1144 1185 #endif 1145 }1146 1147 const char *owl_zephyr_normalize_exposure(const char *exposure)1148 {1149 if (exposure == NULL)1150 return NULL;1151 #ifdef HAVE_LIBZEPHYR1152 return ZParseExposureLevel(zstr(exposure));1153 #else1154 return exposure;1155 #endif1156 }1157 1158 int owl_zephyr_set_default_exposure(const char *exposure)1159 {1160 #ifdef HAVE_LIBZEPHYR1161 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 #endif1173 return 0;1174 }1175 1176 const char *owl_zephyr_get_default_exposure(void)1177 {1178 #ifdef HAVE_LIBZEPHYR1179 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 #else1187 return "";1188 #endif1189 }1190 1191 int owl_zephyr_set_exposure(const char *exposure)1192 {1193 #ifdef HAVE_LIBZEPHYR1194 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 #endif1206 return 0;1207 1186 } 1208 1187 … … 1470 1449 } 1471 1450 1472 void owl_zephyr_process_events(const owl_io_dispatch *d, void *data) 1473 { 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) { 1474 1482 _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.