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.");
92 return _MessagePortProxy::GetProxy()->SendMessage(__remoteAppId, __remotePort, __isTrusted, (HashMap*)pMessage);
96 _RemoteMessagePortImpl::SendMessage(const LocalMessagePort* pLocalMessagePort, const IMap* pMessage)
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.");
101 return _MessagePortProxy::GetProxy()->SendMessage(pLocalMessagePort->GetName(), pLocalMessagePort->IsTrusted(), __remoteAppId, __remotePort, __isTrusted, (HashMap*)pMessage);
105 _RemoteMessagePortImpl::GetMessagePort(const AppId& remoteAppId, const String& remotePort, bool isTrusted)
107 result r = E_SUCCESS;
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.");
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.");
115 r = pImpl->Construct(remoteAppId, remotePort, isTrusted);
116 SysTryCatch(NID_IO, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
118 pRemoteMessagePort->__pRemoteMessagePortImpl = pImpl.release();
121 return pRemoteMessagePort;
124 delete pRemoteMessagePort;
130 _RemoteMessagePortImpl::GetMessagePortOnly(const AppId& remoteAppId, const String& remotePort, bool isTrusted)
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.");
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.");
138 pImpl->__remoteAppId = remoteAppId;
139 pImpl->__remotePort = remotePort;
140 pImpl->__isTrusted = isTrusted;
142 pRemoteMessagePort->__pRemoteMessagePortImpl = pImpl.release();
144 SetLastResult(E_SUCCESS);
145 return pRemoteMessagePort;
148 delete pRemoteMessagePort;