Added support for task enumeration in task_manager_t
authorMartin Willi <martin@revosec.ch>
Mon, 7 Jun 2010 08:45:25 +0000 (10:45 +0200)
committerMartin Willi <martin@revosec.ch>
Mon, 7 Jun 2010 08:45:25 +0000 (10:45 +0200)
src/libcharon/sa/task_manager.c
src/libcharon/sa/task_manager.h

index 5b575b5..8bf6d4d 100644 (file)
@@ -1013,6 +1013,22 @@ METHOD(task_manager_t, reset, void,
        this->reset = TRUE;
 }
 
+METHOD(task_manager_t, create_task_enumerator, enumerator_t*,
+       private_task_manager_t *this, task_queue_t queue)
+{
+       switch (queue)
+       {
+               case TASK_QUEUE_ACTIVE:
+                       return this->active_tasks->create_enumerator(this->active_tasks);
+               case TASK_QUEUE_PASSIVE:
+                       return this->passive_tasks->create_enumerator(this->passive_tasks);
+               case TASK_QUEUE_QUEUED:
+                       return this->queued_tasks->create_enumerator(this->queued_tasks);
+               default:
+                       return enumerator_create_empty();
+       }
+}
+
 METHOD(task_manager_t, destroy, void,
        private_task_manager_t *this)
 {
@@ -1043,6 +1059,7 @@ task_manager_t *task_manager_create(ike_sa_t *ike_sa)
                        .reset = _reset,
                        .adopt_tasks = _adopt_tasks,
                        .busy = _busy,
+                       .create_task_enumerator = _create_task_enumerator,
                        .destroy = _destroy,
                },
                .ike_sa = ike_sa,
index 731ed48..14fccd5 100644 (file)
@@ -22,6 +22,7 @@
 #define TASK_MANAGER_H_
 
 typedef struct task_manager_t task_manager_t;
+typedef enum task_queue_t task_queue_t;
 
 #include <limits.h>
 
@@ -55,6 +56,17 @@ typedef struct task_manager_t task_manager_t;
  */
 #define ROUTEABILITY_CHECK_TRIES 10
 
+/**
+ * Type of task queues the task manager uses to handle tasks
+ */
+enum task_queue_t {
+       /** tasks currently active, initiated by us */
+       TASK_QUEUE_ACTIVE,
+       /** passive tasks initiated by the remote peer */
+       TASK_QUEUE_PASSIVE,
+       /** tasks queued for initiated, but not yet activated */
+       TASK_QUEUE_QUEUED,
+};
 
 /**
  * The task manager, juggles task and handles message exchanges.
@@ -158,6 +170,15 @@ struct task_manager_t {
        bool (*busy) (task_manager_t *this);
 
        /**
+        * Create an enumerator over tasks in a specific queue.
+        *
+        * @param queue                 queue to create an enumerator over
+        * @return                              enumerator over task_t
+        */
+       enumerator_t* (*create_task_enumerator)(task_manager_t *this,
+                                                                                       task_queue_t queue);
+
+       /**
         * Destroy the task_manager_t.
         */
        void (*destroy) (task_manager_t *this);