upload tizen1.0 source
[platform/framework/web/wrt.git] / src / wrt-client / wrt-client.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_CLIENT_H
17 #define WRT_CLIENT_H
18
19 #include <dpl/application.h>
20 #include <dpl/generic_event.h>
21 #include <dpl/event/controller.h>
22 #include <dpl/type_list.h>
23 #include <dpl/task.h>
24 #include <dpl/log/log.h>
25 #include <utilX.h>
26 #include <wrt_api.h>
27 #include <string>
28 #include <signal.h>
29 #include <bundle.h>
30
31 DECLARE_GENERIC_EVENT_0(QuitEvent)
32 DECLARE_GENERIC_EVENT_0(NextStepEvent)
33
34 class WrtClient :
35         public DPL::Application,
36         private DPL::Event::Controller<DPL::TypeListDecl<QuitEvent,
37                                                   NextStepEvent>::Type>,
38         public DPL::TaskDecl<WrtClient>
39 {
40   public:
41     WrtClient(int argc,
42               char **argv);
43     virtual ~WrtClient();
44
45     class ReturnStatus
46     {
47       public:
48         enum Type
49         {
50             Failed = -1,
51             Succeeded = 0
52         };
53     };
54
55     ReturnStatus::Type   getReturnStatus() const;
56
57   protected:
58     virtual void         OnStop();
59     virtual void         OnCreate();
60     virtual void         OnResume();
61     virtual void         OnPause();
62     virtual void         OnReset(bundle *b);
63     virtual void         OnTerminate();
64   private:
65     void                   showHelpAndQuit();
66     void                   setStep();
67     void                   setSdkLauncherDebugData();
68
69     // Events
70     virtual void         OnEventReceived(const QuitEvent &event);
71     virtual void         OnEventReceived(const NextStepEvent& event);
72
73     // Installation steps
74     void                 initStep();
75     void                 launchStep();
76     void                 installNewPlugins();
77     void                 launchNameStep();
78     void                 launchGUIDStep();
79     void                 killWidgetStep();
80     void                 finalizeLaunchStep();
81     void                 shutdownStep();
82     void                 setDeveloperModeStep();
83     void                 setComplianceModeStep();
84     void                 setComplianceImeiStep();
85     void                 setComplianceMeidStep();
86     void                 queryListStep();
87
88     // Static callbacks
89     static void          staticWrtInitCallback(WrtErrStatus status,
90                                                void* userdata);
91     static void          staticWrtLaunchWidgetCallback(void*,
92                                               int,
93                                               WrtErrStatus,
94                                               const char*,
95                                               void*);
96     static void          staticWrtStatusCallback(int handle,
97                                                  WrtErrStatus status,
98                                                  void* userdata);
99     static void          staticWrtPluginInstallationCallback(
100             WrtErrStatus status,
101             void* userdata);
102     static void          staticWrtPluginInstallProgressCb(
103             float percent,
104             const char* description,
105             void* userdata);
106     static void          staticWrtResumeStatusCallback(int handle,
107                                               WrtErrStatus status,
108                                               void* userdata);
109     static void          staticWrtSuspendStatusCallback(int handle,
110                                                WrtErrStatus status,
111                                                void* userdata);
112     static void          staticWrtResetStatusCallback(int handle,
113                                                WrtErrStatus status,
114                                                void* userdata);
115     static void          staticCloseWidgetCallback(int widget_handle,
116                                                    void *userdata);
117     static void          staticSetDeveloperModeCallback(void *userParam);
118     static void          staticSetComplianceModeCallback(void *userParam);
119     static void          staticSetComplianceImeiCallback(void *userParam);
120     static void          staticSetComplianceMeidCallback(void *userParam);
121
122     // Private data
123     std::string m_packagePath;
124     int m_handle;
125     std::string m_name;
126     bool m_launched;
127     bool m_initialized;
128     int m_sdkLauncherPid;
129     bool m_debugMode;
130     bundle *m_bundle;
131     unsigned short m_debuggerPort;
132     bool m_developerMode;
133     bool m_complianceMode;
134     std::string m_complianceIMEI;
135     std::string m_complianceMEID;
136     size_t m_numPluginsToInstall;
137     ReturnStatus::Type m_returnStatus;
138     bool m_startupPluginInstallation;
139 };
140
141 struct WrtClientUserData
142 {
143     WrtClient *This;
144     unsigned long *pid;
145     int portnum;
146     bool debugMode;
147
148     WrtClientUserData() :
149         This(NULL),
150         pid(NULL),
151         portnum(-1),
152         debugMode(false)
153     {
154     }
155
156     WrtClientUserData(WrtClient *currentClient,
157             unsigned long *pidNum,
158             int portNum,
159             bool currentDebugMode) :
160         This(currentClient),
161         pid(pidNum),
162         portnum(portNum),
163         debugMode(currentDebugMode)
164     {
165     }
166 };
167
168 #endif // WRT_CLIENT_H