summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--binding-wifi/wifi-api.c187
1 files changed, 47 insertions, 140 deletions
diff --git a/binding-wifi/wifi-api.c b/binding-wifi/wifi-api.c
index aa008ce..ba34c59 100644
--- a/binding-wifi/wifi-api.c
+++ b/binding-wifi/wifi-api.c
@@ -83,21 +83,21 @@ struct event
{
struct event *next;
struct afb_event event;
- char tag[1];
+ char name[];
};
-static struct event *events = 0;
+static struct event *events = NULL;
/**
* \internal
* \brief Helper function that searches for a specific event.
*
- * \param[in] tag of the event
+ * \param[in] name of the event
*/
-static struct event *event_get(const char *tag)
+static struct event *event_get(const char *name)
{
struct event *e = events;
- while(e && strcmp(e->tag, tag))
+ while(e && strcmp(e->name, name))
e = e->next;
return e;
}
@@ -106,40 +106,18 @@ static struct event *event_get(const char *tag)
* \internal
* \brief Helper function that actually pushes the event.
*
- * \param[in] tag of the event
+ * \param[in] name of the event
* \param[in] *args json object that contains data for the event
*
*/
-static int do_event_push(struct json_object *args, const char *tag)
+static int do_event_push(struct json_object *args, const char *name)
{
struct event *e;
- e = event_get(tag);
+ e = event_get(name);
return e ? afb_event_push(e->event, json_object_get(args)) : -1;
}
/**
- * \internal
- * \brief Pushes the event of 'tag' with the 'data
- *
- * \param[in] tag
- * \param[in] data
- *
- */
-static void eventpush (struct afb_req request)
-{
- const char *tag = afb_req_value(request, "tag");
- const char *data = afb_req_value(request, "data");
- json_object *object = data ? json_tokener_parse(data) : NULL;
-
- if (tag == NULL)
- afb_req_fail(request, "failed", "bad arguments");
- else if (0 > do_event_push(object, tag))
- afb_req_fail(request, "failed", "push error");
- else
- afb_req_success(request, NULL, NULL);
-}
-
-/**
*
* \brief Notify user that passkey is necessary.
*
@@ -568,60 +546,26 @@ static void status(struct afb_req request) {
}
}
-static void reconnect() {
- /*TBD*/
-}
-
-
-
/**
* \internal
- * \brief Helper functions that actually delete the tag.
+ * \brief Helper functions that actually creates event of the name.
*
- * \param[in] tag tag to delete
+ * \param[in] name to add
*
* \return result of the request, either "success" or "failed" with description of error
*/
-static int event_del(const char *tag)
-{
- struct event *e, **p;
-
- /* check exists */
- e = event_get(tag);
- if (!e) return -1;
-
- /* unlink */
- p = &events;
- while(*p != e) p = &(*p)->next;
- *p = e->next;
-
- /* destroys */
- afb_event_drop(e->event);
- free(e);
- return 0;
-}
-
-/**
- * \internal
- * \brief Helper functions that actually creates event of the tag.
- *
- * \param[in] tag tag to add
- * \param[in] name name to add
- *
- * \return result of the request, either "success" or "failed" with description of error
- */
-static int event_add(const char *tag, const char *name)
+static int event_add(const char *name)
{
struct event *e;
- /* check valid tag */
- e = event_get(tag);
+ /* check valid name */
+ e = event_get(name);
if (e) return -1;
/* creation */
- e = malloc(strlen(tag) + sizeof *e);
+ e = malloc(strlen(name) + sizeof *e + 1);
if (!e) return -1;
- strcpy(e->tag, tag);
+ strcpy(e->name, name);
/* make the event */
e->event = afb_daemon_make_event(name);
@@ -634,92 +578,50 @@ static int event_add(const char *tag, const char *name)
}
/**
- * \brief Creates event of the tag.
- *
- * \param[in] request tag and name of the event
- *
- * \return result of the request, either "success" or "failed" with description of error
- */
-static void eventadd (struct afb_req request)
-{
- const char *tag = afb_req_value(request, "tag");
- const char *name = afb_req_value(request, "name");
-
- json_object *query = afb_req_json(request);
-
- if (tag == NULL || name == NULL)
- afb_req_fail(request, "failed", "bad arguments");
- else if (0 != event_add(tag, name))
- afb_req_fail(request, "failed", "creation error");
- else
- afb_req_success(request, NULL, NULL);
-}
-
-/**
- * \brief Deletes the event of tag.
- *
- * \param[in] request tag to delete
- *
- * \return result of the request, either "success" or "failed" with description of error
- */
-static void eventdel (struct afb_req request)
-{
- const char *tag = afb_req_value(request, "tag");
-
- if (tag == NULL)
- afb_req_fail(request, "failed", "bad arguments");
- else if (0 != event_del(tag))
- afb_req_fail(request, "failed", "deletion error");
- else
- afb_req_success(request, NULL, NULL);
-}
-
-
-/**
* \internal
- * \brief Helper functions to subscribe for the event of tag.
+ * \brief Helper functions to subscribe for the event of name.
*
- * \param[in] request tag to subscribe for
+ * \param[in] request name to subscribe for
*
* \return result of the request, either "success" or "failed" with description of error
*/
-static int event_subscribe(struct afb_req request, const char *tag)
+static int event_subscribe(struct afb_req request, const char *name)
{
struct event *e;
- e = event_get(tag);
+ e = event_get(name);
return e ? afb_req_subscribe(request, e->event) : -1;
}
/**
* \internal
- * \brief Helper functions to unsubscribe for the event of tag.
+ * \brief Helper functions to unsubscribe for the event of name.
*
- * \param[in] request tag to unsubscribe for
+ * \param[in] request name to unsubscribe for
*
* \return result of the request, either "success" or "failed" with description of error
*/
-static int event_unsubscribe(struct afb_req request, const char *tag)
+static int event_unsubscribe(struct afb_req request, const char *name)
{
struct event *e;
- e = event_get(tag);
+ e = event_get(name);
return e ? afb_req_unsubscribe(request, e->event) : -1;
}
/**
- * \brief Subscribes for the event of tag.
+ * \brief Subscribes for the event of name.
*
- * \param[in] request tag to subscribe for
+ * \param[in] request name to subscribe for
*
* \return result of the request, either "success" or "failed" with description of error
*/
-static void eventsub (struct afb_req request)
+static void subscribe(struct afb_req request)
{
- const char *tag = afb_req_value(request, "tag");
+ const char *name = afb_req_value(request, "value");
- if (tag == NULL)
+ if (name == NULL)
afb_req_fail(request, "failed", "bad arguments");
- else if (0 != event_subscribe(request, tag))
+ else if (0 != event_subscribe(request, name))
afb_req_fail(request, "failed", "subscription error");
else
afb_req_success(request, NULL, NULL);
@@ -727,19 +629,19 @@ static void eventsub (struct afb_req request)
/**
- * \brief Unsubscribes for the event of tag.
+ * \brief Unsubscribes for the event of name.
*
- * \param[in] request tag to unsubscribe for
+ * \param[in] request name to unsubscribe for
*
* \return result of the request, either "success" or "failed" with description of error
*/
-static void eventunsub (struct afb_req request)
+static void unsubscribe(struct afb_req request)
{
- const char *tag = afb_req_value(request, "tag");
+ const char *name = afb_req_value(request, "value");
- if (tag == NULL)
+ if (name == NULL)
afb_req_fail(request, "failed", "bad arguments");
- else if (0 != event_unsubscribe(request, tag))
+ else if (0 != event_unsubscribe(request, name))
afb_req_fail(request, "failed", "unsubscription error");
else
afb_req_success(request, NULL, NULL);
@@ -758,22 +660,27 @@ static const struct afb_verb_v2 binding_verbs[] = {
{ .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'"},
+{ .verb = "subscribe", .session = AFB_SESSION_NONE, .callback = subscribe, .info ="unsubscribes to the event of 'name'"},
+{ .verb = "unsubscribe", .session = AFB_SESSION_NONE, .callback = unsubscribe, .info ="unsubscribes to the event of 'name'"},
{ } /* marker for end of the array */
};
+static int init()
+{
+ event_add("passkey");
+ event_add("networkList");
+
+ return 0;
+}
+
/*
* description of the binding for afb-daemon
*/
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 */
+ .verbs = binding_verbs, /* the array describing the verbs of the API */
+ .init = init,
};