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_CommunicationDispatcherClient.cpp
19 * @brief This is the implementation file for _CommunicationDispatcherClient class.
22 #include <FBaseSysLog.h>
24 #include <sys/types.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 bool ipcReady = false;
37 static const wchar_t* _COMMUNICATION_DISPATCHER_IPC_ID = L"osp.app.ipcserver.communicationdispatcher";
39 _CommunicationDispatcherClient* _CommunicationDispatcherClient::__pCommunicationDispatcherClient = null;
41 _CommunicationDispatcherClient::_CommunicationDispatcherClient()
44 __communicationDispatcherClientList.Construct(0, 0, __strHashCodeProvider, __strComparer);
50 __pIpcClient = new (std::nothrow) _IpcClient();
51 SysTryCatch(NID_SYS, __pIpcClient != null, , r, "It is failed to create IPC client");
53 r = __pIpcClient->Construct(_COMMUNICATION_DISPATCHER_IPC_ID, this);
58 SysTryCatch(NID_SYS, r == E_SUCCESS, , r, "Propagated. [%s]", GetErrorMessage(r));
66 _CommunicationDispatcherClient::~_CommunicationDispatcherClient()
71 __communicationDispatcherClientList.RemoveAll();
74 _CommunicationDispatcherClient*
75 _CommunicationDispatcherClient::GetInstance()
77 if(__pCommunicationDispatcherClient == null)
79 __pCommunicationDispatcherClient = new (std::nothrow) _CommunicationDispatcherClient();
81 return __pCommunicationDispatcherClient;
85 _CommunicationDispatcherClient::GetIpcClient()
94 _CommunicationDispatcherClient::RegisterCommunicationListener(String key, _ICommunicationDispatcherListener& listener)
99 r = __communicationDispatcherClientList.ContainsKey(key, exist);
100 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to check exist check.");
101 SysTryReturnResult(NID_SYS, exist == false, E_OBJ_ALREADY_EXIST, "Required key is already registered.");
102 r = __communicationDispatcherClientList.Add(key, &listener);
108 _CommunicationDispatcherClient::UnregisterCommunicationListener(String key)
110 result r = E_SUCCESS;
112 r = __communicationDispatcherClientList.ContainsKey(key, exist);
113 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to check exist check.");
114 SysTryReturnResult(NID_SYS, exist == true, E_OBJ_NOT_FOUND, "Required key is not registered.");
115 r = __communicationDispatcherClientList.Remove(key);
120 _CommunicationDispatcherClient::OnIpcResponseReceived(_IpcClient& client, const IPC::Message& message)
122 SysLog(NID_SYS, "Enter.");
123 IPC_BEGIN_MESSAGE_MAP(_CommunicationDispatcherClient, message)
124 IPC_MESSAGE_HANDLER_EX(IoService_Data, &client, OnDataReceived)
125 IPC_END_MESSAGE_MAP_EX()
126 SysLog(NID_SYS, "Exit.");
130 _CommunicationDispatcherClient::OnDataReceived(const ArrayList& data)
132 result r = E_SUCCESS;
133 String* pServiceId = (String*) data.GetAt(0);
135 _ICommunicationDispatcherListener* listener = null;
137 SysTryReturnVoidResult(NID_SYS, pServiceId != null, E_SYSTEM, "There is no service id.");
139 r = __communicationDispatcherClientList.GetValue(*pServiceId, listener);
141 SysTryReturnVoidResult(NID_SYS, r == E_SUCCESS && listener != null, E_SYSTEM, "Service[%ls] is available, but listener does not exist. [%s]", pServiceId->GetPointer(), GetErrorMessage(r));
143 listener->OnDataReceived(data);
145 SysLog(NID_SYS, "Message is delivered to \"%ls\"[%x]", pServiceId->GetPointer(), listener);
146 ArrayList* temp = const_cast< ArrayList *> (&data);
147 temp->RemoveAll(true);