Add GetKnownServices api to connaman
PATCH 1/1 Add GetKnownServices api to connaman
Add a way to retrieve all the networks that were configured using connman and not all the ones visible
--- client/commands.c | 14 ++++++++++ src/connman.h | 1 + src/manager.c | 23 +++++++++++++++++ src/service.c | 61 ++++++++++++++++++++++++++++++++++++++++++++ tools/manager-api.c | 33 ++++++++++++++++++++++++ tools/session-test.h | 1 + 6 files changed, 133 insertions(+)
client/commands.c +14 -0
@@ -420,6 +420,18 @@ static int cmd_services(char *args[], int num, struct connman_option *options) object_properties, path, NULL, NULL); } +static int cmd_known_services (char *args[],int num,struct connman_option *options) +{ +if (num >1 ) +return -E2BIG ; + +return __connmanctl_dbus_method_call (connection, +CONNMAN_SERVICE ,CONNMAN_PATH , +"net.connman.Manager" , +"GetKnownServices" , + services_list,NULL ,NULL ,NULL ); +} +static int cmd_peers (char *args[],int num,struct connman_option *options) {char *peer_name =NULL ;
@@ -2808,6 +2820,8 @@ static const struct { "Display tethering clients", NULL }, {"services" ,"[<service>]" , service_options, cmd_services, "Display services", lookup_service_arg }, + { "known-services", NULL, NULL, cmd_known_services, + "Display known services", NULL }, { "peers", "[peer]", NULL, cmd_peers, "Display peers", lookup_peer_arg }, { "scan", "<technology>", NULL, cmd_scan,
src/connman.h +1 -0
@@ -682,6 +682,7 @@ int __connman_service_move(struct connman_service *service, struct connman_service *target, bool before);int __connman_service_load_modifiable (struct connman_service *service); +void __connman_known_service_list_struct (DBusMessageIter *iter);void __connman_service_list_struct (DBusMessageIter *iter); int __connman_service_compare(const struct connman_service *a,
src/manager.c +23 -0
@@ -175,6 +175,11 @@ static const struct connman_notifier technology_notifier = { .idle_state = idle_state, }; +static void append_known_service_structs (DBusMessageIter *iter,void *user_data) +{ +__connman_known_service_list_struct (iter); +} +static void append_service_structs (DBusMessageIter *iter,void *user_data) {__connman_service_list_struct (iter);
@@ -195,6 +200,21 @@ static DBusMessage *get_services(DBusConnection *conn,return reply; } +static DBusMessage *get_known_services (DBusConnection *conn, +DBusMessage *msg,void *data) +{ +DBusMessage *reply; + + reply =dbus_message_new_method_return (msg); +if (!reply) +return NULL ; + +__connman_dbus_append_objpath_dict_array (reply, + append_known_service_structs,NULL ); + +return reply; +} +static void append_peer_structs (DBusMessageIter *iter,void *user_data) {__connman_peer_list_struct (iter);
@@ -534,6 +554,9 @@ static const GDBusMethodTable manager_methods[] = { {GDBUS_DEPRECATED_METHOD ("RemoveProvider" , GDBUS_ARGS({ "provider", "o" }), NULL, remove_provider) }, + { GDBUS_METHOD("GetKnownServices", + NULL, GDBUS_ARGS({"knownServices", "a(oa{sv})" }), + get_known_services) }, { GDBUS_METHOD("GetServices", NULL, GDBUS_ARGS({ "services", "a(oa{sv})" }), get_services) },
src/service.c +61 -0
67 lines not on this page · raw message
tools/manager-api.c +33 -0
@@ -64,6 +64,39 @@ static DBusMessage *set_property(DBusConnection *connection,return reply; } +DBusMessage *manager_get_known_services (DBusConnection *connection) +{ +DBusMessage *message, *reply; +DBusError error; + + message =dbus_message_new_method_call (CONNMAN_SERVICE , +CONNMAN_MANAGER_PATH , +CONNMAN_MANAGER_INTERFACE , +"GetKnownServices" ); + +if (!message) +return NULL ; + +dbus_error_init (&error); + + reply =dbus_connection_send_with_reply_and_block (connection, + message,-1 , &error); +if (!reply) { +if (dbus_error_is_set (&error)) { +LOG ("%s" , error.message); +dbus_error_free (&error); + }else { +LOG ("Failed to get known services" ); + } +dbus_message_unref (message); +return NULL ; + } + +dbus_message_unref (message); + +return reply; +} +DBusMessage *manager_get_services (DBusConnection *connection) {DBusMessage *message, *reply;
tools/session-test.h +1 -0
@@ -114,6 +114,7 @@ DBusMessage *session_disconnect(DBusConnection *connection, struct test_session *session);/* manager-api.c */ +DBusMessage *manager_get_known_services (DBusConnection *connection);DBusMessage *manager_get_services (DBusConnection *connection);DBusMessage *manager_get_properties (DBusConnection *connection); DBusMessage *manager_create_session(DBusConnection *connection,
Signature · 1 line
2.25.1
Hi Michael,
Quoted 4 lines · Michael Trimarchi
Add a way to retrieve all the networks that were configured using connman and not all the ones visible
Signed-off-by Michael Trimarchi <[email protected]>
We don't do the SoB in this project.
src/service.c static void append_struct(gpointer value, gpointer user_data) · line 2713
Quoted 6 lines
src/service.c +6
-0+void __connman_known_service_list_struct (DBusMessageIter *iter) +{ +gchar **services =NULL ; +gchar **service_id_parts =NULL ; +guint i =0 ; +struct connman_service *service =NULL ;
All pre-initialization are not needed.
src/service.c static void append_struct(gpointer value, gpointer user_data) · line 2715
Quoted 2 lines
src/service.c +2
-0+ +DBG ("listing known services" );
Please remove the DBG(). We have way to many these kind of tracing DBGs in the code which fill the log pretty unnecessary.
src/service.c static void append_struct(gpointer value, gpointer user_data) · line 2718
Quoted 3 lines
src/service.c +3
-0+ + services =connman_storage_get_services (); +if (services ==NULL )
if (!service)
src/service.c static void append_struct(gpointer value, gpointer user_data) · line 2723
Quoted 5 lines
src/service.c +5
-0+return ; + +for (i =0 ; i <g_strv_length (services); i++) { + service =connman_service_create (); +if (service ==NULL ) {
if (!service)
src/service.c static void append_struct(gpointer value, gpointer user_data) · line 2734
Quoted 11 lines
src/service.c +11
-0+connman_error ("connman_service_create() allocation failed" ); +return ; + } + + service->identifier =g_strdup (services[i]); + service_id_parts =g_strsplit (services[i],"_" ,-1 ); + +if (service_id_parts ==NULL ) { +g_free (service); +continue ; + }
IIRC, this check will always be false, as g_strsplit() will return a valid array or call abort() if allocation fails.
src/service.c static void append_struct(gpointer value, gpointer user_data) · line 2737
Quoted 3 lines
src/service.c +3
-0+ + service->type =__connman_service_string2type (service_id_parts[0 ]); + service->path =g_strdup_printf ("%s/service/%s" ,CONNMAN_PATH , service->identifier);
Do we really have to do this kind of path/identifier string generation here. Prefixing the path I understand but for the rest I thought we had do this in config.c/storage.c.
src/service.c static void append_struct(gpointer value, gpointer user_data) · line 2740
Quoted 3 lines
src/service.c +3
-0+if (service->type ==CONNMAN_SERVICE_TYPE_WIFI ) + service->security =__connman_service_string2security (service_id_parts[g_strv_length (service_id_parts) -1 ]); +
This looks a bit wierd formatted. Maybe introduce a local variable for the (...) bit and get it correctly indented.
src/service.c static void append_struct(gpointer value, gpointer user_data) · line 2744
Quoted 4 lines
src/service.c +4
-0+if (service->path ==NULL ) { +g_strfreev (service_id_parts); +continue ; + }
Same here, g_strdup_printf() will either succeed or call abort() in the ENOMEM case.
Review
Quoted 2 lines
(quoted diff) +2
-0+ + if (find_service(service->path) != NULL)
Just do a
if (find_service())
src/service.c static void append_struct(gpointer value, gpointer user_data) · line 2750
Quoted 4 lines
src/service.c +4
-0+ service->state = (find_service (service->path))->state; + +if (service->type ==CONNMAN_SERVICE_TYPE_ETHERNET && +find_service (service->path) !=NULL )
same here
src/service.c static void append_struct(gpointer value, gpointer user_data) · line 2753
Quoted 3 lines
src/service.c +3
-0+ service->name = (find_service (service->path))->name; + +if (0 !=service_load (service)) {
Please the other way around, we don't do Misra or whatever standard this recommends.
Quoted 40 lines
src/service.c +15
-0+connman_error ("service_load() returned error" ); +g_free (service); +g_strfreev (service_id_parts); +g_strfreev (services); +return ; + } + +append_struct_service (iter, append_dict_properties, service); +g_strfreev (service_id_parts); +g_free (service); + } + +g_strfreev (services); +} +void __connman_service_list_struct (DBusMessageIter *iter) {g_list_foreach (service_list, append_struct, iter);tools/manager-api.c +14
-0@@ -64,6 +64,39 @@ static DBusMessage *set_property(DBusConnection *connection,return reply; } +DBusMessage *manager_get_known_services (DBusConnection *connection) +{ +DBusMessage *message, *reply; +DBusError error; + + message =dbus_message_new_method_call (CONNMAN_SERVICE , +CONNMAN_MANAGER_PATH , +CONNMAN_MANAGER_INTERFACE , +"GetKnownServices" ); + +if (!message) +return NULL ; + +dbus_error_init (&error);
tools/manager-api.c static DBusMessage *set_property(DBusConnection *connection, · line 90
Quoted 10 lines
tools/manager-api.c +10
-0+ + reply =dbus_connection_send_with_reply_and_block (connection, + message,-1 , &error); +if (!reply) { +if (dbus_error_is_set (&error)) { +LOG ("%s" , error.message); +dbus_error_free (&error); + }else { +LOG ("Failed to get known services" ); + }
Drop these LOG() entries.
tools/manager-api.c static DBusMessage *set_property(DBusConnection *connection, · line 99
Quoted 9 lines
tools/manager-api.c +9
-0+dbus_message_unref (message); +return NULL ; + } + +dbus_message_unref (message); + +return reply; +} +
Please also update the documentation.
Thanks,
Daniel
Hi
Quoted 11 lines · Daniel Wagner
Hi Michael,
Quoted 4 lines · Michael Trimarchi
Add a way to retrieve all the networks that were configured using connman and not all the ones visible
Signed-off-by Michael Trimarchi <[email protected]>We don't do the SoB in this project.
Quoted 8 lines
src/service.c static void append_struct(gpointer value, gpointer user_data) · line 2713
Quoted 6 lines
src/service.c +6
-0+void __connman_known_service_list_struct (DBusMessageIter *iter) +{ +gchar **services =NULL ; +gchar **service_id_parts =NULL ; +guint i =0 ; +struct connman_service *service =NULL ;All pre-initialization are not needed.
Right
Quoted 7 lines
src/service.c static void append_struct(gpointer value, gpointer user_data) · line 2715
Quoted 3 lines
src/service.c +2
-0+ +DBG ("listing known services" );Please remove the
DBG(). We have way to many these kind of tracing DBGs in the code which fill the log pretty unnecessary.
Ok
Quoted 6 lines
src/service.c static void append_struct(gpointer value, gpointer user_data) · line 2718
Quoted 3 lines
src/service.c +3
-0+ + services =connman_storage_get_services (); +if (services ==NULL )if (!service)
Quoted 7 lines
src/service.c static void append_struct(gpointer value, gpointer user_data) · line 2723
Quoted 5 lines
src/service.c +5
-0+return ; + +for (i =0 ; i <g_strv_length (services); i++) { + service =connman_service_create (); +if (service ==NULL ) {if (!service)
Ok
Quoted 16 lines
src/service.c static void append_struct(gpointer value, gpointer user_data) · line 2734
Quoted 12 lines
src/service.c +11
-0+connman_error ("connman_service_create() allocation failed" ); +return ; + } + + service->identifier =g_strdup (services[i]); + service_id_parts =g_strsplit (services[i],"_" ,-1 ); + +if (service_id_parts ==NULL ) { +g_free (service); +continue ; + }IIRC, this check will always be false, as
g_strsplit()will return a valid array or callabort()if allocation fails.
I don't want an abort to be called, I will adjust it.
Quoted 7 lines
src/service.c static void append_struct(gpointer value, gpointer user_data) · line 2737
Quoted 3 lines
src/service.c +3
-0+ + service->type =__connman_service_string2type (service_id_parts[0 ]); + service->path =g_strdup_printf ("%s/service/%s" ,CONNMAN_PATH , service->identifier);Do we really have to do this kind of path/identifier string generation here. Prefixing the path I understand but for the rest I thought we had do this in
config.c/storage.c.
Ok, I will take a look
Quoted 7 lines
src/service.c static void append_struct(gpointer value, gpointer user_data) · line 2740
Quoted 4 lines
src/service.c +3
-0+if (service->type ==CONNMAN_SERVICE_TYPE_WIFI ) + service->security =__connman_service_string2security (service_id_parts[g_strv_length (service_id_parts) -1 ]); +This looks a bit wierd formatted. Maybe introduce a local variable for the (...) bit and get it correctly indented.
Ok
Quoted 8 lines
src/service.c static void append_struct(gpointer value, gpointer user_data) · line 2744
Quoted 5 lines
src/service.c +4
-0+if (service->path ==NULL ) { +g_strfreev (service_id_parts); +continue ; + }Same here,
g_strdup_printf()will either succeed or callabort()in the ENOMEM case.
Ok
I will adjust the rest. I have the patch to remove entries already tested and prepared. That one
will be an RFC because I have too much open questions
Michael
Quoted 89 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+ + if (find_service(service->path) != NULL)Just do a
if (find_service())src/service.c static void append_struct(gpointer value, gpointer user_data) · line 2750
Quoted 4 lines
src/service.c +4
-0+ service->state = (find_service (service->path))->state; + +if (service->type ==CONNMAN_SERVICE_TYPE_ETHERNET && +find_service (service->path) !=NULL )same here
src/service.c static void append_struct(gpointer value, gpointer user_data) · line 2753
Quoted 3 lines
src/service.c +3
-0+ service->name = (find_service (service->path))->name; + +if (0 !=service_load (service)) {Please the other way around, we don't do Misra or whatever standard this recommends.
Quoted 40 lines
src/service.c +15
-0+connman_error ("service_load() returned error" ); +g_free (service); +g_strfreev (service_id_parts); +g_strfreev (services); +return ; + } + +append_struct_service (iter, append_dict_properties, service); +g_strfreev (service_id_parts); +g_free (service); + } + +g_strfreev (services); +} +void __connman_service_list_struct (DBusMessageIter *iter) {g_list_foreach (service_list, append_struct, iter);tools/manager-api.c +14
-0@@ -64,6 +64,39 @@ static DBusMessage *set_property(DBusConnection *connection,return reply; } +DBusMessage *manager_get_known_services (DBusConnection *connection) +{ +DBusMessage *message, *reply; +DBusError error; + + message =dbus_message_new_method_call (CONNMAN_SERVICE , +CONNMAN_MANAGER_PATH , +CONNMAN_MANAGER_INTERFACE , +"GetKnownServices" ); + +if (!message) +return NULL ; + +dbus_error_init (&error);tools/manager-api.c static DBusMessage *set_property(DBusConnection *connection, · line 90
Quoted 10 lines
tools/manager-api.c +10
-0+ + reply =dbus_connection_send_with_reply_and_block (connection, + message,-1 , &error); +if (!reply) { +if (dbus_error_is_set (&error)) { +LOG ("%s" , error.message); +dbus_error_free (&error); + }else { +LOG ("Failed to get known services" ); + }Drop these
LOG()entries.tools/manager-api.c static DBusMessage *set_property(DBusConnection *connection, · line 99
Quoted 9 lines
tools/manager-api.c +9
-0+dbus_message_unref (message); +return NULL ; + } + +dbus_message_unref (message); + +return reply; +} +Please also update the documentation.
Thanks,
Daniel
Signature · 11 lines
Michael Nazzareno Trimarchi Co-Founder & Chief Executive Officer M. +39 347 913 2170 [email protected] __________________________________ Amarula Solutions BV Joop Geesinkweg 125, 1114 AB, Amsterdam, NL T. +31 (0)85 111 9172 [email protected] www.amarulasolutions.com
Quoted 8 lines · Michael Nazzareno Trimarchi
Quoted 8 lines
Quoted 7 lines
src/service.c +7
-0+ service->identifier =g_strdup (services[i]); + service_id_parts =g_strsplit (services[i],"_" ,-1 ); + +if (service_id_parts ==NULL ) { +g_free (service); +continue ; + }
Quoted 5 lines
Quoted 3 lines
IIRC, this check will always be false, as
g_strsplit()will return a valid array or callabort()if allocation fails.I don't want an abort to be called, I will adjust it.
Sorry, I didn't express it clearly, g_strsplit() will call abort(). This means the return value of g_str*() function always succeed, thus you don't have to check for NULL.
Hi Daniel
Quoted 14 lines · Daniel Wagner
Quoted 12 lines · Michael Nazzareno Trimarchi
Quoted 11 lines
src/service.c static void append_struct(gpointer value, gpointer user_data) · line 2734
Quoted 7 lines
src/service.c +7
-0+ service->identifier =g_strdup (services[i]); + service_id_parts =g_strsplit (services[i],"_" ,-1 ); + +if (service_id_parts ==NULL ) { +g_free (service); +continue ; + }IIRC, this check will always be false, as
g_strsplit()will return a valid array or callabort()if allocation fails.
Quoted 5 lines
Quoted 1 line
I don't want an abort to be called, I will adjust it.
Sorry, I didn't express it clearly,
g_strsplit()will callabort(). This means the return value of g_str*() function always succeed, thus you don't have to check for NULL.
Sorry, I have already checked the code in the project in the meantime . I understand
Michael
Signature · 11 lines
Michael Nazzareno Trimarchi Co-Founder & Chief Executive Officer M. +39 347 913 2170 [email protected] __________________________________ Amarula Solutions BV Joop Geesinkweg 125, 1114 AB, Amsterdam, NL T. +31 (0)85 111 9172 [email protected] www.amarulasolutions.com