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 RemoteMessagePort.cpp
20 * @author Kisub Song (kisubs.song@samsung.com)
25 #include "RemoteMessagePort.h"
26 #include "LocalMessagePort.h"
27 #include "MessagePortManagerProxy.h"
31 namespace MessagePort {
34 using namespace WrtDeviceApis::Commons;
36 RemoteMessagePort::RemoteMessagePort(string appId, string name, bool isTrusted) :
40 m_isTrusted(isTrusted)
44 RemoteMessagePort::~RemoteMessagePort()
48 std::string RemoteMessagePort::getMessagePortName() const
53 void RemoteMessagePort::setMessagePortName(const std::string &value)
57 std::string RemoteMessagePort::getAppId() const
62 void RemoteMessagePort::setAppId(const std::string &value)
66 bool RemoteMessagePort::getIsTrusted() const
71 void RemoteMessagePort::setIsTrusted(const bool &value)
75 void RemoteMessagePort::OnRequestReceived(const EventRemoteMessagePortSendMessagePtr &event)
81 if(!event->getDataIsSet())
82 ThrowMsg(InvalidArgumentException, "Failed to get data from event.");
84 MessagePortDataItemMapPtr data = event->getData();
86 if(event->getLocalMessagePortIsSet())
88 LocalMessagePort *localMessagePortImpl =
89 dynamic_cast<LocalMessagePort *>(event->getLocalMessagePort().Get());
90 if(localMessagePortImpl == NULL)
91 ThrowMsg(ConversionException, "Failed to get platform LocalMessagePort from event.");
93 int localPortId = localMessagePortImpl->getPlatformLocalMessagePortId();
94 MessagePortManagerProxySingleton::Instance().sendMessage(m_appId, m_name, m_isTrusted, data, localPortId);
98 MessagePortManagerProxySingleton::Instance().sendMessage(m_appId, m_name, m_isTrusted, data);
101 event->setResult(true);
103 Catch(InvalidArgumentException)
105 LogError("Error [InvalidArguments] : " << _rethrown_exception.GetMessage());
106 event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
107 event->setResult(false);
109 Catch(ConversionException)
111 LogError("Error [ConversionException] : " << _rethrown_exception.GetMessage());
112 event->setExceptionCode(ExceptionCodes::ConversionException);
113 event->setResult(false);
115 Catch(NotFoundException)
117 LogError("Error [NotFound] : " << _rethrown_exception.GetMessage());
118 event->setExceptionCode(ExceptionCodes::NotFoundException);
119 event->setResult(false);
121 Catch(OutOfRangeException)
123 LogError("Error [OutOfRange] : " << _rethrown_exception.GetMessage());
124 event->setExceptionCode(ExceptionCodes::OutOfRangeException);
125 event->setResult(false);
127 Catch(PlatformException)
129 LogError("Error [PlatformException] : " << _rethrown_exception.GetMessage());
130 event->setExceptionCode(ExceptionCodes::PlatformException);
131 event->setResult(false);
135 LogError("Error [Unknown] : " << _rethrown_exception.GetMessage());
136 event->setExceptionCode(ExceptionCodes::UnknownException);
137 event->setResult(false);