2 // Open Service Platform
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 FIo_RemoteMessagePortImpl.cpp
20 * @brief This is the implementation file for the _RemoteMessagePortImpl class.
24 #include <unique_ptr.h>
27 #include <FBaseSysLog.h>
28 #include <FBaseColHashMap.h>
29 #include <FIoLocalMessagePort.h>
30 #include <FIoRemoteMessagePort.h>
31 #include <FIoIMessagePortListener.h>
33 #include "FIo_RemoteMessagePortImpl.h"
34 #include "FIo_MessagePortProxy.h"
38 using namespace Tizen::Base;
39 using namespace Tizen::Base::Collection;
40 using namespace Tizen::App;
42 namespace Tizen { namespace Io
45 _RemoteMessagePortImpl::_RemoteMessagePortImpl(void)
51 _RemoteMessagePortImpl::~_RemoteMessagePortImpl(void)
57 _RemoteMessagePortImpl::Construct(const AppId& remoteAppId, const String& remotePort, bool isTrusted)
59 result r = _MessagePortProxy::GetProxy()->RequestRemotePort(remoteAppId, remotePort, isTrusted);
60 SysTryReturnResult(NID_IO, r == E_SUCCESS, r, "Propagating.");
62 __remoteAppId = remoteAppId;
63 __remotePort = remotePort;
64 __isTrusted = isTrusted;
70 _RemoteMessagePortImpl::GetAppId(void) const
76 _RemoteMessagePortImpl::GetName(void) const
82 _RemoteMessagePortImpl::IsTrusted(void) const
88 _RemoteMessagePortImpl::SendMessage(const IMap* pMessage)
90 SysTryReturnResult(NID_IO, pMessage != null, E_INVALID_ARG, "The argument is null.");
91 SysTryReturnResult(NID_IO, CheckMessageType(pMessage), E_INVALID_ARG, "The argument is invalid.");
93 return _MessagePortProxy::GetProxy()->SendMessage(__remoteAppId, __remotePort, __isTrusted, (HashMap*)pMessage);
97 _RemoteMessagePortImpl::SendMessage(const LocalMessagePort* pLocalMessagePort, const IMap* pMessage)
99 SysTryReturnResult(NID_IO, pLocalMessagePort != null, E_INVALID_ARG, "The argument is null.");
100 SysTryReturnResult(NID_IO, pMessage != null, E_INVALID_ARG, "The argument is null.");
101 SysTryReturnResult(NID_IO, CheckMessageType(pMessage), E_INVALID_ARG, "The argument is invalid.");
103 return _MessagePortProxy::GetProxy()->SendMessage(pLocalMessagePort->GetName(), pLocalMessagePort->IsTrusted(), __remoteAppId, __remotePort, __isTrusted, (HashMap*)pMessage);
107 _RemoteMessagePortImpl::CheckMessageType(const IMap* pMessage)
109 std::unique_ptr<IMapEnumerator> pEnum (pMessage->GetMapEnumeratorN());
110 while(pEnum->MoveNext() == E_SUCCESS)
112 const String* pKey = dynamic_cast<const String*>(pEnum->GetKey());
113 const Object* pValue = pEnum->GetValue();
117 if (typeid(*pValue) != typeid(const String))
119 if (typeid(*pValue) != typeid(const ByteBuffer))
135 _RemoteMessagePortImpl::GetMessagePort(const AppId& remoteAppId, const String& remotePort, bool isTrusted)
137 result r = E_SUCCESS;
139 RemoteMessagePort* pRemoteMessagePort = new (std::nothrow) RemoteMessagePort;
140 SysTryReturn(NID_IO, pRemoteMessagePort != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
142 unique_ptr<_RemoteMessagePortImpl> pImpl(new (std::nothrow) _RemoteMessagePortImpl);
143 SysTryCatch(NID_IO, pImpl != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
145 r = pImpl->Construct(remoteAppId, remotePort, isTrusted);
146 //SysTryCatch(NID_IO, r != E_OBJ_NOT_FOUND, , E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The remote message port is not found.");
147 //SysTryCatch(NID_IO, r != E_CERTIFICATE_VERIFICATION_FAILED, , E_CERTIFICATE_VERIFICATION_FAILED, "[E_CERTIFICATE_VERIFICATION_FAILED] The target application is not signed with the same certificate.");
148 SysTryCatch(NID_IO, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
150 pRemoteMessagePort->__pRemoteMessagePortImpl = pImpl.release();
153 return pRemoteMessagePort;
156 delete pRemoteMessagePort;
162 _RemoteMessagePortImpl::GetMessagePortOnly(const AppId& remoteAppId, const String& remotePort, bool isTrusted)
164 RemoteMessagePort* pRemoteMessagePort = new (std::nothrow) RemoteMessagePort;
165 SysTryReturn(NID_IO, pRemoteMessagePort != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
167 unique_ptr<_RemoteMessagePortImpl> pImpl(new (std::nothrow) _RemoteMessagePortImpl);
168 SysTryCatch(NID_IO, pImpl != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
170 pImpl->__remoteAppId = remoteAppId;
171 pImpl->__remotePort = remotePort;
172 pImpl->__isTrusted = isTrusted;
174 pRemoteMessagePort->__pRemoteMessagePortImpl = pImpl.release();
176 SetLastResult(E_SUCCESS);
177 return pRemoteMessagePort;
180 delete pRemoteMessagePort;