-LDFLAGS = -liw $(shell pkg-config --libs libosso)
-CPPFLAGS = $(shell pkg-config --cflags libosso)
+OSSO_CFLAGS = $(shell pkg-config --cflags libosso)
+OSSO_LDFLAGS = $(shell pkg-config --libs libosso)
+DBUS_CFLAGS = $(shell pkg-config --cflags dbus-1)
+DBUS_LDFLAGS = $(shell pkg-config --libs dbus-1)
+
+GLIB_CFLAGS = $(shell pkg-config --cflags glib-2.0)
+GLIB_LDFLAGS = $(shell pkg-config --libs glib-2.0)
+
+CPPFLAGS =
+CFLAGS = $(DBUS_CFLAGS) $(GLIB_CFLAGS)
+LDFLAGS = -liw $(DBUS_LDFLAGS) $(GLIB_LDFLAGS)
+
+default:
+
+install: wifiscand
+ cp wifiscand $(DESTDIR)$(PREFIX)/sbin
+ cp wifiscand.service $(DESTDIR)$(PREFIX)/share/dbus-1/services
dh_testdir
# Add here commands to compile the package.
dh_testdir
# Add here commands to compile the package.
+ $(MAKE) wifiscand CPPFLAGS="-DHAVE_LIBOSSO"
dh_installdirs
# Add here commands to install the package into debian/tmp
dh_installdirs
# Add here commands to install the package into debian/tmp
- cp wifiscand $(CURDIR)/debian/tmp/usr/sbin
- cp wifiscand.service $(CURDIR)/debian/tmp/usr/share/dbus-1/services
+ make install DESTDIR=$(CURDIR)/debian/tmp
# Build architecture-independent files here.
# Build architecture-independent files here.
-
-#define WIFISCAND_VERSION_STRING "1.0"
+#else
+#include "glib/gtypes.h"
+#include "dbus/dbus.h"
+#define OSSO_OK 0
+#define OSSO_ERROR 1
+#endif
+
+#ifndef HAVE_LIBOSSO
+#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"
#define OSSO_NAME "wifiscan"
#define OSSO_SERVICE "org.javiplx."OSSO_NAME
#define OSSO_NAME "wifiscan"
#define OSSO_SERVICE "org.javiplx."OSSO_NAME
osso_context_t *osso_context;
};
osso_context_t *osso_context;
};
static GMainLoop *event_loop = NULL;
static GMainLoop *event_loop = NULL;
static short int start_flags = 0;
static short int start_flags = 0;
+#ifndef HAVE_LIBOSSO
+int submit_reply_message(DBusConnection *connection, DBusMessage *message, char *string) {
+ DBusMessage *reply = dbus_message_new_method_return (message);
+ if (reply == NULL)
+ exit(0);
+ if (!dbus_message_append_args (reply, DBUS_TYPE_STRING, &string, DBUS_TYPE_INVALID))
+ exit(0);
+ if (!dbus_connection_send (connection, reply, NULL))
+ exit(0);
+ dbus_message_unref (reply);
+ return DBUS_HANDLER_RESULT_HANDLED;
+}
+#endif
+
/* Callback for normal D-BUS messages */
/* Callback for normal D-BUS messages */
gint dbus_req_handler(const gchar * interface, const gchar * method,
GArray * arguments, gpointer data,
osso_rpc_t * retval)
gint dbus_req_handler(const gchar * interface, const gchar * method,
GArray * arguments, gpointer data,
osso_rpc_t * retval)
+#else
+static DBusHandlerResult dbus_req_handler (DBusConnection *connection,
+ DBusMessage *message,
+ void *data)
+#endif
+#ifndef HAVE_LIBOSSO
+ osso_rpc_t *retval = malloc(sizeof(osso_rpc_t));
+#endif
+
AppData *appdata;
appdata = (AppData *) data;
AppData *appdata;
appdata = (AppData *) data;
retval->value.s = (gchar*) malloc( sizeof(gchar *) );
retval->value.s[0] = '\0';
retval->value.s = (gchar*) malloc( sizeof(gchar *) );
retval->value.s[0] = '\0';
if ( strcmp(method,"wakeup")==0 ) {
if ( strcmp(method,"wakeup")==0 ) {
+#else
+ if (dbus_message_is_method_call(message, OSSO_IFACE, "wakeup")) {
+#endif
retval->value.s = (gchar *) realloc(retval->value.s,16*sizeof(gchar *));
snprintf(retval->value.s,16,"WifiScand ready");
retval->value.s = (gchar *) realloc(retval->value.s,16*sizeof(gchar *));
snprintf(retval->value.s,16,"WifiScand ready");
+#else
+ return submit_reply_message(connection, message, retval->value.s);
+#endif
if ( strcmp(method,"start")==0 ) {
if ( strcmp(method,"start")==0 ) {
+#else
+ if (dbus_message_is_method_call(message, OSSO_IFACE, "start")) {
+#endif
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");
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");
+#else
+ return submit_reply_message(connection, message, retval->value.s);
+#endif
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");
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");
+#else
+ return submit_reply_message(connection, message, retval->value.s);
+#endif
}
start_flags = frq.ifr_flags;
}
start_flags = frq.ifr_flags;
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");
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");
+#else
+ return submit_reply_message(connection, message, retval->value.s);
+#endif
}
refresh(&appdata->iface);
retval->value.s = (gchar *) realloc(retval->value.s,22*sizeof(gchar *));
snprintf(retval->value.s,22,"Interface initialized");
}
refresh(&appdata->iface);
retval->value.s = (gchar *) realloc(retval->value.s,22*sizeof(gchar *));
snprintf(retval->value.s,22,"Interface initialized");
+#else
+ return submit_reply_message(connection, message, retval->value.s);
+#endif
if ( strcmp(method,"stop")==0 ) {
if ( strcmp(method,"stop")==0 ) {
+#else
+ if (dbus_message_is_method_call(message, OSSO_IFACE, "stop")) {
+#endif
struct ifreq frq;
strncpy(frq.ifr_name, appdata->iface.ifname, IFNAMSIZ);
if(!ioctl(appdata->iface.sock, SIOCGIFFLAGS, &frq)) {
struct ifreq frq;
strncpy(frq.ifr_name, appdata->iface.ifname, IFNAMSIZ);
if(!ioctl(appdata->iface.sock, SIOCGIFFLAGS, &frq)) {
}
iw_sockets_close(appdata->iface.sock);
appdata->iface.sock = 0;
}
iw_sockets_close(appdata->iface.sock);
appdata->iface.sock = 0;
osso_deinitialize(appdata->osso_context);
osso_deinitialize(appdata->osso_context);
+#else
+ dbus_connection_unref(appdata->osso_context);
+ dbus_shutdown();
+#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");
/* 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");
if ( strcmp(method,"scan")==0 ) {
if ( strcmp(method,"scan")==0 ) {
+#else
+ if (dbus_message_is_method_call(message, OSSO_IFACE, "scan")) {
+#endif
ScanInfo **scan = (ScanInfo **) makeScan(&appdata->iface,retval->value.s);
if(scan == NULL) {
retval->value.s = (gchar *) realloc(retval->value.s,64*sizeof(gchar *));
snprintf(retval->value.s,64,"ERROR");
ScanInfo **scan = (ScanInfo **) makeScan(&appdata->iface,retval->value.s);
if(scan == NULL) {
retval->value.s = (gchar *) realloc(retval->value.s,64*sizeof(gchar *));
snprintf(retval->value.s,64,"ERROR");
+#else
+ return submit_reply_message(connection, message, retval->value.s);
+#endif
retval->value.s = (gchar *) realloc(retval->value.s,23*(i+1)*sizeof(gchar *));
if ( retval->value.s == NULL ) {
retval->value.s = "Error allocating memory";
retval->value.s = (gchar *) realloc(retval->value.s,23*(i+1)*sizeof(gchar *));
if ( retval->value.s == NULL ) {
retval->value.s = "Error allocating memory";
+#else
+ return submit_reply_message(connection, message, retval->value.s);
+#endif
}
sprintf(retval->value.s+strlen(retval->value.s),"%s:%d ",sc->mac,sc->rssi);
}
retval->value.s[strlen(retval->value.s)-1] = '\0';
}
sprintf(retval->value.s+strlen(retval->value.s),"%s:%d ",sc->mac,sc->rssi);
}
retval->value.s[strlen(retval->value.s)-1] = '\0';
+#else
+ return submit_reply_message(connection, message, retval->value.s);
+#endif
}
retval->value.s = (gchar *) realloc(retval->value.s,64*sizeof(gchar *));
snprintf(retval->value.s,64,"Unknown method");
}
retval->value.s = (gchar *) realloc(retval->value.s,64*sizeof(gchar *));
snprintf(retval->value.s,64,"Unknown method");
+#else
+ return submit_reply_message(connection, message, retval->value.s);
+#endif
+#ifndef HAVE_LIBOSSO
+static DBusObjectPathVTable
+dbus_req_handler_vtable = {
+ NULL,
+ dbus_req_handler,
+ NULL,
+};
+#endif
int main( void ) {
osso_context_t *osso_context;
int main( void ) {
osso_context_t *osso_context;
+#ifndef HAVE_LIBOSSO
+ DBusError error;
+#endif
/* Initialize maemo application */
/* Initialize maemo application */
osso_context = osso_initialize(OSSO_NAME, WIFISCAND_VERSION_STRING, TRUE, NULL);
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);
+#endif
/* Check that initialization was ok */
if (osso_context == NULL) {
/* Check that initialization was ok */
if (osso_context == NULL) {
+#ifndef HAVE_LIBOSSO
+ fprintf (stderr, "*** Failed to open connection to activating message bus: %s\n", error.message);
+ dbus_error_free (&error);
+#endif
exit(OSSO_ERROR);
}
/* Create AppData */
AppData *appdata;
exit(OSSO_ERROR);
}
/* Create AppData */
AppData *appdata;
appdata = g_new0(AppData, 1);
appdata = g_new0(AppData, 1);
+#else
+ appdata = malloc(sizeof(AppData));
+#endif
appdata->osso_context = osso_context;
memset(&(appdata->iface.info), 0, sizeof(wireless_info));
appdata->osso_context = osso_context;
memset(&(appdata->iface.info), 0, sizeof(wireless_info));
appdata->iface.sock = 0;
/* Add handler for hello D-BUS messages */
appdata->iface.sock = 0;
/* Add handler for hello D-BUS messages */
osso_return_t result = osso_rpc_set_cb_f(osso_context, OSSO_SERVICE, OSSO_OBJECT, OSSO_IFACE, dbus_req_handler, appdata);
osso_return_t result = osso_rpc_set_cb_f(osso_context, OSSO_SERVICE, OSSO_OBJECT, OSSO_IFACE, dbus_req_handler, appdata);
+#else
+ int result = dbus_connection_register_fallback(osso_context, OSSO_OBJECT, &dbus_req_handler_vtable, appdata);
+#endif
+// NOTE : valid return codes do not match from both functions
+#ifdef HAVE_LIBOSSO
+#else
+ if (!result) {
+#endif
+#ifdef HAVE_LIBOSSO
osso_system_note_infoprint(appdata->osso_context, "Failure while setting OSSO callback", NULL);
osso_system_note_infoprint(appdata->osso_context, "Failure while setting OSSO callback", NULL);
+#ifndef HAVE_LIBOSSO
+ result = dbus_bus_request_name (osso_context, OSSO_SERVICE, 0, &error);
+ if (dbus_error_is_set (&error)) {
+ fprintf (stderr, "Error %s\n", error.message);
+ dbus_error_free (&error);
+ exit (1);
+ }
+#endif
+
/* INITIALIZATION FINISH */
/* INITIALIZATION FINISH */
event_loop = g_main_loop_new(NULL, FALSE);
g_main_loop_run(event_loop);
event_loop = g_main_loop_new(NULL, FALSE);
g_main_loop_run(event_loop);
+#else
+ while (dbus_connection_read_write_dispatch (osso_context, -1)) {}
+#endif
osso_deinitialize(osso_context);
osso_deinitialize(osso_context);
+#else
+ dbus_connection_unref(osso_context);
+ dbus_shutdown();
+#endif