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 FIoClientChannel.cpp
20 * @brief This is the implementation file for the ClientChannel class.
28 #include <FBaseSysLog.h>
29 #include <FIoClientChannel.h>
30 #include <FAppPkg_PackageManagerImpl.h>
31 #include "FIo_ClientChannelImpl.h"
34 using namespace Tizen::App;
35 using namespace Tizen::App::Package;
36 using namespace Tizen::Base;
37 using namespace Tizen::Base::Collection;
39 namespace Tizen { namespace Io
42 ClientChannel* ClientChannel::__pClientChannelInstance = null;
44 ClientChannel::ClientChannel(void)
45 : __pClientChannelImpl(null)
49 ClientChannel::~ClientChannel(void)
51 delete __pClientChannelImpl;
55 ClientChannel::SetChannelResponseEventListener(IChannelResponseEventListener* pResponseListener)
57 SysAssertf(__pClientChannelImpl != null, "Not yet constructed. Construct() should be called before use.\n");
59 __pClientChannelImpl->SetChannelResponseEventListener(pResponseListener);
63 ClientChannel::SendRequest(const String& serverChannelId, const IList* pArgs, RequestId& reqId)
65 SysAssertf(__pClientChannelImpl != null, "Not yet constructed. Construct() should be called before use.\n");
67 SysTryReturnResult(NID_IO, !serverChannelId.IsEmpty(), E_OBJ_NOT_FOUND, "The server channel is not found.");
69 return __pClientChannelImpl->SendRequest(serverChannelId, pArgs, reqId);
73 ClientChannel::GetInstance(void)
75 static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
77 if (__pClientChannelInstance == null)
81 pthread_once(&onceBlock, InitSingleton);
82 result r = GetLastResult();
85 onceBlock = PTHREAD_ONCE_INIT;
86 SysPropagate(NID_IO, r);
90 return __pClientChannelInstance;
94 ClientChannel::GetInstance(const String& channelName)
96 ClientChannel* pClientChannel = _ClientChannelImpl::GetClientChannel(channelName);
97 SysTryReturn(NID_IO, pClientChannel != null, null, E_SYSTEM, "[E_SYSTEM] Failed to create a client channel.");
99 return pClientChannel;
103 ClientChannel::InitSingleton(void)
105 ClientChannel* pInst = new (std::nothrow) ClientChannel();
106 SysTryReturnVoidResult(NID_IO, pInst, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
108 pInst->__pClientChannelImpl = _ClientChannelImpl::GetInstance(pInst);
109 SysTryCatch(NID_IO, pInst->__pClientChannelImpl != null, , E_SYSTEM,
110 "[E_SYSTEM] Failed to initialize the client channel.");
112 __pClientChannelInstance = pInst;
113 std::atexit(DestroySingleton);
121 ClientChannel::DestroySingleton(void)
123 delete __pClientChannelInstance;