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 FIoClientChannel.cpp
19 * @brief This is the implementation file for the ClientChannel class.
27 #include <FBaseSysLog.h>
28 #include <FIoClientChannel.h>
29 #include <FAppPkg_PackageManagerImpl.h>
30 #include "FIo_ClientChannelImpl.h"
33 using namespace Tizen::App;
34 using namespace Tizen::App::Package;
35 using namespace Tizen::Base;
36 using namespace Tizen::Base::Collection;
38 namespace Tizen { namespace Io
41 ClientChannel* ClientChannel::__pClientChannelInstance = null;
43 ClientChannel::ClientChannel(void)
44 : __pClientChannelImpl(null)
48 ClientChannel::~ClientChannel(void)
50 delete __pClientChannelImpl;
54 ClientChannel::SetChannelResponseEventListener(IChannelResponseEventListener* pResponseListener)
56 SysAssertf(__pClientChannelImpl != null, "Not yet constructed. Construct() should be called before use.\n");
58 __pClientChannelImpl->SetChannelResponseEventListener(pResponseListener);
62 ClientChannel::SendRequest(const String& serverChannelId, const IList* pArgs, RequestId& reqId)
64 SysAssertf(__pClientChannelImpl != null, "Not yet constructed. Construct() should be called before use.\n");
66 SysTryReturnResult(NID_IO, !serverChannelId.IsEmpty(), E_OBJ_NOT_FOUND, "The server channel is not found.");
68 return __pClientChannelImpl->SendRequest(serverChannelId, pArgs, reqId);
72 ClientChannel::GetInstance(void)
74 static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
76 if (__pClientChannelInstance == null)
80 pthread_once(&onceBlock, InitSingleton);
81 result r = GetLastResult();
84 onceBlock = PTHREAD_ONCE_INIT;
85 SysPropagate(NID_IO, r);
89 return __pClientChannelInstance;
93 ClientChannel::GetInstance(const String& channelName)
95 ClientChannel* pClientChannel = _ClientChannelImpl::GetClientChannel(channelName);
96 SysTryReturn(NID_IO, pClientChannel != null, null, E_SYSTEM, "[E_SYSTEM] Failed to create a client channel.");
98 return pClientChannel;
102 ClientChannel::InitSingleton(void)
104 ClientChannel* pInst = new (std::nothrow) ClientChannel();
105 SysTryReturnVoidResult(NID_IO, pInst, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
107 pInst->__pClientChannelImpl = _ClientChannelImpl::GetInstance(pInst);
108 SysTryCatch(NID_IO, pInst->__pClientChannelImpl != null, , E_SYSTEM,
109 "[E_SYSTEM] Failed to initialize the client channel.");
111 __pClientChannelInstance = pInst;
112 std::atexit(DestroySingleton);
120 ClientChannel::DestroySingleton(void)
122 delete __pClientChannelInstance;