tizen beta release
[platform/core/appfw/heynoti.git] / SLP_Heynoti_PG.h
1 /*
2  * heynoti
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
7  * Jaeho Lee <jaeho81.lee@samsung.com>
8  *
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
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
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.
20  *
21  */
22
23
24
25 /**
26  *
27  * @ingroup   SLP_PG 
28  * @defgroup   HEYNOTI_PG HEY(ligHt Easy speedY) Notification
29 @{
30 <h1 class="pg">Introduction</h1>
31
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)).
37
38 @image html SLP_Heynoti_PG_image01.png
39
40 <h2 class="pg">Properties</h2>
41 - HEY(ligHt Easy speedY) Notification
42 - Convenient API
43 - Header File : heynoti.h
44
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.
49
50 @code
51 #include <stdio.h>
52 #include <glib.h>
53 #include <heynoti.h>
54
55 void callback(void *data)
56 {
57         printf("I got a testnoti\n");
58 }
59
60 int main(int argc, const char *argv[])
61 {
62         int fd;
63         GMainLoop *loop;
64
65         if((fd = heynoti_init()) < 0) {
66                 fprintf(stderr, "heynoti_init FAIL\n");
67                 return -1;
68         }else
69         printf("heynoti_init OK\n");
70
71         if(heynoti_subscribe(fd, "test_testnoti", callback, NULL))
72                 fprintf(stderr, "heynoti_subscribe FAIL\n");
73         else
74                 printf("heynoti_subscribe OK\n");
75
76         if(heynoti_attach_handler(fd))
77                 fprintf(stderr, "heynoti_attach_handler FAIL\n");
78         else
79                 printf("heynoti_attach_handler OK\n");
80
81         loop = g_main_loop_new(NULL, FALSE);
82         g_main_loop_run(loop);
83
84         heynoti_close(fd);
85         g_main_loop_unref(loop);
86
87         return 0;
88 }
89 @endcode
90
91 And heynoti_poll_event() use polling mechanism. Therefore the process block until notification is received.
92
93 @code
94 #include <stdio.h>
95 #include <heynoti.h>
96
97 void callback(void *data)
98 {
99         printf("I got a testnoti\n");
100 }
101
102 int main(int argc, const char *argv[])
103 {
104         int fd;
105
106         if((fd = heynoti_init()) < 0) {
107                 fprintf(stderr, "heynoti_init FAIL\n");
108                 return -1;
109         }else
110                 printf("heynoti_init OK\n");
111
112         if(heynoti_subscribe(fd, "test_testnoti", callback, NULL))
113                 fprintf(stderr, "heynoti_subscribe FAIL\n");
114         else
115                 printf("heynoti_subscribe OK\n");
116
117         if(!heynoti_poll_event(fd))
118                 fprintf(stderr, "heynoti_poll_event FAIL\n");
119         
120         heynoti_unsubscribe(fd, "test_testnoti", callback);
121
122         return 0;
123 }
124 @endcode
125
126 If developer want to send notification message to the other process that watch the event, call heynoti_publish() API.
127
128 @code
129 #include <stdio.h>
130 #include <heynoti.h>
131
132 int main(int argc, char** argv)
133 {
134         if(argc != 2) {
135                 printf("[usage] %s <noti name>\n", argv[0]);
136                 return -1;
137         }
138         if(!heynoti_publish(argv[1])){
139                 fprintf(stderr, "heynoti_publish() FAIL\n");
140                 return -1;
141         }
142                 
143         return 0;
144 }
145 @endcode
146
147 Also, heynoti can do the monitoring of file. This is a basic faculty of inotify.
148
149 @code
150 #include <stdio.h>
151 #include <glib.h>
152 #include <heynoti.h>
153
154 void callback(void *data)
155 {
156         printf("/home/test/noti_test_file was modified \n");
157 }
158
159 int main(int argc, const char *argv[])
160 {
161         int fd;
162         GMainLoop *loop;
163
164         if((fd = heynoti_init()) < 0) {
165                 fprintf(stderr, "heynoti_init FAIL\n");
166                 return -1;
167         }else
168                 printf("heynoti_init OK\n");
169
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");
172         else
173                 printf("heynoti_subscribe_file OK\n");
174         if(heynoti_attach_handler(fd))
175                 fprintf(stderr, "heynoti_attach_handler FAIL\n");
176         else
177                 printf("heynoti_attach_handler OK\n");
178
179         loop = g_main_loop_new(NULL, FALSE);
180         g_main_loop_run(loop);
181
182         heynoti_close(fd);
183         g_main_loop_unref(loop);
184
185         return 0;
186 }
187 @endcode
188 */
189
190 /**
191 @}
192 */