2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FSys_SettingClient.cpp
20 * @brief This is the implementation file for _SettingClient class.
23 #include <unique_ptr.h>
25 #include "FSys_SystemClient.h"
27 #include <FBaseSysLog.h>
29 #include <FIo_AppServiceIpcMessages.h>
30 #include "FSys_CommunicationDispatcherClient.h"
34 using namespace Tizen::Base;
35 using namespace Tizen::Base::Collection;
36 using namespace Tizen::Base::Runtime;
37 using namespace Tizen::Io;
39 namespace Tizen { namespace System
42 static const wchar_t* _SYSTEM_SERVICE_ID = L"osp.system.service";
43 static const wchar_t* _SYSTEM_COMMAND_GET_BOOL = L"osp.system.command.system.get.bool";
44 static const wchar_t* _SYSTEM_COMMAND_GET_INT = L"osp.system.command.system.get.int";
45 static const wchar_t* _SYSTEM_COMMAND_GET_STRING = L"osp.system.command.system.get.string";
47 static const wchar_t* _SYSTEM_OK = L"osp.system.result.ok";
48 static const wchar_t* _SYSTEM_INVALID_ARG = L"osp.system.result.invalid_arg";
49 static const wchar_t* _SYSTEM_OBJ_NOT_FOUND = L"osp.system.result.obj_not_found";
50 static const wchar_t* _SYSTEM_ERROR = L"osp.system.result.error";
52 _SystemClient* _SystemClient::__pSystemClient = null;
55 _SystemClient::GetInstance(void)
57 if(__pSystemClient == null)
59 __pSystemClient = new (std::nothrow) _SystemClient();
61 return __pSystemClient;
64 _SystemClient::_SystemClient()
68 _CommunicationDispatcherClient* pCommunicationDispatcherClient = _CommunicationDispatcherClient::GetInstance();
69 r = pCommunicationDispatcherClient->RegisterCommunicationListener(_SYSTEM_SERVICE_ID, *this);
70 __pIpcClient = pCommunicationDispatcherClient->GetIpcClient();
73 _SystemClient::~_SystemClient()
78 _SystemClient::ConvertResultCode(String code)
81 if(code == _SYSTEM_OK)
85 else if(code == _SYSTEM_OBJ_NOT_FOUND)
93 _SystemClient::GetValue(const String& key, bool& value)
96 String requestKey(key);
97 String serviceId(_SYSTEM_SERVICE_ID);
98 String commandId(_SYSTEM_COMMAND_GET_BOOL);
100 _CommunicationDispatcherClient* pCommunicationDispatcherClient = _CommunicationDispatcherClient::GetInstance();
101 SysTryReturnResult(NID_SYS, pCommunicationDispatcherClient != null, E_SYSTEM, "It is failed to get Communication Dispatcher.");
103 __pIpcClient = pCommunicationDispatcherClient->GetIpcClient();
104 SysTryReturnResult(NID_SYS, __pIpcClient != null, E_SYSTEM, "It is failed to get IPC client.");
106 ArrayList requestMessages;
107 ArrayList responseMessages;
109 requestMessages.Construct();
110 responseMessages.Construct();
112 requestMessages.Add(serviceId);
113 requestMessages.Add(commandId);
114 requestMessages.Add(requestKey);
116 unique_ptr<IoService_Request> pMsg(new (std::nothrow) IoService_Request(requestMessages, &responseMessages));
118 r = __pIpcClient->SendRequest(*pMsg);
119 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send request by IPC [%s]", GetErrorMessage(r));
121 String* pResult = (String*)responseMessages.GetAt(2);
122 SysTryReturnResult(NID_SYS, pResult != null, E_SYSTEM, "There is no result code.");
124 r = ConvertResultCode(*pResult);
125 SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "Error is occured.");
127 String* pValue = (String*)responseMessages.GetAt(3);
128 SysTryReturnResult(NID_SYS, pValue != null, E_SYSTEM, "There is no result value.");
130 if(pValue->Equals(L"1", false))
138 responseMessages.RemoveAll(true);
143 _SystemClient::GetValue(const String& key, int& value)
145 result r = E_SUCCESS;
146 String requestKey(key);
147 String serviceId(_SYSTEM_SERVICE_ID);
148 String commandId(_SYSTEM_COMMAND_GET_INT);
150 _CommunicationDispatcherClient* pCommunicationDispatcherClient = _CommunicationDispatcherClient::GetInstance();
151 SysTryReturnResult(NID_SYS, pCommunicationDispatcherClient != null, E_SYSTEM, "It is failed to get Communication Dispatcher.");
153 __pIpcClient = pCommunicationDispatcherClient->GetIpcClient();
154 SysTryReturnResult(NID_SYS, __pIpcClient != null, E_SYSTEM, "It is failed to get IPC client.");
156 ArrayList requestMessages;
157 ArrayList responseMessages;
159 requestMessages.Construct();
160 responseMessages.Construct();
162 requestMessages.Add(serviceId);
163 requestMessages.Add(commandId);
164 requestMessages.Add(requestKey);
166 unique_ptr<IoService_Request> pMsg(new (std::nothrow) IoService_Request(requestMessages, &responseMessages));
168 r = __pIpcClient->SendRequest(*pMsg);
169 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send request by IPC [%s]", GetErrorMessage(r));
171 String* pResult = (String*)responseMessages.GetAt(2);
172 SysTryReturnResult(NID_SYS, pResult != null, E_SYSTEM, "There is no result code.");
174 r = ConvertResultCode(*pResult);
175 SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "Error is occured.");
177 String* pValue = (String*)responseMessages.GetAt(3);
178 SysTryReturnResult(NID_SYS, pValue != null, E_SYSTEM, "There is no result value.");
180 r = Integer::Parse(*pValue, value);
181 SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "Result value[%ls] convert is failed.", pValue->GetPointer());
183 responseMessages.RemoveAll(true);
189 _SystemClient::GetValue(const String& key, String& value)
191 result r = E_SUCCESS;
192 String requestKey(key);
193 String serviceId(_SYSTEM_SERVICE_ID);
194 String commandId(_SYSTEM_COMMAND_GET_STRING);
196 _CommunicationDispatcherClient* pCommunicationDispatcherClient = _CommunicationDispatcherClient::GetInstance();
197 SysTryReturnResult(NID_SYS, pCommunicationDispatcherClient != null, E_SYSTEM, "It is failed to get Communication Dispatcher.");
199 __pIpcClient = pCommunicationDispatcherClient->GetIpcClient();
200 SysTryReturnResult(NID_SYS, __pIpcClient != null, E_SYSTEM, "It is failed to get IPC client.");
202 ArrayList requestMessages;
203 ArrayList responseMessages;
205 requestMessages.Construct();
206 responseMessages.Construct();
208 requestMessages.Add(serviceId);
209 requestMessages.Add(commandId);
210 requestMessages.Add(requestKey);
212 unique_ptr<IoService_Request> pMsg(new (std::nothrow) IoService_Request(requestMessages, &responseMessages));
214 r = __pIpcClient->SendRequest(*pMsg);
215 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send request by IPC [%s]", GetErrorMessage(r));
217 String* pResult = (String*)responseMessages.GetAt(2);
218 SysTryReturnResult(NID_SYS, pResult != null, E_SYSTEM, "There is no result code.");
220 r = ConvertResultCode(*pResult);
221 SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "Error is occured.");
223 String* pValue = (String*)responseMessages.GetAt(3);
224 SysTryReturnResult(NID_SYS, pValue != null, E_SYSTEM, "There is no result value.");
228 responseMessages.RemoveAll(true);
233 _SystemClient::OnDataReceived(const Tizen::Base::Collection::ArrayList& data)