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 FIo_ChannelServiceManager.cpp
20 * @brief This is the implementation file for the _ChannelServiceManager class.
24 #include <FBaseSysLog.h>
25 #include "FIo_ChannelServiceManager.h"
26 #include "FIo_ChannelServiceProxy.h"
28 namespace Tizen { namespace Io
31 _ChannelServiceManager* _ChannelServiceManager::__pChannnelServiceManager = null;
33 _ChannelServiceManager::_ChannelServiceManager(void)
34 : __pIChannelService(null)
39 _ChannelServiceManager::~_ChannelServiceManager(void)
44 _ChannelServiceManager*
45 _ChannelServiceManager::GetInstance(void)
48 // Use lock to prevent duplicated creation.
49 if (__pChannnelServiceManager == null)
51 __pChannnelServiceManager = new (std::nothrow) _ChannelServiceManager;
52 SysTryReturn(NID_IO, __pChannnelServiceManager != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
55 return __pChannnelServiceManager;
58 // This method is called by channel daemon.
59 // Cahnnel daemon should call this before GetChanelService is called.
61 _ChannelServiceManager::SetChannelService(_IChannelService* pIChannelService)
63 __pIChannelService = pIChannelService;
66 // This method returns an _IChannelService interface.
67 // If this is called by application process a proxy implementation is returned.
68 // Or if this is called by channel daemon the service implementation is returned.
70 _ChannelServiceManager::GetChannelService(void)
72 if (__pIChannelService == null)
76 _ChannelServiceProxy* pProxy = new (std::nothrow) _ChannelServiceProxy();
77 SysTryReturn(NID_IO, pProxy, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
79 r = pProxy->Construct();
80 SysTryCatch(NID_IO, !IsFailed(r), , E_SYSTEM, "[E_SYSTEM] Failed to initialize channel proxy.");
82 __pIChannelService = pProxy;
85 return __pIChannelService;
88 delete __pIChannelService;
89 __pIChannelService = null;