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>
28 #include <indicator-buffer.h>
29 #include <server-connection.h>
30 #include <shared-file.h>
47 typedef unsigned int PixmapId;
50 * The Indicator class connects to the indicator server, and gets and draws the indicator
51 * for the given orientation.
53 class Indicator : public ConnectionTracker, public ServerConnection::Observer
64 INDICATOR_TYPE_UNKNOWN,
74 * Notify the observer if the indicator type changes
75 * @param[in] type The new indicator type
77 virtual void IndicatorTypeChanged( Type type ) = 0;
80 * Notify the observer when the upload has completed.
81 * @param[in] indicator The indicator that has finished uploading.
83 virtual void IndicatorClosed(Indicator* indicator) = 0;
86 * Notify the observer when the indicator visible status is changed.
87 * @param[in] isShowing Whether the indicator is visible.
89 virtual void IndicatorVisibilityChanged( bool isVisible ) = 0;
94 * Class to encapsulate lock file
100 * Constructor. open lock file
102 LockFile(const std::string filename);
110 * Grab an exclusive lock on this file
111 * @return true if the lock succeeded, false if it failed
121 * Test if there is an error with the lock file, and clears
123 * @return true if an error was thrown
125 bool RetrieveAndClearErrorStatus();
128 std::string mFilename;
134 * Class to ensure lock/unlock through object destruction
140 * Constructor - creates a lock on the lockfile
141 * @param[in] lockFile The lockfile to use
143 ScopedLock( LockFile* lockFile );
146 * Destructor - removes the lock (if any) on the lockfile
151 * Method to test if the locking succeeded
152 * @return TRUE if locked
157 LockFile* mLockFile; ///< The lock file to use
158 bool mLocked; ///< Whether the lock succeeded
164 * Constructor. Creates a new indicator and opens a connection for
165 * the required orientation.
166 * @param[in] orientation The orientation in which to draw the indicator
167 * @param[in] observer The indicator closed
169 Indicator( Adaptor* adaptor,
170 Dali::Window::WindowOrientation orientation,
171 Observer* observer );
176 virtual ~Indicator();
178 void SetAdaptor(Adaptor* adaptor);
181 * Get the actor which contains the indicator image. Ensure that the handle is
182 * released when no longer needed.
183 * Changes from the indicator service will modify the image and resize the actor appropriately.
184 * @return The indicator actor.
186 Dali::Actor GetActor();
189 * Opens a new connection for the required orientation.
190 * @param[in] orientation The new orientation
192 void Open( Dali::Window::WindowOrientation orientation );
195 * Close the current connection. Will respond with Observer::IndicatorClosed()
197 * @note, IndicatorClosed() will be called synchronously if there's no update
198 * in progress, or asychronously if waiting for SignalUploaded )
203 * Set the opacity mode of the indicator background.
204 * @param[in] mode opacity mode
206 void SetOpacityMode( Dali::Window::IndicatorBgOpacity mode );
209 * Set whether the indicator is visible or not.
210 * @param[in] visibleMode visible mode for indicator bar.
211 * @param[in] forceUpdate true if want to change visible mode forcely
213 void SetVisible( Dali::Window::IndicatorVisibleMode visibleMode, bool forceUpdate = false );
216 * Check whether the indicator is connected to the indicator service.
217 * @return whether the indicator is connected or not.
222 * Send message to the indicator service.
223 * @param[in] messageDomain Message Reference number
224 * @param[in] messageId Reference number of the message this message refers to
225 * @param[in] data The data to send as part of the message
226 * @param[in] size Length of the data, in bytes, to send
227 * @return whether the message is sent successfully or not
229 bool SendMessage( int messageDomain, int messageId, const void *data, int size );
233 * Initialize the indicator actors
238 * Set the opacity of the background image
240 void SetBackgroundOpacity( Dali::Window::IndicatorBgOpacity opacity );
243 * Touch event callback.
244 * It should pass the valid touch event to indicator server
246 * @param[in] indicator The indicator actor that was touched
247 * @param[in] touchEvent The touch event
249 bool OnTouched(Dali::Actor indicator, const TouchEvent& touchEvent);
252 * Pan gesture callback.
253 * It finds flick down gesture to show hidden indicator image
255 * @param[in] actor The actor for gesture
256 * @param[in] gesture The gesture event
258 void OnPan( Dali::Actor actor, const Dali::PanGesture& gesture );
261 * Touch event callback on stage.
262 * If stage is touched, hide showing indicator image
264 * @param[in] touchEvent The touch event
266 void OnStageTouched(const Dali::TouchEvent& touchEvent);
269 * Connect to the indicator service
274 * Start the reconnection timer. This will run every second until we reconnect to
275 * the indicator service.
277 void StartReconnectionTimer();
280 * If connection failed, attempt to re-connect every second
282 bool OnReconnectTimer();
285 * Disconnect from the indicator service
290 * Handle Resize event
291 * @param[in] width The new width
292 * @param[in] height The new height
294 void Resize( int width, int height );
297 * Set the lock file info.
298 * @param[in] epcEvent Current ecore event.
300 void SetLockFileInfo( Ecore_Ipc_Event_Server_Data *epcEvent );
303 * Set the shared indicator image info
304 * @param[in] epcEvent The event containing the image data
306 void SetSharedImageInfo( Ecore_Ipc_Event_Server_Data *epcEvent );
309 * Load the shared indicator image
310 * @param[in] epcEvent The event containing the image data
312 void LoadSharedImage( Ecore_Ipc_Event_Server_Data *epcEvent );
315 * Load the pixmap indicator image
316 * @param[in] epcEvent The event containing the image data
318 void LoadPixmapImage( Ecore_Ipc_Event_Server_Data *epcEvent );
321 * Inform dali that the indicator data has been updated.
322 * @param[in] bufferNumber The shared file number
324 void UpdateImageData( int bufferNumber );
327 * Lock the temporary file, Copy the shared image into IndicatorBuffer
328 * and then unlock the temporary file.
329 * Caller should ensure we are not writing image to gl texture.
330 * @param[in] bufferNumber The shared file number
332 bool CopyToBuffer( int bufferNumber );
335 * Update the background with the correct colors
337 void SetBackground();
340 * Create a new image for the indicator, and set up signal handling for it.
341 * @param[in] bufferNumber The shared file number
343 void CreateNewImage( int bufferNumber );
346 * Create a new pixmap image for the indicator, and set up signal handling for it.
348 void CreateNewPixmapImage();
351 * Indicator type has changed.
353 * @param[in] type The new indicator type
355 void OnIndicatorTypeChanged( Type type );
358 * Check whether the indicator could be visible or invisible
359 * @return true if indicator should be shown
361 bool CheckVisibleState();
364 * Show/Hide indicator actor with effect
365 * @param[in] duration how long need to show the indicator,
366 * if it equal to 0, hide the indicator
367 * if it less than 0, show always
369 void ShowIndicator( float duration );
372 * Showing timer callback
377 * Showing animation finished callback
378 * @param[in] animation
380 void OnAnimationFinished( Dali::Animation& animation );
382 private: // Implementation of ServerConnection::Observer
384 * @copydoc Dali::Internal::Adaptor::ServerConnection::Observer::DataReceived()
386 virtual void DataReceived( void* event );
389 * @copydoc Dali::Internal::Adaptor::ServerConnection::Observer::DataReceived()
391 virtual void ConnectionClosed();
396 * Clear shared file info
398 void ClearSharedFileInfo();
402 struct SharedFileInfo
412 mSharedFileNumber( 0 )
416 LockFile* mLock; ///< File lock for the shared file
417 SharedFile* mSharedFile; ///< Shared file
419 int mImageWidth; ///< Shared image width
420 int mImageHeight; ///< Shared image height
422 std::string mLockFileName; ///< Lock file name
423 std::string mSharedFileName; ///< Shared file name
424 int mSharedFileID; ///< Shared file ID
425 int mSharedFileNumber; ///< Shared file number
428 static const int SHARED_FILE_NUMBER = 2; ///< Shared file number
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 mIndicatorActor; ///< Handle to topmost indicator actor
436 Dali::Actor mEventActor; ///< Handle to event
437 Dali::PanGestureDetector mPanDetector; ///< Pan detector to find flick gesture for hidden indicator
438 float mGestureDeltaY; ///< Checking how much panning moved
439 bool mGestureDetected; ///< Whether find the flick gesture
441 Dali::Timer mReconnectTimer; ///< Reconnection timer
442 SlotDelegate< Indicator > mConnection;
444 Dali::Window::IndicatorBgOpacity mOpacityMode; ///< Opacity enum for background
445 Indicator::State mState; ///< The connection state
448 ServerConnection* mServerConnection;
449 Indicator::Observer* mObserver; ///< Upload observer
451 Dali::Window::WindowOrientation mOrientation;
454 Dali::Window::IndicatorVisibleMode mVisible; ///< Whether the indicator is visible
456 Dali::Timer mShowTimer; ///< Timer to show indicator
457 bool mIsShowing; ///< Whether the indicator is showing on the screen
458 Dali::Animation mIndicatorAnimation; ///< Animation to show/hide indicator image
460 bool mIsAnimationPlaying; ///< Whether the animation is playing
462 int mCurrentSharedFile; ///< Current shared file number
463 SharedFileInfo mSharedFileInfo[SHARED_FILE_NUMBER]; ///< Table to store shared file info