Initialize Tizen 2.3
[framework/system/deviced.git] / src / core / noti.c
1 /*
2  * deviced
3  *
4  * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
5  *
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
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  */
18
19
20 #include <heynoti.h>
21 #include "log.h"
22 #include "data.h"
23 #include "devices.h"
24 #include "common.h"
25
26 static int noti_fd;
27
28 int noti_getfd()
29 {
30         return noti_fd;
31 }
32
33 int noti_send(char *filename)
34 {
35         return heynoti_publish(filename);
36 }
37
38 int noti_add(const char *noti, void (*cb) (void *), void *data)
39 {
40         if (noti_fd < 0)
41                 return -1;
42
43         return heynoti_subscribe(noti_fd, noti, cb, data);
44 }
45
46 static void noti_init(void *data)
47 {
48         struct main_data *ad = (struct main_data*)data;
49
50         if ((ad->noti_fd = heynoti_init()) < 0) {
51                 _E("Hey Notification Initialize failed");
52                 return;
53         }
54         if (heynoti_attach_handler(ad->noti_fd) != 0) {
55                 _E("fail to attach hey noti handler");
56                 return;
57         }
58
59         noti_fd = heynoti_init();
60         if (noti_fd < 0) {
61                 _E("heynoti_init error");
62                 return;
63         }
64
65         if (heynoti_attach_handler(noti_fd) < 0) {
66                 _E("heynoti_attach_handler error");
67                 return;
68         }
69 }
70
71 static void noti_exit(void *data)
72 {
73         struct main_data *ad = (struct main_data*)data;
74
75         heynoti_close(ad->noti_fd);
76         heynoti_close(noti_fd);
77 }
78
79 static const struct device_ops noti_device_ops = {
80         .priority = DEVICE_PRIORITY_NORMAL,
81         .name     = "noti",
82         .init     = noti_init,
83         .exit     = noti_exit,
84 };
85
86 DEVICE_OPS_REGISTER(&noti_device_ops)