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>
|
2018-09-26 Markus Gans <guru.mail@muenster.de>
|
||||||
* The FListViewItem class now has a getData() and a setData() method
|
* The FListViewItem class now has a getData() and a setData() method
|
||||||
similar to the FListBoxItem class.
|
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()
|
void FApplication::processCloseWidget()
|
||||||
{
|
{
|
||||||
|
@ -1233,4 +1188,11 @@ bool FApplication::processNextEvent()
|
||||||
return ( num_events > 0 );
|
return ( num_events > 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
void FApplication::performTimerAction ( const FObject* receiver
|
||||||
|
, const FEvent* event )
|
||||||
|
{
|
||||||
|
sendEvent(receiver, event);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace finalcut
|
} // namespace finalcut
|
||||||
|
|
|
@ -240,22 +240,8 @@ int FObject::addTimer (int interval)
|
||||||
timeval time_interval;
|
timeval time_interval;
|
||||||
timeval currentTime;
|
timeval currentTime;
|
||||||
int id = 1;
|
int id = 1;
|
||||||
|
|
||||||
timer_modify_lock = true;
|
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
|
// find an unused timer id
|
||||||
if ( ! timer_list->empty() )
|
if ( ! timer_list->empty() )
|
||||||
{
|
{
|
||||||
|
@ -389,4 +375,52 @@ bool FObject::event (FEvent* ev)
|
||||||
void FObject::onTimer (FTimerEvent*)
|
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
|
} // namespace finalcut
|
||||||
|
|
|
@ -175,9 +175,10 @@ class FApplication : public FWidget
|
||||||
void sendWheelEvent (const FPoint&, const FPoint&);
|
void sendWheelEvent (const FPoint&, const FPoint&);
|
||||||
void processMouseEvent();
|
void processMouseEvent();
|
||||||
void processResizeEvent();
|
void processResizeEvent();
|
||||||
uInt processTimerEvent();
|
|
||||||
void processCloseWidget();
|
void processCloseWidget();
|
||||||
bool processNextEvent();
|
bool processNextEvent();
|
||||||
|
virtual void performTimerAction ( const FObject*
|
||||||
|
, const FEvent* );
|
||||||
|
|
||||||
// Data Members
|
// Data Members
|
||||||
int app_argc;
|
int app_argc;
|
||||||
|
|
|
@ -71,37 +71,37 @@ class FObject
|
||||||
virtual ~FObject();
|
virtual ~FObject();
|
||||||
|
|
||||||
// Accessors
|
// Accessors
|
||||||
virtual const char* getClassName() const;
|
virtual const char* getClassName() const;
|
||||||
FObject* getParent() const;
|
FObject* getParent() const;
|
||||||
FObject* getChild (int) const;
|
FObject* getChild (int) const;
|
||||||
const FObjectList& getChildren() const;
|
const FObjectList& getChildren() const;
|
||||||
int numOfChildren() const;
|
int numOfChildren() const;
|
||||||
FObjectIterator begin();
|
FObjectIterator begin();
|
||||||
FObjectIterator end();
|
FObjectIterator end();
|
||||||
constFObjectIterator begin() const;
|
constFObjectIterator begin() const;
|
||||||
constFObjectIterator end() const;
|
constFObjectIterator end() const;
|
||||||
|
|
||||||
// Inquiries
|
// Inquiries
|
||||||
bool hasParent() const;
|
bool hasParent() const;
|
||||||
bool hasChildren() const;
|
bool hasChildren() const;
|
||||||
bool isChild (FObject*) const;
|
bool isChild (FObject*) const;
|
||||||
bool isDirectChild (FObject*) const;
|
bool isDirectChild (FObject*) const;
|
||||||
bool isWidget() const;
|
bool isWidget() const;
|
||||||
bool isInstanceOf (const char[]) const;
|
bool isInstanceOf (const char[]) const;
|
||||||
bool isTimerInUpdating() const;
|
bool isTimerInUpdating() const;
|
||||||
|
|
||||||
// Methods
|
// Methods
|
||||||
void removeParent();
|
void removeParent();
|
||||||
void addChild (FObject*);
|
void addChild (FObject*);
|
||||||
void delChild (FObject*);
|
void delChild (FObject*);
|
||||||
|
|
||||||
// Timer methods
|
// Timer methods
|
||||||
static void getCurrentTime (timeval*);
|
static void getCurrentTime (timeval*);
|
||||||
static bool isTimeout (timeval*, long);
|
static bool isTimeout (timeval*, long);
|
||||||
int addTimer (int);
|
int addTimer (int);
|
||||||
bool delTimer (int);
|
bool delTimer (int);
|
||||||
bool delOwnTimer();
|
bool delOwnTimer();
|
||||||
bool delAllTimer();
|
bool delAllTimer();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
struct timer_data
|
struct timer_data
|
||||||
|
@ -115,13 +115,18 @@ class FObject
|
||||||
// Typedef
|
// Typedef
|
||||||
typedef std::vector<timer_data> TimerList;
|
typedef std::vector<timer_data> TimerList;
|
||||||
|
|
||||||
// Event handler
|
// Accessor
|
||||||
virtual bool event (FEvent*);
|
TimerList* getTimerList() const;
|
||||||
virtual void onTimer (FTimerEvent*);
|
|
||||||
|
|
||||||
// Data Members
|
// Method
|
||||||
static TimerList* timer_list;
|
uInt processTimerEvent();
|
||||||
bool widget_object;
|
|
||||||
|
// Event handler
|
||||||
|
virtual bool event (FEvent*);
|
||||||
|
virtual void onTimer (FTimerEvent*);
|
||||||
|
|
||||||
|
// Data Member
|
||||||
|
bool widget_object;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Disable copy constructor
|
// Disable copy constructor
|
||||||
|
@ -130,11 +135,15 @@ class FObject
|
||||||
// Disable assignment operator (=)
|
// Disable assignment operator (=)
|
||||||
FObject& operator = (const FObject&);
|
FObject& operator = (const FObject&);
|
||||||
|
|
||||||
|
// Method
|
||||||
|
virtual void performTimerAction (const FObject*, const FEvent*);
|
||||||
|
|
||||||
// Data Members
|
// Data Members
|
||||||
FObject* parent_obj;
|
FObject* parent_obj;
|
||||||
FObjectList children_list;
|
FObjectList children_list;
|
||||||
bool has_parent;
|
bool has_parent;
|
||||||
static bool timer_modify_lock;
|
static bool timer_modify_lock;
|
||||||
|
static TimerList* timer_list;
|
||||||
};
|
};
|
||||||
|
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
@ -195,6 +204,10 @@ inline bool FObject::isInstanceOf (const char classname[]) const
|
||||||
inline bool FObject::isTimerInUpdating() const
|
inline bool FObject::isTimerInUpdating() const
|
||||||
{ return timer_modify_lock; }
|
{ return timer_modify_lock; }
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
inline FObject::TimerList* FObject::getTimerList() const
|
||||||
|
{ return timer_list; }
|
||||||
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
// Operator functions for timeval
|
// Operator functions for timeval
|
||||||
|
|
|
@ -65,7 +65,7 @@ class FTermcap
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
virtual ~FTermcap()
|
~FTermcap()
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
// Accessors
|
// Accessors
|
||||||
|
|
|
@ -46,9 +46,9 @@ class FObject_protected : public finalcut::FObject
|
||||||
return finalcut::FObject::event(ev);
|
return finalcut::FObject::event(ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
finalcut::FObject::TimerList* getTimerList() const
|
TimerList* getTimerList() const
|
||||||
{
|
{
|
||||||
return timer_list;
|
return finalcut::FObject::getTimerList();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
@ -334,6 +334,9 @@ void FObjectTest::timeTest()
|
||||||
CPPUNIT_ASSERT ( ! finalcut::FObject::isTimeout (&time1, timeout) );
|
CPPUNIT_ASSERT ( ! finalcut::FObject::isTimeout (&time1, timeout) );
|
||||||
sleep(1);
|
sleep(1);
|
||||||
CPPUNIT_ASSERT ( finalcut::FObject::isTimeout (&time1, timeout) );
|
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