X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=bindings%2Fsamples%2Ftic-tac-toe.c;h=d600e192a12710ae7880724e0a3d1a568676106e;hb=refs%2Fheads%2Feel;hp=fb5eb92678ca78aadbcfeae042c598eaa9c8b4eb;hpb=a38382e89710db2c298f7f101e3ba0cf3681287c;p=src%2Fapp-framework-binder.git diff --git a/bindings/samples/tic-tac-toe.c b/bindings/samples/tic-tac-toe.c index fb5eb926..d600e192 100644 --- a/bindings/samples/tic-tac-toe.c +++ b/bindings/samples/tic-tac-toe.c @@ -20,13 +20,9 @@ #include #include +#define AFB_BINDING_VERSION 2 #include -/* - * the interface to afb-daemon - */ -const struct afb_binding_interface *afbitf; - /* * definition of waiters */ @@ -299,7 +295,7 @@ static void changed(struct board *board, const char *reason) waiter = next; } - afb_daemon_broadcast_event(afbitf->daemon, reason, description); + afb_daemon_broadcast_event(reason, description); } /* @@ -319,7 +315,7 @@ static void new(struct afb_req req) /* retrieves the context for the session */ board = board_of_req(req); - INFO(afbitf, "method 'new' called for boardid %d", board->id); + AFB_INFO("method 'new' called for boardid %d", board->id); /* reset the game */ memset(board->board, ' ', sizeof board->board); @@ -342,7 +338,7 @@ static void board(struct afb_req req) /* retrieves the context for the session */ board = board_of_req(req); - INFO(afbitf, "method 'board' called for boardid %d", board->id); + AFB_INFO("method 'board' called for boardid %d", board->id); /* describe the board */ description = describe(board); @@ -362,7 +358,7 @@ static void move(struct afb_req req) /* retrieves the context for the session */ board = board_of_req(req); - INFO(afbitf, "method 'move' called for boardid %d", board->id); + AFB_INFO("method 'move' called for boardid %d", board->id); /* retrieves the arguments of the move */ index = afb_req_value(req, "index"); @@ -370,27 +366,27 @@ static void move(struct afb_req req) /* checks validity of arguments */ if (i < 0 || i > 8) { - WARNING(afbitf, "can't move to %s: %s", index?:"?", index?"wrong value":"not set"); + AFB_WARNING("can't move to %s: %s", index?:"?", index?"wrong value":"not set"); afb_req_fail(req, "error", "bad request"); return; } /* checks validity of the state */ if (winner(board->board) != 0) { - WARNING(afbitf, "can't move to %s: game is terminated", index); + AFB_WARNING("can't move to %s: game is terminated", index); afb_req_fail(req, "error", "game terminated"); return; } /* checks validity of the move */ if (board->board[i] != ' ') { - WARNING(afbitf, "can't move to %s: room occupied", index); + AFB_WARNING("can't move to %s: room occupied", index); afb_req_fail(req, "error", "occupied"); return; } /* applies the move */ - INFO(afbitf, "method 'move' for boardid %d, index=%s", board->id, index); + AFB_INFO("method 'move' for boardid %d, index=%s", board->id, index); add_move(board, i); /* replies */ @@ -411,7 +407,7 @@ static void level(struct afb_req req) /* retrieves the context for the session */ board = board_of_req(req); - INFO(afbitf, "method 'level' called for boardid %d", board->id); + AFB_INFO("method 'level' called for boardid %d", board->id); /* retrieves the arguments */ level = afb_req_value(req, "level"); @@ -419,13 +415,13 @@ static void level(struct afb_req req) /* 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_WARNING("can't set level to %s: %s", level?:"?", level?"wrong value":"not set"); afb_req_fail(req, "error", "bad request"); return; } /* set the level */ - INFO(afbitf, "method 'level' for boardid %d, level=%d", board->id, l); + AFB_INFO("method 'level' for boardid %d, level=%d", board->id, l); board->level = l; /* replies */ @@ -445,7 +441,7 @@ static void join(struct afb_req req) /* retrieves the context for the session */ board = board_of_req(req); - INFO(afbitf, "method 'join' called for boardid %d", board->id); + AFB_INFO("method 'join' called for boardid %d", board->id); /* retrieves the arguments */ id = afb_req_value(req, "boardid"); @@ -482,7 +478,7 @@ success: return; bad_request: - WARNING(afbitf, "can't join boardid %s: %s", id ? : "?", !id ? "no boardid" : atoi(id) ? "not found" : "bad boardid"); + AFB_WARNING("can't join boardid %s: %s", id ? : "?", !id ? "no boardid" : atoi(id) ? "not found" : "bad boardid"); afb_req_fail(req, "error", "bad request"); return; } @@ -497,11 +493,11 @@ static void undo(struct afb_req req) /* retrieves the context for the session */ board = board_of_req(req); - INFO(afbitf, "method 'undo' called for boardid %d", board->id); + AFB_INFO("method 'undo' called for boardid %d", board->id); /* checks the state */ if (board->moves == 0) { - WARNING(afbitf, "can't undo"); + AFB_WARNING("can't undo"); afb_req_fail(req, "error", "bad request"); return; } @@ -527,11 +523,11 @@ static void play(struct afb_req req) /* retrieves the context for the session */ board = board_of_req(req); - INFO(afbitf, "method 'play' called for boardid %d", board->id); + AFB_INFO("method 'play' called for boardid %d", board->id); /* checks validity of the state */ if (winner(board->board) != 0 || board->moves == 9) { - WARNING(afbitf, "can't play: game terminated (%s)", winner(board->board) ? "has winner" : "no room left"); + AFB_WARNING("can't play: game terminated (%s)", winner(board->board) ? "has winner" : "no room left"); afb_req_fail(req, "error", "game terminated"); return; } @@ -554,7 +550,7 @@ static void wait(struct afb_req req) /* retrieves the context for the session */ board = board_of_req(req); - INFO(afbitf, "method 'wait' called for boardid %d", board->id); + AFB_INFO("method 'wait' called for boardid %d", board->id); /* creates the waiter and enqueues it */ waiter = calloc(1, sizeof *waiter); @@ -567,39 +563,25 @@ static void wait(struct afb_req req) /* * array of the verbs exported to afb-daemon */ -static const struct afb_verb_desc_v1 binding_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= "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" }, - { .name= NULL } /* marker for end of the array */ +static const struct afb_verb_v2 verbs[] = { + { .verb="new", .callback=new }, + { .verb="play", .callback=play }, + { .verb="move", .callback=move }, + { .verb="board", .callback=board }, + { .verb="level", .callback=level }, + { .verb="join", .callback=join }, + { .verb="undo", .callback=undo }, + { .verb="wait", .callback=wait }, + { .verb=NULL } }; /* * 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= "tictactoe", /* the API name (or binding name or prefix) */ - .info= "Sample tac-tac-toe game", /* short description of of the binding */ - .verbs = binding_verbs /* the array describing the verbs of the API */ - } +const afb_binding_v2 afbBindingV2 = { + .api = "tictactoe", + .specification = NULL, + .verbs = verbs }; -/* - * 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 -}