Inkscape
Vector Graphics Editor
Inkscape::Extension::ExpirationTimer Class Reference

#include <timer.h>

Public Member Functions

 ExpirationTimer (Extension *in_extension)
 Create a new expiration timer. More...
 
virtual ~ExpirationTimer ()
 Deletes a ExpirationTimer. More...
 
void touch ()
 Touches the timer to extend the length before it expires. More...
 
void lock ()
 
void unlock ()
 

Static Public Member Functions

static void set_timeout (long in_seconds)
 Set the timeout variable. More...
 

Private Member Functions

bool expired () const
 Check to see if the timer has expired. More...
 

Static Private Member Functions

static bool idle_func ()
 This function goes in the idle loop to find expired extensions. More...
 
static bool timer_func ()
 A timer function to set up the idle function. More...
 

Private Attributes

int locked
 Is this extension locked from being unloaded? More...
 
ExpirationTimernext
 Next entry in the list. More...
 
Glib::DateTime expiration
 When this timer expires. More...
 
Extensionextension
 What extension this function relates to. More...
 

Static Private Attributes

static ExpirationTimertimer_list = nullptr
 Circularly linked list of all timers. More...
 
static ExpirationTimeridle_start = nullptr
 Which timer was on top when we started the idle loop. More...
 
static long timeout = 240
 What the current timeout is (in seconds) More...
 
static bool timer_started = false
 Has the timer been started? More...
 

Detailed Description

Definition at line 26 of file timer.h.

Constructor & Destructor Documentation

◆ ExpirationTimer()

Inkscape::Extension::ExpirationTimer::ExpirationTimer ( Extension in_extension)

Create a new expiration timer.

Parameters
in_extensionWhich extension this timer is related to

This function creates the timer, and sets the time to the current time, plus what ever the current timeout is. Also, if this is the first timer extension, the timer is kicked off. This function also sets up the circularly linked list of all the timers.

Definition at line 37 of file timer.cpp.

References expiration, next, timeout, timer_func(), timer_list, and timer_started.

◆ ~ExpirationTimer()

Inkscape::Extension::ExpirationTimer::~ExpirationTimer ( )
virtual

Deletes a ExpirationTimer.

The most complex thing that this function does is remove the timer from the circularly linked list. If this is the only entry in the list that is easy, otherwise all the entries must be found, and this one removed from the list.

Definition at line 67 of file timer.cpp.

References idle_start, next, and timer_list.

Member Function Documentation

◆ expired()

bool Inkscape::Extension::ExpirationTimer::expired ( ) const
private

Check to see if the timer has expired.

Checks the time against the current time.

Definition at line 123 of file timer.cpp.

References current, expiration, and locked.

Referenced by idle_func().

◆ idle_func()

bool Inkscape::Extension::ExpirationTimer::idle_func ( )
staticprivate

This function goes in the idle loop to find expired extensions.

Returns
Whether the function should be requeued or not

This function first insures that there is a timer list, and then checks to see if the one on the top of the list has expired. If it has expired it unloads the module. By unloading the module, the timer gets deleted (happens in the unload function). If the list is no empty, the function returns that it should be dequeued and sets the timer_started variable so that the timer will be reissued when a timer is added. If there is entries left, but the next one is where this function started, then the timer is set up. The timer will then re-add the idle loop function when it runs.

Definition at line 147 of file timer.cpp.

References expired(), extension, idle_start, next, Inkscape::Extension::Extension::set_state(), Inkscape::Extension::Extension::STATE_UNLOADED, timeout, timer_func(), timer_list, and timer_started.

Referenced by timer_func().

◆ lock()

void Inkscape::Extension::ExpirationTimer::lock ( )
inline

Definition at line 55 of file timer.h.

References locked.

◆ set_timeout()

static void Inkscape::Extension::ExpirationTimer::set_timeout ( long  in_seconds)
inlinestatic

Set the timeout variable.

Definition at line 59 of file timer.h.

References timeout.

◆ timer_func()

bool Inkscape::Extension::ExpirationTimer::timer_func ( )
staticprivate

A timer function to set up the idle function.

Returns
Always false – to disable the timer

This function sets up the idle loop when it runs. The idle loop is the one that unloads all the extensions.

Definition at line 191 of file timer.cpp.

References idle_func(), idle_start, and timer_list.

Referenced by ExpirationTimer(), and idle_func().

◆ touch()

void Inkscape::Extension::ExpirationTimer::touch ( )

Touches the timer to extend the length before it expires.

Basically it adds more time to the timer. One thing that is kinda tricky is that it adds half the time remaining back into the timer. This allows for some extensions that are used regularly to having extended expiration times. So, in the end, they stay loaded longer. Extensions that are only used once will expire at a standard rate set by timeout.

Definition at line 106 of file timer.cpp.

References current, expiration, and timeout.

◆ unlock()

void Inkscape::Extension::ExpirationTimer::unlock ( )
inline

Definition at line 56 of file timer.h.

References locked.

Member Data Documentation

◆ expiration

Glib::DateTime Inkscape::Extension::ExpirationTimer::expiration
private

When this timer expires.

Definition at line 41 of file timer.h.

Referenced by ExpirationTimer(), expired(), and touch().

◆ extension

Extension* Inkscape::Extension::ExpirationTimer::extension
private

What extension this function relates to.

Definition at line 43 of file timer.h.

Referenced by idle_func().

◆ idle_start

ExpirationTimer * Inkscape::Extension::ExpirationTimer::idle_start = nullptr
staticprivate

Which timer was on top when we started the idle loop.

Definition at line 30 of file timer.h.

Referenced by idle_func(), timer_func(), and ~ExpirationTimer().

◆ locked

int Inkscape::Extension::ExpirationTimer::locked
private

Is this extension locked from being unloaded?

Definition at line 37 of file timer.h.

Referenced by expired(), lock(), and unlock().

◆ next

ExpirationTimer* Inkscape::Extension::ExpirationTimer::next
private

Next entry in the list.

Definition at line 39 of file timer.h.

Referenced by ExpirationTimer(), idle_func(), and ~ExpirationTimer().

◆ timeout

long Inkscape::Extension::ExpirationTimer::timeout = 240
staticprivate

What the current timeout is (in seconds)

Definition at line 32 of file timer.h.

Referenced by ExpirationTimer(), idle_func(), set_timeout(), and touch().

◆ timer_list

ExpirationTimer * Inkscape::Extension::ExpirationTimer::timer_list = nullptr
staticprivate

Circularly linked list of all timers.

Definition at line 28 of file timer.h.

Referenced by ExpirationTimer(), idle_func(), timer_func(), and ~ExpirationTimer().

◆ timer_started

bool Inkscape::Extension::ExpirationTimer::timer_started = false
staticprivate

Has the timer been started?

Definition at line 34 of file timer.h.

Referenced by ExpirationTimer(), and idle_func().


The documentation for this class was generated from the following files: