-//
-// Copyright (c) 2012 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-/**
- * @file FSys_RuntimeClientEx.cpp
- * @brief This is the implementation file for _RuntimeClientEx class.
- */
-
-#include <unique_ptr.h>
-
-#include <FBaseInteger.h>
-#include <FBaseLongLong.h>
-#include <FBaseSysLog.h>
-
-#include <FApp_AppInfo.h>
-
-#include <FIo_AppServiceIpcMessages.h>
-#include "FSys_SystemServiceMessageClient.h"
-#include "FSys_RuntimeClientEx.h"
-
-using namespace std;
-
-using namespace Tizen::App;
-using namespace Tizen::Base;
-using namespace Tizen::Base::Collection;
-using namespace Tizen::Base::Runtime;
-using namespace Tizen::Io;
-
-namespace Tizen { namespace System
-{
-
-static const int _RUNTIME_GET_PARAM_TYPE = 1;
-static const wchar_t* _RUNTIME_SERVICE_ID = L"osp.sys.ipcserver.runtimeinfo";
-static const wchar_t* _RUNTIME_GET_SIZE = L"osp.system.command.runtime.get.size";
-static const wchar_t* _RUNTIME_RESULT_SUCCESS = L"osp.system.result.success";
-static const wchar_t* _RUNTIME_RESULT_SYSTEM = L"osp.system.result.system";
-
-_RuntimeClientEx* _RuntimeClientEx::__pRuntimeClientEx= null;
-
-class _RuntimeAsyncEventArg : public IEventArg
-{
-public:
- long long value;
- result rCode;
-};
-
-class _RuntimeAsyncEvent : public Event
-{
-protected:
- virtual void FireImpl(IEventListener& listener, const IEventArg& arg)
- {
- IRuntimeInfoGetLonglongAsyncResultListener* pListener = dynamic_cast<IRuntimeInfoGetLonglongAsyncResultListener*> (&listener);
- const _RuntimeAsyncEventArg* pArg = dynamic_cast<const _RuntimeAsyncEventArg*>(&arg);
-
- if(pListener == null || pArg == null)
- {
- SysLogException(NID_SYS, E_SYSTEM, "It is failed to get listener or arguemnt");
- return;
- }
- pListener->OnResultReceivedForGetValueAsync(pArg->value, pArg->rCode);
- RemoveListener(listener);
- }
-};
-
-_RuntimeClientEx*
-_RuntimeClientEx::GetInstance(void)
-{
- if(__pRuntimeClientEx == null)
- {
- __pRuntimeClientEx = new (std::nothrow) _RuntimeClientEx();
- }
- return __pRuntimeClientEx;
-}
-
-_RuntimeClientEx::_RuntimeClientEx()
- : __msgCount(0)
- , __pMessageClient(null)
-{
- result r = E_SUCCESS;
- static String RUNTIME_SERVICE_ID(_RUNTIME_SERVICE_ID);
-
- __pMessageClient = _SystemServiceMessageClient::CreateInstance(RUNTIME_SERVICE_ID);
- SysTryCatch(NID_SYS, __pMessageClient != null, r = E_SYSTEM, r, "It is failed to create SystemServiceMessageClient.");
-
- r = __pMessageClient->RegisterListener(RUNTIME_SERVICE_ID, *this);
- SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, r, "It is failed to register on MessageClient.");
-
- __asyncEventList.Construct();
-CATCH:
- SetLastResult(r);
-}
-
-_RuntimeClientEx::~_RuntimeClientEx()
-{
- result r = E_SUCCESS;
- String key(_RUNTIME_SERVICE_ID);
- r = __pMessageClient->UnregisterListener(key);
- SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, r, "It is failed to register on MessageClient.");
-
- __asyncEventList.RemoveAll(true);
- delete __pMessageClient;
-CATCH:
- SetLastResult(r);
-}
-
-result
-_RuntimeClientEx::GetDirectorySizeValueAsync(const String& path, IRuntimeInfoGetLonglongAsyncResultListener* listener)
-{
- result r = E_SUCCESS;
-
- ArrayList requestMessages;
- ArrayList responseMessages;
-
- requestMessages.Construct();
- responseMessages.Construct();
-
- String serviceId(_RUNTIME_SERVICE_ID);
- String commandId(_RUNTIME_GET_SIZE);
- String messageId;
- messageId.Append(__msgCount);
-
- requestMessages.Add(serviceId);
- requestMessages.Add(commandId);
- requestMessages.Add(path);
- requestMessages.Add(messageId);
-
- unique_ptr<IoService_Request> pMsg(new (std::nothrow) IoService_Request(requestMessages, &responseMessages));
- r = __pMessageClient->GetIpcClient()->SendRequest(*pMsg);
- SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send request by IPC [%s]", GetErrorMessage(r));
-
- String* pResult = (String*)responseMessages.GetAt(2);
- SysTryReturnResult(NID_SYS, pResult != null, E_SYSTEM, "There is no result code.");
-
- if(*pResult == _RUNTIME_RESULT_SUCCESS)
- r = E_SUCCESS;
- else
- r = E_SYSTEM;
-
- SysLog(NID_SYS, "r is %s.", GetErrorMessage(r));
-
- if(r == E_SUCCESS)
- {
- _RuntimeAsyncEvent* pEvent = new (std::nothrow) _RuntimeAsyncEvent();
- pEvent->AddListener(*listener);
-
- __asyncEventList.Add(new Integer(__msgCount), pEvent);
-
- __msgCount++;
- }
- return r;
-}
-
-void
-_RuntimeClientEx::OnDataReceived(const Tizen::Base::Collection::ArrayList& data)
-{
- SysLog(NID_SYS, "Receive result");
- String* pServiceId = (String*)(data.GetAt(0));
- String* pResponseId = (String*)(data.GetAt(1));
- String* pMessageId = (String*)(data.GetAt(2));
- String* pValue = (String*)(data.GetAt(3));
- String* pResultCode = (String*)(data.GetAt(4));
-
- SysTryReturnVoidResult(NID_SYS, pServiceId != null && pResponseId != null && pMessageId != null && pValue != null && pResultCode != null, E_SYSTEM, "There is no result data.");
-
- int msg_id = 0;
- Integer::Parse(*pMessageId, msg_id);
-
- Integer msgKey(msg_id);
-
- _RuntimeAsyncEvent* pEvent = dynamic_cast <_RuntimeAsyncEvent*> (__asyncEventList.GetValue(msgKey));
- SysTryReturnVoidResult(NID_SYS, pEvent != null, E_SYSTEM, "There is no registered event.");
-
- _RuntimeAsyncEventArg* pEventArg = new (std::nothrow) _RuntimeAsyncEventArg();
-
- LongLong::Parse(*pValue, pEventArg->value);
-
- if(*pResultCode == _RUNTIME_RESULT_SUCCESS)
- {
- pEventArg->rCode = E_SUCCESS;
- }
- else
- {
- pEventArg->rCode = E_SYSTEM;
- }
-
- pEvent->Fire(*pEventArg);
-}
-
-} } // Tizen::System
-