1 #ifndef __DALI_INTERNAL_INDICATOR_H__
2 #define __DALI_INTERNAL_INDICATOR_H__
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
21 #include <dali/public-api/images/bitmap-image.h>
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/adaptor-framework/common/window.h>
26 #include <dali/public-api/adaptor-framework/common/timer.h>
27 #include <dali/public-api/animation/animation.h>
30 #include <internal/common/indicator-buffer.h>
31 #include <internal/common/server-connection.h>
32 #include <internal/common/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;
88 * Class to encapsulate lock file
94 * Constructor. open lock file
96 LockFile(const char* filename);
104 * Grab an exclusive lock on this file
105 * @return true if the lock succeeded, false if it failed
115 * Test if there is an error with the lock file, and clears
117 * @return true if an error was thrown
119 bool RetrieveAndClearErrorStatus();
122 std::string mFilename;
128 * Class to ensure lock/unlock through object destruction
134 * Constructor - creates a lock on the lockfile
135 * @param[in] lockFile The lockfile to use
137 ScopedLock( LockFile* lockFile );
140 * Destructor - removes the lock (if any) on the lockfile
145 * Method to test if the locking succeeded
146 * @return TRUE if locked
151 LockFile* mLockFile; ///< The lock file to use
152 bool mLocked; ///< Whether the lock succeeded
158 * Constructor. Creates a new indicator and opens a connection for
159 * the required orientation.
160 * @param[in] orientation The orientation in which to draw the indicator
161 * @param[in] observer The indicator closed
163 Indicator( Adaptor* adaptor,
164 Dali::Window::WindowOrientation orientation,
165 Observer* observer );
170 virtual ~Indicator();
172 void SetAdaptor(Adaptor* adaptor);
175 * Get the actor which contains the indicator image. Ensure that the handle is
176 * released when no longer needed.
177 * Changes from the indicator service will modify the image and resize the actor appropriately.
178 * @return The indicator actor.
180 Dali::Actor GetActor();
183 * Opens a new connection for the required orientation.
184 * @param[in] orientation The new orientation
186 void Open( Dali::Window::WindowOrientation orientation );
189 * Close the current connection. Will respond with Observer::IndicatorClosed()
191 * @note, IndicatorClosed() will be called synchronously if there's no update
192 * in progress, or asychronously if waiting for SignalUploaded )
197 * Set the opacity mode of the indicator background.
198 * @param[in] mode opacity mode
200 void SetOpacityMode( Dali::Window::IndicatorBgOpacity mode );
203 * Set whether the indicator is visible or not.
204 * @param[in] visibleMode visible mode for indicator bar.
206 void SetVisible( Dali::Window::IndicatorVisibleMode visibleMode );
209 * Check whether the indicator is connected to the indicator service.
210 * @return whether the indicator is connected or not.
215 * Send message to the indicator service.
216 * @param[in] messageDomain Message Reference number
217 * @param[in] messageId Reference number of the message this message refers to
218 * @param[in] data The data to send as part of the message
219 * @param[in] size Length of the data, in bytes, to send
220 * @return whether the message is sent successfully or not
222 bool SendMessage( int messageDomain, int messageId, const void *data, int size );
226 * Initialize the indicator actors
231 * Set the opacity of the background image
233 void SetBackgroundOpacity( Dali::Window::IndicatorBgOpacity opacity );
236 * Touch event callback.
237 * @param[in] indicator The indicator actor that was touched
238 * @param[in] touchEvent The touch event
240 bool OnTouched(Dali::Actor indicator, const TouchEvent& touchEvent);
243 * Touch event callback on stage.
244 * @param[in] touchEvent The touch event
246 void OnStageTouched(const Dali::TouchEvent& touchEvent);
249 * Return the given orientation in degrees
250 * @param[in] orientation The given indicator orientation
251 * @return value of 0, 90, 180 or 270
253 int OrientationToDegrees( Dali::Window::WindowOrientation orientation );
256 * Connect to the indicator service matching the orientation
257 * @param[in] orientation The current indicator orientation
259 bool Connect( Dali::Window::WindowOrientation orientation );
262 * Connect to the indicator service
263 * @param[in] serviceName The indicator service name
265 bool Connect( const char *serviceName );
268 * Start the reconnection timer. This will run every second until we reconnect to
269 * the indicator service.
271 void StartReconnectionTimer();
274 * If connection failed, attempt to re-connect every second
276 bool OnReconnectTimer();
279 * Disconnect from the indicator service
284 * Close existing lock file and open the new lock file.
285 * @param[in] epcEvent Current ecore event.
287 void NewLockFile(Ecore_Ipc_Event_Server_Data *epcEvent);
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 * Load the shared indicator image
298 * @param[in] epcEvent The event containing the image data
300 void LoadSharedImage(Ecore_Ipc_Event_Server_Data *epcEvent);
303 * Load the pixmap indicator image
304 * @param[in] epcEvent The event containing the image data
306 void LoadPixmapImage( Ecore_Ipc_Event_Server_Data *epcEvent );
309 * Inform dali that the indicator data has been updated.
311 void UpdateImageData();
314 * Lock the temporary file, Copy the shared image into IndicatorBuffer
315 * and then unlock the temporary file.
316 * Caller should ensure we are not writing image to gl texture.
321 * Update the background with the correct colors
323 void SetBackground();
326 * Create a new image for the indicator, and set up signal handling for it.
328 void CreateNewImage();
331 * Create a new pixmap image for the indicator, and set up signal handling for it.
333 void CreateNewPixmapImage();
336 * Indicator type has changed.
338 * @param[in] type The new indicator type
340 void OnIndicatorTypeChanged( Type type );
343 * Check whether the indicator could be visible or invisible
344 * @return true if indicator should be shown
346 bool CheckVisibleState();
349 * Show/Hide indicator actor with effect
350 * @param[in] duration how long need to show the indicator,
351 * if it equal to 0, hide the indicator
352 * if it less than 0, show always
354 void ShowIndicator(float duration);
357 * Showing timer callback
362 * Showing animation finished callback
363 * @param[in] animation
365 void OnAnimationFinished(Dali::Animation& animation);
367 private: // Implementation of ServerConnection::Observer
369 * @copydoc Dali::Internal::Adaptor::ServerConnection::Observer::DataReceived()
371 virtual void DataReceived(void* event);
374 * @copydoc Dali::Internal::Adaptor::ServerConnection::Observer::DataReceived()
376 virtual void ConnectionClosed();
380 * Construct the gradient mesh
382 void ConstructBackgroundMesh();
386 IndicatorBufferPtr mIndicatorBuffer; ///< class which handles indicator rendering
387 PixmapId mPixmap; ///< Pixmap including indicator content
388 Dali::Image mImage; ///< Image created from mIndicatorBuffer
389 Dali::ImageActor mIndicatorImageActor; ///< Actor created from mImage
391 Dali::AnimatableMesh mBackgroundMesh;
392 Dali::MeshActor mBackgroundActor; ///< Actor for background
393 Dali::Actor mIndicatorActor; ///< Handle to topmost indicator actor
394 Dali::Actor mEventActor; ///< Handle to event
396 Dali::Timer mReconnectTimer; ///< Reconnection timer
397 SlotDelegate< Indicator > mConnection;
399 Dali::Window::IndicatorBgOpacity mOpacityMode; ///< Opacity enum for background
400 Indicator::State mState; ///< The connection state
403 ServerConnection* mServerConnection;
404 LockFile* mLock; ///< File lock for the shared file
405 SharedFile* mSharedFile; ///< Shared file
406 Indicator::Observer* mObserver; ///< Upload observer
408 Dali::Window::WindowOrientation mOrientation;
409 int mRotation; ///< Orientation in degrees
412 Dali::Window::IndicatorVisibleMode mVisible; ///< Whether the indicator is visible
414 Dali::Timer mShowTimer; ///< Timer to show indicator
415 bool mIsShowing; ///< Whether the indicator is showing on the screen
416 Dali::Animation mIndicatorAnimation; ///< Animation to show/hide indicator image
418 bool mIsAnimationPlaying; ///< Whether the animation is playing
419 bool mTouchedDown; ///< Whether the indicator area touched down
420 Dali::Vector2 mTouchDownPosition; ///< Indicator area touched down position