On Fri, 22 Jul 2011, Enlightenment SVN wrote:

> Log:
> Ecorexx::Timer design changed to have a factory and provide destroy function 
> to wrap C interface better than before
>  also used sigc++ slots as callback provider

what about using shared_ptr for your factory ?

Vincent

>
> Author:       andreas
> Date:         2011-07-22 15:39:05 -0700 (Fri, 22 Jul 2011)
> New Revision: 61598
> Trac:         http://trac.enlightenment.org/e/changeset/61598
>
> Modified:
>  trunk/BINDINGS/cxx/ecorexx/include/ecorexx/Timer.h 
> trunk/BINDINGS/cxx/ecorexx/src/Timer.cpp
>
> Modified: trunk/BINDINGS/cxx/ecorexx/include/ecorexx/Timer.h
> ===================================================================
> --- trunk/BINDINGS/cxx/ecorexx/include/ecorexx/Timer.h        2011-07-22 
> 18:58:25 UTC (rev 61597)
> +++ trunk/BINDINGS/cxx/ecorexx/include/ecorexx/Timer.h        2011-07-22 
> 22:39:05 UTC (rev 61598)
> @@ -9,24 +9,13 @@
>
> namespace Ecorexx {
>
> -// TODO: maybe change signal architecture back to callback architecture. 
> Think about it!
> -
> class Timer
> {
> -  typedef sigc::signal <void> Signal;
> -  typedef sigc::signal <void> Loop;
> -  //typedef sigc::slot1  <void, void> Slot;
> -
> public:
> -  Timer( double seconds, bool singleshot = false );
> -  virtual ~Timer();
> +  static Timer *factory (double seconds, sigc::slot<bool, Timer&> task, bool 
> loop = false);
>
> -  //virtual void tick();
> -
> -//  static Timer* singleShot( double seconds, const Timer::Slot& ); // TODO: 
> CountedPtr
> +  void destroy ();
>
> -  void del ();
> -
>   void setInterval (double interval);
>
>   double getInterval ();
> @@ -43,16 +32,18 @@
>
>   static void setPrecision (double precision);
>
> -
> -public: /* signals */
> -  Timer::Signal timeout;
> -  Timer::Loop loop;
> -
> +  static void dump ();
> +
> private:
> -  Ecore_Timer* _et;
> -  bool _ss;
> +  Ecore_Timer *mETimer;
> +  sigc::slot<bool, Timer&> mTask;
>
> -  static Eina_Bool __dispatcher( void* data );
> +  static Eina_Bool dispatcherFunc (void *data);
> +
> +  Timer (); // allow no construction
> +  Timer (const Timer&); // forbid copy constructor
> +  Timer (double seconds, sigc::slot<bool, Timer&> task, bool loop);  // 
> private construction -> use factory ()
> +  virtual ~Timer (); // forbid direct delete -> use destroy()
> };
>
> } // end namespace Ecorexx
>
> Modified: trunk/BINDINGS/cxx/ecorexx/src/Timer.cpp
> ===================================================================
> --- trunk/BINDINGS/cxx/ecorexx/src/Timer.cpp  2011-07-22 18:58:25 UTC (rev 
> 61597)
> +++ trunk/BINDINGS/cxx/ecorexx/src/Timer.cpp  2011-07-22 22:39:05 UTC (rev 
> 61598)
> @@ -9,60 +9,67 @@
>
> namespace Ecorexx {
>
> -Timer::Timer( double seconds, bool singleshot )
> -    :_ss( singleshot )
> +Timer::Timer (double seconds, sigc::slot<bool, Timer&> task, bool loop) :
> +  mETimer (NULL),
> +  mTask (task)
> {
> -  Dout( dc::notice, "Timer::Timer() - current frequency is " << seconds );
> -  _et = ecore_timer_add( seconds, &Timer::__dispatcher, this );
> -
> -  // TODO: find out why to use this function and the difference between 
> ecore_time_get() and ecore_loop_time_get()
> -  //ecore_timer_loop_add (double in, int (*func) (void *data), const void 
> *data);
> +  if (!loop)
> +  {
> +    mETimer = ecore_timer_add (seconds, Timer::dispatcherFunc, this);
> +  }
> +  else
> +  {
> +    mETimer = ecore_timer_loop_add (seconds, Timer::dispatcherFunc, this);
> +  }
> }
>
> +Timer *Timer::factory (double seconds, sigc::slot<bool, Timer&> task, bool 
> loop)
> +{
> +  return new Timer (seconds, task, loop);
> +}
> +
> Timer::~Timer()
> {
> -  ecore_timer_del( _et );
> }
>
> -/*Timer* Timer::singleShot( double seconds, const Timer::Slot& slot )
> +void Timer::destroy ()
> {
> -  Timer* ecoretimer = new Timer( seconds, true );
> -  ecoretimer->timeout.connect( slot );
> -}*/
> +  assert (ecore_timer_del (mETimer));
>
> -void Timer::del ()
> -{
> -  assert (ecore_timer_del (_et));
> +  // !!!ATTENTION!!!
> +  // suicide for a C++ object is dangerous, but allowed
> +  // the simple rule is that no member functions or member variables are 
> allowed to access after this point!
> +  delete (this);
> }
>
> void Timer::setInterval (double seconds)
> {
> -  ecore_timer_interval_set (_et, seconds);
> +  ecore_timer_interval_set (mETimer, seconds);
> }
>
> double Timer::getInterval ()
> {
> -  return ecore_timer_interval_get (_et);
> +  return ecore_timer_interval_get (mETimer);
> }
>
> void Timer::freeze ()
> {
> -  ecore_timer_freeze (_et);
> +  ecore_timer_freeze (mETimer);
> }
>
> void Timer::thaw ()
> {
> -  ecore_timer_thaw (_et);
> +  ecore_timer_thaw (mETimer);
> }
>
> void Timer::delay (double add)
> {
> -  ecore_timer_delay (_et, add);
> +  ecore_timer_delay (mETimer, add);
> }
>
> double Timer::getPending ()
> {
> -  return ecore_timer_pending_get (_et);
> +  return ecore_timer_pending_get (mETimer);
> }
>
> double Timer::getPrecision ()
> @@ -75,21 +82,27 @@
>   ecore_timer_precision_set (precision);
> }
>
> -/*void Timer::tick()
> +void Timer::dump ()
> {
> -  Dout( dc::notice, "Timer[ " << this << " ]::tick()" );
> -}*/
> +  ecore_timer_dump ();
> +}
>
> -Eina_Bool Timer::__dispatcher( void* data )
> +Eina_Bool Timer::dispatcherFunc (void *data)
> {
> -  Timer* object = reinterpret_cast<Timer*>( data );
> -  assert( object );
> -  object->timeout.emit( );
> -  //object->tick();
> -  /*bool singleshot = object->_ss;
> -  if ( singleshot ) delete object;
> -  return singleshot? 0:1;*/
> -  return ECORE_CALLBACK_RENEW;
> +  Timer* eTimer = static_cast <Timer*>( data );
> +  assert (eTimer);
> +
> +  bool ret = eTimer->mTask (*eTimer);
> +
> +  if (!ret)
> +  {
> +    // do a suicide as the delete operator isn't public available
> +    // the reason is that the C design below is a suicide design :-(
> +    delete eTimer;
> +    return false;
> +  }
> +
> +  return ret;
> }
>
> } // end namespace Ecorexx
>
>
> ------------------------------------------------------------------------------
> 10 Tips for Better Web Security
> Learn 10 ways to better secure your business today. Topics covered include:
> Web security, SSL, hacker attacks & Denial of Service (DoS), private keys,
> security Microsoft Exchange, secure Instant Messaging, and much more.
> http://www.accelacomm.com/jaw/sfnl/114/51426210/
> _______________________________________________
> enlightenment-svn mailing list
> enlightenment-...@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/enlightenment-svn
>
>

------------------------------------------------------------------------------
Storage Efficiency Calculator
This modeling tool is based on patent-pending intellectual property that
has been used successfully in hundreds of IBM storage optimization engage-
ments, worldwide.  Store less, Store more with what you own, Move data to 
the right place. Try It Now! http://www.accelacomm.com/jaw/sfnl/114/51427378/
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to