e611d0cc0f71aaa2b925f3c8854076179d112439
[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 inicietig widget uninstallation.
54  *
55  * WidgetHandler is used to point witch widget shuld be uninstalled
56  */
57 DECLARE_GENERIC_EVENT_2(UninstallWidgetEvent,
58                         WidgetHandle,
59                         WidgetUninstallationStruct)
60
61 /**
62  * @brief Event for pushing installation process forward.
63  */
64 DECLARE_GENERIC_EVENT_1(NextStepEvent, Jobs::Job *)
65
66 DECLARE_GENERIC_EVENT_0(InstallDeferredWidgetPackagesEvent)
67
68 DECLARE_GENERIC_EVENT_0(InitializeEvent)
69 DECLARE_GENERIC_EVENT_0(TerminateEvent)
70
71 } // namespace InstallerEvents
72
73
74 namespace Logic {
75
76 /**
77  * @brief Controls Widget installation
78  *
79  * Main Controler of wiget installation/uninstallation, this is also used
80  * for pushing forward each of processes.
81  * It waits for three events:
82  * <ul>
83  *     <li>InstallWidgetEvent</li>
84  *     <li>UninstallWidgetEvent</li>
85  *     <li>NextStepEvent</li>
86  * </ul>
87  */
88
89 typedef DPL::TypeListDecl<
90     InstallerControllerEvents::InstallWidgetEvent,
91     InstallerControllerEvents::InstallPluginEvent,
92     InstallerControllerEvents::UninstallWidgetEvent,
93     InstallerControllerEvents::NextStepEvent,
94     InstallerControllerEvents::InstallDeferredWidgetPackagesEvent,
95     InstallerControllerEvents::InitializeEvent,
96     InstallerControllerEvents::TerminateEvent>::Type
97 InstallerControllerEventsSet;
98
99 class InstallerController : public DPL::Event::Controller<InstallerControllerEventsSet>
100 {
101   protected:
102     /**
103      * @brief Executed on InstallWidgetEvent received.
104      */
105     virtual void OnEventReceived(
106             const InstallerControllerEvents::InstallWidgetEvent &event);
107
108     /**
109      * @brief Executed on InstallPluginEvent received.
110      */
111     virtual void OnEventReceived(
112             const InstallerControllerEvents::InstallPluginEvent &event);
113
114     /**
115      * @brief Executed on UninstallWidgetEvent received.
116      */
117     virtual void OnEventReceived(
118             const InstallerControllerEvents::UninstallWidgetEvent &event);
119     /**
120      * @brief Executed on NextStepEvent received.
121      */
122     virtual void OnEventReceived(
123             const InstallerControllerEvents::NextStepEvent &event);
124
125     virtual void OnEventReceived(
126             const InstallerControllerEvents::InstallDeferredWidgetPackagesEvent
127             &event);
128
129     virtual void OnEventReceived(
130             const InstallerControllerEvents::InitializeEvent &event);
131     virtual void OnEventReceived(
132             const InstallerControllerEvents::TerminateEvent &event);
133
134   private:
135     // Embedded logic
136     Logic::InstallerLogic m_installerLogic;
137
138     InstallerController();
139
140     static Eina_Bool AddNextStep(void *data);
141
142     friend class DPL::Singleton<InstallerController>;
143 };
144
145 typedef DPL::Singleton<InstallerController> InstallerControllerSingleton;
146
147 }
148
149 #endif // INSTALLER_CONTROLLER_H