tizen beta release
[framework/system/sensor-framework.git] / server / src / cfilter_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 <dlfcn.h>
29 #include <string.h>
30
31 #include <sys/un.h>
32 #include <netinet/in.h>
33 #include <arpa/inet.h>
34
35 #include <common.h>
36 #include <cobject_type.h>
37
38 #include <clist.h>
39 #include <cmutex.h>
40 #include <ccatalog.h>
41 #include <csync.h>
42 #include <cworker.h>
43 #include <cipc_worker.h>
44 #include <csock.h>
45 #include <cpacket.h>
46 #include <sf_common.h>
47 #include <cmodule.h>
48 #include <csensor_module.h>
49 #include <cfilter_module.h>
50 #include <cfilter_catalog.h>
51
52 #include <resource_str.h>
53
54
55
56 cfilter_catalog::cfilter_catalog()
57 {
58 }
59
60
61
62 cfilter_catalog::~cfilter_catalog()
63 {
64 }
65
66
67
68 bool cfilter_catalog::create(char *file)
69 {
70         void *handle;
71         char *name;
72         char *value;
73         cmodule *module;
74
75         if (ccatalog::load(file) == false) {
76                 if ( ccatalog::is_loaded() ) {
77                         DBG("The catalog is already loaded , so first unload it");
78                         ccatalog::unload();
79                 }
80                 ERR("Failed to load a catalog file\n");
81                 return false;
82         }
83
84         handle = ccatalog::iterate_init();
85         while (handle) {
86                 name = ccatalog::iterate_get_name(handle);
87                 handle = ccatalog::iterate_next(handle);
88                 if (!name) {
89                         ERR("Name is null\n");
90                         continue;
91                 }
92
93                 value = ccatalog::value(name, (char*)STR_DISABLE);
94                 if (value && !strcasecmp(value, STR_YES)) {
95                         ERR("%s is disabled\n", name);
96                         continue;
97                 }
98
99                 value = ccatalog::value(name, (char*)STR_PATH);
100                 if (!value) {
101                         ERR("Module path is not defined\n");
102                         continue;
103                 }
104
105                 module = cfilter_module::register_module(value, NULL, NULL);
106                 if (!module) {
107                         ERR("Failed to register a module %s\n", name);
108                         continue;
109                 }
110
111                 value = ccatalog::value(name, (char*)STR_OVERRIDE);
112                 if (value && !strcasecmp(value, STR_YES)) {
113                         DBG("Let's override module description\n");
114
115                         if (module->update_name(name) == false) {
116                                 ERR("Failed to update module name\n");
117                         }
118
119                         value = ccatalog::value(name, (char*)STR_ID);
120                         if (value) {
121                                 if (module->update_id(atoi(value)) == false) {
122                                         ERR("Failed to update ID\n");
123                                 }
124                         }
125
126                         value = ccatalog::value(name, (char*)STR_VERSION);
127                         if (value) {
128                                 if (module->update_version(atoi(value)) == false) {
129                                         ERR("Failed to update version\n");
130                                 }
131                         }
132                 }
133         }
134
135         DBG("Finished registeration , unload filter.conf ");
136         ccatalog::unload();
137         
138         return true;
139 }
140
141
142
143 void cfilter_catalog::destroy(void)
144 {
145         if ( ccatalog::is_loaded() ) {
146                 ccatalog::unload();
147         }
148 }
149
150
151
152 //! End of a file