/*
- * Copyright (C) 2016, 2017, 2018 "IoT.bzh"
+ * Copyright (C) 2015-2020 "IoT.bzh"
* Author José Bollo <jose.bollo@iot.bzh>
*
* Licensed under the Apache License, Version 2.0 (the "License");
/*
* Creates a new board and returns it.
*/
-static struct board *get_new_board(afb_req_t req)
+static struct board *get_new_board()
{
/* allocation */
struct board *board = calloc(1, sizeof *board);
board->id = (rand() >> 2) % 1000;
} while(board->id == 0 || search_board(board->id) != NULL);
board->event = afb_daemon_make_event("board");
- afb_req_subscribe(req, board->event);
/* link */
board->next = all_boards;
return board;
}
-static void *get_new_board_cb(void *closure)
-{
- afb_req_t req = closure;
- return get_new_board(req);
-}
-
/*
* Release a board
*/
}
}
-static void release_board_cb(void *closure)
-{
- struct board *board = closure;
- return release_board(board);
-}
-
/*
* Checks who wins
* Returns zero if there is no winner
afb_event_push(board->event, json_object_new_string(reason));
}
+static void *get_new_board_cb(void *closure)
+{
+ afb_req_t req = closure;
+ struct board *board = get_new_board();
+ afb_req_subscribe(req, board->event);
+ return board;
+}
+
+static void release_board_cb(void *closure)
+{
+ struct board *board = closure;
+ return release_board(board);
+}
+
/*
* retrieves the board of the request
*/
/* none is a special id for joining a new session */
if (strcmp(id, "none") == 0) {
- new_board = get_new_board(req);
+ new_board = get_new_board();
goto setctx;
}
new_board->use_count++;
setctx:
/* set the new board (and leaves the previous one) */
- afb_req_context(req, 1, NULL, release_board_cb, new_board);
afb_req_unsubscribe(req, board->event);
+ afb_req_context(req, 1, NULL, release_board_cb, new_board);
+ afb_req_subscribe(req, new_board->event);
success:
/* replies */