tizen beta release
[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
30 DECLARE_GENERIC_EVENT_0(QuitEvent)
31 DECLARE_GENERIC_EVENT_0(NextStepEvent)
32
33 class WrtClient :
34         public DPL::Application,
35         private DPL::Event::Controller<DPL::TypeListDecl<QuitEvent,
36                                                   NextStepEvent>::Type>,
37         public DPL::TaskDecl<WrtClient>
38 {
39   public:
40     WrtClient(int argc,
41               char **argv);
42     virtual ~WrtClient();
43
44     class ReturnStatus
45     {
46       public:
47         enum Type
48         {
49             Failed = -1,
50             Succeeded = 0
51         };
52     };
53
54     ReturnStatus::Type   getReturnStatus() const;
55
56   protected:
57     virtual void         OnStop();
58     virtual void         OnCreate();
59     virtual void         OnResume();
60     virtual void         OnPause();
61     virtual void         OnReset(bundle *b);
62     virtual void         OnTerminate();
63   private:
64     void                   showHelpAndQuit();
65     void                   setStep();
66     void                   setSdkLauncherDebugData();
67
68     // Events
69     virtual void         OnEventReceived(const QuitEvent &event);
70     virtual void         OnEventReceived(const NextStepEvent& event);
71
72     // Installation steps
73     void                 initStep();
74     void                 launchStep();
75     void                 installNewPlugins();
76     void                 launchNameStep();
77     void                 launchGUIDStep();
78     void                 killWidgetStep();
79     void                 finalizeLaunchStep();
80     void                 shutdownStep();
81     void                 setDeveloperModeStep();
82     void                 setComplianceModeStep();
83     void                 setComplianceImeiStep();
84     void                 setComplianceMeidStep();
85     void                 queryListStep();
86
87     // Static callbacks
88     static void          staticWrtInitCallback(WrtErrStatus status,
89                                                void* userdata);
90     static void          staticWrtLaunchWidgetCallback(void*,
91                                               int,
92                                               WrtErrStatus,
93                                               const char*,
94                                               void*);
95     static void          staticWrtStatusCallback(int handle,
96                                                  WrtErrStatus status,
97                                                  void* userdata);
98     static void          staticWrtPluginInstallationCallback(
99             WrtErrStatus status,
100             void* userdata);
101     static void          staticWrtPluginInstallProgressCb(
102             float percent,
103             const char* description,
104             void* userdata);
105     static void          staticWrtResumeStatusCallback(int handle,
106                                               WrtErrStatus status,
107                                               void* userdata);
108     static void          staticWrtSuspendStatusCallback(int handle,
109                                                WrtErrStatus status,
110                                                void* userdata);
111     static void          staticCloseWidgetCallback(int widget_handle,
112                                                    void *userdata);
113     static void          staticSetDeveloperModeCallback(void *userParam);
114     static void          staticSetComplianceModeCallback(void *userParam);
115     static void          staticSetComplianceImeiCallback(void *userParam);
116     static void          staticSetComplianceMeidCallback(void *userParam);
117     static void          staticSetAppServiceData(const char *key,
118                                                  const char *val,
119                                                  void *data);
120
121     // Private data
122     std::string m_bundleValue;
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     unsigned short m_debuggerPort;
131     bool m_developerMode;
132     bool m_complianceMode;
133     std::string m_complianceIMEI;
134     std::string m_complianceMEID;
135     size_t m_numPluginsToInstall;
136     ReturnStatus::Type m_returnStatus;
137     bool m_startupPluginInstallation;
138 };
139
140 struct WrtClientUserData
141 {
142     WrtClient *This;
143     unsigned long *pid;
144     int portnum;
145     bool debugMode;
146 };
147
148 #endif // WRT_CLIENT_H