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/animation/animation.h>
24 #include <dali/public-api/events/pan-gesture.h>
25 #include <dali/public-api/events/pan-gesture-detector.h>
26 #include <dali/devel-api/rendering/renderer.h>
29 #include <indicator-buffer.h>
30 #include <server-connection.h>
31 #include <shared-file.h>
48 typedef unsigned int PixmapId;
51 * The Indicator class connects to the indicator server, and gets and draws the indicator
52 * for the given orientation.
54 class Indicator : public ConnectionTracker, public ServerConnection::Observer
65 INDICATOR_TYPE_UNKNOWN,
75 * Notify the observer if the indicator type changes
76 * @param[in] type The new indicator type
78 virtual void IndicatorTypeChanged( Type type ) = 0;
81 * Notify the observer when the upload has completed.
82 * @param[in] indicator The indicator that has finished uploading.
84 virtual void IndicatorClosed(Indicator* indicator) = 0;
87 * Notify the observer when the indicator visible status is changed.
88 * @param[in] isShowing Whether the indicator is visible.
90 virtual void IndicatorVisibilityChanged( bool isVisible ) = 0;
95 * Class to encapsulate lock file
101 * Constructor. open lock file
103 LockFile(const std::string filename);
111 * Grab an exclusive lock on this file
112 * @return true if the lock succeeded, false if it failed
122 * Test if there is an error with the lock file, and clears
124 * @return true if an error was thrown
126 bool RetrieveAndClearErrorStatus();
129 std::string mFilename;
135 * Class to ensure lock/unlock through object destruction
141 * Constructor - creates a lock on the lockfile
142 * @param[in] lockFile The lockfile to use
144 ScopedLock( LockFile* lockFile );
147 * Destructor - removes the lock (if any) on the lockfile
152 * Method to test if the locking succeeded
153 * @return TRUE if locked
158 LockFile* mLockFile; ///< The lock file to use
159 bool mLocked; ///< Whether the lock succeeded
165 * Constructor. Creates a new indicator and opens a connection for
166 * the required orientation.
167 * @param[in] orientation The orientation in which to draw the indicator
168 * @param[in] observer The indicator closed
170 Indicator( Adaptor* adaptor,
171 Dali::Window::WindowOrientation orientation,
172 Observer* observer );
177 virtual ~Indicator();
179 void SetAdaptor(Adaptor* adaptor);
182 * Get the actor which contains the indicator image. Ensure that the handle is
183 * released when no longer needed.
184 * Changes from the indicator service will modify the image and resize the actor appropriately.
185 * @return The indicator actor.
187 Dali::Actor GetActor();
190 * Opens a new connection for the required orientation.
191 * @param[in] orientation The new orientation
193 void Open( Dali::Window::WindowOrientation orientation );
196 * Close the current connection. Will respond with Observer::IndicatorClosed()
198 * @note, IndicatorClosed() will be called synchronously if there's no update
199 * in progress, or asychronously if waiting for SignalUploaded )
204 * Set the opacity mode of the indicator background.
205 * @param[in] mode opacity mode
207 void SetOpacityMode( Dali::Window::IndicatorBgOpacity mode );
210 * Set whether the indicator is visible or not.
211 * @param[in] visibleMode visible mode for indicator bar.
212 * @param[in] forceUpdate true if want to change visible mode forcely
214 void SetVisible( Dali::Window::IndicatorVisibleMode visibleMode, bool forceUpdate = false );
217 * Check whether the indicator is connected to the indicator service.
218 * @return whether the indicator is connected or not.
223 * Send message to the indicator service.
224 * @param[in] messageDomain Message Reference number
225 * @param[in] messageId Reference number of the message this message refers to
226 * @param[in] data The data to send as part of the message
227 * @param[in] size Length of the data, in bytes, to send
228 * @return whether the message is sent successfully or not
230 bool SendMessage( int messageDomain, int messageId, const void *data, int size );
234 * Initialize the indicator actors
239 * Constructs the renderers used for the background
241 Dali::Geometry CreateBackgroundGeometry();
244 * Touch event callback.
245 * It should pass the valid touch event to indicator server
247 * @param[in] indicator The indicator actor that was touched
248 * @param[in] touchEvent The touch event
250 bool OnTouched(Dali::Actor indicator, const TouchEvent& touchEvent);
253 * Pan gesture callback.
254 * It finds flick down gesture to show hidden indicator image
256 * @param[in] actor The actor for gesture
257 * @param[in] gesture The gesture event
259 void OnPan( Dali::Actor actor, const Dali::PanGesture& gesture );
262 * Touch event callback on stage.
263 * If stage is touched, hide showing indicator image
265 * @param[in] touchEvent The touch event
267 void OnStageTouched(const Dali::TouchEvent& touchEvent);
270 * Connect to the indicator service
275 * Start the reconnection timer. This will run every second until we reconnect to
276 * the indicator service.
278 void StartReconnectionTimer();
281 * If connection failed, attempt to re-connect every second
283 bool OnReconnectTimer();
286 * Disconnect from the indicator service
291 * Handle Resize event
292 * @param[in] width The new width
293 * @param[in] height The new height
295 void Resize( int width, int height );
298 * Set the lock file info.
299 * @param[in] epcEvent Current ecore event.
301 void SetLockFileInfo( Ecore_Ipc_Event_Server_Data *epcEvent );
304 * Set the shared indicator image info
305 * @param[in] epcEvent The event containing the image data
307 void SetSharedImageInfo( Ecore_Ipc_Event_Server_Data *epcEvent );
310 * Load the shared indicator image
311 * @param[in] epcEvent The event containing the image data
313 void LoadSharedImage( Ecore_Ipc_Event_Server_Data *epcEvent );
316 * Load the pixmap indicator image
317 * @param[in] epcEvent The event containing the image data
319 void LoadPixmapImage( Ecore_Ipc_Event_Server_Data *epcEvent );
322 * Inform dali that the indicator data has been updated.
323 * @param[in] bufferNumber The shared file number
325 void UpdateImageData( int bufferNumber );
328 * Lock the temporary file, Copy the shared image into IndicatorBuffer
329 * and then unlock the temporary file.
330 * Caller should ensure we are not writing image to gl texture.
331 * @param[in] bufferNumber The shared file number
333 bool CopyToBuffer( int bufferNumber );
336 * Create a new image for the indicator, and set up signal handling for it.
337 * @param[in] bufferNumber The shared file number
339 void CreateNewImage( int bufferNumber );
342 * Create a new pixmap image for the indicator, and set up signal handling for it.
344 void CreateNewPixmapImage();
347 * Indicator type has changed.
349 * @param[in] type The new indicator type
351 void OnIndicatorTypeChanged( Type type );
354 * Check whether the indicator could be visible or invisible
355 * @return true if indicator should be shown
357 bool CheckVisibleState();
360 * Show/Hide indicator actor with effect
361 * @param[in] duration how long need to show the indicator,
362 * if it equal to 0, hide the indicator
363 * if it less than 0, show always
365 void ShowIndicator( float duration );
368 * Showing timer callback
373 * Showing animation finished callback
374 * @param[in] animation
376 void OnAnimationFinished( Dali::Animation& animation );
378 private: // Implementation of ServerConnection::Observer
380 * @copydoc Dali::Internal::Adaptor::ServerConnection::Observer::DataReceived()
382 virtual void DataReceived( void* event );
385 * @copydoc Dali::Internal::Adaptor::ServerConnection::Observer::DataReceived()
387 virtual void ConnectionClosed();
392 * Clear shared file info
394 void ClearSharedFileInfo();
398 struct SharedFileInfo
408 mSharedFileNumber( 0 )
412 LockFile* mLock; ///< File lock for the shared file
413 SharedFile* mSharedFile; ///< Shared file
415 int mImageWidth; ///< Shared image width
416 int mImageHeight; ///< Shared image height
418 std::string mLockFileName; ///< Lock file name
419 std::string mSharedFileName; ///< Shared file name
420 int mSharedFileID; ///< Shared file ID
421 int mSharedFileNumber; ///< Shared file number
424 static const int SHARED_FILE_NUMBER = 2; ///< Shared file number
426 Dali::Geometry mTranslucentGeometry; ///< Geometry used for rendering the translucent background
427 Dali::Geometry mSolidGeometry; ///< Geometry used for rendering the opaque background
428 Dali::Material mBackgroundMaterial; ///< Material used for rendering the background
430 IndicatorBufferPtr mIndicatorBuffer; ///< class which handles indicator rendering
431 PixmapId mPixmap; ///< Pixmap including indicator content
432 Dali::Image mImage; ///< Image created from mIndicatorBuffer
433 Dali::ImageActor mIndicatorImageActor; ///< Actor created from mImage
435 Dali::Actor mIndicatorImageContainerActor; ///< Actor container for image and background
436 Dali::Actor mBackgroundActor; ///< Actor for background
437 Dali::Actor mIndicatorActor; ///< Handle to topmost indicator actor
438 Dali::Actor mEventActor; ///< Handle to event
439 Dali::PanGestureDetector mPanDetector; ///< Pan detector to find flick gesture for hidden indicator
440 float mGestureDeltaY; ///< Checking how much panning moved
441 bool mGestureDetected; ///< Whether find the flick gesture
443 Dali::Timer mReconnectTimer; ///< Reconnection timer
444 SlotDelegate< Indicator > mConnection;
446 Dali::Window::IndicatorBgOpacity mOpacityMode; ///< Opacity enum for background
447 Indicator::State mState; ///< The connection state
450 ServerConnection* mServerConnection;
451 Indicator::Observer* mObserver; ///< Upload observer
453 Dali::Window::WindowOrientation mOrientation;
456 Dali::Window::IndicatorVisibleMode mVisible; ///< Whether the indicator is visible
458 Dali::Timer mShowTimer; ///< Timer to show indicator
459 bool mIsShowing; ///< Whether the indicator is showing on the screen
460 Dali::Animation mIndicatorAnimation; ///< Animation to show/hide indicator image
462 bool mIsAnimationPlaying; ///< Whether the animation is playing
464 int mCurrentSharedFile; ///< Current shared file number
465 SharedFileInfo mSharedFileInfo[SHARED_FILE_NUMBER]; ///< Table to store shared file info