Update the size check in MessagePort
[platform/framework/native/appfw.git] / src / io / FIo_RemoteMessagePortImpl.cpp
1 //
2 // Open Service Platform
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        FIo_RemoteMessagePortImpl.cpp
20  * @brief       This is the implementation file for the _RemoteMessagePortImpl class.
21  *
22  */
23
24 #include <unique_ptr.h>
25 #include <typeinfo>
26
27 #include <FBaseSysLog.h>
28 #include <FBaseColHashMap.h>
29 #include <FIoLocalMessagePort.h>
30 #include <FIoRemoteMessagePort.h>
31 #include <FIoIMessagePortListener.h>
32
33 #include "FIo_RemoteMessagePortImpl.h"
34 #include "FIo_MessagePortProxy.h"
35
36 using namespace std;
37
38 using namespace Tizen::Base;
39 using namespace Tizen::Base::Collection;
40 using namespace Tizen::App;
41
42 namespace Tizen { namespace Io
43 {
44
45 _RemoteMessagePortImpl::_RemoteMessagePortImpl(void)
46         : __isTrusted(false)
47 {
48
49 }
50
51 _RemoteMessagePortImpl::~_RemoteMessagePortImpl(void)
52 {
53
54 }
55
56 result
57 _RemoteMessagePortImpl::Construct(const AppId& remoteAppId, const String& remotePort, bool isTrusted)
58 {
59         result r = _MessagePortProxy::GetProxy()->RequestRemotePort(remoteAppId, remotePort, isTrusted);
60         SysTryReturnResult(NID_IO, r == E_SUCCESS, r, "Propagating.");
61
62         __remoteAppId = remoteAppId;
63         __remotePort = remotePort;
64         __isTrusted = isTrusted;
65
66         return E_SUCCESS;
67 }
68
69 AppId
70 _RemoteMessagePortImpl::GetAppId(void) const
71 {
72         return __remoteAppId;
73 }
74
75 String
76 _RemoteMessagePortImpl::GetName(void) const
77 {
78         return __remotePort;
79 }
80
81 bool
82 _RemoteMessagePortImpl::IsTrusted(void) const
83 {
84         return __isTrusted;
85 }
86
87 result
88 _RemoteMessagePortImpl::SendMessage(const IMap* pMessage)
89 {
90         SysTryReturnResult(NID_IO, pMessage != null, E_INVALID_ARG, "The argument is null.");
91
92         return _MessagePortProxy::GetProxy()->SendMessage(__remoteAppId, __remotePort, __isTrusted, (HashMap*)pMessage);
93 }
94
95 result
96 _RemoteMessagePortImpl::SendMessage(const LocalMessagePort* pLocalMessagePort, const IMap* pMessage)
97 {
98         SysTryReturnResult(NID_IO, pLocalMessagePort != null, E_INVALID_ARG, "The argument is null.");
99         SysTryReturnResult(NID_IO, pMessage != null, E_INVALID_ARG, "The argument is null.");
100
101         return _MessagePortProxy::GetProxy()->SendMessage(pLocalMessagePort->GetName(), pLocalMessagePort->IsTrusted(), __remoteAppId, __remotePort, __isTrusted, (HashMap*)pMessage);
102 }
103
104 RemoteMessagePort*
105 _RemoteMessagePortImpl::GetMessagePort(const AppId& remoteAppId, const String& remotePort, bool isTrusted)
106 {
107         result r = E_SUCCESS;
108
109         RemoteMessagePort* pRemoteMessagePort = new (std::nothrow) RemoteMessagePort;
110         SysTryReturn(NID_IO, pRemoteMessagePort != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
111
112         unique_ptr<_RemoteMessagePortImpl> pImpl(new (std::nothrow) _RemoteMessagePortImpl);
113         SysTryCatch(NID_IO, pImpl != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
114
115         r = pImpl->Construct(remoteAppId, remotePort, isTrusted);
116         SysTryCatch(NID_IO, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
117
118         pRemoteMessagePort->__pRemoteMessagePortImpl = pImpl.release();
119
120         SetLastResult(r);
121         return pRemoteMessagePort;
122
123 CATCH:
124         delete pRemoteMessagePort;
125
126         return null;
127 }
128
129 RemoteMessagePort*
130 _RemoteMessagePortImpl::GetMessagePortOnly(const AppId& remoteAppId, const String& remotePort, bool isTrusted)
131 {
132         RemoteMessagePort* pRemoteMessagePort = new (std::nothrow) RemoteMessagePort;
133         SysTryReturn(NID_IO, pRemoteMessagePort != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
134
135         unique_ptr<_RemoteMessagePortImpl> pImpl(new (std::nothrow) _RemoteMessagePortImpl);
136         SysTryCatch(NID_IO, pImpl != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
137
138         pImpl->__remoteAppId = remoteAppId;
139         pImpl->__remotePort = remotePort;
140         pImpl->__isTrusted = isTrusted;
141
142         pRemoteMessagePort->__pRemoteMessagePortImpl = pImpl.release();
143
144         SetLastResult(E_SUCCESS);
145         return pRemoteMessagePort;
146
147 CATCH:
148         delete pRemoteMessagePort;
149
150         return null;
151 }
152
153 } } // Tizen::Io