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_ChannelServiceManager.cpp
19 * @brief This is the implementation file for the _ChannelServiceManager class.
23 #include <FBaseSysLog.h>
24 #include "FIo_ChannelServiceManager.h"
25 #include "FIo_ChannelServiceProxy.h"
27 namespace Tizen { namespace Io
30 _ChannelServiceManager* _ChannelServiceManager::__pChannnelServiceManager = null;
32 _ChannelServiceManager::_ChannelServiceManager(void)
33 : __pIChannelService(null)
38 _ChannelServiceManager::~_ChannelServiceManager(void)
43 _ChannelServiceManager*
44 _ChannelServiceManager::GetInstance(void)
47 // Use lock to prevent duplicated creation.
48 if (__pChannnelServiceManager == null)
50 __pChannnelServiceManager = new (std::nothrow) _ChannelServiceManager;
51 SysTryReturn(NID_IO, __pChannnelServiceManager != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
54 return __pChannnelServiceManager;
57 // This method is called by channel daemon.
58 // Cahnnel daemon should call this before GetChanelService is called.
60 _ChannelServiceManager::SetChannelService(_IChannelService* pIChannelService)
62 __pIChannelService = pIChannelService;
65 // This method returns an _IChannelService interface.
66 // If this is called by application process a proxy implementation is returned.
67 // Or if this is called by channel daemon the service implementation is returned.
69 _ChannelServiceManager::GetChannelService(void)
71 if (__pIChannelService == null)
75 _ChannelServiceProxy* pProxy = new (std::nothrow) _ChannelServiceProxy();
76 SysTryReturn(NID_IO, pProxy, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
78 r = pProxy->Construct();
79 SysTryCatch(NID_IO, !IsFailed(r), , E_SYSTEM, "[E_SYSTEM] Failed to initialize channel proxy.");
81 __pIChannelService = pProxy;
84 return __pIChannelService;
87 delete __pIChannelService;
88 __pIChannelService = null;