2635a46ab89b7a14d3d51b242ea1c090d112acdd
[platform/core/uifw/libscl-ui-nui.git] / scl / input_mode_configure_bin_parser.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 "input_mode_configure_bin_parser.h"
19 #include "simple_debug.h"
20 #include "put_record.h"
21 using namespace std;
22
23 BinInputModeConfigParser::BinInputModeConfigParser() {
24     m_inputmode_size = 0;
25     memset(m_input_mode_configure_table, 0x00, sizeof(SclInputModeConfigure) * MAX_SCL_INPUT_MODE);
26     parser_info_provider = NULL;
27 }
28
29 BinInputModeConfigParser::~BinInputModeConfigParser() {
30 }
31
32 BinInputModeConfigParser*
33 BinInputModeConfigParser::get_instance() {
34     static BinInputModeConfigParser instance;
35     return &instance;
36 }
37
38 void
39 BinInputModeConfigParser::init(const FileStorage& storage, int offset, int size, IParserInfo_Provider* provider) {
40     m_storage.set_str_provider(parser_info_provider);
41     m_storage.get_storage(storage, offset, size);
42     this->parser_info_provider = provider;
43     parsing_input_mode_configure_table();
44 }
45
46 int
47 BinInputModeConfigParser::get_inputmode_id(const char *name) {
48     if (name == NULL) return -1;
49
50     for (int i = 0; i < MAX_SCL_INPUT_MODE; ++i) {
51         if ( m_input_mode_configure_table[i].name ) {
52             if ( 0 == strcmp(m_input_mode_configure_table[i].name, name) ) {
53                 return i;
54             }
55         }
56     }
57
58     return -1;
59 }
60
61 const char*
62 BinInputModeConfigParser::get_inputmode_name(int id) {
63     if (id >= 0 && id < MAX_SCL_INPUT_MODE) {
64         return m_input_mode_configure_table[id].name;
65     }
66
67     return NULL;
68 }
69
70 int
71 BinInputModeConfigParser::get_inputmode_size() {
72     return m_inputmode_size;
73 }
74
75 void
76 BinInputModeConfigParser::parsing_input_mode_configure_table() {
77     // skip data_size
78     m_storage.advance(8);
79
80     //rec_num
81     m_inputmode_size = m_storage.get<sint_t>(4);
82
83     Input_mode_configure_width record_width;
84     set_input_mode_configure_width(*parser_info_provider, record_width);
85
86     PSclInputModeConfigure cur = m_input_mode_configure_table;
87
88     for (int i = 0; i < m_inputmode_size; ++i) {
89         //name
90         m_storage.get_str(&(cur->name), record_width.name, m_string_collector);
91         //layout_portrait
92         m_storage.get_str(&(cur->layouts[0]), record_width.layout_portrait, m_string_collector);
93         //layout_landscape
94         m_storage.get_str(&(cur->layouts[1]), record_width.layout_landscape, m_string_collector);
95         //use_virtual_window
96         cur->use_virtual_window = m_storage.get<sint_t>(record_width.use_virtual_window);
97         //use_dim_window
98         cur->use_dim_window = m_storage.get<sint_t>(record_width.use_dim_window);
99
100         cur->timeout = m_storage.get<sint_t>(record_width.timeout);
101
102         cur++;
103     }
104
105 #ifdef __SCL_TXT_DEBUG
106     put_input_mode_configure_table(DECODE, m_input_mode_configure_table);
107 #endif
108 }
109
110 PSclInputModeConfigure
111 BinInputModeConfigParser::get_input_mode_configure_table() {
112     return m_input_mode_configure_table;
113 }
114