License conversion from Flora to Apache 2.0
[platform/core/uifw/dali-adaptor.git] / adaptors / tizen / internal / livebox-plugin-impl.h
1 #ifndef __DALI_INTERNAL_LIVEBOX_H__
2 #define __DALI_INTERNAL_LIVEBOX_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <boost/bind.hpp>
23 #include <boost/function.hpp>
24 #include <boost/thread.hpp>
25
26 #include <dali/public-api/math/rect.h>
27 #include <dali/integration-api/events/touch-event-integ.h>
28
29 #include <Ecore_X.h>
30 #include <Ecore.h>
31
32 #include <livebox-client.h>
33
34 // INTERNAL INCLUDES
35 #include <public-api/adaptor-framework/livebox-plugin.h>
36 #include <internal/framework.h>
37
38 namespace Dali
39 {
40
41 class Adaptor;
42
43 namespace Internal
44 {
45
46 namespace Adaptor
47 {
48
49 class CommandLineOptions;
50 class EventLoop;
51
52 typedef Dali::Rect<int> PositionSize;
53
54 namespace ECoreX
55 {
56 class RenderSurface;
57 }
58
59 /**
60  * Implementation of the LiveboxPlugin class.
61  */
62 class LiveboxPlugin : public Framework::Observer
63 {
64 public:
65
66   typedef Dali::LiveboxPlugin::LiveboxPluginSignalV2 LiveboxPluginSignalV2;
67
68   /**
69    * Constructor
70    * @param[in]  livebox         The public instance of the LiveboxPlugin
71    * @param[in]  argc        A pointer to the number of arguments
72    * @param[in]  argv        A pointer to the argument list
73    * @param[in]  name        A name of livebox
74    * @param[in]  baseLayout  The base layout that the livebox has been written for
75    */
76   LiveboxPlugin(Dali::LiveboxPlugin& livebox, int* argc, char **argv[], const std::string& name, const DeviceLayout& baseLayout);
77
78   /**
79    * Destructor
80    */
81   virtual ~LiveboxPlugin();
82
83 public:
84
85   /**
86    * @copydoc Dali::LiveboxPlugin::SetTitle()
87    */
88   void SetTitle(const std::string& title) {mTitle = title; };
89
90   /**
91    * @copydoc Dali::LiveboxPlugin::SetContent()
92    */
93   void SetContent(const std::string& content) {mContent = content; };
94
95   /**
96    * @copydoc Dali::LiveboxPlugin::GetGlanceBarGeometry()
97    */
98   const PositionSize& GetGlanceBarGeometry() const { return mGlanceGeometry; };
99
100   /**
101    * @copydoc Dali::LiveboxPlugin::GetGlanceBarEventInfo()
102    */
103   const GlanceBarEventInfo& GetGlanceBarEventInfo() const { return mGlanceBarEventInfo; };
104
105   /**
106    * @copydoc Dali::LiveboxPlugin::GetLiveboxSizeType()
107    */
108   LiveboxSizeType GetLiveboxSizeType() const { return mBoxSizeType; };
109
110   /**
111    * @copydoc Dali::LiveboxPlugin::Run()
112    */
113   void Run();
114
115   /**
116    * @copydoc Dali::LiveboxPlugin::Quit()
117    */
118   void Quit();
119
120   /**
121    * @copydoc Dali::LiveboxPlugin::AddIdle()
122    */
123   bool AddIdle(boost::function<void(void)> callBack);
124
125   /**
126    * @copydoc Dali::LiveboxPlugin::Get();
127    */
128   static Dali::LiveboxPlugin& Get();
129
130
131 public: // From Framework::Observer
132
133   /**
134    * Called when the framework is initialised.
135    */
136   virtual void OnInit();
137
138   /**
139    * Called when the framework is terminated.
140    */
141   virtual void OnTerminate();
142
143   /**
144    * Called when the framework is paused.
145    */
146   virtual void OnPause();
147
148   /**
149    * Called when the framework resumes from a paused state.
150    */
151   virtual void OnResume();
152
153   /**
154    * Called when the framework informs the livebox that it should reset itself.
155    */
156   virtual void OnReset();
157
158   /**
159    * Called when the framework informs the livebox that the language of the device has changed.
160    */
161   virtual void OnLanguageChanged();
162
163 public:
164   /**
165    * Client handlers
166    */
167
168   /**
169    * Notify the livebox was created.
170    *
171    * @param[in] pkgname package name
172    * @param[in] id livebox id string
173    * @param[in] content content string of livebox
174    * @param[in] width width of livebox
175    * @param[in] height height of livebox
176    */
177   void OnLiveboxCreated(const std::string& content, int width, int height, double period);
178
179   /**
180    * Notify the livebox should be destroyed.
181    */
182   void OnLiveboxDestroyed();
183
184   /**
185    * Notify the client should be resized.
186    *
187    * @param[in] resizedWidth new width of livebox
188    * @param[in] resizedHeight new height of livebox
189    */
190   void OnLiveboxResized(int resizedWidth, int resizedHeight);
191
192   /**
193    * Send event to livebox.
194    *
195    * @param[in] point touch point
196    * @param[in] timeStamp time value of event
197    */
198   void OnLiveboxTouchEvent(TouchPoint& point, unsigned int timeStamp);
199
200   void OnPeriodUpdated(double period);
201   void OnUpdateRequested();
202
203   /**
204    * Notify the glance was created.
205    *
206    * @param[in] pdWidth width of pd
207    * @param[in] pdHeight height of pd
208    * @param[in] arrowX x position of pd's arrow
209    * @param[in] arrowY y position of pd's arrow
210    */
211   void OnGlanceCreated(int width, int height, int arrowX, int arrowY);
212
213   /**
214    * Notify the glance should be destroyed.
215    */
216   void OnGlanceDestroyed();
217
218   void OnGlanceTouchEvent();
219   void OnGlanceMoved(int arrowX, int arrowY, int width, int height);
220   void OnGlanceScriptEventCallback(std::string emission, std::string source, struct livebox_event_info *info);
221
222   /**
223    * Notify the surface was damaged.
224    * When it was damager, this client should send update to master
225    */
226   void OnDamaged();
227
228 public:  // Signals
229
230   /**
231    * @copydoc Dali::LiveboxPlugin::InitializedSignal()
232    */
233   LiveboxPluginSignalV2& InitializedSignal() { return mInitializedSignalV2; }
234
235   /**
236    * @copydoc Dali::LiveboxPlugin::TerminatedSignal()
237    */
238   LiveboxPluginSignalV2& TerminatedSignal() { return mTerminatedSignalV2; }
239
240   /**
241    * @copydoc Dali::LiveboxPlugin::PausedSignal()
242    */
243   LiveboxPluginSignalV2& PausedSignal() { return mPausedSignalV2; }
244
245   /**
246    * @copydoc Dali::LiveboxPlugin::ResumedSignal()
247    */
248   LiveboxPluginSignalV2& ResumedSignal() { return mResumedSignalV2; }
249
250   /**
251    * @copydoc Dali::LiveboxPlugin::ResizedSignal()
252    */
253   LiveboxPluginSignalV2& ResizedSignal() { return mResizedSignalV2; }
254
255   /**
256    * @copydoc Dali::LiveboxPlugin::GlanceCreatedSignal()
257    */
258   LiveboxPluginSignalV2& GlanceCreatedSignal() { return mGlanceCreatedSignalV2; }
259
260   /**
261    * @copydoc Dali::LiveboxPlugin::GlanceDestroyedSignal()
262    */
263   LiveboxPluginSignalV2& GlanceDestroyedSignal() { return mGlanceDestroyedSignalV2; }
264
265   /**
266    * @copydoc Dali::LiveboxPlugin::GlanceTouchedSignal()
267    */
268   LiveboxPluginSignalV2& GlanceTouchedSignal() { return mGlanceTouchedSignalV2; }
269
270   /**
271    * @copydoc Dali::LiveboxPlugin::GlanceMovedSignal()
272    */
273   LiveboxPluginSignalV2& GlanceMovedSignal() { return mGlanceMovedSignalV2; }
274
275   /**
276    * @copydoc Dali::LiveboxPlugin::GlanceScriptEventSignal()
277    */
278   LiveboxPluginSignalV2& GlanceScriptEventSignal() { return mGlanceScriptEventSignalV2; }
279
280   /**
281    * @copydoc Dali::LiveboxPlugin::LanguageChangedSignal()
282    */
283   LiveboxPluginSignalV2& LanguageChangedSignal() { return mLanguageChangedSignalV2; }
284
285 private:
286
287   // Undefined
288   LiveboxPlugin(const LiveboxPlugin&);
289   LiveboxPlugin& operator=(LiveboxPlugin&);
290
291 private:
292
293   /**
294    * Create pixmap surface for mSurface.
295    * If there is no mSurface, it will create mSurface with new display.
296    * If mSurface is existed already, then it uses existed display but overwrite mSurface by new one
297    * It make a callback for damage notify automatically
298    */
299   void CreateSurface(Ecore_X_Pixmap pixmap);
300
301   /**
302    * Quits from the main loop
303    */
304   void QuitFromMainLoop();
305
306 private:
307
308   LiveboxPluginSignalV2      mInitializedSignalV2;
309   LiveboxPluginSignalV2      mTerminatedSignalV2;
310   LiveboxPluginSignalV2      mPausedSignalV2;
311   LiveboxPluginSignalV2      mResumedSignalV2;
312   LiveboxPluginSignalV2      mResizedSignalV2;
313   LiveboxPluginSignalV2      mGlanceCreatedSignalV2;
314   LiveboxPluginSignalV2      mGlanceDestroyedSignalV2;
315   LiveboxPluginSignalV2      mGlanceTouchedSignalV2;
316   LiveboxPluginSignalV2      mGlanceMovedSignalV2;
317   LiveboxPluginSignalV2      mGlanceScriptEventSignalV2;
318   LiveboxPluginSignalV2      mLanguageChangedSignalV2;
319
320   Dali::LiveboxPlugin&                    mLiveboxPlugin;
321
322   Framework*                            mFramework;
323
324   CommandLineOptions*                   mCommandLineOptions;
325
326   Dali::Adaptor*                        mAdaptor;
327   std::string                           mName;
328
329   bool                                  mInitialized;
330   DeviceLayout                          mBaseLayout;
331
332   // client properties
333   livebox_h mLiveboxHandle;
334   std::string mTitle;
335   std::string mContent;
336   double mPeriod;
337
338   PositionSize mGlanceGeometry;
339   GlanceBarEventInfo mGlanceBarEventInfo;
340
341   LiveboxSizeType mBoxSizeType;
342
343 public:
344   /* for rendering control : these public members will be used in static function */
345   Ecore_Event_Handler*                        mDamageEventHandler;
346   Ecore_X_Damage                              mDamage;
347   ECoreX::RenderSurface*                      mSurface;
348
349 public:
350   inline static LiveboxPlugin& GetImplementation(Dali::LiveboxPlugin& livebox) { return *livebox.mImpl; }
351 };
352
353 } // namespace Adaptor
354
355 } // namespace Internal
356
357 } // namespace Dali
358
359 #endif // __DALI_INTERNAL_LIVEBOX_H__
360