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>,
7 * Jaeho Lee <jaeho81.lee@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
28 * @defgroup HEYNOTI_PG HEY(ligHt Easy speedY) Notification
30 <h1 class="pg">Introduction</h1>
32 Heynoti is notification system which uses the Linux kernel inotify subsystem. <br>
33 It is ligHt, Easy, speedY, so that is named 'Heynoti'. <br>
34 But it doesn't support data delivery, is just sent event notification. <br>
35 If developers want to send event with data like integer, string, they have to use DBus for IPC. <br>
36 Heynoti is based on inotify in Linux Sytem. So for more information about inotify, refer to manpage(inotify(7)).
38 @image html SLP_Heynoti_PG_image01.png
40 <h2 class="pg">Properties</h2>
41 - HEY(ligHt Easy speedY) Notification
43 - Header File : heynoti.h
45 <h1 class="pg">Programming Guide</h1>
46 For receiving notification, we can use heynoti_attach_handler() or heynoti_poll_event().
47 heynoti_attach_handler() use g_main_loop of default context.
48 For g_main_loop, refer to glib manual.
55 void callback(void *data)
57 printf("I got a testnoti\n");
60 int main(int argc, const char *argv[])
65 if((fd = heynoti_init()) < 0) {
66 fprintf(stderr, "heynoti_init FAIL\n");
69 printf("heynoti_init OK\n");
71 if(heynoti_subscribe(fd, "test_testnoti", callback, NULL))
72 fprintf(stderr, "heynoti_subscribe FAIL\n");
74 printf("heynoti_subscribe OK\n");
76 if(heynoti_attach_handler(fd))
77 fprintf(stderr, "heynoti_attach_handler FAIL\n");
79 printf("heynoti_attach_handler OK\n");
81 loop = g_main_loop_new(NULL, FALSE);
82 g_main_loop_run(loop);
85 g_main_loop_unref(loop);
91 And heynoti_poll_event() use polling mechanism. Therefore the process block until notification is received.
97 void callback(void *data)
99 printf("I got a testnoti\n");
102 int main(int argc, const char *argv[])
106 if((fd = heynoti_init()) < 0) {
107 fprintf(stderr, "heynoti_init FAIL\n");
110 printf("heynoti_init OK\n");
112 if(heynoti_subscribe(fd, "test_testnoti", callback, NULL))
113 fprintf(stderr, "heynoti_subscribe FAIL\n");
115 printf("heynoti_subscribe OK\n");
117 if(!heynoti_poll_event(fd))
118 fprintf(stderr, "heynoti_poll_event FAIL\n");
120 heynoti_unsubscribe(fd, "test_testnoti", callback);
126 If developer want to send notification message to the other process that watch the event, call heynoti_publish() API.
132 int main(int argc, char** argv)
135 printf("[usage] %s <noti name>\n", argv[0]);
138 if(!heynoti_publish(argv[1])){
139 fprintf(stderr, "heynoti_publish() FAIL\n");
147 Also, heynoti can do the monitoring of file. This is a basic faculty of inotify.
154 void callback(void *data)
156 printf("/home/test/noti_test_file was modified \n");
159 int main(int argc, const char *argv[])
164 if((fd = heynoti_init()) < 0) {
165 fprintf(stderr, "heynoti_init FAIL\n");
168 printf("heynoti_init OK\n");
170 if(heynoti_subscribe_file(fd, "/home/test/noti_test_file", callback, NULL, IN_CLOSE_WRITE | IN_DELETE_SELF))
171 fprintf(stderr, "heynoti_subscribe_file FAIL\n");
173 printf("heynoti_subscribe_file OK\n");
174 if(heynoti_attach_handler(fd))
175 fprintf(stderr, "heynoti_attach_handler FAIL\n");
177 printf("heynoti_attach_handler OK\n");
179 loop = g_main_loop_new(NULL, FALSE);
180 g_main_loop_run(loop);
183 g_main_loop_unref(loop);