Added trigger event facility to adaptor
authorNick Holland <nick.holland@partner.samsung.com>
Mon, 14 Apr 2014 09:01:15 +0000 (10:01 +0100)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Wed, 16 Apr 2014 11:09:58 +0000 (12:09 +0100)
[Issue] No ability to create trigger events from the adaptor base files

[Problem] No support

[Cause] No code

[Solution] Add support.

Change-Id: I4439fddb5a56c09f1d403e55102bf0a625439e59

adaptors/base/interfaces/trigger-event-factory-interface.h [new file with mode: 0644]
adaptors/base/interfaces/trigger-event-interface.h
adaptors/tizen/internal/common/adaptor-impl.cpp
adaptors/tizen/internal/common/adaptor-impl.h
adaptors/tizen/internal/common/file.list
adaptors/tizen/internal/common/trigger-event-factory.cpp [new file with mode: 0644]
adaptors/tizen/internal/common/trigger-event-factory.h [new file with mode: 0644]
adaptors/tizen/internal/common/trigger-event.cpp
adaptors/tizen/internal/common/trigger-event.h

diff --git a/adaptors/base/interfaces/trigger-event-factory-interface.h b/adaptors/base/interfaces/trigger-event-factory-interface.h
new file mode 100644 (file)
index 0000000..655aba6
--- /dev/null
@@ -0,0 +1,92 @@
+#ifndef __DALI_INTERNAL_BASE_TRIGGER_EVENT_FACTORY_INTERFACE_H__
+#define __DALI_INTERNAL_BASE_TRIGGER_EVENT_FACTORY_INTERFACE_H__
+
+//
+// Copyright (c) 2014 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://floralicense.org/license/
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an AS IS BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+// INTERNAL INCLUDES
+#include <base/interfaces/trigger-event-interface.h>
+
+// EXTERNAL INCLUDES
+#include <boost/function.hpp>
+
+
+namespace Dali
+{
+
+namespace Internal
+{
+
+namespace Adaptor
+{
+
+/**
+ * @brief Trigger interface factory class for creating a TriggerEvents
+ *
+ */
+class TriggerEventFactoryInterface
+{
+public:
+
+
+  /**
+   * @brief Create a new concrete implementation of the event trigger interface.
+   * @param functor the function to call when interface->Trigger() is called
+   * @return pointer to a new trigger event
+   */
+  virtual TriggerEventInterface* CreateTriggerEvent( boost::function<void()> functor,
+                                                     TriggerEventInterface::Options options = TriggerEventInterface::NONE) = 0;
+  /**
+   * @brief destroy a trigger event
+   * @param trigger event to destroy
+   */
+  virtual void DestroyTriggerEvent( TriggerEventInterface* triggerEventInterface ) = 0;
+
+protected:
+
+  /**
+   * @brief  Constructor
+   */
+  TriggerEventFactoryInterface()
+  {
+  }
+
+  /**
+   * @brief Virtual Destructor
+   */
+  virtual ~TriggerEventFactoryInterface()
+  {
+  }
+
+private:
+
+
+  // Undefined copy constructor.
+  TriggerEventFactoryInterface( const TriggerEventFactoryInterface& );
+
+  // Undefined assignment operator.
+  TriggerEventFactoryInterface& operator=( const TriggerEventFactoryInterface& );
+
+};
+
+
+} // namespace Internal
+
+} // namespace Adaptor
+
+} // namespace Dali
+
+#endif // __DALI_INTERNAL_BASE_TRIGGER_EVENT_FACTORY_INTERFACE_H__
index 2f27bca..71b2b44 100644 (file)
@@ -28,7 +28,10 @@ namespace Adaptor
 {
 
 /**
- * Interface for a trigger event class
+ * @brief Interface for a trigger event class.
+ *
+ * The trigger event is a way of running a function call back on the main event thread of Dali.
+ * To create a trigger event use the factory interface.
  */
 class TriggerEventInterface
 {
@@ -36,7 +39,16 @@ class TriggerEventInterface
 public:
 
   /**
-   * Triggers the event.
+   * @brief trigger event options
+   */
+  enum Options
+  {
+    NONE,
+    DELETE_AFTER_TRIGGER,  // automatically delete the trigger event object, after Trigger() is called.
+  };
+
+  /**
+   * @brief Triggers the event.
    *
    * This can be called from one thread in order to wake up another thread.
    */
@@ -45,19 +57,21 @@ public:
 protected:
 
   /**
-   * Constructor
+   * @brief Constructor
    */
-  TriggerEventInterface()
+  TriggerEventInterface( )
   {
   }
 
   /**
-   * Virtual protected destructor, no deletion through this interface
+   * @brief Virtual destructor
    */
   virtual ~TriggerEventInterface()
   {
   }
 
+private:
+
   // Undefined copy constructor.
   TriggerEventInterface( const TriggerEventInterface& );
 
index ceb5b0e..53bc239 100644 (file)
@@ -552,6 +552,10 @@ TriggerEventInterface& Adaptor::GetTriggerEventInterface()
 {
   return *mNotificationTrigger;
 }
+TriggerEventFactoryInterface& Adaptor::GetTriggerEventFactoryInterface()
+{
+  return mTriggerEventFactory;
+}
 RenderSurface* Adaptor::GetRenderSurfaceInterface()
 {
   return mSurface;
index b36c866..4ec0b02 100644 (file)
@@ -43,6 +43,7 @@
 #include <internal/common/damage-observer.h>
 #include <internal/common/window-visibility-observer.h>
 #include <internal/common/kernel-trace.h>
+#include <internal/common/trigger-event-factory.h>
 
 namespace Dali
 {
@@ -318,6 +319,11 @@ public:  //AdaptorInternalServices
   virtual TriggerEventInterface& GetTriggerEventInterface();
 
   /**
+   * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventFactoryInterface()
+   */
+  virtual TriggerEventFactoryInterface& GetTriggerEventFactoryInterface();
+
+  /**
    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetRenderSurfaceInterface()
    */
   virtual RenderSurface* GetRenderSurfaceInterface();
@@ -509,7 +515,8 @@ private: // Data
   DeviceLayout                          mBaseLayout;                  ///< The base layout of the application
   LogOptions                            mLogOptions;                  ///< log options
   PerformanceInterface*                 mPerformanceInterface;        ///< Performance interface
-  KernelTrace                           mKernelTracer;
+  KernelTrace                           mKernelTracer;                ///< Kernel tracer
+  TriggerEventFactory                   mTriggerEventFactory;         ///< Trigger event factory
 public:
   inline static Adaptor& GetImplementation(Dali::Adaptor& adaptor) {return *adaptor.mImpl;}
 };
index 5c4bb98..b8280d2 100644 (file)
@@ -28,6 +28,7 @@ tizen_adaptor_internal_common_src_files = \
   $(tizen_adaptor_internal_src_dir)/tilt-sensor-impl.cpp  \
   $(tizen_adaptor_internal_src_dir)/timer-impl.cpp \
   $(tizen_adaptor_internal_src_dir)/trigger-event.cpp \
+  $(tizen_adaptor_internal_src_dir)/trigger-event-factory.cpp \
   $(tizen_adaptor_internal_src_dir)/tts-player-impl.cpp \
   $(tizen_adaptor_internal_src_dir)/virtual-keyboard-impl.cpp \
   $(tizen_adaptor_internal_src_dir)/vsync-monitor.cpp \
diff --git a/adaptors/tizen/internal/common/trigger-event-factory.cpp b/adaptors/tizen/internal/common/trigger-event-factory.cpp
new file mode 100644 (file)
index 0000000..f178726
--- /dev/null
@@ -0,0 +1,49 @@
+//
+// Copyright (c) 2014 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://floralicense.org/license/
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an AS IS BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+// CLASS HEADER
+#include "trigger-event-factory.h"
+
+// INTERNAL INCLUDES
+#include <internal/common/trigger-event.h>
+
+
+namespace Dali
+{
+
+namespace Internal
+{
+
+namespace Adaptor
+{
+
+TriggerEventInterface* TriggerEventFactory::CreateTriggerEvent(  boost::function<void()> functor,  TriggerEventInterface::Options options )
+{
+  return new TriggerEvent( functor, options );
+}
+
+void TriggerEventFactory::DestroyTriggerEvent( TriggerEventInterface* triggerEventInterface )
+{
+  TriggerEvent* triggerEvent( static_cast< TriggerEvent* >( triggerEventInterface) );
+  delete triggerEvent;
+}
+
+
+} // namespace Internal
+
+} // namespace Adaptor
+
+} // namespace Dali
diff --git a/adaptors/tizen/internal/common/trigger-event-factory.h b/adaptors/tizen/internal/common/trigger-event-factory.h
new file mode 100644 (file)
index 0000000..8d84769
--- /dev/null
@@ -0,0 +1,74 @@
+#ifndef __DALI_INTERNAL_ADAPTOR_TRIGGER_EVENT_FACTORY_H__
+#define __DALI_INTERNAL_ADAPTOR_TRIGGER_EVENT_FACTORY_H__
+
+//
+// Copyright (c) 2014 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://floralicense.org/license/
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an AS IS BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+// INTERNAL INCLUDES
+#include <base/interfaces/trigger-event-factory-interface.h>
+
+namespace Dali
+{
+
+namespace Internal
+{
+
+namespace Adaptor
+{
+
+/**
+ * @brief Trigger interface factory class
+ *
+ */
+class TriggerEventFactory : public TriggerEventFactoryInterface
+{
+
+public:
+
+  /**
+   * @brief Constructor
+   */
+  TriggerEventFactory()
+  {
+  }
+
+  /**
+   * @brief Destructor
+   */
+  virtual ~TriggerEventFactory()
+  {
+  }
+
+  /**
+   * @copydoc TriggerEventFactoryInterface::CreateTriggerEvent
+   */
+  virtual TriggerEventInterface* CreateTriggerEvent(  boost::function<void()> functor, TriggerEventInterface::Options options );
+
+
+  /**
+   * @copydoc TriggerEventFactoryInterface::DestroyTriggerEvent
+   */
+  virtual void DestroyTriggerEvent( TriggerEventInterface* triggerEventInterface );
+
+};
+
+} // namespace Internal
+
+} // namespace Adaptor
+
+} // namespace Dali
+
+#endif // __DALI_INTERNAL_ADAPTOR_TRIGGER_EVENT_FACTORY_H__
index 5294a14..8fa5942 100644 (file)
@@ -36,10 +36,11 @@ namespace Internal
 namespace Adaptor
 {
 
-TriggerEvent::TriggerEvent( boost::function<void()> functor )
+TriggerEvent::TriggerEvent( boost::function<void()> functor, TriggerEventInterface::Options options )
 : mFileDescriptorMonitor(NULL),
   mFunctor(functor),
-  mFileDescriptor(-1)
+  mFileDescriptor(-1),
+  mOptions( options )
 {
   // Create accompanying file descriptor.
   mFileDescriptor = eventfd(0, EFD_NONBLOCK);
@@ -104,6 +105,12 @@ void TriggerEvent::Triggered()
 
   // Call the connected boost function.
   mFunctor();
+
+  //check if we should delete ourselves after the trigger
+  if( mOptions == TriggerEventInterface::DELETE_AFTER_TRIGGER )
+  {
+    delete this;
+  }
 }
 
 } // namespace Adaptor
index 8379d9b..bc68799 100644 (file)
@@ -55,8 +55,9 @@ public:
    * descriptor when there is data.
    *
    * @param[in]  functor to call
+   * @param[in] options, trigger event options.
    */
-  TriggerEvent( boost::function<void()> functor );
+  TriggerEvent( boost::function<void()> functor, TriggerEventInterface::Options options = TriggerEventInterface::NONE );
 
   /**
    * Destructor
@@ -88,6 +89,7 @@ private:
   FileDescriptorMonitor* mFileDescriptorMonitor;
   boost::function<void()> mFunctor; ///< Function object to call
   int mFileDescriptor;
+  TriggerEventInterface::Options mOptions;
 };
 
 } // namespace Adaptor