tizen beta release
[platform/core/appfw/heynoti.git] / test / tst_subscribe_file_mask.c
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 #include <stdio.h>
25 #include <unistd.h>
26 #include <string.h>
27 #include <errno.h>
28 #include <Ecore.h>
29
30 #include "heynoti.h"
31
32 #define NOTI_DIRECT "/tmp/noti/direct"
33
34 int flag;
35 int fd;
36 Ecore_Event_Handler *handler;
37
38 #define NOTI_CB(n) callback##n
39
40 Eina_Bool exit_func(void *data, int ev_type, void *ev)
41 {
42         Ecore_Event_Signal_Exit *e;
43
44         e = (Ecore_Event_Signal_Exit *) ev;
45         if (e->interrupt)
46                 printf("Exit: interrupt\n");
47         else if (e->quit)
48                 printf("Exit: quit\n");
49         else if (e->terminate)
50                 printf("Exit: terminate\n");
51
52         ecore_main_loop_quit();
53
54         return ECORE_CALLBACK_PASS_ON;
55 }
56
57 void in_access(void *data)
58 {
59         printf("%s\n", __func__);
60 }
61
62 void in_modify(void *data)
63 {
64         printf("%s\n", __func__);
65 }
66
67 void in_close_write(void *data)
68 {
69         printf("%s\n", __func__);
70 }
71
72 void in_close_nowrite(void *data)
73 {
74         printf("%s\n", __func__);
75 }
76
77 void in_open(void *data)
78 {
79         printf("%s\n", __func__);
80 }
81
82 void term(int signo)
83 {
84         flag = 1;
85 }
86
87 void step(int signo)
88 {
89         static int step_cnt = 0;
90         int r;
91
92         printf("%s\n", __func__);
93
94         switch (step_cnt) {
95         case 0:
96                 r = heynoti_unsubscribe_file(fd, NOTI_DIRECT, in_access);
97                 printf("noti del: in_access : %d\n", r);
98                 break;
99         case 1:
100                 r = heynoti_unsubscribe_file(fd, NOTI_DIRECT, in_modify);
101                 printf("noti del: in_modify : %d\n", r);
102                 break;
103         case 2:
104                 r = heynoti_unsubscribe_file(fd, NOTI_DIRECT, in_close_write);
105                 printf("noti del: in_close_write : %d\n", r);
106                 break;
107         case 3:
108                 r = heynoti_unsubscribe_file(fd, NOTI_DIRECT, in_close_nowrite);
109                 printf("noti del: in_close_nowrite : %d\n", r);
110                 break;
111         case 4:
112                 r = heynoti_unsubscribe_file(fd, NOTI_DIRECT, in_open);
113                 printf("noti del: in_open : %d\n", r);
114                 break;
115         }
116
117         step_cnt++;
118 }
119
120 int main(int argc, const char *argv[])
121 {
122         int ret;
123
124         ecore_init();
125         ecore_app_args_set(argc, argv);
126
127         fd = heynoti_init();
128         printf("Noti init: %d\n", fd);
129         if (fd == -1)
130                 return -1;
131
132         handler = ecore_event_handler_add(ECORE_EVENT_SIGNAL_EXIT, exit_func, NULL);
133
134         ret = heynoti_subscribe_file(fd, NOTI_DIRECT, in_access, NULL, IN_ACCESS);
135         printf("noti add: in_access : %d\n", ret);
136
137         ret = heynoti_subscribe_file(fd, NOTI_DIRECT, in_modify, NULL, IN_MODIFY);
138         printf("noti add: in_modify : %d\n", ret);
139
140         ret = heynoti_subscribe_file(fd, NOTI_DIRECT, in_close_write, NULL, IN_CLOSE_WRITE);
141         printf("noti add: in_close_write : %d\n", ret);
142
143         ret = heynoti_subscribe_file(fd, NOTI_DIRECT, in_close_nowrite, NULL, IN_CLOSE_NOWRITE);
144         printf("noti add: in_close_nowrite : %d\n", ret);
145
146         ret = heynoti_subscribe_file(fd, NOTI_DIRECT, in_open, NULL, IN_OPEN);
147         printf("noti add: in_open : %d\n", ret);
148
149         ret = heynoti_attach_handler(fd);
150         printf("add main: %d\n", ret);
151         if (ret == -1)
152                 goto err;
153
154         while (!flag) {
155                 sleep(1);
156         }
157
158         ecore_main_loop_begin();
159  err:
160         heynoti_close(fd);
161         ecore_shutdown();
162
163         return 0;
164 }
165