Tizen 2.1 base
[platform/framework/native/ime.git] / src / FUiIme_InputServiceBinder.cpp
1 //\r
2 // Open Service Platform\r
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.\r
4 //\r
5 // Licensed under the Apache License, Version 2.0 (the License);\r
6 // you may not use this file except in compliance with the License.\r
7 // You may obtain a copy of the License at\r
8 //\r
9 //     http://www.apache.org/licenses/LICENSE-2.0\r
10 //\r
11 // Unless required by applicable law or agreed to in writing, software\r
12 // distributed under the License is distributed on an "AS IS" BASIS,\r
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
14 // See the License for the specific language governing permissions and\r
15 // limitations under the License.\r
16 //\r
17 \r
18 /**\r
19  * @file        FUiIme_InputServiceBinder.cpp\r
20  * @brief       This is the implementation file for the %_InputServiceBinder class.\r
21  *\r
22  * This implementation file contains definition of the %_InputServiceBinder class.\r
23  */\r
24 \r
25 #include <new>\r
26 \r
27 #include <FBaseSysLog.h>\r
28 \r
29 #include "FUiIme_ImeInfo.h"\r
30 #include "FUiIme_InputServiceBinder.h"\r
31 #include "FUiIme_ScimDataConverter.h"\r
32 \r
33 using namespace Tizen::Base;\r
34 \r
35 namespace Tizen { namespace Ui { namespace Ime {\r
36 \r
37 _InputServiceBinder* _InputServiceBinder::__pInputServiceBinder = null;\r
38 \r
39 _InputServiceBinder::_InputServiceBinder(void)\r
40         :__pHelperAgent(null)\r
41         ,__pScimDataConverter(null)\r
42 {\r
43 }\r
44 \r
45 _InputServiceBinder::~_InputServiceBinder(void)\r
46 {\r
47         if (IsBound() == true)\r
48         {\r
49                 Unbind();\r
50         }\r
51 \r
52         delete __pHelperAgent;\r
53         __pHelperAgent = null;\r
54 \r
55         delete __pScimDataConverter;\r
56         __pScimDataConverter = null;\r
57 }\r
58 \r
59 result\r
60 _InputServiceBinder::Construct(void)\r
61 {\r
62         result r = E_SUCCESS;\r
63 \r
64         __pHelperAgent = new(std::nothrow) scim::HelperAgent();\r
65         SysTryReturnResult(NID_UI_IME, __pHelperAgent, E_OUT_OF_MEMORY, "Memory allocation failed.");\r
66 \r
67         __pScimDataConverter = new(std::nothrow) _ScimDataConverter();\r
68         SysTryCatch(NID_UI_IME, __pScimDataConverter, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");\r
69 \r
70         return r;\r
71 \r
72 CATCH:\r
73         delete __pHelperAgent;\r
74         __pHelperAgent = null;\r
75 \r
76         return r;\r
77 }\r
78 \r
79 _InputServiceBinder*\r
80 _InputServiceBinder::GetInstance(void)\r
81 {\r
82         result r = E_SUCCESS;\r
83 \r
84         if (!__pInputServiceBinder)\r
85         {\r
86                 __pInputServiceBinder = new(std::nothrow) _InputServiceBinder();\r
87                 SysTryReturn(NID_UI_IME, __pInputServiceBinder, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");\r
88                 \r
89                 r = __pInputServiceBinder->Construct();\r
90                 SysTryCatch(NID_UI_IME, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));\r
91         }\r
92 \r
93         return __pInputServiceBinder;\r
94 \r
95 CATCH:\r
96         delete __pInputServiceBinder;\r
97         __pInputServiceBinder = null;\r
98 \r
99         return null;\r
100 }\r
101 \r
102 scim::HelperAgent*\r
103 _InputServiceBinder::GetHelperAgent(void) const\r
104 {\r
105         return __pHelperAgent;\r
106 }\r
107 \r
108 BindingId\r
109 _InputServiceBinder::Bind(void)\r
110 {\r
111         result r = E_SUCCESS;\r
112 \r
113         int bindingId = -1;\r
114 \r
115         _ImeInfo* pImeInfo = _ImeInfo::GetInstance();\r
116 \r
117         scim::String uuid = pImeInfo->GetUuid();\r
118         scim::String name = pImeInfo->GetName();\r
119 \r
120         scim::HelperInfo helperInfo(uuid, name, "", "",\r
121                                                                 scim::SCIM_HELPER_STAND_ALONE | scim::SCIM_HELPER_NEED_SCREEN_INFO | scim::SCIM_HELPER_AUTO_RESTART);\r
122 \r
123         if (IsBound() == true)\r
124         {\r
125                 r = Unbind();\r
126                 SysTryReturn(NID_UI_IME, r == E_SUCCESS, -1, r, "[%s] Propagating.", GetErrorMessage(r));\r
127         }\r
128 \r
129         bindingId = __pHelperAgent->open_connection(helperInfo, ":0");\r
130         SysTryReturn(NID_UI_IME, bindingId > -1, bindingId, E_CONNECTION_FAILED, "[E_CONNECTION_FAILED] The connection to the specific destination fails.");\r
131 \r
132         SysLog(NID_UI_IME, "The binding ID is %d.", bindingId);\r
133 \r
134         return bindingId;\r
135 }\r
136 \r
137 result\r
138 _InputServiceBinder::Unbind(void)\r
139 {\r
140         result r = E_SUCCESS;\r
141 \r
142         SysTryReturnResult(NID_UI_IME, IsBound() == true, E_HOST_NOT_FOUND, "The destination host is not found.");\r
143 \r
144         __pHelperAgent->close_connection();\r
145 \r
146         return r;\r
147 }\r
148 \r
149 bool\r
150 _InputServiceBinder::IsBound(void) const\r
151 {\r
152         return __pHelperAgent->is_connected();\r
153 }\r
154 \r
155 BindingId\r
156 _InputServiceBinder::GetBindingId(void) const\r
157 {\r
158         int bindingId = __pHelperAgent->get_connection_number();\r
159         SysTryReturn(NID_UI_IME, bindingId > -1, bindingId, E_HOST_NOT_FOUND, "[E_HOST_NOT_FOUND] The destination host is not found.");\r
160 \r
161         return bindingId;\r
162 }\r
163 \r
164 }}} // Tizen::Ui::Ime\r