aboutsummaryrefslogtreecommitdiffstats
path: root/ucs2-afb/ucs_binding.c
diff options
context:
space:
mode:
authortjahnk <tjahnk@users.noreply.github.com>2017-08-03 16:55:45 +0200
committerGitHub <noreply@github.com>2017-08-03 16:55:45 +0200
commit01475efcf23f47c13f44b057e42decb916117d67 (patch)
tree7e48967a3b2587cbb898173ba4da49fc0cdb6a50 /ucs2-afb/ucs_binding.c
parentc69b4176bc56eef84a78e9160ba7516b8c7cc9d7 (diff)
parente9aa8f0519f75d8dc1d698e11596c4720cd977e5 (diff)
Merge pull request #18 from tjahnk/basic_events
Introduced basic event handling, adds subscribe function and node-availability event
Diffstat (limited to 'ucs2-afb/ucs_binding.c')
-rw-r--r--ucs2-afb/ucs_binding.c61
1 files changed, 57 insertions, 4 deletions
diff --git a/ucs2-afb/ucs_binding.c b/ucs2-afb/ucs_binding.c
index fe6e033..8a1174c 100644
--- a/ucs2-afb/ucs_binding.c
+++ b/ucs2-afb/ucs_binding.c
@@ -62,7 +62,13 @@ typedef struct {
UCSI_channelsT *channels;
} ucsContextT;
+typedef struct {
+ struct afb_event node_event;
+
+} EventData_t;
+
static ucsContextT *ucsContextS;
+static EventData_t *eventData = NULL;
PUBLIC void UcsXml_CB_OnError(const char format[], uint16_t vargsCnt, ...) {
/*AFB_DEBUG (afbIface, format, args); */
@@ -200,6 +206,31 @@ void UCSI_CB_OnGpioStateChange(void *pTag, uint16_t nodeAddress, uint8_t gpioPin
{
}
+PUBLIC void UCSI_CB_OnMgrReport(void *pTag, Ucs_MgrReport_t code, uint16_t nodeAddress, Ucs_Rm_Node_t *pNode){
+
+ bool available;
+
+ if (code == UCS_MGR_REP_AVAILABLE) {
+ available = true;
+ }
+ else if (code == UCS_MGR_REP_NOT_AVAILABLE) {
+ available = false;
+ }
+ else {
+ /*untracked event - just exit*/
+ return;
+ }
+
+ if (eventData) {
+
+ json_object *j_event_info = json_object_new_object();
+ json_object_object_add(j_event_info, "node", json_object_new_int(nodeAddress));
+ json_object_object_add(j_event_info, "available", json_object_new_boolean(available));
+
+ afb_event_push(eventData->node_event, j_event_info);
+ }
+}
+
bool Cdev_Init(CdevData_t *d, const char *fileName, bool read, bool write)
{
if (NULL == d || NULL == fileName) goto OnErrorExit;
@@ -531,12 +562,34 @@ PUBLIC void ucs2_listconfig (struct afb_req request) {
return;
}
-PUBLIC void ucs2_monitor (struct afb_req request) {
+PUBLIC void ucs2_subscribe (struct afb_req request) {
- afb_req_success(request,NULL,"UNICENS-to_be_done");
+ if (!eventData) {
+
+ eventData = malloc(sizeof(EventData_t));
+ if (eventData) {
+ eventData->node_event = afb_daemon_make_event ("node-availibility");
+ }
+
+ if (!eventData || !afb_event_is_valid(eventData->node_event)) {
+ afb_req_fail_f (request, "create-event", "Cannot create or register event");
+ goto OnExitError;
+ }
+ }
+
+ if (afb_req_subscribe(request, eventData->node_event) != 0) {
+
+ afb_req_fail_f (request, "subscribe-event", "Cannot subscribe to event");
+ goto OnExitError;
+ }
+
+ afb_req_success(request,NULL,"event subscription successful");
+
+OnExitError:
+ return;
}
-STATIC void ucs2_writei2c_CB(void *result_ptr, void *request_ptr) {
+STATIC void ucs2_writei2c_CB (void *result_ptr, void *request_ptr) {
if (request_ptr){
afb_req *req = (afb_req *)request_ptr;
@@ -560,7 +613,7 @@ STATIC void ucs2_writei2c_CB(void *result_ptr, void *request_ptr) {
}
}
-PUBLIC void ucs2_writei2c(struct afb_req request) {
+PUBLIC void ucs2_writei2c (struct afb_req request) {
struct json_object *j_obj;
static uint8_t i2c_data[I2C_MAX_DATA_SZ];