4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
25 #include <sys/types.h>
32 #include "appcore-internal.h"
34 #define NOTI_COMP(a, b) (strcmp(a->name, b->name))
39 int (*cb_pre) (void *);
41 int (*cb_post) (void *);
45 typedef struct noti_s notis;
48 SGLIB_DEFINE_LIST_PROTOTYPES(notis, NOTI_COMP, next);
49 SGLIB_DEFINE_LIST_FUNCTIONS(notis, NOTI_COMP, next);
51 static struct noti_s *noti_h;
53 static void __main_handle(void *data)
55 struct noti_s *n = data;
57 _ret_if(n == NULL || n->name == NULL);
59 _DBG("[APP %d] noti: %s", getpid(), n->name);
71 static int __del_noti(int fd, struct noti_s *t)
75 r = heynoti_unsubscribe(fd, t->name, __main_handle);
77 sglib_notis_delete(¬i_h, t);
78 free((void *)t->name);
85 static int __del_notis(int fd)
87 struct sglib_notis_iterator it;
90 t = sglib_notis_it_init(&it, noti_h);
93 t = sglib_notis_it_next(&it);
99 int add_noti(int fd, const char *name, int (*cb_pre) (void *),
100 int (*cb) (void *), int (*cb_post) (void *), void *data)
110 if (name == NULL || name[0] == '\0') {
115 t = calloc(1, sizeof(struct noti_s));
119 t->name = strdup(name);
120 if (t->name == NULL) {
127 t->cb_post = cb_post;
130 r = heynoti_subscribe(fd, name, __main_handle, t);
132 free((void *)t->name);
137 sglib_notis_add(¬i_h, t);
142 int del_noti(int fd, const char *name)
153 f = sglib_notis_find_member(noti_h, &t);
159 return __del_noti(fd, f);
162 int noti_start(int fd)
164 return heynoti_attach_handler(fd);
169 return heynoti_init();
172 void noti_exit(int *fd)
174 _ret_if(fd == NULL || *fd < 0);