clear last result to fix GetLastResult() error [N_SE-46568]
[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::App::Package;
40 using namespace Tizen::Base;
41 using namespace Tizen::Base::Collection;
42 using namespace Tizen::Graphics;
43
44 namespace Tizen { namespace Shell
45 {
46
47 AppWidgetManager* AppWidgetManager::__pTheInstance = null;
48
49 AppWidgetManager::AppWidgetManager()
50         :__pAppWidgetManagerImpl(null)
51 {
52
53 }
54
55 AppWidgetManager::~AppWidgetManager()
56 {
57 }
58
59 void
60 AppWidgetManager::InitSingleton(void)
61 {
62         std::unique_ptr<AppWidgetManager> pInst(new (std::nothrow) AppWidgetManager());
63         SysTryReturnVoidResult(NID_SHELL, pInst, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
64
65         result r = pInst->Construct();
66         SysTryReturnVoidResult(NID_SHELL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
67
68         __pTheInstance = pInst.release();
69         std::atexit(DestroySingleton);
70 }
71
72 void
73 AppWidgetManager::DestroySingleton(void)
74 {
75         delete __pTheInstance;
76 }
77
78 AppWidgetManager*
79 AppWidgetManager::GetInstance(void)
80 {
81         ClearLastResult();
82         SysTryReturn(NID_SHELL, _AppWidgetManagerImpl::HasFeature(), null, E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] This operation is not supported.");
83
84         static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
85         if (__pTheInstance == null)
86         {
87                 pthread_once(&onceBlock, InitSingleton);
88                 result r = GetLastResult();
89                 if (IsFailed(r))
90                 {
91                         onceBlock = PTHREAD_ONCE_INIT;
92                 }
93         }
94         return __pTheInstance;
95 }
96
97 result
98 AppWidgetManager::Construct(void)
99 {
100         SysAssert(__pAppWidgetManagerImpl == null);
101
102         SysLog(NID_SHELL, "Enter.");
103         __pAppWidgetManagerImpl = _AppWidgetManagerImpl::GetInstance();
104         SysAssertf(__pAppWidgetManagerImpl, "Failed to construct _AppWidgetManagerImpl!!");
105
106         SysLog(NID_SHELL, "Exit.");
107
108         return E_SUCCESS;
109 }
110
111 //
112 // E_SYSTEM
113 //
114 IList*
115 AppWidgetManager::GetAppWidgetProviderInfoListN(void) const
116 {
117         ClearLastResult();
118         IList* pIList = __pAppWidgetManagerImpl->GetAppWidgetProviderInfoListN();
119         SysTryReturn(NID_SHELL, pIList, null, E_SYSTEM, "[E_SYSTEM] Failed to get the provider information.");
120
121         return pIList;
122 }
123
124 //
125 // E_APP_NOT_INSTALLED
126 // - E_OBJ_NOT_FOUND
127 // - E_SYSTEM
128 //
129 AppWidgetProviderInfo*
130 AppWidgetManager::GetAppWidgetProviderInfoN(const Tizen::App::AppId& appId, const Tizen::Base::String& providerName) const
131 {
132         ClearLastResult();
133         return __pAppWidgetManagerImpl->GetAppWidgetProviderInfoN(appId, providerName);
134 }
135
136 //
137 // E_APP_NOT_INSTALLED
138 // - E_SYSTEM
139 //
140 AppWidgetProviderInfo*
141 AppWidgetManager::GetDefaultAppWidgetProviderInfoN(const Tizen::App::PackageId& packageId) const
142 {
143         ClearLastResult();
144         return __pAppWidgetManagerImpl->GetDefaultAppWidgetProviderInfoN(packageId);
145 }
146
147 //
148 // E_SYSTEM
149 //
150 result
151 AppWidgetManager::SetAppWidgetRequestListener(IAppWidgetRequestListener* pListener)
152 {
153         return __pAppWidgetManagerImpl->SetAppWidgetRequestListener(pListener);
154 }
155
156
157 }} // Tizen::Shell