1 #ifndef __DALI_INTERNAL_ECORE_INDICATOR_H__
2 #define __DALI_INTERNAL_ECORE_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/animation/animation.h>
23 #include <dali/public-api/actors/image-actor.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 <base/interfaces/indicator-interface.h>
30 #include <indicator-buffer.h>
31 #include <ecore-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, public IndicatorInterface
68 * Class to encapsulate lock file
74 * Constructor. open lock file
76 LockFile(const std::string filename);
84 * Grab an exclusive lock on this file
85 * @return true if the lock succeeded, false if it failed
95 * Test if there is an error with the lock file, and clears
97 * @return true if an error was thrown
99 bool RetrieveAndClearErrorStatus();
102 std::string mFilename;
108 * Class to ensure lock/unlock through object destruction
114 * Constructor - creates a lock on the lockfile
115 * @param[in] lockFile The lockfile to use
117 ScopedLock( LockFile* lockFile );
120 * Destructor - removes the lock (if any) on the lockfile
125 * Method to test if the locking succeeded
126 * @return TRUE if locked
131 LockFile* mLockFile; ///< The lock file to use
132 bool mLocked; ///< Whether the lock succeeded
136 public: // Dali::Internal::Adaptor::IndicicatorInterface
138 * @copydoc Dali::Internal::IndicatorInterface::IndicatorInterface
140 Indicator( Adaptor* adaptor,
141 Dali::Window::WindowOrientation orientation,
142 IndicatorInterface::Observer* observer );
145 * @copydoc Dali::Internal::IndicatorInterface::~IndicatorInterface
147 virtual ~Indicator();
150 virtual void SetAdaptor(Adaptor* adaptor);
153 * @copydoc Dali::Internal::IndicatorInterface::GetActor
155 virtual Dali::Actor GetActor();
158 * @copydoc Dali::Internal::IndicatorInterface::Open
160 virtual void Open( Dali::Window::WindowOrientation orientation );
163 * @copydoc Dali::Internal::IndicatorInterface::Close
165 virtual void Close();
168 * @copydoc Dali::Internal::IndicatorInterface::SetOpacityMode
170 virtual void SetOpacityMode( Dali::Window::IndicatorBgOpacity mode );
173 * @copydoc Dali::Internal::IndicatorInterface::SetVisible
175 virtual void SetVisible( Dali::Window::IndicatorVisibleMode visibleMode, bool forceUpdate = false );
178 * @copydoc Dali::Internal::IndicatorInterface::IsConnected
180 virtual bool IsConnected();
183 * @copydoc Dali::Internal::IndicatorInterface::SendMessage
185 virtual bool SendMessage( int messageDomain, int messageId, const void *data, int size );
189 * Initialize the indicator actors
194 * Constructs the renderers used for the background
196 Dali::Geometry CreateBackgroundGeometry();
199 * Set the image to be rendered as indicator foreground
200 * @param[in] image The foreground image.
202 void SetForegroundImage( Dali::Image image );
205 * Touch event callback.
206 * It should pass the valid touch event to indicator server
208 * @param[in] indicator The indicator actor that was touched
209 * @param[in] touchEvent The touch event
211 bool OnTouched(Dali::Actor indicator, const TouchEvent& touchEvent);
214 * Pan gesture callback.
215 * It finds flick down gesture to show hidden indicator image
217 * @param[in] actor The actor for gesture
218 * @param[in] gesture The gesture event
220 void OnPan( Dali::Actor actor, const Dali::PanGesture& gesture );
223 * Touch event callback on stage.
224 * If stage is touched, hide showing indicator image
226 * @param[in] touchEvent The touch event
228 void OnStageTouched(const Dali::TouchEvent& touchEvent);
231 * Connect to the indicator service
236 * Start the reconnection timer. This will run every second until we reconnect to
237 * the indicator service.
239 void StartReconnectionTimer();
242 * If connection failed, attempt to re-connect every second
244 bool OnReconnectTimer();
247 * Disconnect from the indicator service
252 * Handle Resize event
253 * @param[in] width The new width
254 * @param[in] height The new height
256 void Resize( int width, int height );
259 * Set the lock file info.
260 * @param[in] epcEvent Current ecore event.
262 void SetLockFileInfo( Ecore_Ipc_Event_Server_Data *epcEvent );
265 * Set the shared indicator image info
266 * @param[in] epcEvent The event containing the image data
268 void SetSharedImageInfo( Ecore_Ipc_Event_Server_Data *epcEvent );
271 * Load the shared indicator image
272 * @param[in] epcEvent The event containing the image data
274 void LoadSharedImage( Ecore_Ipc_Event_Server_Data *epcEvent );
277 * Load the pixmap indicator image
278 * @param[in] epcEvent The event containing the image data
280 void LoadPixmapImage( Ecore_Ipc_Event_Server_Data *epcEvent );
283 * Inform dali that the indicator data has been updated.
284 * @param[in] bufferNumber The shared file number
286 void UpdateImageData( int bufferNumber );
289 * Lock the temporary file, Copy the shared image into IndicatorBuffer
290 * and then unlock the temporary file.
291 * Caller should ensure we are not writing image to gl texture.
292 * @param[in] bufferNumber The shared file number
294 bool CopyToBuffer( int bufferNumber );
297 * Create a new image for the indicator, and set up signal handling for it.
298 * @param[in] bufferNumber The shared file number
300 void CreateNewImage( int bufferNumber );
303 * Create a new pixmap image for the indicator, and set up signal handling for it.
305 void CreateNewPixmapImage();
308 * Indicator type has changed.
310 * @param[in] type The new indicator type
312 void OnIndicatorTypeChanged( Type type );
315 * Check whether the indicator could be visible or invisible
316 * @return true if indicator should be shown
318 bool CheckVisibleState();
321 * Show/Hide indicator actor with effect
322 * @param[in] duration how long need to show the indicator,
323 * if it equal to 0, hide the indicator
324 * if it less than 0, show always
326 void ShowIndicator( float duration );
329 * Showing timer callback
334 * Showing animation finished callback
335 * @param[in] animation
337 void OnAnimationFinished( Dali::Animation& animation );
339 private: // Implementation of ServerConnection::Observer
341 * @copydoc Dali::Internal::Adaptor::ServerConnection::Observer::DataReceived()
343 virtual void DataReceived( void* event );
346 * @copydoc Dali::Internal::Adaptor::ServerConnection::Observer::DataReceived()
348 virtual void ConnectionClosed();
353 * Clear shared file info
355 void ClearSharedFileInfo();
359 struct SharedFileInfo
369 mSharedFileNumber( 0 )
373 LockFile* mLock; ///< File lock for the shared file
374 SharedFile* mSharedFile; ///< Shared file
376 int mImageWidth; ///< Shared image width
377 int mImageHeight; ///< Shared image height
379 std::string mLockFileName; ///< Lock file name
380 std::string mSharedFileName; ///< Shared file name
381 int mSharedFileID; ///< Shared file ID
382 int mSharedFileNumber; ///< Shared file number
385 static const int SHARED_FILE_NUMBER = 2; ///< Shared file number
387 Dali::Geometry mTranslucentGeometry; ///< Geometry used for rendering the translucent background
388 Dali::Geometry mSolidGeometry; ///< Geometry used for rendering the opaque background
389 Dali::Shader mBackgroundShader; ///< Shader used for rendering the background
391 IndicatorBufferPtr mIndicatorBuffer; ///< class which handles indicator rendering
392 PixmapId mPixmap; ///< Pixmap including indicator content
393 Dali::Renderer mForegroundRenderer; ///< Renderer renders the indicator foreground
394 Dali::Renderer mBackgroundRenderer; ///< Renderer renders the indicator background
396 Dali::Actor mIndicatorContentActor; ///< Actor container for image and background
397 Dali::Actor mIndicatorActor; ///< Handle to topmost indicator actor
398 Dali::Actor mEventActor; ///< Handle to event
399 Dali::PanGestureDetector mPanDetector; ///< Pan detector to find flick gesture for hidden indicator
400 float mGestureDeltaY; ///< Checking how much panning moved
401 bool mGestureDetected; ///< Whether find the flick gesture
403 Dali::Timer mReconnectTimer; ///< Reconnection timer
404 SlotDelegate< Indicator > mConnection;
406 Dali::Window::IndicatorBgOpacity mOpacityMode; ///< Opacity enum for background
407 Indicator::State mState; ///< The connection state
410 ServerConnection* mServerConnection;
411 IndicatorInterface::Observer* mObserver; ///< Upload observer
413 Dali::Window::WindowOrientation mOrientation;
416 Dali::Window::IndicatorVisibleMode mVisible; ///< Whether the indicator is visible
418 Dali::Timer mShowTimer; ///< Timer to show indicator
419 bool mIsShowing; ///< Whether the indicator is showing on the screen
420 Dali::Animation mIndicatorAnimation; ///< Animation to show/hide indicator image
422 bool mIsAnimationPlaying; ///< Whether the animation is playing
424 int mCurrentSharedFile; ///< Current shared file number
425 SharedFileInfo mSharedFileInfo[SHARED_FILE_NUMBER]; ///< Table to store shared file info
427 bool mBackgroundVisible; ///< Indicate whether background is visible