aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/samples
diff options
context:
space:
mode:
authorFulup Ar Foll <fulup@iot.bzh>2016-05-28 11:55:08 +0200
committerFulup Ar Foll <fulup@iot.bzh>2016-05-28 11:55:08 +0200
commit1a66f6a8c0b213e14bc0b1896bfaa68a5c2a5002 (patch)
tree0f84cd21a3fd393bddcab603d2452c84c97defa6 /plugins/samples
parentfcdb6bb4b88510614f5eb96545ea724ce442d606 (diff)
parenteaab2fbbed4601415b5be052b39a0c0df11fdc38 (diff)
Merge branch 'master' of https://github.com/iotbzh/afb-daemon
Diffstat (limited to 'plugins/samples')
-rw-r--r--plugins/samples/ClientCtx.c32
-rw-r--r--plugins/samples/HelloWorld.c4
-rw-r--r--plugins/samples/tic-tac-toe.c39
3 files changed, 29 insertions, 46 deletions
diff --git a/plugins/samples/ClientCtx.c b/plugins/samples/ClientCtx.c
index 353185c3..ef703759 100644
--- a/plugins/samples/ClientCtx.c
+++ b/plugins/samples/ClientCtx.c
@@ -125,22 +125,22 @@ static const struct AFB_verb_desc_v1 verbs[]= {
{"create", AFB_SESSION_CREATE, myCreate , "Create a new session"},
{"action", AFB_SESSION_CHECK , myAction , "Use Session Context"},
{"close" , AFB_SESSION_CLOSE , myClose , "Free Context"},
- {"set_loa_0", AFB_SESSION_RENEW, clientSetLOA0 ,"Set level of authorisation to 0"},
- {"set_loa_1", AFB_SESSION_RENEW, clientSetLOA1 ,"Set level of authorisation to 1"},
- {"set_loa_2", AFB_SESSION_RENEW, clientSetLOA2 ,"Set level of authorisation to 2"},
- {"set_loa_3", AFB_SESSION_RENEW, clientSetLOA3 ,"Set level of authorisation to 3"},
- {"check_loa_ge_0", AFB_SESSION_LOA_GE_0, clientCheckLOA ,"Check whether level of authorisation is greater or equal to 0"},
- {"check_loa_ge_1", AFB_SESSION_LOA_GE_1, clientCheckLOA ,"Check whether level of authorisation is greater or equal to 1"},
- {"check_loa_ge_2", AFB_SESSION_LOA_GE_2, clientCheckLOA ,"Check whether level of authorisation is greater or equal to 2"},
- {"check_loa_ge_3", AFB_SESSION_LOA_GE_3, clientCheckLOA ,"Check whether level of authorisation is greater or equal to 3"},
- {"check_loa_le_0", AFB_SESSION_LOA_LE_0, clientCheckLOA ,"Check whether level of authorisation is lesser or equal to 0"},
- {"check_loa_le_1", AFB_SESSION_LOA_LE_1, clientCheckLOA ,"Check whether level of authorisation is lesser or equal to 1"},
- {"check_loa_le_2", AFB_SESSION_LOA_LE_2, clientCheckLOA ,"Check whether level of authorisation is lesser or equal to 2"},
- {"check_loa_le_3", AFB_SESSION_LOA_LE_3, clientCheckLOA ,"Check whether level of authorisation is lesser or equal to 3"},
- {"check_loa_eq_0", AFB_SESSION_LOA_EQ_0, clientCheckLOA ,"Check whether level of authorisation is equal to 0"},
- {"check_loa_eq_1", AFB_SESSION_LOA_EQ_1, clientCheckLOA ,"Check whether level of authorisation is equal to 1"},
- {"check_loa_eq_2", AFB_SESSION_LOA_EQ_2, clientCheckLOA ,"Check whether level of authorisation is equal to 2"},
- {"check_loa_eq_3", AFB_SESSION_LOA_EQ_3, clientCheckLOA ,"Check whether level of authorisation is equal to 3"},
+ {"set_loa_0", AFB_SESSION_RENEW, clientSetLOA0 ,"Set level of assurance to 0"},
+ {"set_loa_1", AFB_SESSION_RENEW, clientSetLOA1 ,"Set level of assurance to 1"},
+ {"set_loa_2", AFB_SESSION_RENEW, clientSetLOA2 ,"Set level of assurance to 2"},
+ {"set_loa_3", AFB_SESSION_RENEW, clientSetLOA3 ,"Set level of assurance to 3"},
+ {"check_loa_ge_0", AFB_SESSION_LOA_GE_0, clientCheckLOA ,"Check whether level of assurance is greater or equal to 0"},
+ {"check_loa_ge_1", AFB_SESSION_LOA_GE_1, clientCheckLOA ,"Check whether level of assurance is greater or equal to 1"},
+ {"check_loa_ge_2", AFB_SESSION_LOA_GE_2, clientCheckLOA ,"Check whether level of assurance is greater or equal to 2"},
+ {"check_loa_ge_3", AFB_SESSION_LOA_GE_3, clientCheckLOA ,"Check whether level of assurance is greater or equal to 3"},
+ {"check_loa_le_0", AFB_SESSION_LOA_LE_0, clientCheckLOA ,"Check whether level of assurance is lesser or equal to 0"},
+ {"check_loa_le_1", AFB_SESSION_LOA_LE_1, clientCheckLOA ,"Check whether level of assurance is lesser or equal to 1"},
+ {"check_loa_le_2", AFB_SESSION_LOA_LE_2, clientCheckLOA ,"Check whether level of assurance is lesser or equal to 2"},
+ {"check_loa_le_3", AFB_SESSION_LOA_LE_3, clientCheckLOA ,"Check whether level of assurance is lesser or equal to 3"},
+ {"check_loa_eq_0", AFB_SESSION_LOA_EQ_0, clientCheckLOA ,"Check whether level of assurance is equal to 0"},
+ {"check_loa_eq_1", AFB_SESSION_LOA_EQ_1, clientCheckLOA ,"Check whether level of assurance is equal to 1"},
+ {"check_loa_eq_2", AFB_SESSION_LOA_EQ_2, clientCheckLOA ,"Check whether level of assurance is equal to 2"},
+ {"check_loa_eq_3", AFB_SESSION_LOA_EQ_3, clientCheckLOA ,"Check whether level of assurance is equal to 3"},
{NULL}
};
diff --git a/plugins/samples/HelloWorld.c b/plugins/samples/HelloWorld.c
index 78a1eafd..fe117846 100644
--- a/plugins/samples/HelloWorld.c
+++ b/plugins/samples/HelloWorld.c
@@ -54,8 +54,8 @@ static void pingBug (struct afb_req request)
static void pingEvent(struct afb_req request)
{
json_object *query = afb_req_json(request);
- afb_event_sender_push(afb_daemon_get_event_sender(interface->daemon), "event", query);
- ping(request, json_object_get(query), "event");
+ afb_daemon_broadcast_event(interface->daemon, "event", json_object_get(query));
+ ping(request, query, "event");
}
diff --git a/plugins/samples/tic-tac-toe.c b/plugins/samples/tic-tac-toe.c
index a1630c50..31682d94 100644
--- a/plugins/samples/tic-tac-toe.c
+++ b/plugins/samples/tic-tac-toe.c
@@ -299,7 +299,7 @@ static void changed(struct board *board, const char *reason)
waiter = next;
}
- afb_event_sender_push(afb_daemon_get_event_sender(afbitf->daemon), reason, description);
+ afb_daemon_broadcast_event(afbitf->daemon, reason, description);
}
/*
@@ -364,11 +364,11 @@ static void move(struct afb_req req)
board = board_of_req(req);
INFO(afbitf, "method 'move' called for boardid %d", board->id);
- /* retrieves the parameters of the move */
+ /* retrieves the arguments of the move */
index = afb_req_value(req, "index");
i = index == NULL ? -1 : atoi(index);
- /* checks validity of parameters */
+ /* checks validity of arguments */
if (i < 0 || i > 8) {
WARNING(afbitf, "can't move to %s: %s", index?:"?", index?"wrong value":"not set");
afb_req_fail(req, "error", "bad request");
@@ -390,7 +390,7 @@ static void move(struct afb_req req)
}
/* applies the move */
- INFO(afbitf, "method 'move' for boardid %d, index=%d", board->id, index);
+ INFO(afbitf, "method 'move' for boardid %d, index=%s", board->id, index);
add_move(board, i);
/* replies */
@@ -413,11 +413,11 @@ static void level(struct afb_req req)
board = board_of_req(req);
INFO(afbitf, "method 'level' called for boardid %d", board->id);
- /* retrieves the parameters */
+ /* retrieves the arguments */
level = afb_req_value(req, "level");
l = level == NULL ? -1 : atoi(level);
- /* check validity of parameters */
+ /* check validity of arguments */
if (l < 1 || l > 10) {
WARNING(afbitf, "can't set level to %s: %s", level?:"?", level?"wrong value":"not set");
afb_req_fail(req, "error", "bad request");
@@ -447,7 +447,7 @@ static void join(struct afb_req req)
board = board_of_req(req);
INFO(afbitf, "method 'join' called for boardid %d", board->id);
- /* retrieves the parameters */
+ /* retrieves the arguments */
id = afb_req_value(req, "boardid");
if (id == NULL)
goto bad_request;
@@ -549,7 +549,6 @@ static void play(struct afb_req req)
static void wait(struct afb_req req)
{
- int count;
struct board *board;
struct waiter *waiter;
@@ -557,21 +556,6 @@ static void wait(struct afb_req req)
board = board_of_req(req);
INFO(afbitf, "method 'wait' called for boardid %d", board->id);
- /* counts the waiters */
- count = 0;
- waiter = board->waiters;
- while (waiter != NULL) {
- count++;
- waiter = waiter->next;
- }
-
- /* checks ability to wait */
- if (count + 1 >= board->use_count) {
- WARNING(afbitf, "can't wait: count=%d and use_count=%d", count, board->use_count);
- afb_req_fail(req, "error", "can't wait");
- return;
- }
-
/* creates the waiter and enqueues it */
waiter = calloc(1, sizeof *waiter);
waiter->req = req;
@@ -583,18 +567,17 @@ static void wait(struct afb_req req)
/*
* array of the verbs exported to afb-daemon
*/
-static const struct AFB_verb_desc_v1 verbs[] = {
+static const struct AFB_verb_desc_v1 plugin_verbs[] = {
/* VERB'S NAME SESSION MANAGEMENT FUNCTION TO CALL SHORT DESCRIPTION */
{ .name= "new", .session= AFB_SESSION_NONE, .callback= new, .info= "Starts a new game" },
- { .name= "play", .session= AFB_SESSION_NONE, .callback= play, .info= "Tells the server to play" },
+ { .name= "play", .session= AFB_SESSION_NONE, .callback= play, .info= "Asks the server to play" },
{ .name= "move", .session= AFB_SESSION_NONE, .callback= move, .info= "Tells the client move" },
{ .name= "board", .session= AFB_SESSION_NONE, .callback= board, .info= "Get the current board" },
{ .name= "level", .session= AFB_SESSION_NONE, .callback= level, .info= "Set the server level" },
{ .name= "join", .session= AFB_SESSION_CHECK,.callback= join, .info= "Join a board" },
{ .name= "undo", .session= AFB_SESSION_NONE, .callback= undo, .info= "Undo the last move" },
{ .name= "wait", .session= AFB_SESSION_NONE, .callback= wait, .info= "Wait for a change" },
- /* marker for end of the array */
- { .name= NULL }
+ { .name= NULL } /* marker for end of the array */
};
/*
@@ -607,7 +590,7 @@ static const struct AFB_plugin plugin_description =
.v1= { /* fills the v1 field of the union when AFB_PLUGIN_VERSION_1 */
.prefix= "tictactoe", /* the API name (or plugin name or prefix) */
.info= "Sample tac-tac-toe game", /* short description of of the plugin */
- .verbs = verbs /* the array describing the verbs of the API */
+ .verbs = plugin_verbs /* the array describing the verbs of the API */
}
};