Skip to content

Commit

Permalink
adding upstart appsync option
Browse files Browse the repository at this point in the history
  • Loading branch information
Philippe De Swert committed Mar 1, 2012
1 parent 77679b7 commit a41635a
Show file tree
Hide file tree
Showing 18 changed files with 367 additions and 54 deletions.
1 change: 1 addition & 0 deletions TODO
@@ -1,2 +1,3 @@
* verify appsync/usb_moded functionality with multiple sessions
* Fix daemon mode
* Make sure that --enable-dynamic-modes enables app-sync by default
26 changes: 21 additions & 5 deletions configure.ac
@@ -1,4 +1,4 @@
AC_INIT([usb_moded], [0.49])
AC_INIT([usb_moded], [0.52])
AM_INIT_AUTOMAKE([-Wall -Werror foreign])

AM_CONFIG_HEADER([config.h])
Expand All @@ -11,7 +11,7 @@ AC_C_CONST
AC_HEADER_STDC

test_gcc_flag() {
AC_LANG_CONFTEST([int main() {}])
# AC_LANG_CONFTEST([int main() {}])
$CC -c conftest.c $CFLAGS $@ > /dev/null 2> /dev/null
ret=$?
rm -f conftest.o
Expand Down Expand Up @@ -53,11 +53,11 @@ AM_CONDITIONAL([NOKIA], [test x$nokia = xtrue])

AC_ARG_ENABLE([meegodevlock], AS_HELP_STRING([--enable-meegodevlock], [Enable Meego devicelock @<:@default=false@:>@]),
[case "${enableval}" in
yes) meegodevlock=true ; CFLAGS="-DMLOCK $CFLAGS" ;;
yes) meegodevlock=true ; CFLAGS="-DMEEGOLOCK $CFLAGS" ;;
no) meegodevlock=false ;;
*) AC_MSG_ERROR([bad value ${enableval} for --enable-meegodevlock]) ;;
esac],[meegodevlock=false])
AM_CONDITIONAL([MLOCK], [test x$meegodevlock = xtrue])
AM_CONDITIONAL([MEEGOLOCK], [test x$meegodevlock = xtrue])

AC_ARG_ENABLE([n900], AS_HELP_STRING([--enable-n900], [Enable N900 extra's @<:@default=false@:>@]),
[case "${enableval}" in
Expand Down Expand Up @@ -87,10 +87,18 @@ AC_ARG_ENABLE([app_sync], AS_HELP_STRING([--enable-app-sync], [Enable applicatio
[case "${enableval}" in
yes) app_sync=true ; CFLAGS="-DAPP_SYNC $CFLAGS" ;;
no) app_sync=false ;;
*) AC_MSG_ERROR([bad value ${enableval} for --enable-app_sync]) ;;
*) AC_MSG_ERROR([bad value ${enableval} for --enable-app-sync]) ;;
esac],[app_sync=false])
AM_CONDITIONAL([APP_SYNC], [test x$app_sync = xtrue])

AC_ARG_ENABLE([dynamic_modes], AS_HELP_STRING([--enable-dynamic-modes], [Enable adding modes with ini files @<:@default=false@:>@]),
[case "${enableval}" in
yes) dynamic_modes=true ; CFLAGS="-DDYN_MODE $CFLAGS" ;;
no) dynamic_modes=false ;;
*) AC_MSG_ERROR([bad value ${enableval} for --enable-dynamic-modes]) ;;
esac],[dynamic_modes=false])
AM_CONDITIONAL([DYN_MODE], [test x$dynamic_modes = xtrue])

AC_ARG_ENABLE([hal], AS_HELP_STRING([--enable-hal], [Enable deprecated hal interface @<:@default=false@:>@]),
[case "${enableval}" in
yes) hal=true ; CFLAGS="-DHAL -I/usr/include/hal -lhal $CFLAGS" ;;
Expand All @@ -107,6 +115,14 @@ AC_ARG_ENABLE([udev], AS_HELP_STRING([--enable-udev], [Enable udev interface @<:
esac],[udev=false])
AM_CONDITIONAL([UDEV], [test x$udev = xtrue])

AC_ARG_ENABLE([upstart], AS_HELP_STRING([--enable-upstart], [Enable upstart interface for appsync @<:@default=true@:>@]),
[case "${enableval}" in
yes) upstart=true ; CFLAGS="-DUPSTART $CFLAGS" ;;
no) upstart=false ;;
*) AC_MSG_ERROR([bad value ${enableval} for --enable-upstart]) ;;
esac],[upstart=false])
AM_CONDITIONAL([UPSTART], [test x$upstart = xtrue])


#TODO: Figure out how to check for this depending on the gconf flag
# gconf-2.0 >= 2.16.0
Expand Down
14 changes: 14 additions & 0 deletions debian/changelog
@@ -1,3 +1,17 @@
usb-moded (0.52) unstable; urgency=low

* Add upstart appsync functionality
* Coverity fixes

-- Philippe De Swert <philippe.de-swert@nokia.com> Thu, 01 Mar 2012 13:57:21 +0200

usb-moded (0.50) unstable; urgency=low

* Make sure multiple types of devicelock can be used
* Switch to g_ether by default for the time being

-- Philippe De Swert <philippe.de-swert@nokia.com> Wed, 15 Feb 2012 17:42:51 +0200

usb-moded (0.49) unstable; urgency=low

* small memory usage fixes
Expand Down
14 changes: 12 additions & 2 deletions src/Makefile.am
Expand Up @@ -51,7 +51,7 @@ usb_moded_SOURCES += \
usb_moded-trigger.c
endif

if MLOCK
if MEEGOLOCK
usb_moded_SOURCES += \
usb_moded-devicelock.h \
usb_moded-devicelock.c
Expand All @@ -63,7 +63,17 @@ usb_moded_SOURCES += \
usb_moded-appsync.h \
usb_moded-appsync-dbus.c \
usb_moded-appsync-dbus.h \
usb_moded-appsync-dbus-private.h \
usb_moded-appsync-dbus-private.h
endif

if UPSTART
usb_moded_SOURCES += \
usb_moded-upstart.h \
usb_moded-upstart.c
endif

if DYN_MODE
usb_moded_SOURCES += \
usb_moded-dyn-config.c \
usb_moded-dyn-config.h
endif
Expand Down
36 changes: 35 additions & 1 deletion src/usb_moded-appsync.c
Expand Up @@ -38,6 +38,7 @@
#include "usb_moded-appsync-dbus-private.h"
#include "usb_moded-modesetting.h"
#include "usb_moded-log.h"
#include "usb_moded-upstart.h"

static struct list_elem *read_file(const gchar *filename);
static gboolean enumerate_usb(gpointer data);
Expand Down Expand Up @@ -123,6 +124,8 @@ static struct list_elem *read_file(const gchar *filename)
log_debug("Launch = %s\n", list_item->launch);
list_item->mode = g_key_file_get_string(settingsfile, APP_INFO_ENTRY, APP_INFO_MODE_KEY, NULL);
log_debug("Launch mode = %s\n", list_item->mode);
list_item->upstart = g_key_file_get_integer(settingsfile, APP_INFO_ENTRY, APP_INFO_UPSTART_KEY, NULL);
log_debug("Upstart control = %d\n", list_item->upstart);

cleanup:

Expand Down Expand Up @@ -198,7 +201,15 @@ int activate_sync(const char *mode)
if(!strcmp(mode, data->mode))
{
log_debug("launching app %s\n", data->launch);
usb_moded_dbus_app_launch(data->launch);
#ifdef UPSTART
if(data->upstart)
{
if(!upstart_control_job(data->name, UPSTART_START))
mark_active(data->name);
}
else
#endif /* UPSTART */
usb_moded_dbus_app_launch(data->launch);
}
}

Expand Down Expand Up @@ -259,9 +270,12 @@ static gboolean enumerate_usb(gpointer data)
}
else
{

#ifdef NOKIA_EXTRA
/* activate usb connection/enumeration */
write_to_file("/sys/devices/platform/musb_hdrc/gadget/softconnect", "1");
log_debug("Softconnect enumeration done\n");
#endif

enum_tag = sync_tag;

Expand All @@ -276,3 +290,23 @@ static gboolean enumerate_usb(gpointer data)
/* return false to stop the timer from repeating */
return FALSE;
}

#ifdef UPSTART
int appsync_stop(void)
{
GList *iter = 0;

for( iter = sync_list; iter; iter = g_list_next(iter) )
{
struct list_elem *data = iter->data;
if(data->upstart)
{
log_debug("Stopping %s\n", data->launch);
if(upstart_control_job(data->name, UPSTART_STOP))
log_debug("Failed to stop %s\n", data->name);
}
}

return(0);
}
#endif /* UPSTART */
3 changes: 3 additions & 0 deletions src/usb_moded-appsync.h
Expand Up @@ -25,6 +25,7 @@
#define APP_INFO_MODE_KEY "mode"
#define APP_INFO_NAME_KEY "name"
#define APP_INFO_LAUNCH_KEY "launch"
#define APP_INFO_UPSTART_KEY "upstart"

/**
* keep all the needed info together for launching an app
Expand All @@ -36,9 +37,11 @@ typedef struct list_elem
char *mode; /* mode in which to launch the app */
char *launch; /* dbus launch command/address */
int active; /* marker to check if the app has started sucessfully */
int upstart; /* marker to know if we start it with upstart or not */
/*@}*/
}list_elem;

void readlist(void);
int activate_sync(const char *mode);
int mark_active(const gchar *name);
int appsync_stop(void);
8 changes: 3 additions & 5 deletions src/usb_moded-config.c
Expand Up @@ -148,9 +148,8 @@ static const char * get_conf_string(const gchar *entry, const gchar *key)
{
GKeyFile *settingsfile;
gboolean test = FALSE;
gchar **keys;
const char *ret = NULL, *tmp_char;

gchar **keys, *tmp_char;
const char *ret = NULL;
settingsfile = g_key_file_new();
test = g_key_file_load_from_file(settingsfile, FS_MOUNT_CONFIG_FILE, G_KEY_FILE_NONE, NULL);
if(!test)
Expand All @@ -170,13 +169,12 @@ static const char * get_conf_string(const gchar *entry, const gchar *key)
if(tmp_char)
{
log_debug("key %s value = %s\n", key, tmp_char);
ret = g_strdup(tmp_char);
}
}
keys++;
}
g_key_file_free(settingsfile);
return(ret);
return(g_strdup(tmp_char));

}

Expand Down
1 change: 1 addition & 0 deletions src/usb_moded-devicelock.c
Expand Up @@ -32,6 +32,7 @@
#include <dbus/dbus-glib-lowlevel.h>

#include "usb_moded-devicelock.h"
#include "usb_moded-lock.h"
#include "usb_moded-log.h"
#include "usb_moded.h"
#include "usb_moded-modes.h"
Expand Down
2 changes: 0 additions & 2 deletions src/usb_moded-devicelock.h
Expand Up @@ -22,8 +22,6 @@
*/

/*============================================================================= */
int usb_moded_get_export_permission(void);
int start_devicelock_listener(void);

#define DEVICELOCK_SERVICE "com.nokia.devicelock"
#define DEVICELOCK_REQUEST_PATH "/request"
Expand Down
28 changes: 28 additions & 0 deletions src/usb_moded-lock.h
@@ -0,0 +1,28 @@
/*
Copyright (C) 2012 Nokia Corporation. All rights reserved.
Author: Philippe De Swert <philippe.de-swert@nokia.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the Lesser GNU General Public License
version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the Lesser GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301 USA
*/
/*
* Function definitions to interact with a security lock to know if
we can expose the system contents or not
*/

/*============================================================================= */
int usb_moded_get_export_permission(void);
int start_devicelock_listener(void);

1 change: 1 addition & 0 deletions src/usb_moded-modes.h
Expand Up @@ -27,4 +27,5 @@
#define MODE_UNDEFINED "undefined"
#define MODE_ASK "ask"
#define MODE_WINDOWS_NET "windows_network"
#define MODE_DEVELOPER "developer_mode"

19 changes: 13 additions & 6 deletions src/usb_moded-modesetting.c
Expand Up @@ -38,6 +38,7 @@
#include "usb_moded-config.h"
#include "usb_moded-modesetting.h"
#include "usb_moded-network.h"
#include "usb_moded-upstart.h"

static void report_mass_storage_blocker(const char *mountpoint, int try);

Expand Down Expand Up @@ -240,11 +241,10 @@ int set_ovi_suite_mode(void)
int timeout = 1;
#endif /* NOKIA */


#ifdef APP_SYNC
activate_sync(MODE_OVI_SUITE);
#else
//system("echo 1 > /sys/devices/platform/musb_hdrc/gadget/softconnect");
write_to_file("/sys/devices/platform/musb_hdrc/gadget/softconnect", "1");
#endif /* APP_SYNC */
/* bring network interface up in case no other network is up */
Expand All @@ -263,19 +263,21 @@ int set_ovi_suite_mode(void)
}
#endif /* N900 */

#ifdef APP_SYNC
#ifdef DYN_MODE
int set_dynamic_mode(struct mode_list_elem *data)
{
char command[256];
if(data->appsync)
activate_sync(data->mode_name);
if(data->network)
{
g_snprintf(command, 256, "ifdown %s ; ifup %s", data->network_interface, data->network_interface);
system(command);
}

return(0);
}
#endif /* APP_SYNC */
#endif /* DYN_MODE */

#ifdef NOKIA
gboolean export_cdrom(gpointer data)
Expand Down Expand Up @@ -316,6 +318,11 @@ int usb_moded_mode_cleanup(const char *module)
gchar **mounts;
int ret = 0, i = 0;

log_debug("Cleaning up mode\n");

#ifdef UPSTART
appsync_stop();
#endif /* UPSTART */

if(!strcmp(module, MODULE_MASS_STORAGE))
{
Expand Down Expand Up @@ -375,9 +382,9 @@ int usb_moded_mode_cleanup(const char *module)
sync();
/* bring network down immediately */
/*system("ifdown usb0"); */
/* do soft disconnect */
usb_network_down();
write_to_file("/sys/devices/platform/musb_hdrc/gadget/softconnect", "0");
/* do soft disconnect
write_to_file("/sys/devices/platform/musb_hdrc/gadget/softconnect", "0"); */
/* DIRTY WORKAROUND: acm/phonet does not work as it should, remove when it does */
system("killall -SIGTERM acm");
}
Expand Down
3 changes: 2 additions & 1 deletion src/usb_moded-modules.h
Expand Up @@ -21,14 +21,15 @@
/* module name definitions */
#define MODULE_NETWORK "g_nokia"
#ifdef NOKIA
#define MODULE_NETWORK_MTP "g_nokia use_mtp=1 connect=0"
#define MODULE_NETWORK_MTP "g_nokia devmode=0"
#else
#define MODULE_NETWORK_MTP "g_nokia"
#endif /* NOKIA */
#define MODULE_MASS_STORAGE "g_mass_storage"
#define MODULE_CHARGING "g_mass_storage luns=1 stall=0 removable=1"
#define MODULE_NONE "none"
#define MODULE_WINDOWS_NET "g_ether"
#define MODULE_DEVELOPER "g_nokia devmode=1"

/* load module */
int usb_moded_load_module(const char *module);
Expand Down
4 changes: 2 additions & 2 deletions src/usb_moded-network.c
Expand Up @@ -67,7 +67,7 @@ int usb_network_up(void)
return(ret);

#else
system("ifdown usb0 && ifup usb0");
system("ifconfig usb0 192.168.201.42");
return(0);
#endif /* CONNMAN */
}
Expand All @@ -80,7 +80,7 @@ int usb_network_down(void)
{
#if CONNMAN
#else
system("ifdown usb0 down");
system("ifconfig usb0 down");
return(0);
#endif /* CONNMAN */
}

0 comments on commit a41635a

Please sign in to comment.