tizen beta release
[framework/system/sensor-framework.git] / server / src / csensor_catalog.cpp
1 /*
2  *  sensor-framework
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: JuHyun Kim <jh8212.kim@samsung.com>
7  * 
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
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
19  *
20  */ 
21
22
23
24
25
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <stdlib.h>
30 #include <errno.h>
31
32 #include <sys/un.h>
33 #include <netinet/in.h>
34 #include <arpa/inet.h>
35
36 #include <common.h>
37
38 #include <cobject_type.h>
39
40 #include <clist.h>
41 #include <cmutex.h>
42 #include <cpacket.h>
43 #include <csync.h>
44 #include <cworker.h>
45 #include <cipc_worker.h>
46 #include <csock.h>
47
48 #include <sf_common.h>
49 #include <cmodule.h>
50 #include <ccatalog.h>
51 #include <csensor_module.h>
52 #include <csensor_catalog.h>
53
54 #include <resource_str.h>
55
56
57 #define MAX_LINE        512
58
59
60
61 csensor_catalog::csensor_catalog()
62 {
63 }
64
65
66
67 csensor_catalog::~csensor_catalog()
68 {
69 }
70
71
72
73 bool csensor_catalog::create(char *file)
74 {
75         void *handle;
76         char *name;
77         char *value;
78         cmodule *module;
79
80         if (ccatalog::load(file) == false) {
81                 if ( ccatalog::is_loaded() ) {
82                         DBG("The catalog is already loaded , so first unload it");
83                         ccatalog::unload();
84                 }
85                 ERR("Failed to load a catalog file\n");
86                 return false;
87         }
88
89         handle = ccatalog::iterate_init();
90         while (handle) {
91                 name = ccatalog::iterate_get_name(handle);
92                 handle = ccatalog::iterate_next(handle);
93                 if (!name) {
94                         ERR("Name is null\n");
95                         continue;
96                 }
97
98                 value = ccatalog::value(name, (char*)STR_DISABLE);
99                 if (value && !strcasecmp(value, STR_YES)) {
100                         ERR("%s is disabled\n", name);
101                         continue;
102                 }
103
104                 value = ccatalog::value(name, (char*)STR_PATH);
105                 if (!value) {
106                         ERR("Module path is not defined\n");
107                         continue;
108                 }
109
110                 module = csensor_module::register_module(value, NULL, NULL);
111                 if (!module) {
112                         ERR("Failed to register a module %s\n", name);
113                         continue;
114                 }
115
116                 value = ccatalog::value(name, (char*)STR_OVERRIDE);
117                 if (value && !strcasecmp(value, STR_YES)) {
118                         DBG("Let's override module description [%s]\n", name);
119
120                         if (module->update_name(name) == false) {
121                                 ERR("Failed to update module name\n");
122                         }
123
124                         value = ccatalog::value(name, (char*)STR_ID);
125                         if (value) {
126                                 if (module->update_id(atoi(value)) == false) {
127                                         ERR("Failed to update ID\n");
128                                 }
129                         }
130
131                         value = ccatalog::value(name, (char*)STR_VERSION);
132                         if (value) {
133                                 if (module->update_version(atoi(value)) == false) {
134                                         ERR("Failed to update version\n");
135                                 }
136                         }
137
138                         value = ccatalog::value(name, (char*)STR_POLL);
139                         if (value) {
140                                 csensor_module *sensor;
141                                 sensor = (csensor_module*)module;
142                                 if (sensor->update_polling_interval(atoi(value)) == false) {
143                                         ERR("Failed to update polling interval\n");
144                                 }
145                         }
146                 }
147         }
148
149         DBG("Finished registeration , unload sensor.conf ");
150         ccatalog::unload();
151
152         return true;
153 }
154
155
156
157 void csensor_catalog::destroy(void)
158 {
159         if ( ccatalog::is_loaded() ) {
160                 ccatalog::unload();
161         }
162 }
163
164
165
166
167 //! End of a file