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"
27 #include "FIo_ChannelServiceStub.h"
28 #include "FIo_ChannelService.h"
30 namespace Tizen { namespace Io
33 _ChannelServiceManager* _ChannelServiceManager::__pChannnelServiceManager = null;
35 _ChannelServiceManager::_ChannelServiceManager(void)
36 : __pIChannelService(null)
41 _ChannelServiceManager::~_ChannelServiceManager(void)
46 _ChannelServiceManager*
47 _ChannelServiceManager::GetInstance(void)
50 // Use lock to prevent duplicated creation.
51 if (__pChannnelServiceManager == null)
53 __pChannnelServiceManager = new (std::nothrow) _ChannelServiceManager;
54 SysTryReturn(NID_IO, __pChannnelServiceManager != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
57 return __pChannnelServiceManager;
60 // This method is called by channel daemon.
61 // Cahnnel daemon should call this before GetChanelService is called.
63 _ChannelServiceManager::SetChannelService(_IChannelService* pIChannelService)
65 __pIChannelService = pIChannelService;
68 // This method returns an _IChannelService interface.
69 // If this is called by application process a proxy implementation is returned.
70 // Or if this is called by channel daemon the service implementation is returned.
72 _ChannelServiceManager::GetChannelService(void)
74 if (__pIChannelService == null)
78 _ChannelServiceProxy* pProxy = new (std::nothrow) _ChannelServiceProxy();
79 SysTryReturn(NID_IO, pProxy, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
81 r = pProxy->Construct();
82 SysTryCatch(NID_IO, !IsFailed(r), , E_SYSTEM, "[E_SYSTEM] Failed to initialize channel proxy.");
84 __pIChannelService = pProxy;
87 return __pIChannelService;
90 delete __pIChannelService;
91 __pIChannelService = null;