Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add query option to get all the modes
Signed-off-by: Philippe De Swert <philippe.deswert@jollamobile.com>
  • Loading branch information
philippedeswert committed Mar 4, 2013
1 parent e7b1195 commit df6665e
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/usb_moded-doc.txt
Expand Up @@ -47,6 +47,10 @@ To get the currently stored default mode from the config:

dbus-send --system --type=method_call --print-reply --dest=com.meego.usb_moded /com/meego/usb_moded com.meego.usb_moded.get_config

The supported modes can be queried over dbus as follows:

dbus-send --system --type=method_call --print-reply --dest=com.meego.usb_moded /com/meego/usb_moded com.meego.usb_moded.get_modes

=== WITH GCONF ONLY ===

However this can also be optionally handled by setting the following GConf key (gconf has to be compiled in).
Expand Down
7 changes: 7 additions & 0 deletions src/usb_moded-dbus.c
Expand Up @@ -159,6 +159,13 @@ static DBusHandlerResult msg_handler(DBusConnection *const connection, DBusMessa
if((reply = dbus_message_new_method_return(msg)))
dbus_message_append_args (reply, DBUS_TYPE_STRING, &config, DBUS_TYPE_INVALID);
}
else if(!strcmp(member, USB_MODE_LIST))
{
const char *mode_list = get_mode_list();

if((reply = dbus_message_new_method_return(msg)))
dbus_message_append_args (reply, DBUS_TYPE_STRING, &mode_list, DBUS_TYPE_INVALID);
}
else if(!strcmp(member, USB_MODE_RESCUE_OFF))
{
rescue_mode = FALSE;
Expand Down
1 change: 1 addition & 0 deletions src/usb_moded-dbus.h
Expand Up @@ -32,6 +32,7 @@
#define USB_MODE_STATE_REQUEST "mode_request"
#define USB_MODE_RESCUE_OFF "rescue_off"
#define USB_MODE_CONFIG_GET "get_config" /* returns the mode set in the config */
#define USB_MODE_LIST "get_modes" /* returns a comma-separated list of supported modes for ui's */

/**
* @credential usb-moded::USBControl Credential needed to be able to call the set_mode or set_config methods
Expand Down
1 change: 1 addition & 0 deletions src/usb_moded-modes.h
Expand Up @@ -30,3 +30,4 @@
#define MODE_DEVELOPER "developer_mode"
#define MODE_MTP "mtp_mode"

char *get_mode_list(void);
37 changes: 37 additions & 0 deletions src/usb_moded.c
Expand Up @@ -24,6 +24,7 @@

#define _GNU_SOURCE
#include <getopt.h>
#include <stdio.h>

#include <sys/stat.h>
#include <sys/wait.h>
Expand Down Expand Up @@ -331,6 +332,7 @@ else if(!strcmp(mode, MODE_DEVELOPER))
current_mode.mode = strdup(mode);
usb_moded_send_signal(get_usb_mode());
}

/** check if a given usb_mode exists
*
* @param mode The mode to look for
Expand Down Expand Up @@ -364,6 +366,41 @@ int valid_mode(const char *mode)

}

/** make a list of all available usb modes
*
* @return a comma-separated list of modes (MODE_ASK not included as it is not a real mode)
*
*/
char *get_mode_list(void)
{

char *modelist;

#ifdef N900
asprintf(&modelist, "%s, %s, %s, %s, %s, %s", MODE_MASS_STORAGE, MODE_OVI_SUITE, MODE_CHARGING, MODE_WINDOWS_NET, MODE_DEVELOPER, MODE_MTP);
#else
asprintf(&modelist, "%s, %s, %s, %s, %s", MODE_MASS_STORAGE, MODE_CHARGING, MODE_WINDOWS_NET, MODE_DEVELOPER, MODE_MTP);
#endif /* N900 */
#ifdef DYN_MODE
{
/* check dynamic modes */
if(modelist)
{
GList *iter;

for( iter = modelist; iter; iter = g_list_next(iter) )
{
struct mode_list_elem *data = iter->data;
/* TODO : concat correctly the mode names
strconcat(modelist, data->mode_name);
*/
}
}
}
#endif /* DYN_MODE */
return modelist;
}

/** get the usb mode
*
* @return the currently set mode
Expand Down

0 comments on commit df6665e

Please sign in to comment.