2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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.
18 * @file FSys_SettingClient.cpp
19 * @brief This is the implementation file for _SettingClient class.
22 #include <unique_ptr.h>
24 #include "FSys_SystemClient.h"
26 #include <FBaseSysLog.h>
28 #include <FIo_AppServiceIpcMessages.h>
29 #include "FSys_CommunicationDispatcherClient.h"
33 using namespace Tizen::Base;
34 using namespace Tizen::Base::Collection;
35 using namespace Tizen::Base::Runtime;
36 using namespace Tizen::Io;
38 namespace Tizen { namespace System
41 static const wchar_t* _SYSTEM_SERVICE_ID = L"osp.system.service";
42 static const wchar_t* _SYSTEM_COMMAND_GET_BOOL = L"osp.system.command.system.get.bool";
43 static const wchar_t* _SYSTEM_COMMAND_GET_INT = L"osp.system.command.system.get.int";
44 static const wchar_t* _SYSTEM_COMMAND_GET_STRING = L"osp.system.command.system.get.string";
46 static const wchar_t* _SYSTEM_OK = L"osp.system.result.ok";
47 static const wchar_t* _SYSTEM_INVALID_ARG = L"osp.system.result.invalid_arg";
48 static const wchar_t* _SYSTEM_OBJ_NOT_FOUND = L"osp.system.result.obj_not_found";
49 static const wchar_t* _SYSTEM_ERROR = L"osp.system.result.error";
51 _SystemClient* _SystemClient::__pSystemClient = null;
54 _SystemClient::GetInstance(void)
56 if(__pSystemClient == null)
58 __pSystemClient = new (std::nothrow) _SystemClient();
60 return __pSystemClient;
63 _SystemClient::_SystemClient()
67 _CommunicationDispatcherClient* pCommunicationDispatcherClient = _CommunicationDispatcherClient::GetInstance();
68 r = pCommunicationDispatcherClient->RegisterCommunicationListener(_SYSTEM_SERVICE_ID, *this);
69 __pIpcClient = pCommunicationDispatcherClient->GetIpcClient();
72 _SystemClient::~_SystemClient()
77 _SystemClient::ConvertResultCode(String code)
80 if(code == _SYSTEM_OK)
84 else if(code == _SYSTEM_OBJ_NOT_FOUND)
92 _SystemClient::GetValue(const String& key, bool& value)
95 String requestKey(key);
96 String serviceId(_SYSTEM_SERVICE_ID);
97 String commandId(_SYSTEM_COMMAND_GET_BOOL);
99 _CommunicationDispatcherClient* pCommunicationDispatcherClient = _CommunicationDispatcherClient::GetInstance();
100 SysTryReturnResult(NID_SYS, pCommunicationDispatcherClient != null, E_SYSTEM, "It is failed to get Communication Dispatcher.");
102 __pIpcClient = pCommunicationDispatcherClient->GetIpcClient();
103 SysTryReturnResult(NID_SYS, __pIpcClient != null, E_SYSTEM, "It is failed to get IPC client.");
105 ArrayList requestMessages;
106 ArrayList responseMessages;
108 requestMessages.Construct();
109 responseMessages.Construct();
111 requestMessages.Add(serviceId);
112 requestMessages.Add(commandId);
113 requestMessages.Add(requestKey);
115 unique_ptr<IoService_Request> pMsg(new (std::nothrow) IoService_Request(requestMessages, &responseMessages));
117 r = __pIpcClient->SendRequest(*(pMsg.get()));
118 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send request by IPC [%s]", GetErrorMessage(r));
120 String* pResult = (String*)responseMessages.GetAt(2);
121 SysTryReturnResult(NID_SYS, pResult != null, E_SYSTEM, "There is no result code.");
123 r = ConvertResultCode(*pResult);
124 SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "Error is occured.");
126 String* pValue = (String*)responseMessages.GetAt(3);
127 SysTryReturnResult(NID_SYS, pValue != null, E_SYSTEM, "There is no result value.");
129 if(pValue->Equals(L"1", false))
137 responseMessages.RemoveAll(true);
142 _SystemClient::GetValue(const String& key, int& value)
144 result r = E_SUCCESS;
145 String requestKey(key);
146 String serviceId(_SYSTEM_SERVICE_ID);
147 String commandId(_SYSTEM_COMMAND_GET_INT);
149 _CommunicationDispatcherClient* pCommunicationDispatcherClient = _CommunicationDispatcherClient::GetInstance();
150 SysTryReturnResult(NID_SYS, pCommunicationDispatcherClient != null, E_SYSTEM, "It is failed to get Communication Dispatcher.");
152 __pIpcClient = pCommunicationDispatcherClient->GetIpcClient();
153 SysTryReturnResult(NID_SYS, __pIpcClient != null, E_SYSTEM, "It is failed to get IPC client.");
155 ArrayList requestMessages;
156 ArrayList responseMessages;
158 requestMessages.Construct();
159 responseMessages.Construct();
161 requestMessages.Add(serviceId);
162 requestMessages.Add(commandId);
163 requestMessages.Add(requestKey);
165 unique_ptr<IoService_Request> pMsg(new (std::nothrow) IoService_Request(requestMessages, &responseMessages));
167 r = __pIpcClient->SendRequest(*(pMsg.get()));
168 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send request by IPC [%s]", GetErrorMessage(r));
170 String* pResult = (String*)responseMessages.GetAt(2);
171 SysTryReturnResult(NID_SYS, pResult != null, E_SYSTEM, "There is no result code.");
173 r = ConvertResultCode(*pResult);
174 SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "Error is occured.");
176 String* pValue = (String*)responseMessages.GetAt(3);
177 SysTryReturnResult(NID_SYS, pValue != null, E_SYSTEM, "There is no result value.");
179 r = Integer::Parse(*pValue, value);
180 SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "Result value[%ls] convert is failed.", pValue->GetPointer());
182 responseMessages.RemoveAll(true);
188 _SystemClient::GetValue(const String& key, String& value)
190 result r = E_SUCCESS;
191 String requestKey(key);
192 String serviceId(_SYSTEM_SERVICE_ID);
193 String commandId(_SYSTEM_COMMAND_GET_STRING);
195 _CommunicationDispatcherClient* pCommunicationDispatcherClient = _CommunicationDispatcherClient::GetInstance();
196 SysTryReturnResult(NID_SYS, pCommunicationDispatcherClient != null, E_SYSTEM, "It is failed to get Communication Dispatcher.");
198 __pIpcClient = pCommunicationDispatcherClient->GetIpcClient();
199 SysTryReturnResult(NID_SYS, __pIpcClient != null, E_SYSTEM, "It is failed to get IPC client.");
201 ArrayList requestMessages;
202 ArrayList responseMessages;
204 requestMessages.Construct();
205 responseMessages.Construct();
207 requestMessages.Add(serviceId);
208 requestMessages.Add(commandId);
209 requestMessages.Add(requestKey);
211 unique_ptr<IoService_Request> pMsg(new (std::nothrow) IoService_Request(requestMessages, &responseMessages));
213 r = __pIpcClient->SendRequest(*(pMsg.get()));
214 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send request by IPC [%s]", GetErrorMessage(r));
216 String* pResult = (String*)responseMessages.GetAt(2);
217 SysTryReturnResult(NID_SYS, pResult != null, E_SYSTEM, "There is no result code.");
219 r = ConvertResultCode(*pResult);
220 SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "Error is occured.");
222 String* pValue = (String*)responseMessages.GetAt(3);
223 SysTryReturnResult(NID_SYS, pValue != null, E_SYSTEM, "There is no result value.");
227 responseMessages.RemoveAll(true);
232 _SystemClient::OnDataReceived(const Tizen::Base::Collection::ArrayList& data)