From fa0040c286904151e957bcd45ee470b06e8ac7e2 Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Fri, 19 Oct 2007 01:57:15 +0300 Subject: [PATCH] Add (untested) libconic support --- src/iap.c | 110 +++++++++++++++++++++++++++++++++++++++++++++------ src/iap.h | 7 ++++ src/mapper.c | 20 ++++++---- 3 files changed, 117 insertions(+), 20 deletions(-) diff --git a/src/iap.c b/src/iap.c index c26c19f..abf09a3 100644 --- a/src/iap.c +++ b/src/iap.c @@ -1,11 +1,16 @@ #include #ifdef WITH_OSSO - #include -#include -#include + +#ifdef WITH_OSSO_IC #include +#include +#endif + +#ifdef WITH_CONIC +#include +#endif #include "iap.h" #include "map-download.h" @@ -13,9 +18,17 @@ #include "config-gconf.h" gboolean iap_connecting=FALSE; -gboolean iap_connected=TRUE; +gboolean iap_connected=FALSE; + +/*************************************************************/ + +/** + * Old OSSO IC + */ +#ifdef WITH_OSSO_IC -void iap_callback(struct iap_event_t *event, void *arg) +void +iap_callback(struct iap_event_t *event, void *arg) { iap_connecting = FALSE; if (event->type == OSSO_IAP_CONNECTED && !iap_connected) { @@ -27,14 +40,13 @@ if (event->type == OSSO_IAP_CONNECTED && !iap_connected) { } DBusHandlerResult -get_connection_status_signal_cb(DBusConnection * connection, - DBusMessage * message, void *user_data) +get_connection_status_signal_cb(DBusConnection * connection, DBusMessage * message, void *user_data) { gchar *iap_name = NULL, *iap_nw_type = NULL, *iap_state = NULL; /* check signal */ if (!dbus_message_is_signal(message, ICD_DBUS_INTERFACE, ICD_STATUS_CHANGED_SIG)) { - vprintf("%s(): return DBUS_HANDLER_RESULT_NOT_YET_HANDLED\n", __PRETTY_FUNCTION__); + g_printf("%s(): return DBUS_HANDLER_RESULT_NOT_YET_HANDLED\n", __PRETTY_FUNCTION__); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } @@ -43,11 +55,11 @@ if (!dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &iap_nw_type, DBUS_TYPE_STRING, &iap_state, DBUS_TYPE_INVALID)) { - vprintf("%s(): return DBUS_HANDLER_RESULT_NOT_YET_HANDLED\n", __PRETTY_FUNCTION__); + g_printf("%s(): return DBUS_HANDLER_RESULT_NOT_YET_HANDLED\n", __PRETTY_FUNCTION__); return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } -printf(" > iap_state = %s\n", iap_state); +g_printf(" > iap_state = %s\n", iap_state); if (!strcmp(iap_state, "CONNECTED")) { if (!iap_connected) { iap_connected = TRUE; @@ -62,17 +74,76 @@ if (!strcmp(iap_state, "CONNECTED")) { _curl_sid = 0; } } -vprintf("%s(): return DBUS_HANDLER_RESULT_HANDLED\n", __PRETTY_FUNCTION__); +g_printf("%s(): return DBUS_HANDLER_RESULT_HANDLED\n", __PRETTY_FUNCTION__); return DBUS_HANDLER_RESULT_HANDLED; } -void +gboolean iap_connect(void) { if (!iap_connected && !iap_connecting) { iap_connecting = TRUE; osso_iap_connect(OSSO_IAP_ANY, OSSO_IAP_REQUESTED_CONNECT, NULL); + return TRUE; +} +return FALSE; +} + +gboolean +iap_is_connected(void) +{ +return iap_connected; +} + +#endif + +#ifdef WITH_CONIC + +static ConIcConnection *connection=NULL; + +static void +iap_connection_cb(ConIcConnection *connection, ConIcConnectionEvent *event, gpointer user_data) +{ +ConIcConnectionStatus status; +ConIcConnectionError error; + +g_assert(CON_IC_IS_CONNECTION_EVENT(event)); + +status=con_ic_connection_event_get_status(event); + +switch (status) { + case CON_IC_STATUS_CONNECTED: + g_printf("Connected\n"); + iap_connected=TRUE; + iap_connecting=FALSE; + break; + case CON_IC_STATUS_DISCONNECTED: + g_printf("Disconnected\n"); + iap_connected=FALSE; + iap_connecting=FALSE; + break; + case CON_IC_STATUS_DISCONNECTING: + g_printf("Disconnecting\n"); + iap_connecting=FALSE; + break; + default: + break; +} + +} + +gboolean +iap_connect(void) +{ +if (connection==NULL) { + connection=con_ic_connection_new(); + g_signal_connect(G_OBJECT(connection), "connection-event", G_CALLBACK(iap_connection_cb), NULL); } +if (iap_connecting==TRUE) + return TRUE; +g_printf("Requesting connection\n"); +iap_connecting=TRUE; +return con_ic_connection_connect(connection, CON_IC_CONNECT_FLAG_NONE); } gboolean @@ -81,6 +152,21 @@ iap_is_connected(void) return iap_connected; } +#endif + #else +/* !WITH_OSSO */ + +gboolean +iap_connect(void) +{ +return TRUE; +} + +gboolean +iap_is_connected(void) +{ +return TRUE; +} #endif diff --git a/src/iap.h b/src/iap.h index 3d15708..d496966 100644 --- a/src/iap.h +++ b/src/iap.h @@ -1,7 +1,14 @@ #ifndef _IAP_H #define _IAP_H +#include + +#ifdef WITH_OSSO_IC void iap_callback(struct iap_event_t *event, void *arg); DBusHandlerResult get_connection_status_signal_cb(DBusConnection * connection, DBusMessage * message, void *user_data); +#endif + +gboolean iap_connect(void); +gboolean iap_is_connected(void); #endif diff --git a/src/mapper.c b/src/mapper.c index e3a1ea6..989b5a6 100644 --- a/src/mapper.c +++ b/src/mapper.c @@ -162,9 +162,9 @@ return 0; static gint mapper_osso_cb_init(void) { -#ifdef WITH_OSSO gchar *filter_string; +#ifdef WITH_OSSO if (OSSO_OK != osso_rpc_set_default_cb_f(_osso, dbus_cb_default, NULL)) { g_printerr("osso_rpc_set_default_cb_f failed.\n"); return 1; @@ -174,12 +174,14 @@ filter_string = g_strdup_printf("interface=%s", ICD_DBUS_INTERFACE); /* add match */ dbus_bus_add_match(dbus_conn, filter_string, NULL); g_free(filter_string); +#endif + /* add the callback */ +#ifdef WITH_OSSO_IC dbus_connection_add_filter(dbus_conn, get_connection_status_signal_cb, NULL, NULL); - osso_iap_cb(iap_callback); - #endif + return 0; } @@ -232,15 +234,17 @@ switch (mis) { mis=MAPPER_INIT_MISC; break; case MAPPER_INIT_MISC: - #ifdef WITH_OSSO - osso_hw_set_event_cb(_osso, NULL, osso_cb_hw_state, NULL); - #endif - - /* Initialize D-Bus. */ + /* Initialize D-Bus system connection. */ if (NULL == (dbus_conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error))) { g_printerr("Failed to open connection to D-Bus: %s.\n", error->message); error = NULL; } + + /* XXX: Move this */ + #ifdef WITH_OSSO + osso_hw_set_event_cb(_osso, NULL, osso_cb_hw_state, NULL); + #endif + #ifdef WITH_HILDON_DBUS_BT if (NULL == (_rfcomm_req_proxy = dbus_g_proxy_new_for_name(dbus_conn, BTCOND_SERVICE, BTCOND_REQ_PATH, BTCOND_REQ_INTERFACE))) { g_printerr("Failed to open connection to %s.\n", BTCOND_REQ_INTERFACE); -- 2.39.5