Move time event processing from FApplication to FObject
This commit is contained in:
parent
affdf6fe11
commit
11ba43fa0f
|
@ -1,3 +1,6 @@
|
|||
2018-09-27 Markus Gans <guru.mail@muenster.de>
|
||||
* Move time event processing from FApplication to FObject
|
||||
|
||||
2018-09-26 Markus Gans <guru.mail@muenster.de>
|
||||
* The FListViewItem class now has a getData() and a setData() method
|
||||
similar to the FListBoxItem class.
|
||||
|
|
|
@ -1149,51 +1149,6 @@ void FApplication::processResizeEvent()
|
|||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
uInt FApplication::processTimerEvent()
|
||||
{
|
||||
FObject::TimerList::iterator iter, last;
|
||||
timeval currentTime;
|
||||
uInt activated = 0;
|
||||
|
||||
getCurrentTime (¤tTime);
|
||||
|
||||
if ( isTimerInUpdating() )
|
||||
return 0;
|
||||
|
||||
if ( ! timer_list )
|
||||
return 0;
|
||||
|
||||
if ( timer_list->empty() )
|
||||
return 0;
|
||||
|
||||
iter = timer_list->begin();
|
||||
last = timer_list->end();
|
||||
|
||||
while ( iter != last )
|
||||
{
|
||||
if ( ! iter->id
|
||||
|| ! iter->object
|
||||
|| currentTime < iter->timeout ) // no timer expired
|
||||
break;
|
||||
|
||||
iter->timeout += iter->interval;
|
||||
|
||||
if ( iter->timeout < currentTime )
|
||||
iter->timeout = currentTime + iter->interval;
|
||||
|
||||
if ( iter->interval.tv_usec > 0 || iter->interval.tv_sec > 0 )
|
||||
activated++;
|
||||
|
||||
FTimerEvent t_ev(fc::Timer_Event, iter->id);
|
||||
sendEvent(iter->object, &t_ev);
|
||||
|
||||
++iter;
|
||||
}
|
||||
|
||||
return activated;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
void FApplication::processCloseWidget()
|
||||
{
|
||||
|
@ -1233,4 +1188,11 @@ bool FApplication::processNextEvent()
|
|||
return ( num_events > 0 );
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
void FApplication::performTimerAction ( const FObject* receiver
|
||||
, const FEvent* event )
|
||||
{
|
||||
sendEvent(receiver, event);
|
||||
}
|
||||
|
||||
} // namespace finalcut
|
||||
|
|
|
@ -240,22 +240,8 @@ int FObject::addTimer (int interval)
|
|||
timeval time_interval;
|
||||
timeval currentTime;
|
||||
int id = 1;
|
||||
|
||||
timer_modify_lock = true;
|
||||
|
||||
if ( ! timer_list )
|
||||
{
|
||||
try
|
||||
{
|
||||
timer_list = new TimerList();
|
||||
}
|
||||
catch (const std::bad_alloc& ex)
|
||||
{
|
||||
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// find an unused timer id
|
||||
if ( ! timer_list->empty() )
|
||||
{
|
||||
|
@ -389,4 +375,52 @@ bool FObject::event (FEvent* ev)
|
|||
void FObject::onTimer (FTimerEvent*)
|
||||
{ }
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
uInt FObject::processTimerEvent()
|
||||
{
|
||||
FObject::TimerList::iterator iter, last;
|
||||
timeval currentTime;
|
||||
uInt activated = 0;
|
||||
|
||||
getCurrentTime (¤tTime);
|
||||
|
||||
if ( isTimerInUpdating() )
|
||||
return 0;
|
||||
|
||||
if ( ! timer_list )
|
||||
return 0;
|
||||
|
||||
if ( timer_list->empty() )
|
||||
return 0;
|
||||
|
||||
iter = timer_list->begin();
|
||||
last = timer_list->end();
|
||||
|
||||
while ( iter != last )
|
||||
{
|
||||
if ( ! iter->id
|
||||
|| ! iter->object
|
||||
|| currentTime < iter->timeout ) // no timer expired
|
||||
break;
|
||||
|
||||
iter->timeout += iter->interval;
|
||||
|
||||
if ( iter->timeout < currentTime )
|
||||
iter->timeout = currentTime + iter->interval;
|
||||
|
||||
if ( iter->interval.tv_usec > 0 || iter->interval.tv_sec > 0 )
|
||||
activated++;
|
||||
|
||||
FTimerEvent t_ev(fc::Timer_Event, iter->id);
|
||||
performTimerAction (iter->object, &t_ev);
|
||||
++iter;
|
||||
}
|
||||
|
||||
return activated;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
void FObject::performTimerAction (const FObject*, const FEvent*)
|
||||
{ }
|
||||
|
||||
} // namespace finalcut
|
||||
|
|
|
@ -175,9 +175,10 @@ class FApplication : public FWidget
|
|||
void sendWheelEvent (const FPoint&, const FPoint&);
|
||||
void processMouseEvent();
|
||||
void processResizeEvent();
|
||||
uInt processTimerEvent();
|
||||
void processCloseWidget();
|
||||
bool processNextEvent();
|
||||
virtual void performTimerAction ( const FObject*
|
||||
, const FEvent* );
|
||||
|
||||
// Data Members
|
||||
int app_argc;
|
||||
|
|
|
@ -115,12 +115,17 @@ class FObject
|
|||
// Typedef
|
||||
typedef std::vector<timer_data> TimerList;
|
||||
|
||||
// Accessor
|
||||
TimerList* getTimerList() const;
|
||||
|
||||
// Method
|
||||
uInt processTimerEvent();
|
||||
|
||||
// Event handler
|
||||
virtual bool event (FEvent*);
|
||||
virtual void onTimer (FTimerEvent*);
|
||||
|
||||
// Data Members
|
||||
static TimerList* timer_list;
|
||||
// Data Member
|
||||
bool widget_object;
|
||||
|
||||
private:
|
||||
|
@ -130,11 +135,15 @@ class FObject
|
|||
// Disable assignment operator (=)
|
||||
FObject& operator = (const FObject&);
|
||||
|
||||
// Method
|
||||
virtual void performTimerAction (const FObject*, const FEvent*);
|
||||
|
||||
// Data Members
|
||||
FObject* parent_obj;
|
||||
FObjectList children_list;
|
||||
bool has_parent;
|
||||
static bool timer_modify_lock;
|
||||
static TimerList* timer_list;
|
||||
};
|
||||
|
||||
#pragma pack(pop)
|
||||
|
@ -195,6 +204,10 @@ inline bool FObject::isInstanceOf (const char classname[]) const
|
|||
inline bool FObject::isTimerInUpdating() const
|
||||
{ return timer_modify_lock; }
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
inline FObject::TimerList* FObject::getTimerList() const
|
||||
{ return timer_list; }
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Operator functions for timeval
|
||||
|
|
|
@ -65,7 +65,7 @@ class FTermcap
|
|||
{ }
|
||||
|
||||
// Destructor
|
||||
virtual ~FTermcap()
|
||||
~FTermcap()
|
||||
{ }
|
||||
|
||||
// Accessors
|
||||
|
|
|
@ -46,9 +46,9 @@ class FObject_protected : public finalcut::FObject
|
|||
return finalcut::FObject::event(ev);
|
||||
}
|
||||
|
||||
finalcut::FObject::TimerList* getTimerList() const
|
||||
TimerList* getTimerList() const
|
||||
{
|
||||
return timer_list;
|
||||
return finalcut::FObject::getTimerList();
|
||||
}
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
@ -334,6 +334,9 @@ void FObjectTest::timeTest()
|
|||
CPPUNIT_ASSERT ( ! finalcut::FObject::isTimeout (&time1, timeout) );
|
||||
sleep(1);
|
||||
CPPUNIT_ASSERT ( finalcut::FObject::isTimeout (&time1, timeout) );
|
||||
time1.tv_sec = 300;
|
||||
time1.tv_usec = 2000000; // > 1000000 µs to test diff underflow
|
||||
CPPUNIT_ASSERT ( finalcut::FObject::isTimeout (&time1, timeout) );
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue