The Assimilation Project  based on Assimilation version 1.1.7.1474836767
resourcequeue.c File Reference

Implements ResourceQueue class. More...

#include <projectcommon.h>
#include <resourcequeue.h>
Include dependency graph for resourcequeue.c:

Go to the source code of this file.

Data Structures

struct  _RscQElem
 
#define uSPERSEC   ((guint64)1000000)
 
typedef struct _RscQElem RscQElem
 
FSTATIC void _resource_queue_hash_data_destructor (gpointer dataptr)
 self->resources is a hash table of GQueue indexed by the resource name. More...
 
FSTATIC void _resource_queue_hash_key_destructor (gpointer keyptr)
 Function for destroying keys when an element is removed from self->resources hash table. More...
 
FSTATIC void _resource_queue_cmd_remove (ResourceQueue *self, RscQElem *qelem)
 Remove the first instance of a ResourceCmd from a ResourceQueue. More...
 
FSTATIC gboolean _resource_queue_Qcmd (ResourceQueue *self, ConfigContext *request, ResourceCmdCallback callback, gpointer user_data)
 Append a ResourceQuee. More...
 
FSTATIC gboolean _resource_queue_cancel (ResourceQueue *self, ConfigContext *request)
 Cancel a specific request. More...
 
FSTATIC void _resource_queue_cancelall (ResourceQueue *self)
 Cancel all outstanding requests. More...
 
FSTATIC gboolean _resource_queue_cmd_append (ResourceQueue *self, ResourceCmd *cmd, ResourceCmdCallback cb, gpointer user_data)
 Append a ResourceCmd to a ResourceQueue. More...
 
FSTATIC void _resource_queue_finalize (AssimObj *aself)
 Finalize a ResourceQueue – RIP. More...
 
FSTATIC RscQElem_resource_queue_qelem_new (ResourceCmd *cmd, ResourceQueue *parent, ResourceCmdCallback callback, gpointer user_data, GQueue *Q)
 Create a new RscQElem object. More...
 
FSTATIC void _resource_queue_qelem_finalize (RscQElem *self)
 Finalize (free) a RscQElem object. More...
 
FSTATIC gboolean _resource_queue_runqueue (gpointer pself)
 Examine our queues and run anything that needs running. More...
 
FSTATIC void _resource_queue_endnotify (ConfigContext *request, gpointer user_data, enum HowDied exittype, int rc, int signal, gboolean core_dumped, const char *stringresult)
 Called when an operation completes - it calls requestor's callback if no repeat, and requeues it if it is going to repeat. More...
 
FSTATIC gint _queue_compare_requestid (gconstpointer a, gconstpointer b)
 Compare the request ids of two different ResourceCmds using GCompareFunc style arguments for use with g_queue_find_custom() More...
 
ResourceQueueresourcequeue_new (guint structsize)
 Construct a new ResourceQueue system (you probably only need one) More...
 

Detailed Description

Implements ResourceQueue class.

Supports the implementation of the Resource Queue class - for queueuing resource requests.

Author
Alan Robertson alanr.nosp@m.@uni.nosp@m.x.sh - Copyright © 2013 - Assimilation Systems Limited
This file is part of the Assimilation Project. The Assimilation software is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

The Assimilation software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with the Assimilation Project software. If not, see http://www.gnu.org/licenses/

Definition in file resourcequeue.c.

Macro Definition Documentation

#define uSPERSEC   ((guint64)1000000)

Class implementing the ResourceQueue class - allowing us to support repeating operations and ensure that only one operation at a time happens on any given resource.

Definition at line 31 of file resourcequeue.c.

Referenced by _resource_queue_endnotify(), and _resource_queue_qelem_new().

Typedef Documentation

typedef struct _RscQElem RscQElem

Definition at line 33 of file resourcequeue.c.

Function Documentation

FSTATIC gint _queue_compare_requestid ( gconstpointer  a,
gconstpointer  b 
)

Compare the request ids of two different ResourceCmds using GCompareFunc style arguments for use with g_queue_find_custom()

Definition at line 155 of file resourcequeue.c.

References CASTTOCONSTCLASS, FSTATIC, and _RscQElem::requestid.

Referenced by _resource_queue_cmd_append().

Here is the caller graph for this function:

FSTATIC gboolean _resource_queue_cancel ( ResourceQueue self,
ConfigContext request 
)

Cancel a specific request.

Definition at line 223 of file resourcequeue.c.

References _resource_queue_cmd_remove(), CASTTOCLASS, CONFIGNAME_INSTANCE, FSTATIC, _ConfigContext::getint, _ConfigContext::getstring, REQIDENTIFIERNAMEFIELD, and _RscQElem::requestid.

Referenced by _resource_queue_cancelall(), and resourcequeue_new().

Here is the call graph for this function:

Here is the caller graph for this function:

FSTATIC void _resource_queue_cancelall ( ResourceQueue self)

Cancel all outstanding requests.

Definition at line 204 of file resourcequeue.c.

References _resource_queue_cancel(), CASTTOCLASS, _RscQElem::cmd, FSTATIC, and _ResourceCmd::request.

Referenced by resourcequeue_new().

Here is the call graph for this function:

Here is the caller graph for this function:

FSTATIC gboolean _resource_queue_cmd_append ( ResourceQueue self,
ResourceCmd cmd,
ResourceCmdCallback  cb,
gpointer  user_data 
)

Append a ResourceCmd to a ResourceQueue.

Definition at line 165 of file resourcequeue.c.

References __FUNCTION__, _queue_compare_requestid(), _resource_queue_qelem_finalize(), _resource_queue_qelem_new(), _resource_queue_runqueue(), FMT_64BIT, FSTATIC, g_info, _ConfigContext::getint, REQIDENTIFIERNAMEFIELD, _ResourceCmd::request, _RscQElem::requestid, _ResourceCmd::resourcename, and _ResourceCmd::user_data.

Referenced by _resource_queue_Qcmd().

Here is the call graph for this function:

Here is the caller graph for this function:

FSTATIC void _resource_queue_cmd_remove ( ResourceQueue self,
RscQElem qelem 
)

Remove the first instance of a ResourceCmd from a ResourceQueue.

Definition at line 276 of file resourcequeue.c.

References _resource_queue_qelem_finalize(), _RscQElem::cmd, FSTATIC, g_queue_remove_boolean(), _RscQElem::ourQ, and _ResourceCmd::resourcename.

Referenced by _resource_queue_cancel().

Here is the call graph for this function:

Here is the caller graph for this function:

FSTATIC void _resource_queue_endnotify ( ConfigContext request,
gpointer  user_data,
enum HowDied  exittype,
int  rc,
int  signal,
gboolean  core_dumped,
const char *  stringresult 
)

Called when an operation completes - it calls requestor's callback if no repeat, and requeues it if it is going to repeat.

Definition at line 408 of file resourcequeue.c.

References __FUNCTION__, _resource_queue_finalize(), _resource_queue_qelem_finalize(), _resource_queue_runqueue(), _ResourceQueue::activechildcnt, _ResourceQueue::baseclass, CASTTOCLASS, _RscQElem::cmd, DEBUGMSG1, DEBUGMSG3, EXITED_ZERO, FMT_64BIT, g_get_monotonic_time(), _ResourceCmd::last_success, _ResourceCmd::loggingname, _RscQElem::parent, _ResourceCmd::resourcename, _ResourceQueue::shuttingdown, _ResourceCmd::starttime, UNREF, and uSPERSEC.

Referenced by _resource_queue_Qcmd(), and _resource_queue_runqueue().

Here is the call graph for this function:

Here is the caller graph for this function:

FSTATIC void _resource_queue_finalize ( AssimObj aself)

Finalize a ResourceQueue – RIP.

Definition at line 107 of file resourcequeue.c.

References _assimobj_finalize(), CASTTOCLASS, and FSTATIC.

Referenced by _resource_queue_endnotify(), and resourcequeue_new().

Here is the call graph for this function:

Here is the caller graph for this function:

FSTATIC void _resource_queue_hash_data_destructor ( gpointer  dataptr)

self->resources is a hash table of GQueue indexed by the resource name.

Function for destroying data when an element is removed from self->resources hash table.

The resource name duplicates a field in the ResourceCmd. Each GQueue element has a RscQElem* as its data element. As a given ResourceCmd completes, we remove its RscQElem from its queue. If it repeats, then we put it on the end of its queue with a delay before executing. If it won't repeat, then we call its callback and UNREF it.

Definition at line 334 of file resourcequeue.c.

References _resource_queue_qelem_finalize(), CASTTOCLASS, and FSTATIC.

Referenced by resourcequeue_new().

Here is the call graph for this function:

Here is the caller graph for this function:

FSTATIC void _resource_queue_hash_key_destructor ( gpointer  dataptr)

Function for destroying keys when an element is removed from self->resources hash table.

Definition at line 350 of file resourcequeue.c.

References FSTATIC.

Referenced by resourcequeue_new().

Here is the caller graph for this function:

FSTATIC gboolean _resource_queue_Qcmd ( ResourceQueue self,
ConfigContext request,
ResourceCmdCallback  callback,
gpointer  user_data 
)

Append a ResourceQuee.

Definition at line 128 of file resourcequeue.c.

References _resource_queue_cmd_append(), _resource_queue_endnotify(), _RscQElem::callback, _RscQElem::cmd, EXITED_INVAL, FSTATIC, resourcecmd_new(), and UNREF.

Referenced by resourcequeue_new().

Here is the call graph for this function:

Here is the caller graph for this function:

FSTATIC void _resource_queue_qelem_finalize ( RscQElem self)

Finalize (free) a RscQElem object.

Definition at line 324 of file resourcequeue.c.

References __FUNCTION__, DEBUGMSG3, FREECLASSOBJ, FSTATIC, and UNREF.

Referenced by _resource_queue_cmd_append(), _resource_queue_cmd_remove(), _resource_queue_endnotify(), and _resource_queue_hash_data_destructor().

Here is the caller graph for this function:

FSTATIC RscQElem * _resource_queue_qelem_new ( ResourceCmd cmd,
ResourceQueue parent,
ResourceCmdCallback  cb,
gpointer  user_data,
GQueue *  Q 
)
FSTATIC gboolean _resource_queue_runqueue ( gpointer  pself)

Examine our queues and run anything that needs running.

(this code is more expensive than it could be, but in practice it may not matter)

Definition at line 359 of file resourcequeue.c.

References __FUNCTION__, _resource_queue_endnotify(), CASTTOCLASS, _RscQElem::cmd, DEBUGMSG3, DEBUGMSG4, _ResourceCmd::execute, FSTATIC, g_get_monotonic_time(), _ResourceCmd::is_running, REF, and _ResourceCmd::starttime.

Referenced by _resource_queue_cmd_append(), _resource_queue_endnotify(), and resourcequeue_new().

Here is the call graph for this function:

Here is the caller graph for this function:

ResourceQueue* resourcequeue_new ( guint  structsize)