Changes in zephyr.c [959cb85:3b8a563]
Legend:
- Unmodified
- Added
- Removed
-
zephyr.c
r959cb85 r3b8a563 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 15 9 #ifdef HAVE_LIBZEPHYR 16 10 static GList *deferred_subs = NULL; … … 22 16 23 17 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 NULL30 };31 18 #endif 32 19 … … 97 84 Code_t code; 98 85 char *perl; 99 GSource *event_source;100 86 101 87 owl_select_remove_io_dispatch(d); … … 113 99 } 114 100 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); 118 102 119 103 owl_global_set_havezephyr(&g); … … 143 127 perl = owl_perlconfig_execute("BarnOwl::Zephyr::_zephyr_startup()"); 144 128 g_free(perl); 129 130 owl_select_add_pre_select_action(owl_zephyr_pre_select_action, NULL, NULL); 145 131 } 146 132 … … 194 180 if((code = ZPending()) < 0) { 195 181 owl_function_debugmsg("Error (%s) in ZPending()\n", 196 error_message(code));197 return 0;198 }199 return code;200 }201 #endif202 return 0;203 }204 205 int owl_zephyr_zqlength(void)206 {207 #ifdef HAVE_LIBZEPHYR208 Code_t code;209 if(owl_global_is_havezephyr(&g)) {210 if((code = ZQLength()) < 0) {211 owl_function_debugmsg("Error (%s) in ZQLength()\n",212 182 error_message(code)); 213 183 return 0; … … 447 417 return 0; 448 418 } 449 if (buffer) 450 g_free(buffer); 419 g_free(buffer); 451 420 452 421 return owl_zephyr_loadsubs_helper(subs, count); … … 1049 1018 { 1050 1019 #ifdef HAVE_LIBZEPHYR 1051 char *exposure, *eset;1052 Code_t ret;1053 1054 1020 ZResetAuthentication(); 1055 1021 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)); 1066 1024 #endif 1067 1025 } … … 1184 1142 ZInitLocationInfo(zstr(host), zstr(val)); 1185 1143 #endif 1144 } 1145 1146 const 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 1157 int 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 1175 const 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 1190 int 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; 1186 1206 } 1187 1207 … … 1449 1469 } 1450 1470 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) { 1471 void owl_zephyr_process_events(const owl_io_dispatch *d, void *data) 1472 { 1482 1473 _owl_zephyr_process_events(); 1483 return TRUE; 1484 } 1474 } 1475 1476 int 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.