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_CommunicationDispatcherClient.cpp
20 * @brief This is the implementation file for _CommunicationDispatcherClient class.
23 #include <FBaseSysLog.h>
25 #include <FIo_AppServiceIpcMessages.h>
27 #include "FSys_CommunicationDispatcherClient.h"
29 using namespace Tizen::Base;
30 using namespace Tizen::Base::Collection;
31 using namespace Tizen::Io;
33 namespace Tizen { namespace System
36 static const wchar_t* _COMMUNICATION_DISPATCHER_IPC_ID = L"osp.app.ipcserver.communicationdispatcher";
38 _CommunicationDispatcherClient* _CommunicationDispatcherClient::__pCommunicationDispatcherClient = null;
40 _CommunicationDispatcherClient::_CommunicationDispatcherClient()
43 __communicationDispatcherClientList.Construct(0, 0, __strHashCodeProvider, __strComparer);
46 __pIpcClient = new (std::nothrow) _IpcClient();
47 SysTryCatch(NID_SYS, __pIpcClient != null, , r, "It is failed to create IPC client");
49 r = __pIpcClient->Construct(_COMMUNICATION_DISPATCHER_IPC_ID, this);
50 SysTryCatch(NID_SYS, r == E_SUCCESS, , r, "Propagated. [%s]", GetErrorMessage(r));
57 _CommunicationDispatcherClient::~_CommunicationDispatcherClient()
62 __communicationDispatcherClientList.RemoveAll();
65 _CommunicationDispatcherClient*
66 _CommunicationDispatcherClient::GetInstance()
68 if(__pCommunicationDispatcherClient == null)
70 __pCommunicationDispatcherClient = new (std::nothrow) _CommunicationDispatcherClient();
72 return __pCommunicationDispatcherClient;
76 _CommunicationDispatcherClient::GetIpcClient()
82 _CommunicationDispatcherClient::RegisterCommunicationListener(String key, _ICommunicationDispatcherListener& listener)
87 r = __communicationDispatcherClientList.ContainsKey(key, exist);
88 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to check exist check.");
89 SysTryReturnResult(NID_SYS, exist == false, E_OBJ_ALREADY_EXIST, "Required key is already registered.");
90 r = __communicationDispatcherClientList.Add(key, &listener);
96 _CommunicationDispatcherClient::UnregisterCommunicationListener(String key)
100 r = __communicationDispatcherClientList.ContainsKey(key, exist);
101 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to check exist check.");
102 SysTryReturnResult(NID_SYS, exist == true, E_OBJ_NOT_FOUND, "Required key is not registered.");
103 r = __communicationDispatcherClientList.Remove(key);
108 _CommunicationDispatcherClient::OnIpcResponseReceived(_IpcClient& client, const IPC::Message& message)
110 SysLog(NID_SYS, "Enter.");
111 IPC_BEGIN_MESSAGE_MAP(_CommunicationDispatcherClient, message)
112 IPC_MESSAGE_HANDLER_EX(IoService_Data, &client, OnDataReceived)
113 IPC_END_MESSAGE_MAP_EX()
114 SysLog(NID_SYS, "Exit.");
118 _CommunicationDispatcherClient::OnDataReceived(const ArrayList& data)
120 result r = E_SUCCESS;
121 String* pServiceId = (String*) data.GetAt(0);
123 _ICommunicationDispatcherListener* listener = null;
125 SysTryReturnVoidResult(NID_SYS, pServiceId != null, E_SYSTEM, "There is no service id.");
127 r = __communicationDispatcherClientList.GetValue(*pServiceId, listener);
129 SysTryReturnVoidResult(NID_SYS, r == E_SUCCESS && listener != null, E_SYSTEM, "Service[%ls] is available, but listener does not exist. [%s]", pServiceId->GetPointer(), GetErrorMessage(r));
131 listener->OnDataReceived(data);
133 SysLog(NID_SYS, "Message is delivered to \"%ls\"[%x]", pServiceId->GetPointer(), listener);