From 7298ce428f8857b9f08df41edfe794f179e3d7e3 Mon Sep 17 00:00:00 2001 From: Matt Ranostay Date: Tue, 8 Aug 2017 11:50:42 -0700 Subject: binding: wifi: switch to v2 binding format Update functions and structure to use the new version 2 of the afm binder framework Bug-AGL: SPEC-816 SPEC-913 Change-Id: I4fafc4e2302991dc895a1938f88754ace1a6360e Signed-off-by: Matt Ranostay --- binding-wifi/agent.c | 26 +++++++------- binding-wifi/export.map | 2 +- binding-wifi/wifi-api.c | 88 ++++++++++++++++++++------------------------- binding-wifi/wifi-connman.c | 52 +++++++++++++-------------- binding-wifi/wifi-connman.h | 9 +---- 5 files changed, 80 insertions(+), 97 deletions(-) diff --git a/binding-wifi/agent.c b/binding-wifi/agent.c index 6b0f235..492b53f 100644 --- a/binding-wifi/agent.c +++ b/binding-wifi/agent.c @@ -52,7 +52,7 @@ static void handle_method_call(GDBusConnection *connection, const gchar *sender, //MyObject *myobj = user_data; if (g_strcmp0(method_name, "RequestInput") == 0) { - DEBUG(afbitf,"RequestInput method on Agent interface has been called\n"); + AFB_DEBUG("RequestInput method on Agent interface has been called\n"); invocation_passkey = invocation; @@ -79,25 +79,25 @@ static void handle_method_call(GDBusConnection *connection, const gchar *sender, ) ] */ - NOTICE(afbitf,"Passphrase requested for network : %s\n", object_path); + AFB_NOTICE("Passphrase requested for network : %s\n", object_path); (*password_callback)(0, object_path); } if (g_strcmp0(method_name, "ReportError") == 0) { - ERROR(afbitf,"ReportError method on Agent interface has een called\n"); + AFB_ERROR("ReportError method on Agent interface has een called\n"); gchar *error_string; // = NULL; gchar * object_path; g_variant_get(parameters, "(os)", &object_path, &error_string); - ERROR(afbitf, "Error %s for %s\n", error_string, object_path); + AFB_ERROR("Error %s for %s\n", error_string, object_path); if (g_strcmp0(error_string, "invalid-key") == 0) { - WARNING(afbitf, "Passkey is not correct.\n"); + AFB_WARNING( "Passkey is not correct.\n"); (*password_callback)(1, "invalid-key"); } @@ -110,7 +110,7 @@ GError* sendPasskey(gchar *passkey) { GVariantBuilder *builder; GVariant *value = NULL; - NOTICE(afbitf, "Passkey to send: %s\n", passkey); + AFB_NOTICE("Passkey to send: %s\n", passkey); builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); @@ -158,7 +158,7 @@ static void test_signal_handler (GDBusConnection *connection, const gchar *sende else if (g_strcmp0(signal_name, "BSSAdded") == 0) { (*wifiListChanged_callback)(2, "BSSAdded"); } - else WARNING(afbitf,"unhandled signal %s %s %s, %s", sender_name, object_path, interface_name, signal_name); + else AFB_WARNING("unhandled signal %s %s %s, %s", sender_name, object_path, interface_name, signal_name); } @@ -217,8 +217,8 @@ GError* create_agent(GDBusConnection *connection) { err = pthread_create((&tid[0]), NULL, register_agent, NULL); if (err != 0) { - ERROR(afbitf,"\ncan't create thread :[%d]", err); - ERROR(afbitf,"Fatal error!\n\n"); + AFB_ERROR("\ncan't create thread :[%d]", err); + AFB_ERROR("Fatal error!\n\n"); return NULL; } @@ -237,12 +237,12 @@ GError* create_agent(GDBusConnection *connection) { DBUS_REPLY_TIMEOUT, NULL, &error); if (error) { - ERROR(afbitf,"error: %d:%s\n", error->code, error->message); + AFB_ERROR("error: %d:%s\n", error->code, error->message); return error; } else { - INFO(afbitf,"Agent registered\n"); + AFB_INFO("Agent registered\n"); return NULL; } @@ -267,11 +267,11 @@ GError* stop_agent(GDBusConnection *connection) { DBUS_REPLY_TIMEOUT, NULL, &error); if (error) { - ERROR(afbitf, "error: %d:%s\n", error->code, error->message); + AFB_ERROR("error: %d:%s\n", error->code, error->message); return error; } else { - DEBUG(afbitf,"Agent unregistered\n"); + AFB_DEBUG("Agent unregistered\n"); return NULL; } diff --git a/binding-wifi/export.map b/binding-wifi/export.map index 0ef1ac7..eea0d7b 100644 --- a/binding-wifi/export.map +++ b/binding-wifi/export.map @@ -1 +1 @@ -{ global: afbBindingV1Register; local: *; }; +{ global: afbBindingV2*; local: *; }; diff --git a/binding-wifi/wifi-api.c b/binding-wifi/wifi-api.c index 30552e8..aa008ce 100644 --- a/binding-wifi/wifi-api.c +++ b/binding-wifi/wifi-api.c @@ -27,6 +27,8 @@ #include #include #include + +#define AFB_BINDING_VERSION 2 #include #include "wifi-api.h" @@ -61,7 +63,7 @@ static void insertpasskey(struct afb_req request) { /* retrieves the argument, expects passkey string */ passkey_from_user = afb_req_value(request, "passkey"); - NOTICE(afbitf, "Passkey inserted: %s\n", passkey_from_user); + AFB_NOTICE("Passkey inserted: %s\n", passkey_from_user); sendPasskey(passkey_from_user); @@ -70,7 +72,7 @@ static void insertpasskey(struct afb_req request) { registerPasskey(passkey); } else { - NOTICE(afbitf, "Please enter the passkey first\n"); + AFB_NOTICE("Please enter the passkey first\n"); } } @@ -148,8 +150,8 @@ static void eventpush (struct afb_req request) * */ void ask_for_passkey(int number, const char* asciidata) { - NOTICE(afbitf, "Passkey for %s network needed.", asciidata); - NOTICE(afbitf, "Sending event."); + AFB_NOTICE("Passkey for %s network needed.", asciidata); + AFB_NOTICE("Sending event."); json_object *jresp = json_object_new_object(); @@ -357,7 +359,7 @@ static void scan_result(struct afb_req request) /*AFB_SESSION_CHECK*/ json_object_object_add(jresp, "IPAddress", jstring3); json_object_object_add(jresp, "State", jstring4); - DEBUG(afbitf, "The object json: %s\n", json_object_to_json_string(jresp)); + AFB_DEBUG("The object json: %s\n", json_object_to_json_string(jresp)); /*input each scan result into my_array*/ json_object_array_add(my_array, jresp); @@ -432,7 +434,7 @@ static void connect(struct afb_req request) { else { network_index = atoi(network); - NOTICE(afbitf,"Joining network number %d\n", network_index); + AFB_NOTICE("Joining network number %d\n", network_index); } @@ -442,14 +444,14 @@ static void connect(struct afb_req request) { if (item == NULL) { //Index starts from 1 - ERROR(afbitf, "Network with number %d not found.\n", network_index + 1); + AFB_ERROR("Network with number %d not found.\n", network_index + 1); //TODO:better error message afb_req_fail(request, "failed", "bad arguments"); } else { wifiProfileToConnect = (struct wifi_profile_info *) item; - INFO(afbitf, "Name: %s, strength: %d, %s\n", wifiProfileToConnect->ESSID, + AFB_INFO("Name: %s, strength: %d, %s\n", wifiProfileToConnect->ESSID, wifiProfileToConnect->Strength, wifiProfileToConnect->NetworkPath); } @@ -498,7 +500,7 @@ static void disconnect(struct afb_req request) { else { network_index = atoi(network); - NOTICE(afbitf, "Joining network number %d\n", network_index); + AFB_NOTICE("Joining network number %d\n", network_index); } @@ -507,14 +509,14 @@ static void disconnect(struct afb_req request) { if (item == NULL) { //Index starts from 1 - ERROR(afbitf,"Network with number %d not found.\n", network_index + 1); + AFB_ERROR("Network with number %d not found.\n", network_index + 1); //TODO:better error message afb_req_fail(request, "failed", "bad arguments"); } else { wifiProfileToConnect = (struct wifi_profile_info *) item; - INFO(afbitf, "Name: %s, strength: %d, %s\n", wifiProfileToConnect->ESSID, + AFB_INFO("Name: %s, strength: %d, %s\n", wifiProfileToConnect->ESSID, wifiProfileToConnect->Strength, wifiProfileToConnect->NetworkPath); } @@ -546,18 +548,18 @@ static void status(struct afb_req request) { json_object_object_add(jresp, "Power", json_object_new_string("OFF")); //json_object_object_add(jresp, "Connection", json_object_new_string("Disconnected")); - DEBUG(afbitf, "Wi-Fi OFF\n"); + AFB_DEBUG("Wi-Fi OFF\n"); } else {/*Wi-Fi is ON*/ json_object_object_add(jresp, "Power", json_object_new_string("ON")); if (status->connected == 0) {/*disconnected*/ json_object_object_add(jresp, "Connection", json_object_new_string("Disconnected")); - DEBUG(afbitf, "Wi-Fi ON - Disconnected \n"); + AFB_DEBUG("Wi-Fi ON - Disconnected \n"); } else {/*Connected*/ json_object_object_add(jresp, "Connection", json_object_new_string("Connected")); - DEBUG(afbitf, "Wi-Fi ON - Connected \n"); + AFB_DEBUG("Wi-Fi ON - Connected \n"); } } afb_req_success(request, jresp, "Wi-Fi - Connection Status Checked"); @@ -622,7 +624,7 @@ static int event_add(const char *tag, const char *name) strcpy(e->tag, tag); /* make the event */ - e->event = afb_daemon_make_event(afbitf->daemon, name); + e->event = afb_daemon_make_event(name); if (!e->event.closure) { free(e); return -1; } /* link */ @@ -747,43 +749,31 @@ static void eventunsub (struct afb_req request) /* * array of the verbs exported to afb-daemon */ -static const struct afb_verb_desc_v1 binding_verbs[] = { +static const struct afb_verb_v2 binding_verbs[] = { /* VERB'S NAME SESSION MANAGEMENT FUNCTION TO CALL SHORT DESCRIPTION */ -{ .name = "activate", .session = AFB_SESSION_NONE, .callback = activate, .info = "Activate Wi-Fi" }, -{ .name = "deactivate", .session = AFB_SESSION_NONE, .callback = deactivate, .info ="Deactivate Wi-Fi" }, -{ .name = "scan", .session = AFB_SESSION_NONE, .callback = scan, .info ="Scanning Wi-Fi" }, -{ .name = "scan_result", .session = AFB_SESSION_NONE, .callback = scan_result, .info = "Get scan result Wi-Fi" }, -{ .name = "connect", .session = AFB_SESSION_NONE, .callback = connect, .info ="Connecting to Access Point" }, -{ .name = "status", .session = AFB_SESSION_NONE, .callback = status, .info ="Check connection status" }, -{ .name = "disconnect", .session = AFB_SESSION_NONE, .callback = disconnect, .info ="Disconnecting connection" }, -{ .name = "reconnect", .session = AFB_SESSION_NONE, .callback = reconnect, .info ="Reconnecting to Access Point" }, -{ .name = "insertpasskey",.session = AFB_SESSION_NONE, .callback = insertpasskey, .info ="inputs the passkey after it has been requsted"}, -{ .name = "eventadd", .session = AFB_SESSION_NONE, .callback = eventadd, .info ="adds the event of 'name' for the 'tag'"}, -{ .name = "eventsub", .session = AFB_SESSION_NONE, .callback = eventsub, .info ="unsubscribes to the event of 'tag'"}, -{ .name = "eventpush", .session = AFB_SESSION_NONE, .callback = eventpush, .info ="pushes the event of 'tag' with the 'data'"}, -{ .name = "eventunsub", .session = AFB_SESSION_NONE, .callback = eventunsub, .info ="unsubscribes to the event of 'tag'"}, -{ .name = "eventdel", .session = AFB_SESSION_NONE, .callback = eventdel, .info ="deletes the event of 'tag'"}, - -{ .name = NULL } /* marker for end of the array */ +{ .verb = "activate", .session = AFB_SESSION_NONE, .callback = activate, .info = "Activate Wi-Fi" }, +{ .verb = "deactivate", .session = AFB_SESSION_NONE, .callback = deactivate, .info ="Deactivate Wi-Fi" }, +{ .verb = "scan", .session = AFB_SESSION_NONE, .callback = scan, .info ="Scanning Wi-Fi" }, +{ .verb = "scan_result", .session = AFB_SESSION_NONE, .callback = scan_result, .info = "Get scan result Wi-Fi" }, +{ .verb = "connect", .session = AFB_SESSION_NONE, .callback = connect, .info ="Connecting to Access Point" }, +{ .verb = "status", .session = AFB_SESSION_NONE, .callback = status, .info ="Check connection status" }, +{ .verb = "disconnect", .session = AFB_SESSION_NONE, .callback = disconnect, .info ="Disconnecting connection" }, +{ .verb = "reconnect", .session = AFB_SESSION_NONE, .callback = reconnect, .info ="Reconnecting to Access Point" }, +{ .verb = "insertpasskey",.session = AFB_SESSION_NONE, .callback = insertpasskey, .info ="inputs the passkey after it has been requsted"}, +{ .verb = "eventadd", .session = AFB_SESSION_NONE, .callback = eventadd, .info ="adds the event of 'name' for the 'tag'"}, +{ .verb = "eventsub", .session = AFB_SESSION_NONE, .callback = eventsub, .info ="unsubscribes to the event of 'tag'"}, +{ .verb = "eventpush", .session = AFB_SESSION_NONE, .callback = eventpush, .info ="pushes the event of 'tag' with the 'data'"}, +{ .verb = "eventunsub", .session = AFB_SESSION_NONE, .callback = eventunsub, .info ="unsubscribes to the event of 'tag'"}, +{ .verb = "eventdel", .session = AFB_SESSION_NONE, .callback = eventdel, .info ="deletes the event of 'tag'"}, + +{ } /* marker for end of the array */ }; /* * description of the binding for afb-daemon */ -static const struct afb_binding binding_description = { -/* description conforms to VERSION 1 */ -.type = AFB_BINDING_VERSION_1, .v1 = { /* fills the v1 field of the union when AFB_BINDING_VERSION_1 */ -.prefix = "wifi-manager", /* the API name (or binding name or prefix) */ -.info = "wifi API", /* short description of of the binding */ -.verbs = binding_verbs /* the array describing the verbs of the API */ -} }; - -/* - * activation function for registering the binding called by afb-daemon - */ -const struct afb_binding *afbBindingV1Register( - const struct afb_binding_interface *itf) { - afbitf = itf; // records the interface for accessing afb-daemon - return &binding_description; // returns the description of the binding -} - +const struct afb_binding_v2 afbBindingV2 = { + .api = "wifi-manager", /* the API name (or binding name or prefix) */ + .specification = "wifi API", /* short description of of the binding */ + .verbs = binding_verbs /* the array describing the verbs of the API */ +}; diff --git a/binding-wifi/wifi-connman.c b/binding-wifi/wifi-connman.c index 924898e..a7673b4 100644 --- a/binding-wifi/wifi-connman.c +++ b/binding-wifi/wifi-connman.c @@ -106,7 +106,7 @@ int wifi_state(struct wifiStatus *status) { connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); if (connection == NULL) { - ERROR(afbitf,"Cannot connect to D-Bus, %s", error->message); + AFB_ERROR("Cannot connect to D-Bus, %s", error->message); return -1; } message = g_dbus_connection_call_sync(connection, CONNMAN_SERVICE, @@ -114,7 +114,7 @@ int wifi_state(struct wifiStatus *status) { NULL, NULL, G_DBUS_CALL_FLAGS_NONE, DBUS_REPLY_TIMEOUT, NULL, &error); if (message == NULL) { - ERROR(afbitf,"Error %s while calling GetProperties method", error->message); + AFB_ERROR("Error %s while calling GetProperties method", error->message); return -1; } g_variant_get(message, "(a{sv})", &array); @@ -148,7 +148,7 @@ GError* do_wifiActivate() { connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); if (connection == NULL) { - ERROR(afbitf,"Cannot connect to D-Bus, %s", error->message); + AFB_ERROR("Cannot connect to D-Bus, %s", error->message); return error; } @@ -164,13 +164,13 @@ GError* do_wifiActivate() { params, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, &error); if (error) { - ERROR(afbitf,"Error %s while calling SetProperty method", error->message); + AFB_ERROR("Error %s while calling SetProperty method", error->message); return error; } else { - NOTICE(afbitf,"Power ON succeeded\n"); + AFB_NOTICE("Power ON succeeded\n"); return NULL; } @@ -185,7 +185,7 @@ GError* do_wifiDeactivate() { /*connection = gdbus_conn->connection;*/ connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); if (connection == NULL) { - ERROR(afbitf,"Cannot connect to D-Bus, %s", error->message); + AFB_ERROR("Cannot connect to D-Bus, %s", error->message); return error; } @@ -193,7 +193,7 @@ GError* do_wifiDeactivate() { error = stop_agent(connection); if (error) { - WARNING(afbitf, "Error while unregistering the agent, ignoring."); + AFB_WARNING( "Error while unregistering the agent, ignoring."); } @@ -202,13 +202,13 @@ GError* do_wifiDeactivate() { params, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, &error); if (error) { - ERROR(afbitf,"Error %s while calling SetProperty method", error->message); + AFB_ERROR("Error %s while calling SetProperty method", error->message); return error; } else { - NOTICE(afbitf, "Power OFF succeeded\n"); + AFB_NOTICE( "Power OFF succeeded\n"); return NULL; } } @@ -220,7 +220,7 @@ GError* do_wifiScan() { /*connection = gdbus_conn->connection;*/ connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); if (connection == NULL) { - ERROR(afbitf,"Cannot connect to D-Bus, %s", error->message); + AFB_ERROR("Cannot connect to D-Bus, %s", error->message); return error; } @@ -228,13 +228,13 @@ GError* do_wifiScan() { CONNMAN_WIFI_TECHNOLOGY_PREFIX, CONNMAN_TECHNOLOGY_INTERFACE, "Scan", NULL, NULL, G_DBUS_CALL_FLAGS_NONE, DBUS_REPLY_TIMEOUT, NULL, NULL, &error); if (error) { - ERROR(afbitf,"Error %s while calling Scan method", error->message); + AFB_ERROR("Error %s while calling Scan method", error->message); return error; } else { - INFO(afbitf, "Scan succeeded\n"); + AFB_INFO( "Scan succeeded\n"); return NULL; } } @@ -251,7 +251,7 @@ GError* do_displayScan(GSList **wifi_list) { /*connection = gdbus_conn->connection;*/ connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); if (connection == NULL) { - ERROR(afbitf,"Cannot connect to D-Bus, %s", error->message); + AFB_ERROR("Cannot connect to D-Bus, %s", error->message); return error; } message = g_dbus_connection_call_sync(connection, CONNMAN_SERVICE, @@ -259,7 +259,7 @@ GError* do_displayScan(GSList **wifi_list) { G_DBUS_CALL_FLAGS_NONE, DBUS_REPLY_TIMEOUT, NULL, &error); if (message == NULL) { - ERROR(afbitf,"Error %s while calling GetServices method", error->message); + AFB_ERROR("Error %s while calling GetServices method", error->message); return error; } g_variant_get(message, "(a(oa{sv}))", &array); @@ -271,12 +271,12 @@ GError* do_displayScan(GSList **wifi_list) { extract_values(content, wifiProfile); wifiProfile->NetworkPath = g_try_malloc0(strlen(object)); strcpy(wifiProfile->NetworkPath, object); - DEBUG(afbitf, + AFB_DEBUG( "SSID= %s, security= %s, path= %s, Strength= %d, wps support= %d\n", wifiProfile->ESSID, wifiProfile->Security.sec_type, wifiProfile->NetworkPath, wifiProfile->Strength, wifiProfile->Security.wps_support); - DEBUG(afbitf, "method= %s, ip address= %s, netmask= %s\n", + AFB_DEBUG( "method= %s, ip address= %s, netmask= %s\n", wifiProfile->wifiNetwork.method, wifiProfile->wifiNetwork.IPaddress, wifiProfile->wifiNetwork.netmask); @@ -291,7 +291,7 @@ GError* do_displayScan(GSList **wifi_list) { GError* do_connectNetwork(gchar *networkPath) { - NOTICE(afbitf, "Connecting to: %s\n", networkPath); + AFB_NOTICE( "Connecting to: %s\n", networkPath); GVariant *message = NULL; GError *error = NULL; @@ -307,10 +307,10 @@ GError* do_connectNetwork(gchar *networkPath) { //TODO: do we need retunrn value in message if (error) { - ERROR(afbitf,"Error %s while calling Connect method", error->message); + AFB_ERROR("Error %s while calling Connect method", error->message); return error; } else { - INFO(afbitf,"Connection succeeded\n"); + AFB_INFO("Connection succeeded\n"); return NULL; } @@ -318,7 +318,7 @@ GError* do_connectNetwork(gchar *networkPath) { GError* do_disconnectNetwork(gchar *networkPath) { - NOTICE(afbitf, "Connecting to: %s\n", networkPath); + AFB_NOTICE( "Connecting to: %s\n", networkPath); GVariant *message = NULL; GError *error = NULL; @@ -327,7 +327,7 @@ GError* do_disconnectNetwork(gchar *networkPath) { connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); if (connection == NULL) { - ERROR(afbitf,"Cannot connect to D-Bus, %s", error->message); + AFB_ERROR("Cannot connect to D-Bus, %s", error->message); return error; } @@ -339,10 +339,10 @@ GError* do_disconnectNetwork(gchar *networkPath) { //TODO: do we need return value in message if (error) { - ERROR(afbitf,"Error %s while calling Disconnect method", error->message); + AFB_ERROR("Error %s while calling Disconnect method", error->message); return error; } else { - INFO(afbitf,"Disconnection succeeded\n"); + AFB_INFO("Disconnection succeeded\n"); return NULL; } @@ -350,7 +350,7 @@ GError* do_disconnectNetwork(gchar *networkPath) { void registerPasskey(gchar *passkey) { - INFO(afbitf,"Passkey: %s\n", passkey); + AFB_INFO("Passkey: %s\n", passkey); sendPasskey(passkey); @@ -373,7 +373,7 @@ GError* setHMIStatus(enum wifiStates state) { connection = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error); if (connection == NULL) { - ERROR(afbitf,"Cannot connect to D-Bus, %s", error->message); + AFB_ERROR("Cannot connect to D-Bus, %s", error->message); return error; } @@ -385,7 +385,7 @@ GError* setHMIStatus(enum wifiStates state) { DBUS_REPLY_TIMEOUT, NULL, &error); if (error) { - ERROR(afbitf,"Error %s while setting up the status icon", error->message); + AFB_ERROR("Error %s while setting up the status icon", error->message); return error; } else { diff --git a/binding-wifi/wifi-connman.h b/binding-wifi/wifi-connman.h index dfc0d5b..14d4f32 100644 --- a/binding-wifi/wifi-connman.h +++ b/binding-wifi/wifi-connman.h @@ -21,20 +21,13 @@ #include #include +#define AFB_BINDING_VERSION 2 #include #ifdef __cplusplus extern "C" { #endif -// - - -/* - * the interface to afb-daemon - */ -const struct afb_binding_interface *afbitf; - /** Maximum Profile Count */ #define CONNMAN_MAX_BUFLEN 512 -- cgit 1.2.3-korg