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()
73 bool CWebHelperAgent::init()
78 bool CWebHelperAgent::exit()
83 void CWebHelperAgent::signal(int sig)
88 void CWebHelperAgent::log(const char *str)
90 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
92 //impl->logise_log(str);
96 void CWebHelperAgent::commit_string(const char *str)
98 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
100 impl->commit_string(-1, "", str);
104 void CWebHelperAgent::update_preedit_string(const char *str)
106 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
108 impl->update_preedit_string(-1, "", str);
112 void CWebHelperAgent::send_key_event(unsigned int key, unsigned int key_mask)
114 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
116 impl->send_key_event(-1, "", key, key_mask);
120 void CWebHelperAgent::forward_key_event(unsigned int key)
122 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
124 impl->forward_key_event(-1, "", key, scim::SCIM_KEY_NullMask);
128 void CWebHelperAgent::set_keyboard_sizes(int portrait_width, int portrait_height, int landscape_width, int landscape_height)
130 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
132 SclSize portrait, landscape;
133 portrait.width = portrait_width;
134 portrait.height = portrait_height;
135 landscape.width = landscape_width;
136 landscape.height = landscape_height;
137 impl->set_keyboard_size_hints(portrait, landscape);
141 void CWebHelperAgent::set_selection(int start_index, int end_index)
143 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
145 impl->set_selection(start_index, end_index);
149 void CWebHelperAgent::get_selection()
151 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
153 //impl->get_selection(-1, "", );
157 void CWebHelperAgent::get_surrounding_text(int maxlen_before, int maxlen_after)
159 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
161 impl->get_surrounding_text("", maxlen_before, maxlen_after);
165 void CWebHelperAgent::delete_surrounding_text(int offset, int len)
167 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
169 impl->delete_surrounding_text(offset, len);
173 std::string CMagicKeyManager::get_magic_key()
175 static std::string current_magic_key;
177 /* If we don't have magic key generated yet */
178 if (current_magic_key.length() != MAGIC_KEY_LENGTH) {
179 char magic_key[MAGIC_KEY_LENGTH + 1];
180 /* We are going to generate a magic key that contains ascii characters in the range of '0' to 'z' */
181 const char magic_key_range_lower = '0';
182 const char magic_key_range_upper = 'Z';
185 for(int loop = 0;loop < MAGIC_KEY_LENGTH;loop++) {
186 magic_key[loop] = (rand() % (magic_key_range_upper - magic_key_range_lower)) + magic_key_range_lower;
188 magic_key[MAGIC_KEY_LENGTH] = '\0';
190 current_magic_key = magic_key;
193 return current_magic_key;