Skip to content

Commit

Permalink
Modification on services even when not connected
Browse files Browse the repository at this point in the history
Change-Id: I6d5393624d53dfece4d2c9e5082ee1063cf374d4
  • Loading branch information
Guittet Thibault committed Aug 25, 2014
1 parent 93b6ad0 commit 1b5357f
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 16 deletions.
4 changes: 3 additions & 1 deletion commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,9 @@ static void config_append_json_array_of_strings(DBusMessageIter *iter,
continue;

str = json_object_get_string(strobj);
dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &str);

if (str)
dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &str);
}
}
}
Expand Down
21 changes: 21 additions & 0 deletions engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,25 @@ static int remove_service(struct json_object *jobj)
return __cmd_remove(serv_dbus_name);
}

/*
* Return via engine_callback everything on the service matching the service
* name in jobj.
* @param jobj json object with a valid dbus service name
* @return [ "service dbus name", { service dict } ]
*/
static int engine_get_service(struct json_object *jobj)
{
struct json_object *tmp;
const char *serv_dbus_name;

json_object_object_get_ex(jobj, key_service, &tmp);
serv_dbus_name = json_object_get_string(tmp);
tmp = coating(key_engine_get_service, get_service(serv_dbus_name));
engine_callback(0, tmp);

return -EINPROGRESS;
}

/*
* This is the list of commands engine_query will answer to.
* If you want to use a json object instead of a regex for data verification,
Expand Down Expand Up @@ -636,6 +655,8 @@ static struct {
{ key_engine_toggle_offline_mode, toggle_offline_mode, true, { "" } },
{ key_engine_remove_service, remove_service, true, {
key_engine_serv_regex } },
{ key_engine_get_service, engine_get_service, true, {
key_engine_serv_regex } },
{ NULL, }, // this is a sentinel
};

Expand Down
1 change: 1 addition & 0 deletions keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const char key_engine_toggle_offline_mode[] = "toggle_offline_mode";
const char key_engine_remove_service[] = "remove_service";
const char key_engine_tech_regex[] = "{ \"technology\": \"(%5C%5C|/|([a-zA-Z]))+\" }";
const char key_engine_serv_regex[] = "{ \"service\": \"(%5C%5C|/|([a-zA-Z]))+\" }";
const char key_engine_get_service[] = "get_service";

const char key_success[] = "OK";
const char key_error[] = "ERROR";
Expand Down
1 change: 1 addition & 0 deletions keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ extern const char key_engine_toggle_offline_mode[];
extern const char key_engine_remove_service[];
extern const char key_engine_tech_regex[];
extern const char key_engine_serv_regex[];
extern const char key_engine_get_service[];

extern const char key_success[];
extern const char key_error[];
Expand Down
72 changes: 67 additions & 5 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ static void connect_to_service(void);
static void get_state(void);
static void print_home_page(void);
static void exec_refresh(void);
static void get_service_settings(void);

// Refres isn't automatic, this could be problematic in high wifi density areas:
// your cursor would move around endlessly. Thus, automatic refresh is disabled
Expand Down Expand Up @@ -95,6 +96,8 @@ static struct {
print_services_for_tech }, // CONTEXT_SERVICE_CONFIG
{ connect_to_service, __renderers_free_services, print_home_page,
print_services_for_tech }, // CONTEXT_SERVICES
{ NULL, __renderers_free_service_config, print_services_for_tech,
get_service_settings }, // CONTEXT_SERVICE_CONFIG_STANDALONE
};

/*
Expand Down Expand Up @@ -171,6 +174,7 @@ static void get_help_window()
break;

case CONTEXT_SERVICE_CONFIG:
case CONTEXT_SERVICE_CONFIG_STANDALONE:
msg = " This view list the connection/service settings. Use it wisely !\n"
" /!\\ WARNING: Setting IPv4/6 'Method' to 'off' can block future connections to this service.\n"
" You can modify underlined settings. Some settings require arrays of strings. Those have the following format: '[ \"string\", ... ]'.\n"
Expand All @@ -185,6 +189,7 @@ static void get_help_window()
case CONTEXT_SERVICES:
msg = " This view list services the technology can connect to.\n"
" 'f' at the start of the line means that this service has 'Favorite' = True\n"
" * Press 's' to configure the service\n"
" * Press 'r' to remove saved information on a service\n"
" * Press 'Return'/'Enter' to connect\n"
" * Press 'F5' to force a refresh\n"
Expand Down Expand Up @@ -437,12 +442,13 @@ static void exec_action(struct userptr_data *data)
}

/*
* Free the current context and execute func_back(). Also refresh the popup (if
* it exists)
* Free the current context and execute func_back().
*/
static void exec_back(void)
{
context_free_userptr_data();
if (context.current_context != CONTEXT_SERVICE_CONFIG_STANDALONE)
context_free_userptr_data();

context_actions[context.current_context].func_free();
context_actions[context.current_context].func_back();
}
Expand All @@ -453,7 +459,7 @@ static void exec_back(void)
*/
static void action_on_cmd_callback(struct json_object *jobj)
{
struct json_object *data;
struct json_object *data, *tmp, *array;
const char *cmd_name;

json_object_object_get_ex(jobj, key_command_data, &data);
Expand All @@ -469,7 +475,14 @@ static void action_on_cmd_callback(struct json_object *jobj)
else if (strcmp(key_engine_get_state, cmd_name) == 0)
__renderers_state(data);

else
else if (strcmp(key_engine_get_service, cmd_name) == 0) {
tmp = json_object_new_object();
array = json_object_new_array();
json_object_array_add(array, data);
json_object_object_add(tmp, key_services, array);
__renderers_services(tmp);

} else
print_info_in_footer(true, "Unknown command called");
}

Expand Down Expand Up @@ -991,6 +1004,7 @@ static void scan_tech(const char *tech_dbus_name)

cmd = json_object_new_object();
tmp = json_object_new_object();

json_object_object_add(tmp, key_technology,
json_object_new_string(tech_dbus_name));
json_object_object_add(cmd, key_command,
Expand Down Expand Up @@ -1023,6 +1037,30 @@ static void remove_service(struct userptr_data *data)
report_error();
}

/*
* Asks for the complete information on the current service (identified by
* context.serv->dbus_name).
*/
static void get_service_settings(void)
{
struct json_object *cmd, *tmp;

if (!context.serv->dbus_name)
return;

cmd = json_object_new_object();
tmp = json_object_new_object();

json_object_object_add(cmd, key_command,
json_object_new_string(key_engine_get_service));
json_object_object_add(tmp, key_service,
json_object_new_string(context.serv->dbus_name));
json_object_object_add(cmd, key_command_data, tmp);

if (engine_query(cmd) == -EINVAL)
report_error();
}

/*
* Return the position of the previous label suffixed with ".Configuration".
*/
Expand Down Expand Up @@ -1124,6 +1162,8 @@ static void modify_service_config(void)
struct json_object *options = json_object_new_object();
struct json_object *tmp;
char *key_str;
const char *are_obj[] = { key_serv_ipv4_config, key_serv_ipv6_config,
key_serv_proxy_config };

for (i = 0; main_fields[i]; i++) {
if (!((unsigned)field_opts(main_fields[i]) & O_EDIT))
Expand Down Expand Up @@ -1151,6 +1191,15 @@ static void modify_service_config(void)
}
}

// Check if the IPv4, IPv6 and Proxy Configurations are objects (connman
// sometimes send crappy data).
for (i = 0; i < 3; i++) {
json_object_object_get_ex(options, are_obj[i], &tmp);

if (tmp && json_object_is_type(tmp, json_type_object) == FALSE)
json_object_object_del(options, are_obj[i]);
}

json_object_object_add(cmd_data, key_service,
json_object_new_string(context.serv->dbus_name));
json_object_object_add(cmd_data, key_options, options);
Expand Down Expand Up @@ -1302,6 +1351,7 @@ static void exec_action_context_service_config(int ch)
static void exec_action_context_services(int ch)
{
ITEM *item;
struct userptr_data *userptr;

switch (ch) {
case KEY_DOWN:
Expand Down Expand Up @@ -1332,6 +1382,17 @@ static void exec_action_context_services(int ch)
print_info_in_footer(false, "Scanning %s...",
context.tech->pretty_name);
break;

case 's':
item = current_item(main_menu);
userptr = item_userptr(item);

if (!userptr)
break;

context.serv->dbus_name = strdup(userptr->dbus_name);
get_service_settings();
break;
}
}

Expand Down Expand Up @@ -1401,6 +1462,7 @@ void ncurses_action(void)
break;

case CONTEXT_SERVICE_CONFIG:
case CONTEXT_SERVICE_CONFIG_STANDALONE:
exec_action_context_service_config(ch);
break;

Expand Down
4 changes: 2 additions & 2 deletions ncurses_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ void refresh_home_msg(void)
void refresh_services_msg(void)
{
print_info_in_footer(false, "'F5' to refresh network list, "
"'F6' to force a scan");
print_info_in_footer2(false, "'r' to remove favorite, 'Esc' to get "
"'F6' to force a scan, 's' to configure");
print_info_in_footer2(false, "'r' to remove favorite, 'Esc' to get"
"back, 'F1' for help");
}

Expand Down
20 changes: 13 additions & 7 deletions renderers.c
Original file line number Diff line number Diff line change
Expand Up @@ -479,11 +479,9 @@ static void render_fields_from_jobj(int longest_key_len, int *pos,
* connman has on a service, some of the settings can be modified. See
* connman/doc/services-api.txt for more informations.
* The first label contain the service name in the user pointer.
* @param tech_array Array of json objects representing technologies
* @param serv_array Array of json objects representing services
*/
static void renderers_service_config(struct json_object *tech_array,
struct json_object *serv_array)
static void renderers_service_config(struct json_object *serv_array)
{
struct json_object *serv_dict, *tmp, *tmp_val;
int longest_key_len, i, k;
Expand Down Expand Up @@ -780,14 +778,21 @@ void __renderers_services(struct json_object *jobj)

json_object_object_get_ex(jobj, key_technology, &tech_array);
json_object_object_get_ex(jobj, key_services, &serv_array);
werase(win_body);
box(win_body, 0, 0);

if (!tech_array && serv_array) {
renderers_service_config(json_object_array_get_idx(serv_array, 0));
context.current_context = CONTEXT_SERVICE_CONFIG_STANDALONE;
__renderers_services_config_paging();
return;
}

if (tech_array == NULL || serv_array == NULL)
return;

tech_dict = json_object_array_get_idx(tech_array, 1);
nb_pages = 0;
werase(win_body);
box(win_body, 0, 0);

if (tech_is_connected(tech_dict)) {
if (!serv_array || json_object_array_length(serv_array) == 0) {
Expand All @@ -796,15 +801,16 @@ void __renderers_services(struct json_object *jobj)
}

// propose modifications of service parameters
renderers_service_config(tech_array,
json_object_array_get_idx(serv_array, 0));
renderers_service_config(json_object_array_get_idx(serv_array, 0));
context.current_context = CONTEXT_SERVICE_CONFIG;
__renderers_services_config_paging();
} else {
// propose to connect to one service
renderers_services(serv_array);
context.current_context = CONTEXT_SERVICES;
}

wrefresh(win_body);
}

/*
Expand Down
2 changes: 1 addition & 1 deletion renderers.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct userptr_data {
};

// Different contexts we can be in
typedef enum {CONTEXT_HOME, CONTEXT_SERVICE_CONFIG, CONTEXT_SERVICES} context_t;
typedef enum {CONTEXT_HOME, CONTEXT_SERVICE_CONFIG, CONTEXT_SERVICES, CONTEXT_SERVICE_CONFIG_STANDALONE} context_t;

// This keep track of the execution context, the cursor position and current
// service and technology user pointers.
Expand Down

0 comments on commit 1b5357f

Please sign in to comment.