Upload initial version
[platform/core/uifw/libscl-ui-nui.git] / scl / sclres_manager.cpp
1 /*
2  * Copyright (c) 2012 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include "sclres_manager.h"
19 #include "xmlresource.h"
20 #include "binary_xmlresource.h"
21 #include <assert.h>
22 #include "simple_debug.h"
23 using namespace xmlresource;
24 using namespace binary_xmlresource;
25 using namespace sclres;
26 #include "put_record.h"
27
28 static sclres::SclRes *_current_parser = NULL;
29
30 SclResParserManager::~SclResParserManager() {
31     _current_parser = NULL;
32     m_initialized = false;
33 }
34
35 SclResParserManager*
36 SclResParserManager::get_instance() {
37     static SclResParserManager instance;
38     return &instance;
39 }
40
41 SclResParserManager::SclResParserManager() {
42     _current_parser = NULL;
43     m_initialized = false;
44 }
45
46 void
47 SclResParserManager::init(const SCLParserType parser_type, const char *entry_filepath) {
48     if (!m_initialized) {
49         if (parser_type == SCL_PARSER_TYPE_XML) {
50             SCLLOG(SclLog::MESSAGE, "Use text xml\n");
51             _current_parser = XMLResource::get_instance();
52         } else if (parser_type == SCL_PARSER_TYPE_BINARY_XML) {
53             SCLLOG(SclLog::MESSAGE, "Use binary xml\n");
54             _current_parser = BinResource::get_instance();
55         }
56
57         /* Let's acquire the directory information from filepath */
58         std::string str = entry_filepath;
59         size_t found;
60         found = str.find_last_of("/\\");
61
62         std::string filepath = str.substr(0, found);
63         std::string filename = str.substr(found + 1);
64
65         //assert(_current_parser != NULL);
66         if (_current_parser != NULL) {
67             /* Assume the directory where the main entry file exists, is the default resource directory */
68             _current_parser->set_resource_directory(filepath.c_str());
69             _current_parser->init(filename.c_str());
70 #ifdef __SCL_TXT_DEBUG
71             put_autopopup_configure(PARSER, *(_current_parser->get_autopopup_configure()));
72             put_default_configure(PARSER, *(_current_parser->get_default_configure()));
73             put_input_mode_configure_table(PARSER, _current_parser->get_input_mode_configure_table());
74             put_key_coordinate_frame(PARSER, _current_parser->get_key_coordinate_pointer_frame());
75             put_label_properties_frame(PARSER, _current_parser->get_label_properties_frame());
76             put_layout_table(PARSER, _current_parser->get_layout_table());
77             put_magnifier_wnd_configure(PARSER, *(_current_parser->get_magnifier_configure()));
78             put_modifier_decoration(PARSER, _current_parser->get_modifier_decoration_table());
79             //put_nine_patch_info(PARSER, _current_parser->get_nine_patch_file_list());
80 #endif
81         }
82         m_initialized = true;
83     }
84 }
85
86 void
87 SclResParserManager::load(int layout_id) {
88     if (_current_parser) {
89         _current_parser->load(layout_id);
90     }
91 }
92
93 void
94 SclResParserManager::unload() {
95     if (_current_parser) {
96         _current_parser->unload();
97     }
98 }
99
100 bool
101 SclResParserManager::loaded(int layout_id) {
102     if (_current_parser == NULL) return false;
103
104     return _current_parser->loaded(layout_id);
105 }
106
107 void
108 SclResParserManager::reload() {
109     if (_current_parser) {
110         _current_parser->reload();
111     }
112 }
113
114 PSclInputModeConfigure
115 SclResParserManager::get_input_mode_configure_table() {
116     if (_current_parser == NULL) return NULL;
117
118     return _current_parser->get_input_mode_configure_table();
119 }
120
121 PSclLayout
122 SclResParserManager::get_layout_table() {
123     if (_current_parser == NULL) return NULL;
124
125     return _current_parser->get_layout_table();
126 }
127
128 PSclLayoutKeyCoordinatePointerTable
129 SclResParserManager::get_key_coordinate_pointer_frame() {
130     if (_current_parser == NULL) return NULL;
131
132     return _current_parser->get_key_coordinate_pointer_frame();
133 }
134
135 PSclModifierDecoration
136 SclResParserManager::get_modifier_decoration_table() {
137     if (_current_parser == NULL) return NULL;
138
139     return _current_parser->get_modifier_decoration_table();
140 }
141
142 PSclLabelPropertiesTable
143 SclResParserManager::get_label_properties_frame() {
144     if (_current_parser == NULL) return NULL;
145
146     return _current_parser->get_label_properties_frame();
147 }
148
149 PSclDefaultConfigure
150 SclResParserManager::get_default_configure() {
151     if (_current_parser == NULL) return NULL;
152
153     return _current_parser->get_default_configure();
154 }
155
156 PSclAutoPopupConfigure
157 SclResParserManager::get_autopopup_configure() {
158     if (_current_parser == NULL) return NULL;
159
160     return _current_parser->get_autopopup_configure();
161 }
162
163 PSclMagnifierWndConfigure
164 SclResParserManager::get_magnifier_configure() {
165     if (_current_parser == NULL) return NULL;
166
167     return _current_parser->get_magnifier_configure();
168 }
169
170 const char*
171 SclResParserManager::get_resource_directory() {
172     if (_current_parser == NULL) return NULL;
173
174     return _current_parser->get_resource_directory();
175 }
176
177 int
178 SclResParserManager::get_inputmode_id(const char *name) {
179     if (_current_parser == NULL) return -1;
180
181     return _current_parser->get_inputmode_id(name);
182 }
183
184 const char*
185 SclResParserManager::get_inputmode_name(int id) {
186     if (_current_parser == NULL) return NULL;
187
188     return _current_parser->get_inputmode_name(id);
189 }
190
191 int
192 SclResParserManager::get_inputmode_size() {
193     if (_current_parser == NULL) return 0;
194
195     return _current_parser->get_inputmode_size();
196 }
197
198 int
199 SclResParserManager::get_layout_size() {
200     if (_current_parser == NULL) return 0;
201
202     return _current_parser->get_layout_size();
203 }
204
205 int
206 SclResParserManager::get_layout_id(const char *name) {
207     if (_current_parser == NULL) return -1;
208
209     return _current_parser->get_layout_id(name);
210 }
211
212 int
213 SclResParserManager::get_labelproperty_size() {
214     if (_current_parser == NULL) return 0;
215
216     return _current_parser->get_labelproperty_size();
217 }
218
219 int
220 SclResParserManager::get_modifier_decoration_id(const char *name) {
221     if (_current_parser == NULL) return -1;
222
223     return _current_parser->get_modifier_decoration_id(name);
224 }
225
226 bool
227 SclResParserManager::get_nine_patch_info(const char *filename, SclNinePatchInfo *info) {
228     if (_current_parser == NULL) return false;
229
230     return _current_parser->get_nine_patch_info(filename, info);
231 }
232
233 const char*
234 SclResParserManager::get_name() {
235     if (_current_parser == NULL) return NULL;
236
237     return _current_parser->get_name();
238 }