2 // Tizen Web Device API
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 MessagePortManager.cpp
25 #include "MessagePortManager.h"
26 #include "MessagePortManagerProxy.h"
30 namespace MessagePort {
33 using namespace WrtDeviceApis::Commons;
35 MessagePortManager::MessagePortManager() :
41 MessagePortManager::~MessagePortManager()
46 void MessagePortManager::OnRequestReceived(const EventMessagePortManagerRequestLocalMessagePortPtr &event)
52 if (!event->getLocalMessagePortNameIsSet()) {
53 LOGE("Failed to get LocalMessagePortName from event.");
54 ThrowMsg(InvalidArgumentException, "Failed to get LocalMessagePortName from event.");
56 string messagePortName = event->getLocalMessagePortName();
58 LocalMessagePortPtr localMessagePort =
59 MessagePortManagerProxySingleton::Instance().requestLocalMessagePort(messagePortName);
61 event->setLocalMessagePort(localMessagePort);
62 event->setResult(true);
64 Catch(InvalidArgumentException)
66 LOGE("Error [InvalidArgumentException] : %s", _rethrown_exception.GetMessage().c_str());
67 event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
68 event->setResult(false);
70 Catch(PlatformException)
72 LOGE("Error [PlatformException] : %s", _rethrown_exception.GetMessage().c_str());
73 event->setExceptionCode(ExceptionCodes::PlatformException);
74 event->setResult(false);
78 LOGE("Error [UnknownException] : %s", _rethrown_exception.GetMessage().c_str());
79 event->setExceptionCode(ExceptionCodes::UnknownException);
80 event->setResult(false);
84 void MessagePortManager::OnRequestReceived(const EventMessagePortManagerRequestTrustedLocalMessagePortPtr &event)
90 if (!event->getLocalMessagePortNameIsSet()) {
91 LOGE("Failed to get LocalMessagePortName from event.");
92 ThrowMsg(InvalidArgumentException, "Failed to get LocalMessagePortName from event.");
94 string messagePortName = event->getLocalMessagePortName();
96 LocalMessagePortPtr localMessagePort =
97 MessagePortManagerProxySingleton::Instance().requestTrustedLocalMessagePort(messagePortName);
99 event->setLocalMessagePort(localMessagePort);
100 event->setResult(true);
102 Catch(InvalidArgumentException)
104 LOGE("Error [InvalidArgumentException] : %s", _rethrown_exception.GetMessage().c_str());
105 event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
106 event->setResult(false);
108 Catch(PlatformException)
110 LOGE("Error [PlatformException] : %s", _rethrown_exception.GetMessage().c_str());
111 event->setExceptionCode(ExceptionCodes::PlatformException);
112 event->setResult(false);
116 LOGE("Error [UnknownException] : %s", _rethrown_exception.GetMessage().c_str());
117 event->setExceptionCode(ExceptionCodes::UnknownException);
118 event->setResult(false);
122 void MessagePortManager::OnRequestReceived(const EventMessagePortManagerRequestRemoteMessagePortPtr &event)
128 if (!event->getAppIdIsSet()) {
129 LOGE("Failed to get appId from event.");
130 ThrowMsg(InvalidArgumentException, "Failed to get appId from event.");
132 if (!event->getRemoteMessagePortNameIsSet()) {
133 LOGE("Failed to get remoteMessagePortName from event.");
134 ThrowMsg(InvalidArgumentException, "Failed to get remoteMessagePortName from event.");
136 string appId = event->getAppId();
137 string messagePortName = event->getRemoteMessagePortName();
139 RemoteMessagePortPtr remoteMessagePort =
140 MessagePortManagerProxySingleton::Instance().requestRemoteMessagePort(appId, messagePortName);
142 event->setRemoteMessagePort(remoteMessagePort);
143 event->setResult(true);
145 Catch(InvalidArgumentException)
147 LOGE("Error [InvalidArgumentException] : %s", _rethrown_exception.GetMessage().c_str());
148 event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
149 event->setResult(false);
151 Catch(NotFoundException)
153 LOGE("Error [NotFoundException] : %s", _rethrown_exception.GetMessage().c_str());
154 event->setExceptionCode(ExceptionCodes::NotFoundException);
155 event->setResult(false);
157 Catch(PlatformException)
159 LOGE("Error [PlatformException] : %s", _rethrown_exception.GetMessage().c_str());
160 event->setExceptionCode(ExceptionCodes::PlatformException);
161 event->setResult(false);
165 LOGE("Error [UnknownException] : %s", _rethrown_exception.GetMessage().c_str());
166 event->setExceptionCode(ExceptionCodes::UnknownException);
167 event->setResult(false);
171 void MessagePortManager::OnRequestReceived(const EventMessagePortManagerRequestTrustedRemoteMessagePortPtr &event)
177 if (!event->getAppIdIsSet()) {
178 LOGE("Failed to get appId from event.");
179 ThrowMsg(InvalidArgumentException, "Failed to get appId from event.");
181 if (!event->getRemoteMessagePortNameIsSet()) {
182 LOGE("Failed to get remoteMessagePortName from event.");
183 ThrowMsg(InvalidArgumentException, "Failed to get remoteMessagePortName from event.");
185 string appId = event->getAppId();
186 string messagePortName = event->getRemoteMessagePortName();
188 RemoteMessagePortPtr remoteMessagePort =
189 MessagePortManagerProxySingleton::Instance().requestTrustedRemoteMessagePort(appId, messagePortName);
191 event->setRemoteMessagePort(remoteMessagePort);
192 event->setResult(true);
194 Catch(InvalidArgumentException)
196 LOGE("Error [InvalidArgumentException] : %s", _rethrown_exception.GetMessage().c_str());
197 event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
198 event->setResult(false);
200 Catch(NotFoundException)
202 LOGE("Error [NotFoundException] : %s", _rethrown_exception.GetMessage().c_str());
203 event->setExceptionCode(ExceptionCodes::NotFoundException);
204 event->setResult(false);
206 Catch(PlatformWrongStateException)
208 LOGE("Error [PlatformWrongStateException] : %s", _rethrown_exception.GetMessage().c_str());
209 event->setExceptionCode(ExceptionCodes::PlatformWrongStateException);
210 event->setResult(false);
212 Catch(PlatformException)
214 LOGE("Error [PlatformException] : %s", _rethrown_exception.GetMessage().c_str());
215 event->setExceptionCode(ExceptionCodes::PlatformException);
216 event->setResult(false);
220 LOGE("Error [UnknownException] : %s", _rethrown_exception.GetMessage().c_str());
221 event->setExceptionCode(ExceptionCodes::UnknownException);
222 event->setResult(false);