Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[hidden modes] Add interface to get list of hidden modes. Contributes…
… to MER#1540
  • Loading branch information
martinjones committed Apr 4, 2016
1 parent 1bcc68e commit 22a0f77
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 12 deletions.
2 changes: 1 addition & 1 deletion docs/usb_moded-doc.txt
Expand Up @@ -415,4 +415,4 @@ For example
hide=developer_mode,bastard_mode

Modes can also be set and removed through dbus (one mode at a time)
See usb_moded_util (-i and -u)
See usb_moded_util (-v, -i and -u)
14 changes: 14 additions & 0 deletions src/com.meego.usb_moded.xml
Expand Up @@ -30,6 +30,17 @@
<method name="get_modes">
<arg name="modes" type="s" direction="out"/>
</method>
<method name="hide_mode">
<arg name="mode" type="s" direction="in"/>
<arg name="mode" type="s" direction="out"/>
</method>
<method name="unhide_mode">
<arg name="mode" type="s" direction="in"/>
<arg name="mode" type="s" direction="out"/>
</method>
<method name="get_hidden">
<arg name="modes" type="s" direction="out"/>
</method>
<method name="rescue_off"/>
<signal name="sig_usb_state_ind">
<arg name="mode" type="s"/>
Expand All @@ -45,5 +56,8 @@
<arg name="key" type="s"/>
<arg name="value" type="s"/>
</signal>
<signal name="sig_usb_hidden_modes_ind">
<arg name="modes" type="s"/>
</signal>
</interface>
</node>
1 change: 1 addition & 0 deletions src/usb_moded-config-private.h
Expand Up @@ -28,4 +28,5 @@ char * get_mode_setting(void);
set_config_result_t set_mode_setting(const char *mode);
set_config_result_t set_hide_mode_setting(const char *mode);
set_config_result_t set_unhide_mode_setting(const char *mode);
char * get_hidden_modes(void);
set_config_result_t set_network_setting(const char *config, const char *setting);
21 changes: 14 additions & 7 deletions src/usb_moded-config.c
Expand Up @@ -434,6 +434,8 @@ static const char * make_hidden_modes_string(const char *hidden, int hide)

for(i = 0; hidden_mode_split[i] != NULL; i++)
{
if(strlen(hidden_mode_split[i]) == 0)
continue;
if(!strcmp(hidden_mode_split[i], hidden))
{
/* if hiding a mode that is already hidden do nothing */
Expand All @@ -442,13 +444,14 @@ static const char * make_hidden_modes_string(const char *hidden, int hide)
if(!hide)
continue;
}
if(strlen(modelist_str->str) != 0)
modelist_str = g_string_append(modelist_str, ",");
modelist_str = g_string_append(modelist_str, hidden_mode_split[i]);
if(hidden_mode_split[i+1] != NULL)
modelist_str = g_string_append(modelist_str, ",");
}
if(hide)
{
modelist_str = g_string_append(modelist_str, ",");
if(strlen(modelist_str->str) != 0)
modelist_str = g_string_append(modelist_str, ",");
modelist_str = g_string_append(modelist_str, hidden);
}

Expand All @@ -461,8 +464,10 @@ set_config_result_t set_hide_mode_setting(const char *mode)
set_config_result_t ret;

ret = set_config_setting(MODE_SETTING_ENTRY, MODE_HIDE_KEY, make_hidden_modes_string(mode, 1));
if(ret == SET_CONFIG_UPDATED)
send_supported_modes_signal();
if(ret == SET_CONFIG_UPDATED) {
send_hidden_modes_signal();
send_supported_modes_signal();
}
return(ret);
}

Expand All @@ -471,8 +476,10 @@ set_config_result_t set_unhide_mode_setting(const char *mode)
set_config_result_t ret;

ret = set_config_setting(MODE_SETTING_ENTRY, MODE_HIDE_KEY, make_hidden_modes_string(mode, 0));
if(ret == SET_CONFIG_UPDATED)
send_supported_modes_signal();
if(ret == SET_CONFIG_UPDATED) {
send_hidden_modes_signal();
send_supported_modes_signal();
}
return(ret);
}

Expand Down
3 changes: 3 additions & 0 deletions src/usb_moded-dbus-private.h
Expand Up @@ -32,3 +32,6 @@ int usb_moded_send_error_signal(const char *error);

/* send supported modes signal system bus */
int usb_moded_send_supported_modes_signal(const char *supported_modes);

/* send hidden modes signal system bus */
int usb_moded_send_hidden_modes_signal(const char *hidden_modes);
21 changes: 21 additions & 0 deletions src/usb_moded-dbus.c
Expand Up @@ -244,6 +244,15 @@ static DBusHandlerResult msg_handler(DBusConnection *const connection, DBusMessa
}
dbus_error_free(&err);
}
else if(!strcmp(member, USB_MODE_HIDDEN_GET))
{
char *config = get_hidden_modes();
if(!config)
config = strdup("");
if((reply = dbus_message_new_method_return(msg)))
dbus_message_append_args (reply, DBUS_TYPE_STRING, &config, DBUS_TYPE_INVALID);
free(config);
}
else if(!strcmp(member, USB_MODE_NETWORK_SET))
{
char *config = 0, *setting = 0;
Expand Down Expand Up @@ -499,3 +508,15 @@ int usb_moded_send_supported_modes_signal(const char *supported_modes)
{
return(usb_moded_dbus_signal(USB_MODE_SUPPORTED_MODES_SIGNAL_NAME, supported_modes));
}

/**
* Send regular usb_moded hidden mode list signal
*
* @return 0 on success, 1 on failure
* @param hidden_modes list of supported modes
*
*/
int usb_moded_send_hidden_modes_signal(const char *hidden_modes)
{
return(usb_moded_dbus_signal(USB_MODE_HIDDEN_MODES_SIGNAL_NAME, hidden_modes));
}
2 changes: 2 additions & 0 deletions src/usb_moded-dbus.h
Expand Up @@ -37,6 +37,7 @@
#define USB_MODE_CONFIG_SIGNAL_NAME "sig_usb_config_ind"
#define USB_MODE_ERROR_SIGNAL_NAME "sig_usb_state_error_ind"
#define USB_MODE_SUPPORTED_MODES_SIGNAL_NAME "sig_usb_supported_modes_ind"
#define USB_MODE_HIDDEN_MODES_SIGNAL_NAME "sig_usb_hidden_modes_ind"

/* supported methods */
#define USB_MODE_STATE_REQUEST "mode_request" /* returns the current mode */
Expand All @@ -45,6 +46,7 @@
#define USB_MODE_LIST "get_modes" /* returns a comma-separated list of supported modes for ui's */
#define USB_MODE_HIDE "hide_mode" /* hide a mode */
#define USB_MODE_UNHIDE "unhide_mode" /* unhide a mode */
#define USB_MODE_HIDDEN_GET "get_hidden" /* return the hidden modes */
#define USB_MODE_STATE_SET "set_mode" /* set a mode (only works when connected) */
#define USB_MODE_CONFIG_SET "set_config" /* set the mode that needs to be activated in the config file */
#define USB_MODE_NETWORK_SET "net_config" /* set the network config in the config file */
Expand Down
1 change: 1 addition & 0 deletions src/usb_moded-modes.h
Expand Up @@ -46,3 +46,4 @@
#define MODE_CHARGER "dedicated_charger"

void send_supported_modes_signal(void);
void send_hidden_modes_signal(void);
39 changes: 35 additions & 4 deletions src/usb_moded-util.c
Expand Up @@ -240,6 +240,31 @@ static int set_unhide_mode_config (char *mode)
return 1;
}

static int get_hiddenlist (void)
{
DBusMessage *req = NULL, *reply = NULL;
char *ret = 0;

if ((req = dbus_message_new_method_call(USB_MODE_SERVICE, USB_MODE_OBJECT, USB_MODE_INTERFACE, USB_MODE_HIDDEN_GET)) != NULL)
{
if ((reply = dbus_connection_send_with_reply_and_block(conn, req, -1, NULL)) != NULL)
{
dbus_message_get_args(reply, NULL, DBUS_TYPE_STRING, &ret, DBUS_TYPE_INVALID);
dbus_message_unref(reply);
}
dbus_message_unref(req);
}

if(ret)
{
printf("hidden modes are = %s\n", ret);
return 0;
}

/* not everything went as planned, return error */
return 1;
}

static int handle_network(char *network)
{
char *operation = 0, *setting = 0, *value = 0;
Expand Down Expand Up @@ -314,7 +339,7 @@ static int handle_network(char *network)
int main (int argc, char *argv[])
{
int query = 0, network = 0, setmode = 0, config = 0;
int modelist = 0, mode_configured = 0, hide = 0, unhide = 0;
int modelist = 0, mode_configured = 0, hide = 0, unhide = 0, hiddenlist = 0;
int res = 1, opt, rescue = 0;
char *option = 0;

Expand All @@ -324,7 +349,7 @@ int main (int argc, char *argv[])
exit(1);
}

while ((opt = getopt(argc, argv, "c:dhi:mn:qrs:u:")) != -1)
while ((opt = getopt(argc, argv, "c:dhi:mn:qrs:u:v")) != -1)
{
switch (opt) {
case 'c':
Expand Down Expand Up @@ -359,6 +384,9 @@ int main (int argc, char *argv[])
unhide = 1;
option = optarg;
break;
case 'v':
hiddenlist = 1;
break;
case 'h':
default:
fprintf(stderr, "\nUsage: %s -<option> <args>\n\n \
Expand All @@ -371,8 +399,9 @@ int main (int argc, char *argv[])
\t-m to get the list of supported modes, \n \
\t-q to query the current mode,\n \
\t-r turn rescue mode off,\n \
\t-s to set/activate a mode\n \
\t-u unhide a mode\n",
\t-s to set/activate a mode,\n \
\t-u unhide a mode,\n \
\t-v to get the list of hidden modes\n",
argv[0]);
exit(1);
}
Expand Down Expand Up @@ -407,6 +436,8 @@ int main (int argc, char *argv[])
res = set_hide_mode_config(option);
else if (unhide)
res = set_unhide_mode_config(option);
else if (hiddenlist)
res = get_hiddenlist();

/* subfunctions will return 1 if an error occured, print message */
if(res)
Expand Down
11 changes: 11 additions & 0 deletions src/usb_moded.c
Expand Up @@ -714,6 +714,16 @@ void send_supported_modes_signal(void)
g_free(mode_list);
}

void send_hidden_modes_signal(void)
{
/* Send hidden modes signal */
gchar *mode_list = get_hidden_modes();
if(mode_list) {
usb_moded_send_hidden_modes_signal(mode_list);
g_free(mode_list);
}
}

/** Pipe fd for transferring signals to mainloop context */
static int sigpipe_fd = -1;

Expand Down Expand Up @@ -997,6 +1007,7 @@ int main(int argc, char* argv[])
#endif /* SYSTEMD */

send_supported_modes_signal();
send_hidden_modes_signal();

if(hw_fallback)
{
Expand Down

0 comments on commit 22a0f77

Please sign in to comment.