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 FIoServerChannel.cpp
19 * @brief This is the implementation file for the ServerChannel class.
26 #include <FBaseSysLog.h>
27 #include <FIoServerChannel.h>
28 #include <FAppPkg_PackageManagerImpl.h>
29 #include "FIo_ServerChannelImpl.h"
31 using namespace Tizen::App;
32 using namespace Tizen::App::Package;
33 using namespace Tizen::Base;
34 using namespace Tizen::Base::Collection;
36 namespace Tizen { namespace Io
39 ServerChannel* ServerChannel::__pServerChannelInstance = null;
41 ////////////////////////////////////////////////////////////////////////////////
44 ServerChannel::ServerChannel(void)
45 : __pServerChannelImpl(null)
49 ServerChannel::~ServerChannel(void)
51 delete __pServerChannelImpl;
55 ServerChannel::SetChannelRequestEventListener(IChannelRequestEventListener* pRequestListener)
57 SysAssertf(__pServerChannelImpl != null, "Not yet constructed. Construct() should be called before use.\n");
58 __pServerChannelImpl->SetChannelRequestEventListener(pRequestListener);
62 ServerChannel::SendResponse(const String& clientChannelId, RequestId reqId, const IList* pArgs)
64 SysAssertf(__pServerChannelImpl != null, "Not yet constructed. Construct() should be called before use.\n");
66 SysTryReturnResult(NID_IO, !clientChannelId.IsEmpty(), E_OBJ_NOT_FOUND, "The client channel is not found.");
68 return __pServerChannelImpl->SendResponse(clientChannelId, pArgs, reqId);
72 ServerChannel::GetInstance(void)
74 static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
76 if (__pServerChannelInstance == null)
80 pthread_once(&onceBlock, InitSingleton);
81 result r = GetLastResult();
84 onceBlock = PTHREAD_ONCE_INIT;
85 SysPropagate(NID_IO, r);
89 return __pServerChannelInstance;
93 ServerChannel::GetInstance(const String& channelName)
95 ServerChannel* pServerChannel = _ServerChannelImpl::GetServerChannel(channelName);
96 SysTryReturn(NID_IO, pServerChannel != null, null, E_SYSTEM, "[E_SYSTEM] Failed to create a server channel.");
98 return pServerChannel;
102 ServerChannel::InitSingleton(void)
104 ServerChannel* pInst = new (std::nothrow) ServerChannel();
105 SysTryReturnVoidResult(NID_IO, pInst != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
107 pInst->__pServerChannelImpl = _ServerChannelImpl::GetInstance(pInst);
108 SysTryCatch(NID_IO, pInst->__pServerChannelImpl != null, ,E_SYSTEM,
109 "[E_SYSTEM] Failed to initialize the server channel.");
111 __pServerChannelInstance = pInst;
112 std::atexit(DestroySingleton);
120 ServerChannel::DestroySingleton(void)
122 delete __pServerChannelInstance;