Upload initial version
[platform/core/uifw/libscl-ui-nui.git] / xml2binary / encode_input_mode_configure.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 "resource_storage_impl.h"
19 #include "encode_input_mode_configure.h"
20 #include <string>
21 #include <libxml/parser.h>
22 #include "xmlresource.h"
23 #include "imetadata_helper.h"
24 #include "put_record.h"
25 #include "_auto_metadata.h"
26 using namespace std;
27 using namespace xmlresource;
28
29 static void
30 encode_input_mode_configure_record(ResourceStorage& storage, const PSclInputModeConfigure cur, const Input_mode_configure_width& record_width) {
31     //name
32     storage.encode_string(cur->name, record_width.name);
33     //layout_portrait
34     storage.encode_string(cur->layouts[0], record_width.layout_portrait);
35     //layout_landscape
36     storage.encode_string(cur->layouts[1], record_width.layout_landscape);
37     //use_virtual_window
38     storage.put<sint_t>(cur->use_virtual_window, record_width.use_virtual_window);
39     //use_dim_window
40     storage.put<sint_t>(cur->use_dim_window, record_width.use_dim_window);
41     //timeout
42     storage.put<sint_t>(cur->timeout, record_width.timeout);
43 }
44
45 int encode_input_mode_configure_file(ResourceStorage& storage, IMetaData_Helper& md_helper) {
46     int init_size = storage.get_size();
47     /*size 4bytes*/
48     const int INPUT_MODE_CONFIGURE_SIZE_WIDTH = 4;
49
50
51     XMLResource *xmlresource = XMLResource::get_instance();
52     PSclInputModeConfigure inputModeConfigureTable = xmlresource->get_input_mode_configure_table();
53     int size = xmlresource->get_inputmode_size();
54 #ifdef __SCL_TXT_DEBUG
55     put_input_mode_configure_table(ENCODE, inputModeConfigureTable);
56
57 #endif
58     PSclInputModeConfigure cur = inputModeConfigureTable;
59
60     //first 8 byte is the size of the block
61     storage.reserve(8);
62     storage.put<sint_t>(size, INPUT_MODE_CONFIGURE_SIZE_WIDTH);
63
64     Input_mode_configure_width record_width;
65     set_input_mode_configure_width(md_helper, record_width);
66     for ( int i = 0; i < size; ++i ) {
67         encode_input_mode_configure_record(storage, cur, record_width);
68         cur++;
69     }
70
71     int advance_size = storage.get_size() - init_size;
72     storage.random_put<sint_t>(advance_size, 8, init_size);
73     return storage.get_size();
74 }
75
76 int encode_input_mode_configure_file(const char* file, int& offset, IMetaData_Helper& md_helper) {
77     if (!file) return 0;
78
79     ResourceStorage storage;
80     encode_input_mode_configure_file(storage, md_helper);
81     storage.toFile(file, offset);
82
83     return storage.get_size();
84 }
85
86 int encode_input_mode_configure_file(const char* file, IMetaData_Helper& md_helper) {
87     if (!file) return 0;
88
89     ResourceStorage storage;
90     encode_input_mode_configure_file(storage, md_helper);
91     storage.toFile(file);
92
93     return storage.get_size();
94 }