refactoring (now _AppContext manages list of _AppWidgetContext, IpcConnection state...
[framework/osp/appwidget-service.git] / src / OspAppWidgetService.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        OspAppWidgetService.cpp
19  * @brief       This is the implementation for the OspAppWidgetService class.
20  */
21
22 #include <FAppAppControlProviderManager.h>
23 #include <FBase_StringConverter.h>
24 #include "FShell_AppWidgetManagerService.h"
25 #include "OspAppWidgetService.h"
26
27 using namespace Tizen::App;
28 using namespace Tizen::Base;
29 using namespace Tizen::System;
30 using namespace Tizen::Shell::App;
31
32 const wchar_t OPERATION_MAIN[] = L"http://tizen.org/appcontrol/operation/main";
33 const wchar_t KEY_NAME[] = L"name";
34
35 OspAppWidgetService::OspAppWidgetService(void)
36 {
37 }
38
39 OspAppWidgetService::~OspAppWidgetService(void)
40 {
41 }
42
43 ServiceApp*
44 OspAppWidgetService::CreateInstance(void)
45 {
46         // Create the instance through the constructor.
47         return new (std::nothrow) OspAppWidgetService();
48 }
49
50 bool
51 OspAppWidgetService::OnAppInitializing(AppRegistry& appRegistry)
52 {
53         AppControlProviderManager::GetInstance()->SetAppControlProviderEventListener(this);
54
55         return true;
56 }
57
58 bool
59 OspAppWidgetService::OnAppInitialized(void)
60 {
61         return true;
62 }
63
64 bool
65 OspAppWidgetService::OnAppWillTerminate(void)
66 {
67         return true;
68 }
69
70 bool
71 OspAppWidgetService::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination)
72 {
73         return true;
74 }
75
76 void
77 OspAppWidgetService::OnLowMemory(void)
78 {
79 }
80
81 void
82 OspAppWidgetService::OnBatteryLevelChanged(BatteryLevel batteryLevel)
83 {
84 }
85
86 void
87 OspAppWidgetService::OnAppControlRequestReceived(RequestId reqId, const Tizen::Base::String& operationId, const Tizen::Base::String* pUriData, const Tizen::Base::String* pMimeType, const Tizen::Base::Collection::IMap* pExtraData)
88 {
89         if (operationId == OPERATION_MAIN)
90         {
91                 static bool isServiceCreated = false;
92
93                 if (isServiceCreated == true)
94                 {
95                         return;
96                 }
97
98                 AppWidgetManagerService* pSvc = null;
99                 String coreDaemonId = "osp-appwidget-service";
100                 if (pExtraData)
101                 {
102                         String key(KEY_NAME);
103                         const String* pValue = dynamic_cast<const String*>(pExtraData->GetValue(key));
104
105                         if (pValue)
106                         {
107                                 coreDaemonId = *pValue;
108                         }
109                 }
110
111                 std::unique_ptr<char[]> pIdForCoreDaemon(_StringConverter::CopyToCharArrayN(coreDaemonId));
112                 pSvc = AppWidgetManagerService::CreateInstance(pIdForCoreDaemon.get());
113                 AppAssertf(pSvc != null, "AppWidgetManagerService::GetInstance() failed.");
114                 isServiceCreated = true;
115         }
116 }
117
118 void
119 OspAppWidgetService::OnUserEventReceivedN(RequestId reqId, Tizen::Base::Collection::IList* pArgs)
120 {
121         AppWidgetManagerService::GetInstance()->OnUserEventReceivedN(reqId, pArgs);
122 }