upload tizen1.0 source
[framework/web/wrt-installer.git] / src / logic / installer_controller.h
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (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://www.apache.org/licenses/LICENSE-2.0
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 #ifndef WRT_SRC_INSTALLER_CORE_INSTALLER_CONTROLLER_H_
17 #define WRT_SRC_INSTALLER_CORE_INSTALLER_CONTROLLER_H_
18
19 #include <dpl/singleton.h>
20 #include <dpl/event/controller.h>
21 #include <dpl/generic_event.h>
22 #include <string>
23 #include <map>
24 #include <dpl/task_list.h>
25 #include <dpl/task.h>
26 #include <dpl/type_list.h>
27 #include <widget_install/widget_installer_struct.h>
28 #include <installer_logic.h>
29 #include <job.h>
30
31 /**
32  * @brief holds events send to InstallControler
33  */
34 namespace InstallerControllerEvents {
35 /**
36  * @brief Event for inicieting instalation process.
37  *
38  * This event holds std::string witch should be path to widget package
39  */
40 DECLARE_GENERIC_EVENT_2(InstallWidgetEvent,
41                         std::string,
42                         WidgetInstallationStruct)                                  // (zipFileName, installerStruct)
43
44 /**
45  * @brief Event for iniciating plugin instalation process.
46  * This event holds std::string witch should be path to plugin directory
47  * and PluginInstallerStruct which contain
48  * StatusCallack, progressCallback and private data for callbacks
49  */
50 DECLARE_GENERIC_EVENT_2(InstallPluginEvent, std::string, PluginInstallerStruct)
51
52 /**
53  * @brief Event for indiciating W3C Geolocation plugin instalation process.
54  */
55 DECLARE_GENERIC_EVENT_1(InstallPluginGeolocationEvent, PluginInstallerStruct) //
56
57 /**
58  * @brief Event for inicietig widget uninstallation.
59  *
60  * WidgetHandler is used to point witch widget shuld be uninstalled
61  */
62 DECLARE_GENERIC_EVENT_2(UninstallWidgetEvent,
63                         WidgetHandle,
64                         WidgetUninstallationStruct)
65
66 /**
67  * @brief Event for pushing installation process forward.
68  */
69 DECLARE_GENERIC_EVENT_1(NextStepEvent, Jobs::Job *)
70
71 DECLARE_GENERIC_EVENT_0(InstallDeferredWidgetPackagesEvent)
72
73 DECLARE_GENERIC_EVENT_0(InitializeEvent)
74 DECLARE_GENERIC_EVENT_0(TerminateEvent)
75
76 /**
77  * @brief Event for initiating from web widget installation. This event
78  * contains widget url and optionally widget icon url.
79  */
80 DECLARE_GENERIC_EVENT_3(InstallWidgetFromBrowserEvent,
81                         std::string,
82                         std::string,
83                         WidgetInstallationStruct)
84
85 } // namespace InstallerEvents
86
87 /**
88  * @brief Controls Widget installation
89  *
90  * Main Controler of wiget installation/uninstallation, this is also used
91  * for pushing forward each of processes.
92  * It waits for three events:
93  * <ul>
94  *     <li>InstallWidgetEvent</li>
95  *     <li>UninstallWidgetEvent</li>
96  *     <li>NextStepEvent</li>
97  * </ul>
98  */
99
100 typedef DPL::TypeListDecl<
101     InstallerControllerEvents::InstallWidgetEvent,
102     InstallerControllerEvents::InstallPluginEvent,
103     InstallerControllerEvents::InstallPluginGeolocationEvent,
104     InstallerControllerEvents::UninstallWidgetEvent,
105     InstallerControllerEvents::NextStepEvent,
106     InstallerControllerEvents::InstallDeferredWidgetPackagesEvent,
107     InstallerControllerEvents::InitializeEvent,
108     InstallerControllerEvents::TerminateEvent,
109     InstallerControllerEvents::InstallWidgetFromBrowserEvent>::Type
110 InstallerControllerEventsSet;
111
112 class InstallerController : public DPL::Event::Controller<InstallerControllerEventsSet>
113 {
114   protected:
115     /**
116      * @brief Executed on InstallWidgetEvent received.
117      */
118     virtual void OnEventReceived(
119             const InstallerControllerEvents::InstallWidgetEvent &event);
120
121     /**
122      * @brief Executed on InstallPluginEvent received.
123      */
124     virtual void OnEventReceived(
125             const InstallerControllerEvents::InstallPluginEvent &event);
126
127     /**
128      * @brief Executed on InstallPluginEvent received.
129      */
130     virtual void OnEventReceived(
131             const InstallerControllerEvents::InstallPluginGeolocationEvent
132             &event);
133
134     /**
135      * @brief Executed on UninstallWidgetEvent received.
136      */
137     virtual void OnEventReceived(
138             const InstallerControllerEvents::UninstallWidgetEvent &event);
139     /**
140      * @brief Executed on NextStepEvent received.
141      */
142     virtual void OnEventReceived(
143             const InstallerControllerEvents::NextStepEvent &event);
144
145     virtual void OnEventReceived(
146             const InstallerControllerEvents::InstallDeferredWidgetPackagesEvent
147             &event);
148
149     virtual void OnEventReceived(
150             const InstallerControllerEvents::InitializeEvent &event);
151     virtual void OnEventReceived(
152             const InstallerControllerEvents::TerminateEvent &event);
153
154     virtual void OnEventReceived(
155             const InstallerControllerEvents::InstallWidgetFromBrowserEvent &event);
156
157   private:
158     // Embedded logic
159     InstallerLogic m_installerLogic;
160
161     InstallerController();
162
163     static Eina_Bool AddNextStep(void *data);
164
165     friend class DPL::Singleton<InstallerController>;
166 };
167
168 typedef DPL::Singleton<InstallerController> InstallerControllerSingleton;
169
170 #endif // INSTALLER_CONTROLLER_H