From 93b0b7a95922defa19951dde01b1dce4047bb0e7 Mon Sep 17 00:00:00 2001 From: Jordan Augé Date: Sun, 24 Nov 2019 23:51:45 +0100 Subject: [HICN-408] Add a face manager interface for face priority control MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I768112c920154380a614d0c5858f50efa135903d Signed-off-by: Jordan Augé --- .../priority_controller/priority_controller.c | 29 ++++++++++++---------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'ctrl/facemgr/src/interfaces/priority_controller') diff --git a/ctrl/facemgr/src/interfaces/priority_controller/priority_controller.c b/ctrl/facemgr/src/interfaces/priority_controller/priority_controller.c index 5c5afdb6c..b8e7271bb 100644 --- a/ctrl/facemgr/src/interfaces/priority_controller/priority_controller.c +++ b/ctrl/facemgr/src/interfaces/priority_controller/priority_controller.c @@ -22,7 +22,7 @@ int priority_controller_initialize(interface_t * interface, void * cfg) pc_data_t * data = malloc(sizeof(pc_data_t)); if (!data) { INFO("Priority controller data memory allocation error"); - return -1; + goto ERR_MALLOC; } interface->data = data; @@ -32,7 +32,7 @@ int priority_controller_initialize(interface_t * interface, void * cfg) if (data->fd < 0) { INFO("Priority controller socket error"); perror("socket error"); - return -1; + goto ERR_SOCKET; } memset(&addr, 0, sizeof(addr)); @@ -43,12 +43,23 @@ int priority_controller_initialize(interface_t * interface, void * cfg) if (bind(data->fd, (struct sockaddr*)&addr, sizeof(addr)) < 0) { INFO("Priority controller socket bind error"); perror("bind error"); - return -1; + goto ERR_BIND; + } + if (interface_register_fd(interface, data->fd, NULL) < 0) { + ERROR("[priority_controller_initialize] Error registering fd"); + goto ERR_FD; } - interface_register_fd(interface, data->fd, NULL); INFO("Priority controller successfully initialized"); - return data->fd; + return 0; + +ERR_FD: +ERR_BIND: + close(data->fd); +ERR_SOCKET: + free(data); +ERR_MALLOC: + return -1; } int priority_controller_finalize(interface_t * interface) @@ -67,12 +78,6 @@ int priority_controller_callback(interface_t * interface, int fd, void * unused) char buf[100]; int rc; - struct sockaddr_in addr; - memset(&addr, 0, sizeof(addr)); - addr.sin_family = AF_INET; - addr.sin_addr.s_addr = inet_addr("127.0.0.1"); - addr.sin_port = htons(9533); - INFO("Priority controller receiving command"); rc = recv(data->fd, buf, 100, 0); @@ -119,8 +124,6 @@ int priority_controller_callback(interface_t * interface, int fd, void * unused) interface_raise_event(interface, facelet_w); interface_raise_event(interface, facelet_c); - facelet_free(facelet_w); - facelet_free(facelet_c); return 0; } -- cgit 1.2.3-korg