sync with tizen_2.0
[platform/framework/native/appfw.git] / src / io / FIo_ChannelServiceManager.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 /**
19  * @file        FIo_ChannelServiceManager.cpp
20  * @brief       This is the implementation file for the _ChannelServiceManager class.
21  *
22  */
23
24 #include <FBaseSysLog.h>
25 #include "FIo_ChannelServiceManager.h"
26 #include "FIo_ChannelServiceProxy.h"
27 #include "FIo_ChannelServiceStub.h"
28 #include "FIo_ChannelService.h"
29
30 namespace Tizen { namespace Io
31 {
32
33 _ChannelServiceManager* _ChannelServiceManager::__pChannnelServiceManager = null;
34
35 _ChannelServiceManager::_ChannelServiceManager(void)
36         : __pIChannelService(null)
37 {
38
39 }
40
41 _ChannelServiceManager::~_ChannelServiceManager(void)
42 {
43
44 }
45
46 _ChannelServiceManager*
47 _ChannelServiceManager::GetInstance(void)
48 {
49         // FIXME:
50         // Use lock to prevent duplicated creation.
51         if (__pChannnelServiceManager == null)
52         {
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.");
55         }
56
57         return __pChannnelServiceManager;
58 }
59
60 // This method is called by channel daemon.
61 // Cahnnel daemon should call this before GetChanelService is called.
62 void
63 _ChannelServiceManager::SetChannelService(_IChannelService* pIChannelService)
64 {
65         __pIChannelService = pIChannelService;
66 }
67
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.
71 _IChannelService*
72 _ChannelServiceManager::GetChannelService(void)
73 {
74         if (__pIChannelService == null)
75         {
76                 result r = E_SUCCESS;
77
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.");
80
81                 r = pProxy->Construct();
82                 SysTryCatch(NID_IO, !IsFailed(r), , E_SYSTEM, "[E_SYSTEM] Failed to initialize channel proxy.");
83
84                 __pIChannelService = pProxy;
85         }
86
87         return __pIChannelService;
88
89 CATCH:
90         delete __pIChannelService;
91         __pIChannelService = null;
92
93         return null;
94 }
95
96 }}