/* for complex link stuff */ #include "config.h" #include #ifdef HAVE_EDBUS #include #include #include #include #include static E_DBus_Connection *conn = NULL; static E_DBus_Signal_Handler *changed_h = NULL; static E_DBus_Signal_Handler *namech_h = NULL; static Ecore_Timer *try_again_timer = NULL; static int success = 0; static int try_again(void *data); static void *signal_unmarhsall(DBusMessage *msg, DBusError *err); static void signal_callback(void *data, void *ret, DBusError *err); static void signal_result_free(void *data); static void get_signal(void); static void signal_changed(void *data, DBusMessage *msg); static void name_changed(void *data, DBusMessage *msg); static int try_again(void *data) { get_signal(); try_again_timer = 0; return 0; } static void * signal_unmarhsall(DBusMessage *msg, DBusError *err) { dbus_int32_t str = -1; if (dbus_message_get_args(msg, NULL, DBUS_TYPE_INT32, &str, DBUS_TYPE_INVALID)) { int *str_ret; str_ret = malloc(sizeof(int)); if (str_ret) { *str_ret = str; return str_ret; } } return NULL; } static void signal_callback(void *data, void *ret, DBusError *err) { if (ret) { if (!success) { if (changed_h) { e_dbus_signal_handler_del(conn, changed_h); changed_h = e_dbus_signal_handler_add(conn, "org.openmoko.qtopia.Phonestatus", "/Status", "org.openmoko.qtopia.Phonestatus", "signalStrengthChanged", signal_changed, NULL); } success = 1; } int *str_ret; str_ret = ret; printf("%i\n", *str_ret); fflush(stdout); } else { success = 0; if (try_again_timer) ecore_timer_del(try_again_timer); try_again_timer = ecore_timer_add(1.0, try_again, NULL); } } static void signal_result_free(void *data) { free(data); } static void get_signal(void) { DBusMessage *msg; if (!conn) return; msg = dbus_message_new_method_call("org.openmoko.qtopia.Phonestatus", "/Status", "org.openmoko.qtopia.Phonestatus", "signalStrength"); if (!msg) return; e_dbus_method_call_send(conn, msg, signal_unmarhsall, signal_callback, signal_result_free, -1, NULL); dbus_message_unref(msg); } static void signal_changed(void *data, DBusMessage *msg) { DBusError err; dbus_int32_t str = -1; dbus_error_init(&err); if (!dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &str, DBUS_TYPE_INVALID)) return; printf("%i\n", str); fflush(stdout); } static void name_changed(void *data, DBusMessage *msg) { DBusError err; // dbus_int32_t str = -1; const char *s1, *s2, *s3; dbus_error_init(&err); if (!dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &s1, DBUS_TYPE_STRING, &s2, DBUS_TYPE_STRING, &s3, DBUS_TYPE_INVALID)) return; if (strcmp(s1, "org.openmoko.qtopia.Phonestatus")) return; if (changed_h) { e_dbus_signal_handler_del(conn, changed_h); changed_h = e_dbus_signal_handler_add(conn, "org.openmoko.qtopia.Phonestatus", "/Status", "org.openmoko.qtopia.Phonestatus", "signalStrengthChanged", signal_changed, NULL); get_signal(); } } #endif int main(int argc, char **argv) { #ifdef HAVE_EDBUS int sleeptime = 8; ecore_init(); ecore_string_init(); ecore_app_args_set(argc, (const char **)argv); e_dbus_init(); if (argc > 1) sleeptime = atoi(argv[1]); conn = e_dbus_bus_get(DBUS_BUS_SESSION); namech_h = e_dbus_signal_handler_add(conn, "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "NameOwnerChanged", name_changed, NULL); changed_h = e_dbus_signal_handler_add(conn, "org.openmoko.qtopia.Phonestatus", "/Status", "org.openmoko.qtopia.Phonestatus", "signalStrengthChanged", signal_changed, NULL); get_signal(); ecore_main_loop_begin(); if (conn) e_dbus_connection_close(conn); e_dbus_shutdown(); ecore_string_shutdown(); ecore_shutdown(); #endif return 0; }