59bcc907bfd0907cb321483e2f9def01f7a9bd7c
[framework/web/wrt-installer.git] / src / wrt-installer / wrt-installer.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 /**
17  * @file    wrt-installer.h
18  * @version 1.0
19  * @brief   Implementation file for installer
20  */
21 #ifndef WRT_INSTALLER_H
22 #define WRT_INSTALLER_H
23
24 #include <dpl/application.h>
25 #include <dpl/generic_event.h>
26 #include <dpl/event/controller.h>
27 #include <dpl/task.h>
28 #include <dpl/string.h>
29 #include <string>
30 #include <map>
31 #include <wrt_installer_api.h>
32 #include <wrt_install_mode.h>
33
34 namespace WRTInstallerNS { //anonymous
35 DECLARE_GENERIC_EVENT_0(QuitEvent)
36 DECLARE_GENERIC_EVENT_0(NextStepEvent)
37 DECLARE_GENERIC_EVENT_0(InstallPluginEvent)
38 }
39
40 typedef void (*ShowResultCallback)(void *data, Evas_Object *obj,
41                                    void *event_info);
42 namespace CSCConfiguration {
43 typedef std::map<std::string, std::string> dataMap;
44 typedef std::pair<std::string, std::string> dataPair;
45 const char* const KEY_OP = "op";
46 const char* const KEY_PATH = "path";
47 const char* const VALUE_INSTALL = "install";
48 const char* const VALUE_UNINSTALL = "uninstall";
49 }
50
51 enum ReturnValue
52 {
53     RE_SUCCESS,
54     RE_FAIL
55 };
56
57 class WrtInstaller :
58     public DPL::Application,
59     private DPL::Event::Controller<DPL::TypeListDecl<
60                                        WRTInstallerNS::QuitEvent,
61                                        WRTInstallerNS::NextStepEvent,
62                                        WRTInstallerNS::InstallPluginEvent>::
63                                        Type>,
64     public DPL::TaskDecl<WrtInstaller>
65 {
66   public:
67     WrtInstaller(int argc,
68                  char **argv);
69     virtual ~WrtInstaller();
70
71     int getReturnStatus() const;
72
73   protected:
74     virtual void OnStop();
75     virtual void OnCreate();
76     virtual void OnReset(bundle *b);
77     virtual void OnTerminate();
78
79   private:
80     void         showHelpAndQuit();
81
82     // Events
83     virtual void OnEventReceived(const WRTInstallerNS::QuitEvent &event);
84     virtual void OnEventReceived(const WRTInstallerNS::NextStepEvent& event);
85     virtual void OnEventReceived(
86         const WRTInstallerNS::InstallPluginEvent& event);
87
88     // Installation steps
89     void initStep();
90     void installStep();
91     void installPluginsStep();
92     void uninstallPkgNameStep();
93     void unistallWgtFileStep();
94     void shutdownStep();
95
96     // Static callbacks
97     static void staticWrtInitCallback(WrtErrStatus status,
98                                       void* userdata);
99     static void staticWrtStatusCallback(std::string tizenId,
100                                         WrtErrStatus status,
101                                         void* userdata);
102     static void staticWrtPluginInstallationCallback(WrtErrStatus status,
103                                                     void* userdata);
104     static void staticWrtPluginInstallProgressCb(float percent,
105                                                  const char* description,
106                                                  void* userdata);
107     static void staticWrtInstallProgressCallback(float percent,
108                                                  const char* description,
109                                                  void* userdata);
110
111     static void staticWrtUninstallProgressCallback(float percent,
112                                                    const char* description,
113                                                    void* userdata);
114
115     static void showResultCallback(void *data, Evas_Object *obj,
116                                    void *event_info);
117     static void failResultCallback(void *data, Evas_Object *obj,
118                                    void *event_info);
119
120     void installNewPlugins();
121     bool popupsEnabled() const;
122     CSCConfiguration::dataMap parseCSCConfiguration(std::string str);
123
124     // Private data
125     std::shared_ptr<PackageManager::IPkgmgrSignal> pkgmgrSignalInterface;
126     InstallMode m_installMode;
127     std::string m_packagePath;
128     std::string m_name;
129     bool m_initialized;
130     size_t m_numPluginsToInstall;
131     size_t m_totalPlugins;
132     int m_returnStatus;
133     bool m_installByPkgmgr;
134     bool m_startupPluginInstallation;
135     CSCConfiguration::dataMap m_CSCconfigurationMap;
136
137     typedef std::list<std::string> PluginPathList;
138     DPL::Optional<PluginPathList> m_pluginsPaths;
139 };
140 #endif // WRT_INSTALLER_H