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_SUPPORTED = L"osp.system.command.system.get.bool";
45 static const wchar_t* _SYSTEM_OK = L"osp.system.result.ok";
46 static const wchar_t* _SYSTEM_INVALID_ARG = L"osp.system.result.invalid_arg";
47 static const wchar_t* _SYSTEM_ERROR = L"osp.system.result.error";
49 _SystemClient* _SystemClient::__pSystemClient = null;
52 _SystemClient::GetInstance(void)
54 if(__pSystemClient == null)
56 __pSystemClient = new (std::nothrow) _SystemClient();
58 return __pSystemClient;
61 _SystemClient::_SystemClient()
65 _CommunicationDispatcherClient* pCommunicationDispatcherClient = _CommunicationDispatcherClient::GetInstance();
66 r = pCommunicationDispatcherClient->RegisterCommunicationListener(_SYSTEM_SERVICE_ID, *this);
67 __pIpcClient = pCommunicationDispatcherClient->GetIpcClient();
70 _SystemClient::~_SystemClient()
75 _SystemClient::ConvertResultCode(String code)
78 if(code == _SYSTEM_OK)
82 else if(code == _SYSTEM_INVALID_ARG)
90 _SystemClient::GetValue(const Tizen::Base::String& key, bool& value)
93 String requestKey(key);
94 String serviceId(_SYSTEM_SERVICE_ID);
95 String commandId(_SYSTEM_COMMAND_SUPPORTED);
97 _CommunicationDispatcherClient* pCommunicationDispatcherClient = _CommunicationDispatcherClient::GetInstance();
99 __pIpcClient = pCommunicationDispatcherClient->GetIpcClient();
101 ArrayList requestMessages;
102 ArrayList responseMessages;
104 requestMessages.Construct();
105 responseMessages.Construct();
107 requestMessages.Add(serviceId);
108 requestMessages.Add(commandId);
109 requestMessages.Add(requestKey);
111 unique_ptr<IoService_Request> pMsg(new (std::nothrow) IoService_Request(requestMessages, &responseMessages));
113 r = __pIpcClient->SendRequest(*pMsg);
114 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send request by IPC [%s]", GetErrorMessage(r));
116 String* pResult = (String*)responseMessages.GetAt(2);
117 SysTryReturnResult(NID_SYS, pResult != null, E_SYSTEM, "There is no result code.");
119 r = ConvertResultCode(*pResult);
120 SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "Error is occured.");
122 String* pValue = (String*)responseMessages.GetAt(3);
123 SysTryReturnResult(NID_SYS, pValue != null, E_SYSTEM, "There is no result value.");
124 if(pValue->GetPointer() == L"1")
133 responseMessages.RemoveAll(true);
138 _SystemClient::OnDataReceived(const Tizen::Base::Collection::ArrayList& data)