refactoring GetSizeInfoListN()
[platform/framework/native/shell.git] / src / FShellAppWidgetManager.cpp
1 //
2 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.1 (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
7 //
8 //     http://floralicense.org/license/
9 //
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.
15 //
16
17 /**
18  * @file        FShellAppWidgetManager.cpp
19  * @brief       This is the implementation for the AppWidgetManager class.
20  */
21
22 #include <cstdlib>
23 #include <unique_ptr.h>
24 #include <shortcut.h>
25 #include <livebox-service/livebox-service.h>
26 #include <FBaseSysLog.h>
27 #include <FBaseCol.h>
28 #include <FGraphics.h>
29 #include <FApp.h>
30 #include <FApp_Types.h>
31 #include <FApp_AppInfo.h>
32 #include <FShellAppWidgetManager.h>
33 #include <FShellAppWidgetProviderInfo.h>
34 #include <FShellIAppWidgetRequestListener.h>
35 #include "FShell_AppWidgetManagerImpl.h"
36
37 using namespace std;
38 using namespace Tizen::App;
39 using namespace Tizen::Base;
40 using namespace Tizen::Base::Collection;
41 using namespace Tizen::Graphics;
42
43 namespace Tizen { namespace Shell
44 {
45
46 AppWidgetManager* AppWidgetManager::__pTheInstance = null;
47
48 AppWidgetManager::AppWidgetManager()
49         :__pAppWidgetManagerImpl(null)
50 {
51
52 }
53
54 AppWidgetManager::~AppWidgetManager()
55 {
56 }
57
58 void
59 AppWidgetManager::InitSingleton(void)
60 {
61         std::unique_ptr<AppWidgetManager> pInst(new (std::nothrow) AppWidgetManager());
62         SysTryReturnVoidResult(NID_SHELL, pInst, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
63
64         result r = pInst->Construct();
65         SysTryReturnVoidResult(NID_SHELL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
66
67         __pTheInstance = pInst.release();
68         std::atexit(DestroySingleton);
69 }
70
71 void
72 AppWidgetManager::DestroySingleton(void)
73 {
74         delete __pTheInstance;
75 }
76
77 AppWidgetManager*
78 AppWidgetManager::GetInstance(void)
79 {
80         ClearLastResult();
81         SysTryReturn(NID_SHELL, _AppWidgetManagerImpl::HasFeature(), null, E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] This operation is not supported.");
82
83         static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
84         if (__pTheInstance == null)
85         {
86                 pthread_once(&onceBlock, InitSingleton);
87                 result r = GetLastResult();
88                 if (IsFailed(r))
89                 {
90                         onceBlock = PTHREAD_ONCE_INIT;
91                 }
92         }
93         return __pTheInstance;
94 }
95
96 result
97 AppWidgetManager::Construct(void)
98 {
99         SysAssert(__pAppWidgetManagerImpl == null);
100
101         SysLog(NID_SHELL, "Enter.");
102         __pAppWidgetManagerImpl = _AppWidgetManagerImpl::GetInstance();
103         SysAssertf(__pAppWidgetManagerImpl, "Failed to construct _AppWidgetManagerImpl!!");
104
105         SysLog(NID_SHELL, "Exit.");
106
107         return E_SUCCESS;
108 }
109
110 //
111 // E_SYSTEM
112 //
113 IList*
114 AppWidgetManager::GetAppWidgetProviderInfoListN(void) const
115 {
116         ClearLastResult();
117         IList* pIList = __pAppWidgetManagerImpl->GetAppWidgetProviderInfoListN();
118         SysTryReturn(NID_SHELL, pIList, null, E_SYSTEM, "[E_SYSTEM] Failed to get the provider information.");
119
120         return pIList;
121 }
122
123 //
124 // E_APP_NOT_INSTALLED
125 // - E_OBJ_NOT_FOUND
126 // - E_SYSTEM
127 //
128 AppWidgetProviderInfo*
129 AppWidgetManager::GetAppWidgetProviderInfoN(const Tizen::App::AppId& appId, const Tizen::Base::String& providerName) const
130 {
131         ClearLastResult();
132         return __pAppWidgetManagerImpl->GetAppWidgetProviderInfoN(appId, providerName);
133 }
134
135 //
136 // E_APP_NOT_INSTALLED
137 // - E_SYSTEM
138 //
139 AppWidgetProviderInfo*
140 AppWidgetManager::GetDefaultAppWidgetProviderInfoN(const Tizen::App::PackageId& packageId) const
141 {
142         ClearLastResult();
143         return __pAppWidgetManagerImpl->GetDefaultAppWidgetProviderInfoN(packageId);
144 }
145
146 //
147 // E_SYSTEM
148 //
149 result
150 AppWidgetManager::SetAppWidgetRequestListener(IAppWidgetRequestListener* pListener)
151 {
152         return __pAppWidgetManagerImpl->SetAppWidgetRequestListener(pListener);
153 }
154
155
156 }} // Tizen::Shell