Merge "Fix memory leaks in Locales" into tizen_2.1
[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
28 namespace Tizen { namespace Io
29 {
30
31 _ChannelServiceManager* _ChannelServiceManager::__pChannnelServiceManager = null;
32
33 _ChannelServiceManager::_ChannelServiceManager(void)
34         : __pIChannelService(null)
35 {
36
37 }
38
39 _ChannelServiceManager::~_ChannelServiceManager(void)
40 {
41
42 }
43
44 _ChannelServiceManager*
45 _ChannelServiceManager::GetInstance(void)
46 {
47         // FIXME:
48         // Use lock to prevent duplicated creation.
49         if (__pChannnelServiceManager == null)
50         {
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.");
53         }
54
55         return __pChannnelServiceManager;
56 }
57
58 // This method is called by channel daemon.
59 // Cahnnel daemon should call this before GetChanelService is called.
60 void
61 _ChannelServiceManager::SetChannelService(_IChannelService* pIChannelService)
62 {
63         __pIChannelService = pIChannelService;
64 }
65
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.
69 _IChannelService*
70 _ChannelServiceManager::GetChannelService(void)
71 {
72         if (__pIChannelService == null)
73         {
74                 result r = E_SUCCESS;
75
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.");
78
79                 r = pProxy->Construct();
80                 SysTryCatch(NID_IO, !IsFailed(r), , E_SYSTEM, "[E_SYSTEM] Failed to initialize channel proxy.");
81
82                 __pIChannelService = pProxy;
83         }
84
85         return __pIChannelService;
86
87 CATCH:
88         delete __pIChannelService;
89         __pIChannelService = null;
90
91         return null;
92 }
93
94 }}