2 * Copyright (c) 2012 - 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include "web_helper_agent.h"
23 #include "websocket.h"
24 #include "sclcoreimpl.h"
30 WEB_HELPER_AGENT_TYPE agent_type;
31 } WEB_HELPER_AGENT_TYPES_FOR_VERSIONS;
33 static WEB_HELPER_AGENT_TYPES_FOR_VERSIONS web_helper_agent_types_for_versions[] = {
34 {1, WEB_HELPER_AGENT_WEBSOCKET}, /* Major version 1 indicates that it uses websocket for communication */
37 static int WEB_HELPER_AGENT_TYPES_FOR_VERSIONS_NUM = \
38 sizeof(web_helper_agent_types_for_versions) / sizeof(WEB_HELPER_AGENT_TYPES_FOR_VERSIONS);
40 WEB_HELPER_AGENT_TYPE CWebHelperAgent::get_web_helper_agent_type_from_major_version(int version)
42 for (int loop = 0;loop < WEB_HELPER_AGENT_TYPES_FOR_VERSIONS_NUM;loop++) {
43 if (web_helper_agent_types_for_versions[loop].major_version == version) {
44 return web_helper_agent_types_for_versions[loop].agent_type;
47 return WEB_HELPER_AGENT_UNKNOWN;
50 CWebHelperAgent* CWebHelperAgent::create_web_helper_agent(WEB_HELPER_AGENT_TYPE type)
52 CWebHelperAgent *ret = NULL;
53 if (type == WEB_HELPER_AGENT_WEBSOCKET) {
54 ret = new CWebHelperAgentWebSocket;
59 void CWebHelperAgent::destroy_web_helper_agent(CWebHelperAgent* agent)
61 if (agent) delete agent;
64 CWebHelperAgent::CWebHelperAgent()
68 CWebHelperAgent::~CWebHelperAgent()
72 bool CWebHelperAgent::init()
77 bool CWebHelperAgent::exit()
82 void CWebHelperAgent::signal(int sig)
86 void CWebHelperAgent::log(const char *str)
88 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
90 //impl->logise_log(str);
94 void CWebHelperAgent::commit_string(const char *str)
96 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
98 impl->commit_string(-1, "", str);
102 void CWebHelperAgent::update_preedit_string(const char *str)
104 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
106 impl->update_preedit_string(-1, "", str);
110 void CWebHelperAgent::send_key_event(unsigned int key, unsigned int key_mask)
112 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
114 impl->send_key_event(-1, "", key, key_mask);
118 void CWebHelperAgent::forward_key_event(unsigned int key)
120 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
122 impl->forward_key_event(-1, "", key, scim::SCIM_KEY_NullMask);
126 void CWebHelperAgent::set_keyboard_sizes(int portrait_width, int portrait_height, int landscape_width, int landscape_height)
128 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
130 SclSize portrait, landscape;
131 portrait.width = portrait_width;
132 portrait.height = portrait_height;
133 landscape.width = landscape_width;
134 landscape.height = landscape_height;
135 impl->set_keyboard_size_hints(portrait, landscape);
139 void CWebHelperAgent::set_selection(int start_index, int end_index)
141 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
143 impl->set_selection(start_index, end_index);
147 void CWebHelperAgent::get_selection()
149 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
151 //impl->get_selection(-1, "", );
155 void CWebHelperAgent::get_surrounding_text(int maxlen_before, int maxlen_after)
157 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
159 impl->get_surrounding_text("", maxlen_before, maxlen_after);
163 void CWebHelperAgent::delete_surrounding_text(int offset, int len)
165 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
167 impl->delete_surrounding_text(offset, len);
171 std::string CMagicKeyManager::get_magic_key()
173 static std::string current_magic_key;
175 /* If we don't have magic key generated yet */
176 if (current_magic_key.length() != MAGIC_KEY_LENGTH) {
177 char magic_key[MAGIC_KEY_LENGTH + 1];
178 /* We are going to generate a magic key that contains ascii characters in the range of '0' to 'z' */
179 const char magic_key_range_lower = '0';
180 const char magic_key_range_upper = 'Z';
182 unsigned int seed = time(NULL);
183 for (int loop = 0;loop < MAGIC_KEY_LENGTH;loop++) {
184 magic_key[loop] = (rand_r(&seed) % (magic_key_range_upper - magic_key_range_lower)) + magic_key_range_lower;
186 magic_key[MAGIC_KEY_LENGTH] = '\0';
188 current_magic_key = magic_key;
191 return current_magic_key;