94d515d73b55ca88e000b9ddda84280bb2517227
[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 KEY_REMOVABLE = "removable";
48 const char* const VALUE_INSTALL = "install";
49 const char* const VALUE_UNINSTALL = "uninstall";
50 const char* const VALUE_TRUE = "true";
51 const char* const VALUE_FALSE = "false";
52 }
53
54 enum ReturnValue
55 {
56     RE_SUCCESS,
57     RE_FAIL
58 };
59
60 class WrtInstaller :
61     public DPL::Application,
62     private DPL::Event::Controller<DPL::TypeListDecl<
63                                        WRTInstallerNS::QuitEvent,
64                                        WRTInstallerNS::NextStepEvent,
65                                        WRTInstallerNS::InstallPluginEvent>::
66                                        Type>,
67     public DPL::TaskDecl<WrtInstaller>
68 {
69   public:
70     WrtInstaller(int argc,
71                  char **argv);
72     virtual ~WrtInstaller();
73
74     int getReturnStatus() const;
75
76   protected:
77     virtual void OnStop();
78     virtual void OnCreate();
79     virtual void OnReset(bundle *b);
80     virtual void OnTerminate();
81
82   private:
83     void         showHelpAndQuit();
84     void         showArguments();
85
86     // Events
87     virtual void OnEventReceived(const WRTInstallerNS::QuitEvent &event);
88     virtual void OnEventReceived(const WRTInstallerNS::NextStepEvent& event);
89     virtual void OnEventReceived(
90         const WRTInstallerNS::InstallPluginEvent& event);
91
92     // Installation steps
93     void initStep();
94     void installStep();
95     void installPluginsStep();
96     void uninstallPkgNameStep();
97     void unistallWgtFileStep();
98     void removeUpdateStep();
99     void shutdownStep();
100
101     // Static callbacks
102     static void staticWrtInitCallback(WrtErrStatus status,
103                                       void* userdata);
104     static void staticWrtStatusCallback(std::string tizenId,
105                                         WrtErrStatus status,
106                                         void* userdata);
107     static void staticWrtPluginInstallationCallback(WrtErrStatus status,
108                                                     void* userdata);
109     static void staticWrtPluginInstallProgressCb(float percent,
110                                                  const char* description,
111                                                  void* userdata);
112     static void staticWrtInstallProgressCallback(float percent,
113                                                  const char* description,
114                                                  void* userdata);
115
116     static void staticWrtUninstallProgressCallback(float percent,
117                                                    const char* description,
118                                                    void* userdata);
119
120     static void showResultCallback(void *data, Evas_Object *obj,
121                                    void *event_info);
122     static void failResultCallback(void *data, Evas_Object *obj,
123                                    void *event_info);
124
125     static void staticWrtInitializeToPreloadCallback(std::string tizenId,
126                                         WrtErrStatus status,
127                                         void* userdata);
128
129     static void staticWrtInitPreloadStatusCallback(std::string tizenId,
130                                         WrtErrStatus status,
131                                         void* userdata);
132
133     void installNewPlugins();
134     CSCConfiguration::dataMap parseCSCConfiguration(std::string str);
135     void showErrorMsg(WrtErrStatus status, std::string tizenId, std::string
136             printMsg);
137
138     // Private data
139     std::shared_ptr<PackageManager::IPkgmgrSignal> pkgmgrSignalInterface;
140     InstallMode m_installMode;
141     std::string m_packagePath;
142     std::string m_name;
143     bool m_initialized;
144     size_t m_numPluginsToInstall;
145     size_t m_totalPlugins;
146     int m_returnStatus;
147     bool m_installByPkgmgr;
148     bool m_startupPluginInstallation;
149     CSCConfiguration::dataMap m_CSCconfigurationMap;
150
151     typedef std::list<std::string> PluginPathList;
152     DPL::Optional<PluginPathList> m_pluginsPaths;
153 };
154 #endif // WRT_INSTALLER_H