Separated method to start wifiscand and configure interface for scanning
authorjaviplx <javiplx@gmail.com>
Thu, 3 Jun 2010 15:40:47 +0000 (15:40 +0000)
committerjaviplx <javiplx@gmail.com>
Thu, 3 Jun 2010 15:40:47 +0000 (15:40 +0000)
git-svn-id: file:///svnroot/wifihood/trunk@7 c51dfc6a-5949-4919-9c8e-f207a149c383

wifiscand/debian/changelog
wifiscand/wifiscand.c
wifiscanner/debian/control
wifiscanner/wifimap/wifiscan.py

index e62985c..1e86a16 100644 (file)
@@ -1,5 +1,6 @@
 wifiscand (1.1-1) fremantle; urgency=low
 
+  * Added new method to separate daemon and actual scanning start
   * #5730 : fixed restoration of initial interface state
 
  -- Javier Palacios <javiplx@gmail.com>  Fri, 28 May 2010 18:47:22 +0200
index 0ee874e..36780c9 100644 (file)
@@ -226,8 +226,40 @@ gint dbus_req_handler(const gchar * interface, const gchar * method,
     retval->value.s = (gchar*) malloc( sizeof(gchar *) );
     retval->value.s[0] = '\0';
 
+    if ( strcmp(method,"wakeup")==0 ) {
+        retval->value.s = (gchar *) realloc(retval->value.s,16*sizeof(gchar *));
+        snprintf(retval->value.s,16,"WifiScand ready");
+        return OSSO_OK;
+    }
+
     if ( strcmp(method,"start")==0 ) {
-    //    osso_system_note_infoprint(appdata->osso_context, "Starting WifiScan", NULL);
+
+        if( (appdata->iface.sock=iw_sockets_open()) < 0) {
+            retval->value.s = (gchar *) realloc(retval->value.s,33*sizeof(gchar *));
+            snprintf(retval->value.s,33,"Failure in socket initialization");
+            return OSSO_ERROR;
+        }
+
+        struct ifreq frq;
+        strncpy(frq.ifr_name, appdata->iface.ifname, IFNAMSIZ);
+        if(ioctl(appdata->iface.sock, SIOCGIFFLAGS, &frq)) {
+            retval->value.s = (gchar *) realloc(retval->value.s,28*sizeof(gchar *));
+            snprintf(retval->value.s,28,"Cannot get interface status");
+            return OSSO_ERROR;
+        }
+
+        start_flags = frq.ifr_flags;
+        frq.ifr_flags |= IFF_UP | IFF_RUNNING;
+
+        if(ioctl(appdata->iface.sock, SIOCSIFFLAGS, &frq)) {
+            retval->value.s = (gchar *) realloc(retval->value.s,27*sizeof(gchar *));
+            snprintf(retval->value.s,27,"Cannot set interface state");
+            return OSSO_ERROR;
+        }
+
+        refresh(&appdata->iface);
+        retval->value.s = (gchar *) realloc(retval->value.s,22*sizeof(gchar *));
+        snprintf(retval->value.s,22,"Interface initialized");
         return OSSO_OK;
     }
 
@@ -236,17 +268,20 @@ gint dbus_req_handler(const gchar * interface, const gchar * method,
        strncpy(frq.ifr_name, appdata->iface.ifname, IFNAMSIZ);
        if(!ioctl(appdata->iface.sock, SIOCGIFFLAGS, &frq)) {
            frq.ifr_flags = start_flags;
-           ioctl(appdata->iface.sock, SIOCSIFFLAGS, &frq);
+           if(!ioctl(appdata->iface.sock, SIOCSIFFLAGS, &frq))
+                refresh(&appdata->iface);
        }
         iw_sockets_close(appdata->iface.sock);
        appdata->iface.sock = 0;
-    //    osso_system_note_infoprint(appdata->osso_context, "Stopping WifiScan", NULL);
         osso_deinitialize(appdata->osso_context);
+        /* 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);
     }
 
     if ( strcmp(method,"scan")==0 ) {
-    //    osso_system_note_infoprint(appdata->osso_context, "Scanning ...", NULL);
 
         ScanInfo **scan = (ScanInfo **) makeScan(&appdata->iface,retval->value.s);
         if(scan == NULL) {
@@ -304,37 +339,11 @@ int main( void ) {
                return OSSO_ERROR;
        }
 
-       /* INITIALIZATION */
-       appdata->iface.sock = iw_sockets_open();
-
-       if(appdata->iface.sock < 0) {
-               osso_system_note_infoprint(osso_context, "Failure in socket initialization", NULL);
-               return OSSO_ERROR;
-       }
-
-       struct ifreq frq;
-
-       strncpy(frq.ifr_name, appdata->iface.ifname, IFNAMSIZ);
-                       
-       if(ioctl(appdata->iface.sock, SIOCGIFFLAGS, &frq)) {
-               osso_system_note_infoprint(osso_context, "Cannot scan", NULL);
-               return OSSO_ERROR;
-       }
-
-       start_flags = frq.ifr_flags;
-       frq.ifr_flags |= IFF_UP | IFF_RUNNING;
-               
-       ioctl(appdata->iface.sock, SIOCSIFFLAGS, &frq);
-                       
-       refresh(&appdata->iface);
        /* INITIALIZATION FINISH */
 
        event_loop = g_main_loop_new(NULL, FALSE);
        g_main_loop_run(event_loop);
 
-       frq.ifr_flags = start_flags;
-       ioctl(appdata->iface.sock, SIOCSIFFLAGS, &frq);
-                       
        /* Deinitialize OSSO */
        osso_deinitialize(osso_context);
 
index 8883f93..e117372 100644 (file)
@@ -6,7 +6,7 @@ Standards-Version: 3.6.1
 
 Package: wifihood-scanner
 Architecture: any
-Depends: python-osso, ${shlibs:Depends}, ${misc:Depends}
+Depends: python-osso, wifiscand (>= 1.1), ${shlibs:Depends}, ${misc:Depends}
 Description: WifiHood Scanner
 
 #Package: wifihood-mapper
index 41175ad..574582e 100644 (file)
@@ -12,17 +12,17 @@ class Scanner ( gps.GPSObject ) :
     def __init__ ( self , widget=None , ifname="wlan0" ) :
         gps.GPSObject.__init__( self , widget )
         self.osso_context = osso.Context("wifi_scanner", "2.0", False)
+        osso_rpc = osso.Rpc(self.osso_context)
+        scan_out = osso_rpc.rpc_run("org.javiplx.wifiscan", "/org/javiplx/wifiscan", "org.javiplx.wifiscan", "wakeup", wait_reply = True)
         self._timer = None
 
     def start ( self ) :
         osso_rpc = osso.Rpc(self.osso_context)
         scan_out = osso_rpc.rpc_run("org.javiplx.wifiscan", "/org/javiplx/wifiscan", "org.javiplx.wifiscan", "start")
-        osso.SystemNote(self.osso_context).system_note_infoprint("WifiScand started")
 
     def stop ( self ) :
         osso_rpc = osso.Rpc(self.osso_context)
         scan_out = osso_rpc.rpc_run("org.javiplx.wifiscan", "/org/javiplx/wifiscan", "org.javiplx.wifiscan", "stop")
-        osso.SystemNote(self.osso_context).system_note_infoprint("WifiScand stopped")
 
     def scan ( self ) :
         osso_rpc = osso.Rpc(self.osso_context)
@@ -31,7 +31,6 @@ class Scanner ( gps.GPSObject ) :
         except Exception , ex :
             osso.SystemNote(self.osso_context).system_note_infoprint("Exception scanning %s" % ex )
             return True
-        #osso.SystemNote(self.osso_context).system_note_infoprint("Found %d APs" % len(scan_out.split()) )
         out_str = ""
         for net in scan_out.split() :
             items = net.rsplit(":", 1)
@@ -49,7 +48,6 @@ class Scanner ( gps.GPSObject ) :
                 loclist.write ( "%s\n" % ( self.satellites ,) )
                 loclist.close()
             if self.cell_info :
-            #    osso.SystemNote(self.osso_context).system_note_infoprint("Found Cell : %s" % ( self.cell_info ,) )
                 celllist = open( "/home/user/MyDocs/cell.info" , 'a' )
                 celllist.write ( "%s\n" % ( self.cell_info ,) )
                 celllist.close()