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