1 #ifndef __DALI_INTERNAL_INDICATOR_H__
2 #define __DALI_INTERNAL_INDICATOR_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/actors/image-actor.h>
23 #include <dali/public-api/actors/mesh-actor.h>
24 #include <dali/public-api/geometry/animatable-mesh.h>
25 #include <dali/public-api/animation/animation.h>
26 #include <dali/public-api/events/pan-gesture.h>
27 #include <dali/public-api/events/pan-gesture-detector.h>
30 #include <indicator-buffer.h>
31 #include <server-connection.h>
32 #include <shared-file.h>
49 typedef unsigned int PixmapId;
52 * The Indicator class connects to the indicator server, and gets and draws the indicator
53 * for the given orientation.
55 class Indicator : public ConnectionTracker, public ServerConnection::Observer
66 INDICATOR_TYPE_UNKNOWN,
76 * Notify the observer if the indicator type changes
77 * @param[in] type The new indicator type
79 virtual void IndicatorTypeChanged( Type type ) = 0;
82 * Notify the observer when the upload has completed.
83 * @param[in] indicator The indicator that has finished uploading.
85 virtual void IndicatorClosed(Indicator* indicator) = 0;
88 * Notify the observer when the indicator visible status is changed.
89 * @param[in] isShowing Whether the indicator is visible.
91 virtual void IndicatorVisibilityChanged( bool isVisible ) = 0;
96 * Class to encapsulate lock file
102 * Constructor. open lock file
104 LockFile(const std::string filename);
112 * Grab an exclusive lock on this file
113 * @return true if the lock succeeded, false if it failed
123 * Test if there is an error with the lock file, and clears
125 * @return true if an error was thrown
127 bool RetrieveAndClearErrorStatus();
130 std::string mFilename;
136 * Class to ensure lock/unlock through object destruction
142 * Constructor - creates a lock on the lockfile
143 * @param[in] lockFile The lockfile to use
145 ScopedLock( LockFile* lockFile );
148 * Destructor - removes the lock (if any) on the lockfile
153 * Method to test if the locking succeeded
154 * @return TRUE if locked
159 LockFile* mLockFile; ///< The lock file to use
160 bool mLocked; ///< Whether the lock succeeded
166 * Constructor. Creates a new indicator and opens a connection for
167 * the required orientation.
168 * @param[in] orientation The orientation in which to draw the indicator
169 * @param[in] observer The indicator closed
171 Indicator( Adaptor* adaptor,
172 Dali::Window::WindowOrientation orientation,
173 Observer* observer );
178 virtual ~Indicator();
180 void SetAdaptor(Adaptor* adaptor);
183 * Get the actor which contains the indicator image. Ensure that the handle is
184 * released when no longer needed.
185 * Changes from the indicator service will modify the image and resize the actor appropriately.
186 * @return The indicator actor.
188 Dali::Actor GetActor();
191 * Opens a new connection for the required orientation.
192 * @param[in] orientation The new orientation
194 void Open( Dali::Window::WindowOrientation orientation );
197 * Close the current connection. Will respond with Observer::IndicatorClosed()
199 * @note, IndicatorClosed() will be called synchronously if there's no update
200 * in progress, or asychronously if waiting for SignalUploaded )
205 * Set the opacity mode of the indicator background.
206 * @param[in] mode opacity mode
208 void SetOpacityMode( Dali::Window::IndicatorBgOpacity mode );
211 * Set whether the indicator is visible or not.
212 * @param[in] visibleMode visible mode for indicator bar.
213 * @param[in] forceUpdate true if want to change visible mode forcely
215 void SetVisible( Dali::Window::IndicatorVisibleMode visibleMode, bool forceUpdate = false );
218 * Check whether the indicator is connected to the indicator service.
219 * @return whether the indicator is connected or not.
224 * Send message to the indicator service.
225 * @param[in] messageDomain Message Reference number
226 * @param[in] messageId Reference number of the message this message refers to
227 * @param[in] data The data to send as part of the message
228 * @param[in] size Length of the data, in bytes, to send
229 * @return whether the message is sent successfully or not
231 bool SendMessage( int messageDomain, int messageId, const void *data, int size );
235 * Initialize the indicator actors
240 * Set the opacity of the background image
242 void SetBackgroundOpacity( Dali::Window::IndicatorBgOpacity opacity );
245 * Touch event callback.
246 * It should pass the valid touch event to indicator server
248 * @param[in] indicator The indicator actor that was touched
249 * @param[in] touchEvent The touch event
251 bool OnTouched(Dali::Actor indicator, const TouchEvent& touchEvent);
254 * Pan gesture callback.
255 * It finds flick down gesture to show hidden indicator image
257 * @param[in] actor The actor for gesture
258 * @param[in] gesture The gesture event
260 void OnPan( Dali::Actor actor, const Dali::PanGesture& gesture );
263 * Touch event callback on stage.
264 * If stage is touched, hide showing indicator image
266 * @param[in] touchEvent The touch event
268 void OnStageTouched(const Dali::TouchEvent& touchEvent);
271 * Connect to the indicator service
276 * Start the reconnection timer. This will run every second until we reconnect to
277 * the indicator service.
279 void StartReconnectionTimer();
282 * If connection failed, attempt to re-connect every second
284 bool OnReconnectTimer();
287 * Disconnect from the indicator service
292 * Handle Resize event
293 * @param[in] width The new width
294 * @param[in] height The new height
296 void Resize( int width, int height );
299 * Set the lock file info.
300 * @param[in] epcEvent Current ecore event.
302 void SetLockFileInfo( Ecore_Ipc_Event_Server_Data *epcEvent );
305 * Set the shared indicator image info
306 * @param[in] epcEvent The event containing the image data
308 void SetSharedImageInfo( Ecore_Ipc_Event_Server_Data *epcEvent );
311 * Load the shared indicator image
312 * @param[in] epcEvent The event containing the image data
314 void LoadSharedImage( Ecore_Ipc_Event_Server_Data *epcEvent );
317 * Load the pixmap indicator image
318 * @param[in] epcEvent The event containing the image data
320 void LoadPixmapImage( Ecore_Ipc_Event_Server_Data *epcEvent );
323 * Inform dali that the indicator data has been updated.
324 * @param[in] bufferNumber The shared file number
326 void UpdateImageData( int bufferNumber );
329 * Lock the temporary file, Copy the shared image into IndicatorBuffer
330 * and then unlock the temporary file.
331 * Caller should ensure we are not writing image to gl texture.
332 * @param[in] bufferNumber The shared file number
334 bool CopyToBuffer( int bufferNumber );
337 * Update the background with the correct colors
339 void SetBackground();
342 * Create a new image for the indicator, and set up signal handling for it.
343 * @param[in] bufferNumber The shared file number
345 void CreateNewImage( int bufferNumber );
348 * Create a new pixmap image for the indicator, and set up signal handling for it.
350 void CreateNewPixmapImage();
353 * Indicator type has changed.
355 * @param[in] type The new indicator type
357 void OnIndicatorTypeChanged( Type type );
360 * Check whether the indicator could be visible or invisible
361 * @return true if indicator should be shown
363 bool CheckVisibleState();
366 * Show/Hide indicator actor with effect
367 * @param[in] duration how long need to show the indicator,
368 * if it equal to 0, hide the indicator
369 * if it less than 0, show always
371 void ShowIndicator( float duration );
374 * Showing timer callback
379 * Showing animation finished callback
380 * @param[in] animation
382 void OnAnimationFinished( Dali::Animation& animation );
384 private: // Implementation of ServerConnection::Observer
386 * @copydoc Dali::Internal::Adaptor::ServerConnection::Observer::DataReceived()
388 virtual void DataReceived( void* event );
391 * @copydoc Dali::Internal::Adaptor::ServerConnection::Observer::DataReceived()
393 virtual void ConnectionClosed();
398 * Construct the gradient mesh
400 void ConstructBackgroundMesh();
403 * Clear shared file info
405 void ClearSharedFileInfo();
409 struct SharedFileInfo
419 mSharedFileNumber( 0 )
423 LockFile* mLock; ///< File lock for the shared file
424 SharedFile* mSharedFile; ///< Shared file
426 int mImageWidth; ///< Shared image width
427 int mImageHeight; ///< Shared image height
429 std::string mLockFileName; ///< Lock file name
430 std::string mSharedFileName; ///< Shared file name
431 int mSharedFileID; ///< Shared file ID
432 int mSharedFileNumber; ///< Shared file number
435 static const int SHARED_FILE_NUMBER = 2; ///< Shared file number
437 IndicatorBufferPtr mIndicatorBuffer; ///< class which handles indicator rendering
438 PixmapId mPixmap; ///< Pixmap including indicator content
439 Dali::Image mImage; ///< Image created from mIndicatorBuffer
440 Dali::ImageActor mIndicatorImageActor; ///< Actor created from mImage
442 Dali::AnimatableMesh mBackgroundMesh;
443 Dali::MeshActor mBackgroundActor; ///< Actor for background
444 Dali::Actor mIndicatorActor; ///< Handle to topmost indicator actor
445 Dali::Actor mEventActor; ///< Handle to event
446 Dali::PanGestureDetector mPanDetector; ///< Pan detector to find flick gesture for hidden indicator
447 float mGestureDeltaY; ///< Checking how much panning moved
448 bool mGestureDetected; ///< Whether find the flick gesture
450 Dali::Timer mReconnectTimer; ///< Reconnection timer
451 SlotDelegate< Indicator > mConnection;
453 Dali::Window::IndicatorBgOpacity mOpacityMode; ///< Opacity enum for background
454 Indicator::State mState; ///< The connection state
457 ServerConnection* mServerConnection;
458 Indicator::Observer* mObserver; ///< Upload observer
460 Dali::Window::WindowOrientation mOrientation;
463 Dali::Window::IndicatorVisibleMode mVisible; ///< Whether the indicator is visible
465 Dali::Timer mShowTimer; ///< Timer to show indicator
466 bool mIsShowing; ///< Whether the indicator is showing on the screen
467 Dali::Animation mIndicatorAnimation; ///< Animation to show/hide indicator image
469 bool mIsAnimationPlaying; ///< Whether the animation is playing
471 int mCurrentSharedFile; ///< Current shared file number
472 SharedFileInfo mSharedFileInfo[SHARED_FILE_NUMBER]; ///< Table to store shared file info