2 * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
4 * Contact: Jin Yoon <jinny.yoon@samsung.com>
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
22 #include "controller.h"
25 Eina_List *event_cb_list;
27 static struct controller_s controller_info;
29 struct _controller_event_cb_info_s {
31 controller_event_cb event_cb;
34 typedef struct _controller_event_cb_info_s controller_event_cb_info_s;
37 int controller_register_event_cb(const char *event_name, controller_event_cb event_cb, void *data)
39 controller_event_cb_info_s *event_cb_info = NULL;
41 retv_if(!event_name, -1);
42 retv_if(!event_cb, -1);
44 event_cb_info = calloc(1, sizeof(controller_event_cb_info_s));
45 retv_if(!event_cb_info, -1);
47 event_cb_info->event_name = strdup(event_name);
48 goto_if(!event_cb_info->event_name, error);
50 event_cb_info->event_cb = event_cb;
51 event_cb_info->data = data;
53 controller_info.event_cb_list = eina_list_append(controller_info.event_cb_list, event_cb_info);
58 if (event_cb_info) free(event_cb_info);
63 int controller_unregister_event_cb(const char *event_name, controller_event_cb event_cb)
65 controller_event_cb_info_s *event_cb_info = NULL;
66 const Eina_List *l = NULL;
67 const Eina_List *ln = NULL;
69 retv_if(!event_name, -1);
70 retv_if(!event_cb, -1);
72 EINA_LIST_FOREACH_SAFE(controller_info.event_cb_list, l, ln, event_cb_info) {
73 if (event_cb_info->event_name
74 && strcmp(event_cb_info->event_name, event_name)
75 && event_cb_info->event_cb == event_cb)
77 controller_info.event_cb_list = eina_list_remove(controller_info.event_cb_list, event_cb_info);
85 int controller_send_event(const char *event_name, void *event_info)
87 controller_event_cb_info_s *event_cb_info = NULL;
88 const Eina_List *l = NULL;
89 const Eina_List *ln = NULL;
91 retv_if(!event_name, -1);
93 EINA_LIST_FOREACH_SAFE(controller_info.event_cb_list, l, ln, event_cb_info) {
94 if (event_cb_info->event_name
95 && strcmp(event_cb_info->event_name, event_name))
98 ret = event_cb_info->event_cb(event_name, event_info, event_cb_info->data);
99 if (ret < 0) _E("There were errors sending an event");