2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file FIo_RemoteMessagePortImpl.cpp
19 * @brief This is the implementation file for the _RemoteMessagePortImpl class.
23 #include <unique_ptr.h>
26 #include <FBaseSysLog.h>
27 #include <FBaseColHashMap.h>
28 #include <FIoLocalMessagePort.h>
29 #include <FIoRemoteMessagePort.h>
30 #include <FIoIMessagePortListener.h>
32 #include "FIo_RemoteMessagePortImpl.h"
33 #include "FIo_MessagePortProxy.h"
37 using namespace Tizen::Base;
38 using namespace Tizen::Base::Collection;
39 using namespace Tizen::App;
41 namespace Tizen { namespace Io
44 _RemoteMessagePortImpl::_RemoteMessagePortImpl(void)
50 _RemoteMessagePortImpl::~_RemoteMessagePortImpl(void)
56 _RemoteMessagePortImpl::Construct(const AppId& remoteAppId, const String& remotePort, bool isTrusted)
58 result r = _MessagePortProxy::GetProxy()->RequestRemotePort(remoteAppId, remotePort, isTrusted);
59 SysTryReturnResult(NID_IO, r == E_SUCCESS, r, "Propagating.");
61 __remoteAppId = remoteAppId;
62 __remotePort = remotePort;
63 __isTrusted = isTrusted;
69 _RemoteMessagePortImpl::GetAppId(void) const
75 _RemoteMessagePortImpl::GetName(void) const
81 _RemoteMessagePortImpl::IsTrusted(void) const
87 _RemoteMessagePortImpl::SendMessage(const IMap* pMessage)
89 SysTryReturnResult(NID_IO, pMessage != null, E_INVALID_ARG, "The argument is null.");
91 return _MessagePortProxy::GetProxy()->SendMessage(__remoteAppId, __remotePort, __isTrusted, (HashMap*)pMessage);
95 _RemoteMessagePortImpl::SendMessage(const LocalMessagePort* pLocalMessagePort, const IMap* pMessage)
97 SysTryReturnResult(NID_IO, pLocalMessagePort != null, E_INVALID_ARG, "The argument is null.");
98 SysTryReturnResult(NID_IO, pMessage != null, E_INVALID_ARG, "The argument is null.");
100 return _MessagePortProxy::GetProxy()->SendMessage(pLocalMessagePort->GetName(), pLocalMessagePort->IsTrusted(), __remoteAppId, __remotePort, __isTrusted, (HashMap*)pMessage);
104 _RemoteMessagePortImpl::GetMessagePort(const AppId& remoteAppId, const String& remotePort, bool isTrusted)
106 result r = E_SUCCESS;
108 RemoteMessagePort* pRemoteMessagePort = new (std::nothrow) RemoteMessagePort;
109 SysTryReturn(NID_IO, pRemoteMessagePort != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
111 unique_ptr<_RemoteMessagePortImpl> pImpl(new (std::nothrow) _RemoteMessagePortImpl);
112 SysTryCatch(NID_IO, pImpl != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
114 r = pImpl->Construct(remoteAppId, remotePort, isTrusted);
115 SysTryCatch(NID_IO, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
117 pRemoteMessagePort->__pRemoteMessagePortImpl = pImpl.release();
120 return pRemoteMessagePort;
123 delete pRemoteMessagePort;
129 _RemoteMessagePortImpl::GetMessagePortOnly(const AppId& remoteAppId, const String& remotePort, bool isTrusted)
131 RemoteMessagePort* pRemoteMessagePort = new (std::nothrow) RemoteMessagePort;
132 SysTryReturn(NID_IO, pRemoteMessagePort != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
134 unique_ptr<_RemoteMessagePortImpl> pImpl(new (std::nothrow) _RemoteMessagePortImpl);
135 SysTryCatch(NID_IO, pImpl != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
137 pImpl->__remoteAppId = remoteAppId;
138 pImpl->__remotePort = remotePort;
139 pImpl->__isTrusted = isTrusted;
141 pRemoteMessagePort->__pRemoteMessagePortImpl = pImpl.release();
143 SetLastResult(E_SUCCESS);
144 return pRemoteMessagePort;
147 delete pRemoteMessagePort;