tizen beta release
[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 } // namespace InstallerEvents
77
78 /**
79  * @brief Controls Widget installation
80  *
81  * Main Controler of wiget installation/uninstallation, this is also used
82  * for pushing forward each of processes.
83  * It waits for three events:
84  * <ul>
85  *     <li>InstallWidgetEvent</li>
86  *     <li>UninstallWidgetEvent</li>
87  *     <li>NextStepEvent</li>
88  * </ul>
89  */
90
91 typedef DPL::TypeListDecl<
92     InstallerControllerEvents::InstallWidgetEvent,
93     InstallerControllerEvents::InstallPluginEvent,
94     InstallerControllerEvents::InstallPluginGeolocationEvent,
95     InstallerControllerEvents::UninstallWidgetEvent,
96     InstallerControllerEvents::NextStepEvent,
97     InstallerControllerEvents::InstallDeferredWidgetPackagesEvent,
98     InstallerControllerEvents::InitializeEvent,
99     InstallerControllerEvents::TerminateEvent>::Type
100 InstallerControllerEventsSet;
101
102 class InstallerController : public DPL::Event::Controller<InstallerControllerEventsSet>
103 {
104   protected:
105     /**
106      * @brief Executed on InstallWidgetEvent received.
107      */
108     virtual void OnEventReceived(
109             const InstallerControllerEvents::InstallWidgetEvent &event);
110
111     /**
112      * @brief Executed on InstallPluginEvent received.
113      */
114     virtual void OnEventReceived(
115             const InstallerControllerEvents::InstallPluginEvent &event);
116
117     /**
118      * @brief Executed on InstallPluginEvent received.
119      */
120     virtual void OnEventReceived(
121             const InstallerControllerEvents::InstallPluginGeolocationEvent
122             &event);
123
124     /**
125      * @brief Executed on UninstallWidgetEvent received.
126      */
127     virtual void OnEventReceived(
128             const InstallerControllerEvents::UninstallWidgetEvent &event);
129     /**
130      * @brief Executed on NextStepEvent received.
131      */
132     virtual void OnEventReceived(
133             const InstallerControllerEvents::NextStepEvent &event);
134
135     virtual void OnEventReceived(
136             const InstallerControllerEvents::InstallDeferredWidgetPackagesEvent
137             &event);
138
139     virtual void OnEventReceived(
140             const InstallerControllerEvents::InitializeEvent &event);
141     virtual void OnEventReceived(
142             const InstallerControllerEvents::TerminateEvent &event);
143
144   private:
145     // Embedded logic
146     InstallerLogic m_installerLogic;
147
148     InstallerController();
149
150     static Eina_Bool AddNextStep(void *data);
151
152     friend class DPL::Singleton<InstallerController>;
153 };
154
155 typedef DPL::Singleton<InstallerController> InstallerControllerSingleton;
156
157 #endif // INSTALLER_CONTROLLER_H