summaryrefslogtreecommitdiffstats
path: root/binding
diff options
context:
space:
mode:
authorMatt Ranostay <matt.ranostay@konsulko.com>2018-08-10 17:24:47 -0700
committerMatt Ranostay <matt.ranostay@konsulko.com>2018-08-10 19:23:51 -0700
commitd877f551b065f8722e48d9bb38d9326361f3eedc (patch)
tree3a11283938fb620a04419e6ea4555d8e8600559e /binding
parent43d8cb57bce35be9c3bd316752d3cc63162af83a (diff)
binding: networking: remove global state variableflounder_5.99.3flounder/5.99.35.99.3
Switch to the AFB framework v3 functionality to save userdata pointers versus using a global definition. Bug-AGL: SPEC-1660 Change-Id: I71752d3e392b4d8bb00e394f44f414813b83a85d Signed-off-by: Matt Ranostay <matt.ranostay@konsulko.com>
Diffstat (limited to 'binding')
-rw-r--r--binding/network-api.c45
1 files changed, 25 insertions, 20 deletions
diff --git a/binding/network-api.c b/binding/network-api.c
index 47dbfd0..6ee7510 100644
--- a/binding/network-api.c
+++ b/binding/network-api.c
@@ -37,8 +37,6 @@
#include "network-api.h"
#include "network-common.h"
-struct network_state *global_ns;
-
/**
* The global thread
*/
@@ -48,12 +46,18 @@ struct init_data {
GCond cond;
GMutex mutex;
gboolean init_done;
- struct network_state *ns; /* before setting global_ns */
+ afb_api_t api;
+ struct network_state *ns; /* before setting afb_api_set_userdata() */
int rc;
};
static void signal_init_done(struct init_data *id, int rc);
+static struct network_state *network_get_userdata(afb_req_t request) {
+ afb_api_t api = afb_req_get_api(request);
+ return afb_api_get_userdata(api);
+}
+
static void call_work_lock(struct network_state *ns)
{
g_mutex_lock(&ns->cw_mutex);
@@ -998,7 +1002,7 @@ static gpointer network_func(gpointer ptr)
/* note that we wait for agent registration to signal done */
- global_ns = ns;
+ afb_api_set_userdata(id->api, ns);
g_main_loop_run(loop);
g_main_loop_unref(ns->loop);
@@ -1006,7 +1010,7 @@ static gpointer network_func(gpointer ptr)
network_unregister_agent(ns);
network_cleanup(ns);
- global_ns = NULL;
+ afb_api_set_userdata(id->api, NULL);
return NULL;
@@ -1030,6 +1034,7 @@ static int init(afb_api_t api)
memset(id, 0, sizeof(*id));
id->init_done = FALSE;
id->rc = 0;
+ id->api = api;
g_cond_init(&id->cond);
g_mutex_init(&id->mutex);
@@ -1065,7 +1070,7 @@ static int init(afb_api_t api)
static void network_subscribe_unsubscribe(afb_req_t request,
gboolean unsub)
{
- struct network_state *ns = global_ns;
+ struct network_state *ns = network_get_userdata(request);
json_object *jresp = json_object_new_object();
const char *value;
afb_event_t event;
@@ -1114,7 +1119,7 @@ static void network_unsubscribe(afb_req_t request)
static void network_state(afb_req_t request)
{
- struct network_state *ns = global_ns;
+ struct network_state *ns = network_get_userdata(request);
GError *error = NULL;
json_object *jresp;
@@ -1130,7 +1135,7 @@ static void network_state(afb_req_t request)
static void network_offline(afb_req_t request)
{
- struct network_state *ns = global_ns;
+ struct network_state *ns = network_get_userdata(request);
GError *error = NULL;
json_object *jresp = NULL;
const char *value;
@@ -1170,7 +1175,7 @@ static void network_offline(afb_req_t request)
static void network_technologies(afb_req_t request)
{
- struct network_state *ns = global_ns;
+ struct network_state *ns = network_get_userdata(request);
json_object *jresp;
GError *error = NULL;
@@ -1188,7 +1193,7 @@ static void network_technologies(afb_req_t request)
static void network_services(afb_req_t request)
{
- struct network_state *ns = global_ns;
+ struct network_state *ns = network_get_userdata(request);
json_object *jresp;
GError *error = NULL;
@@ -1206,7 +1211,7 @@ static void network_services(afb_req_t request)
static void network_technology_set_powered(afb_req_t request,
gboolean powered)
{
- struct network_state *ns = global_ns;
+ struct network_state *ns = network_get_userdata(request);
GError *error = NULL;
const char *technology;
json_object *jpowered;
@@ -1267,7 +1272,7 @@ static void network_disable_technology(afb_req_t request)
static void network_scan_services(afb_req_t request)
{
- struct network_state *ns = global_ns;
+ struct network_state *ns = network_get_userdata(request);
GVariant *reply = NULL;
GError *error = NULL;
const char *technology;
@@ -1296,7 +1301,7 @@ static void network_scan_services(afb_req_t request)
static void network_move_service(afb_req_t request)
{
- struct network_state *ns = global_ns;
+ struct network_state *ns = network_get_userdata(request);
GVariant *reply = NULL;
GError *error = NULL;
const char *service;
@@ -1343,7 +1348,7 @@ static void network_move_service(afb_req_t request)
static void network_remove_service(afb_req_t request)
{
- struct network_state *ns = global_ns;
+ struct network_state *ns = network_get_userdata(request);
GVariant *reply = NULL;
GError *error = NULL;
const char *service;
@@ -1397,7 +1402,7 @@ out_free:
static void network_reset_counters(afb_req_t request)
{
- struct network_state *ns = global_ns;
+ struct network_state *ns = network_get_userdata(request);
GError *error = NULL;
const char *service;
struct call_work *cw;
@@ -1478,7 +1483,7 @@ out_free:
static void network_connect_service(afb_req_t request)
{
- struct network_state *ns = global_ns;
+ struct network_state *ns = network_get_userdata(request);
GError *error = NULL;
const char *service;
struct call_work *cw;
@@ -1516,7 +1521,7 @@ static void network_connect_service(afb_req_t request)
static void network_disconnect_service(afb_req_t request)
{
- struct network_state *ns = global_ns;
+ struct network_state *ns = network_get_userdata(request);
json_object *jresp;
GVariant *reply = NULL;
GError *error = NULL;
@@ -1546,7 +1551,7 @@ static void network_disconnect_service(afb_req_t request)
static void network_get_property(afb_req_t request)
{
- struct network_state *ns = global_ns;
+ struct network_state *ns = network_get_userdata(request);
json_object *jobj = afb_req_json(request);
const char *technology, *service;
const char *access_type;
@@ -1604,7 +1609,7 @@ static void network_get_property(afb_req_t request)
static void network_set_property(afb_req_t request)
{
- struct network_state *ns = global_ns;
+ struct network_state *ns = network_get_userdata(request);
json_object *jobj = afb_req_json(request);
const char *technology, *service;
const char *access_type;
@@ -1668,7 +1673,7 @@ static void network_set_property(afb_req_t request)
static void network_agent_response(afb_req_t request)
{
- struct network_state *ns = global_ns;
+ struct network_state *ns = network_get_userdata(request);
json_object *jobj = afb_req_json(request);
json_object *jfields;
const char *id_str;