wrt-plugins-tizen_0.4.23
[framework/web/wrt-plugins-tizen.git] / src / MessagePort / RemoteMessagePort.cpp
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 /**
19  * @file        RemoteMessagePort.cpp
20  * @author      Kisub Song (kisubs.song@samsung.com)
21  * @version     0.1
22  * @brief
23  */
24
25 #include "RemoteMessagePort.h"
26 #include "LocalMessagePort.h"
27 #include "MessagePortManagerProxy.h"
28 #include <Logger.h>
29
30 namespace DeviceAPI {
31 namespace MessagePort {
32
33 using namespace std;
34 using namespace WrtDeviceApis::Commons;
35
36 RemoteMessagePort::RemoteMessagePort(string appId, string name, bool isTrusted) :
37                 IRemoteMessagePort(),
38                 m_appId(appId),
39                 m_name(name),
40                 m_isTrusted(isTrusted)
41 {
42 }
43
44 RemoteMessagePort::~RemoteMessagePort()
45 {
46 }
47
48 std::string RemoteMessagePort::getMessagePortName() const
49 {
50         return m_name;
51 }
52
53 void RemoteMessagePort::setMessagePortName(const std::string &value)
54 {
55 }
56
57 std::string RemoteMessagePort::getAppId() const
58 {
59         return m_appId;
60 }
61
62 void RemoteMessagePort::setAppId(const std::string &value)
63 {
64 }
65
66 bool RemoteMessagePort::getIsTrusted() const
67 {
68         return m_isTrusted;
69 }
70
71 void RemoteMessagePort::setIsTrusted(const bool &value)
72 {
73 }
74
75 void RemoteMessagePort::OnRequestReceived(const EventRemoteMessagePortSendMessagePtr &event)
76 {
77         LoggerD("entered");
78
79         Try
80         {
81                 if(!event->getDataIsSet())
82                         ThrowMsg(InvalidArgumentException, "Failed to get data from event.");
83
84                 MessagePortDataItemMapPtr data = event->getData();
85
86                 if(event->getLocalMessagePortIsSet())
87                 {
88                         LocalMessagePort *localMessagePortImpl =
89                                         dynamic_cast<LocalMessagePort *>(event->getLocalMessagePort().Get());
90                         if(localMessagePortImpl == NULL)
91                                 ThrowMsg(ConversionException, "Failed to get platform LocalMessagePort from event.");
92
93                         int localPortId = localMessagePortImpl->getPlatformLocalMessagePortId();
94                         MessagePortManagerProxySingleton::Instance().sendMessage(m_appId, m_name, m_isTrusted, data, localPortId);
95                 }
96                 else
97                 {
98                         MessagePortManagerProxySingleton::Instance().sendMessage(m_appId, m_name, m_isTrusted, data);
99                 }
100
101                 event->setResult(true);
102         }
103         Catch(InvalidArgumentException)
104         {
105                 LogError("Error [InvalidArguments] : " << _rethrown_exception.GetMessage());
106                 event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
107                 event->setResult(false);
108         }
109         Catch(ConversionException)
110         {
111                 LogError("Error [ConversionException] : " << _rethrown_exception.GetMessage());
112                 event->setExceptionCode(ExceptionCodes::ConversionException);
113                 event->setResult(false);
114         }
115         Catch(NotFoundException)
116         {
117                 LogError("Error [NotFound] : " << _rethrown_exception.GetMessage());
118                 event->setExceptionCode(ExceptionCodes::NotFoundException);
119                 event->setResult(false);
120         }
121         Catch(OutOfRangeException)
122         {
123                 LogError("Error [OutOfRange] : " << _rethrown_exception.GetMessage());
124                 event->setExceptionCode(ExceptionCodes::OutOfRangeException);
125                 event->setResult(false);
126         }
127         Catch(PlatformException)
128         {
129                 LogError("Error [PlatformException] : " << _rethrown_exception.GetMessage());
130                 event->setExceptionCode(ExceptionCodes::PlatformException);
131                 event->setResult(false);
132         }
133         Catch(Exception)
134         {
135                 LogError("Error [Unknown] : " << _rethrown_exception.GetMessage());
136                 event->setExceptionCode(ExceptionCodes::UnknownException);
137                 event->setResult(false);
138         }
139 }
140
141 } // MessagePort
142 } // DeviceAPI