Modify log format to store raw output from dbus scan
[wifihood] / wifiscand / wifiscand.c
index 57a5fa9..4c588f5 100644 (file)
@@ -6,6 +6,38 @@
 #else
 #include <glib.h>
 #include <dbus/dbus.h>
+
+#define WIFISCAN_INTROSPECTION "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n\
+         \"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n\
+<node name=\"/org/javiplx/wifiscan\">\n\
+  <interface name=\"org.javiplx.wifiscan\">\n\
+    <method name=\"wakeup\">\n\
+      <arg name=\"result\" type=\"s\" direction=\"out\" />\n\
+    </method>\n\
+    <method name=\"start\">\n\
+      <arg name=\"result\" type=\"s\" direction=\"out\" />\n\
+    </method>\n\
+    <method name=\"scan\">\n\
+      <arg name=\"result\" type=\"s\" direction=\"out\" />\n\
+    </method>\n\
+    <method name=\"stop\">\n\
+      <arg name=\"result\" type=\"s\" direction=\"out\" />\n\
+    </method>\n\
+  </interface>\n\
+</node>\n"
+
+#define OSSO_OK 0
+#define OSSO_ERROR 1
+
+#define osso_context_t DBusConnection
+typedef struct osso_rpc_t_values {
+  int i;
+  char *s;
+  } osso_rpc_t_values;
+typedef struct osso_rpc_t {
+  int type;
+  osso_rpc_t_values value;
+  } osso_rpc_t;
 #endif
 
 #define WIFISCAND_VERSION_STRING  "1.1"
@@ -233,6 +265,14 @@ gint dbus_req_handler(const gchar * interface, const gchar * method,
     retval->value.s = (gchar*) malloc( sizeof(gchar *) );
     retval->value.s[0] = '\0';
 
+#ifndef HAVE_LIBOSSO
+    if ( strcmp(method,"Introspect")==0 ) {
+        retval->value.s = (gchar *) realloc(retval->value.s,630*sizeof(gchar *));
+        snprintf(retval->value.s,strlen(WIFISCAN_INTROSPECTION),WIFISCAN_INTROSPECTION);
+        return OSSO_OK;
+    }
+#endif
+
     if ( strcmp(method,"wakeup")==0 ) {
         retval->value.s = (gchar *) realloc(retval->value.s,16*sizeof(gchar *));
         snprintf(retval->value.s,16,"WifiScand ready");
@@ -282,14 +322,14 @@ gint dbus_req_handler(const gchar * interface, const gchar * method,
        appdata->iface.sock = 0;
 #ifdef HAVE_LIBOSSO
         osso_deinitialize(appdata->osso_context);
-#else
-       dbus_deinitialize(appdata->osso_context);
-#endif
         /* Instead of exiting, signaling finish to main loop could be better
         retval->value.s = (gchar *) realloc(retval->value.s,34*sizeof(gchar *));
         snprintf(retval->value.s,34,"Interface moved to original state");
         */
         exit(0);
+#else
+        return OSSO_OK;
+#endif
     }
 
     if ( strcmp(method,"scan")==0 ) {
@@ -323,18 +363,7 @@ gint dbus_req_handler(const gchar * interface, const gchar * method,
 
 #ifndef HAVE_LIBOSSO
 
-#define OSSO_OK 0
-#define OSSO_ERROR 1
-
-#define osso_context_t DBusConnection
-typedef struct osso_rpc_t_values {
-  int i;
-  char *s;
-  } osso_rpc_t_values;
-typedef struct osso_rpc_t {
-  int type;
-  osso_rpc_t_values value;
-  } osso_rpc_t;
+dbus_bool_t stopped_service = FALSE;
 
 static DBusObjectPathVTable *vtable = NULL;
 
@@ -383,6 +412,9 @@ static DBusHandlerResult handler_wrapper (DBusConnection  *connection,
                                dbus_message_get_member(message),
                                NULL, data, retval);
 
+               if ( strcmp(dbus_message_get_member(message),"stop")==0 )
+                       stopped_service = TRUE;
+
                if ( retval->value.s != NULL ) {
                        DBusMessage *reply = dbus_message_new_method_return (message);
                        if (reply == NULL)
@@ -413,7 +445,7 @@ int main( void ) {
        osso_context = osso_initialize(OSSO_NAME, WIFISCAND_VERSION_STRING, TRUE, NULL);
 #else
        dbus_error_init(&error);
-       osso_context = dbus_bus_get(DBUS_BUS_STARTER, &error);
+       osso_context = dbus_bus_get(DBUS_BUS_SESSION, &error);
 #endif
 
        /* Check that initialization was ok */
@@ -454,7 +486,7 @@ int main( void ) {
        event_loop = g_main_loop_new(NULL, FALSE);
        g_main_loop_run(event_loop);
 #else
-       while (dbus_connection_read_write_dispatch (osso_context, -1)) {}
+       while (dbus_connection_read_write_dispatch(osso_context, -1) && stopped_service==FALSE) {}
 #endif
 
        /* Deinitialize OSSO */