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 <sys/types.h>
26 #include <FIo_AppServiceIpcMessages.h>
28 #include "FSys_CommunicationDispatcherClient.h"
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Collection;
32 using namespace Tizen::Io;
34 namespace Tizen { namespace System
37 bool ipcReady = false;
38 static const wchar_t* _COMMUNICATION_DISPATCHER_IPC_ID = L"osp.app.ipcserver.communicationdispatcher";
40 _CommunicationDispatcherClient* _CommunicationDispatcherClient::__pCommunicationDispatcherClient = null;
42 _CommunicationDispatcherClient::_CommunicationDispatcherClient()
45 __communicationDispatcherClientList.Construct(0, 0, __strHashCodeProvider, __strComparer);
51 __pIpcClient = new (std::nothrow) _IpcClient();
52 SysTryCatch(NID_SYS, __pIpcClient != null, , r, "It is failed to create IPC client");
54 r = __pIpcClient->Construct(_COMMUNICATION_DISPATCHER_IPC_ID, this);
59 SysTryCatch(NID_SYS, r == E_SUCCESS, , r, "Propagated. [%s]", GetErrorMessage(r));
67 _CommunicationDispatcherClient::~_CommunicationDispatcherClient()
72 __communicationDispatcherClientList.RemoveAll();
75 _CommunicationDispatcherClient*
76 _CommunicationDispatcherClient::GetInstance()
78 if(__pCommunicationDispatcherClient == null)
80 __pCommunicationDispatcherClient = new (std::nothrow) _CommunicationDispatcherClient();
82 return __pCommunicationDispatcherClient;
86 _CommunicationDispatcherClient::GetIpcClient()
95 _CommunicationDispatcherClient::RegisterCommunicationListener(String key, _ICommunicationDispatcherListener& listener)
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 == false, E_OBJ_ALREADY_EXIST, "Required key is already registered.");
103 r = __communicationDispatcherClientList.Add(key, &listener);
109 _CommunicationDispatcherClient::UnregisterCommunicationListener(String key)
111 result r = E_SUCCESS;
113 r = __communicationDispatcherClientList.ContainsKey(key, exist);
114 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to check exist check.");
115 SysTryReturnResult(NID_SYS, exist == true, E_OBJ_NOT_FOUND, "Required key is not registered.");
116 r = __communicationDispatcherClientList.Remove(key);
121 _CommunicationDispatcherClient::OnIpcResponseReceived(_IpcClient& client, const IPC::Message& message)
123 SysLog(NID_SYS, "Enter.");
124 IPC_BEGIN_MESSAGE_MAP(_CommunicationDispatcherClient, message)
125 IPC_MESSAGE_HANDLER_EX(IoService_Data, &client, OnDataReceived)
126 IPC_END_MESSAGE_MAP_EX()
127 SysLog(NID_SYS, "Exit.");
131 _CommunicationDispatcherClient::OnDataReceived(const ArrayList& data)
133 result r = E_SUCCESS;
134 String* pServiceId = (String*) data.GetAt(0);
136 _ICommunicationDispatcherListener* listener = null;
138 SysTryReturnVoidResult(NID_SYS, pServiceId != null, E_SYSTEM, "There is no service id.");
140 r = __communicationDispatcherClientList.GetValue(*pServiceId, listener);
142 SysTryReturnVoidResult(NID_SYS, r == E_SUCCESS && listener != null, E_SYSTEM, "Service[%ls] is available, but listener does not exist. [%s]", pServiceId->GetPointer(), GetErrorMessage(r));
144 listener->OnDataReceived(data);
146 SysLog(NID_SYS, "Message is delivered to \"%ls\"[%x]", pServiceId->GetPointer(), listener);
147 ArrayList* temp = const_cast< ArrayList *> (&data);
148 temp->RemoveAll(true);