- moved queues into subfolder queues
authorMartin Willi <martin@strongswan.org>
Fri, 11 Nov 2005 13:31:52 +0000 (13:31 -0000)
committerMartin Willi <martin@strongswan.org>
Fri, 11 Nov 2005 13:31:52 +0000 (13:31 -0000)
- created subdirectory utils for linked_list_t and co.

35 files changed:
Source/charon/event_queue.c [deleted file]
Source/charon/event_queue.h [deleted file]
Source/charon/globals.h
Source/charon/ike_sa.c
Source/charon/ike_sa_manager.c
Source/charon/job_queue.c [deleted file]
Source/charon/job_queue.h [deleted file]
Source/charon/linked_list.c [deleted file]
Source/charon/linked_list.h [deleted file]
Source/charon/logger_manager.c
Source/charon/message.c
Source/charon/queues/event_queue.c [new file with mode: 0644]
Source/charon/queues/event_queue.h [new file with mode: 0644]
Source/charon/queues/job_queue.c [new file with mode: 0644]
Source/charon/queues/job_queue.h [new file with mode: 0644]
Source/charon/queues/send_queue.c [new file with mode: 0644]
Source/charon/queues/send_queue.h [new file with mode: 0644]
Source/charon/receiver.c
Source/charon/scheduler.c
Source/charon/send_queue.c [deleted file]
Source/charon/send_queue.h [deleted file]
Source/charon/sender.c
Source/charon/testcases/event_queue_test.c
Source/charon/testcases/job_queue_test.c
Source/charon/testcases/linked_list_test.c
Source/charon/testcases/receiver_test.c
Source/charon/testcases/scheduler_test.c
Source/charon/testcases/send_queue_test.c
Source/charon/testcases/sender_test.c
Source/charon/testcases/testcases.c [new file with mode: 0644]
Source/charon/tester.c
Source/charon/tests.c [deleted file]
Source/charon/thread_pool.c
Source/charon/utils/linked_list.c [new file with mode: 0644]
Source/charon/utils/linked_list.h [new file with mode: 0644]

diff --git a/Source/charon/event_queue.c b/Source/charon/event_queue.c
deleted file mode 100644 (file)
index a6c1197..0000000
+++ /dev/null
@@ -1,380 +0,0 @@
-/**
- * @file event_queue.c
- *
- * @brief Event-Queue based on class linked_list_t
- *
- */
-
-/*
- * Copyright (C) 2005 Jan Hutter, Martin Willi
- * Hochschule fuer Technik Rapperswil
- *
- * This program 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 2 of the License, or (at your
- * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
- *
- * This program 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.
- */
-
-#include <pthread.h>
-#include <stdlib.h>
-
-#include "allocator.h"
-#include "types.h"
-#include "event_queue.h"
-#include "linked_list.h"
-
-
-
-/**
- * @brief Represents an event as it is stored in the event queue.
- *
- * A event consists of a event time and an assigned job object.
- *
- */
-typedef struct event_s event_t;
-
-struct event_s{
-       /**
-        * Time to fire the event.
-        */
-       timeval_t time;
-
-       /**
-        * Every event has its assigned job.
-        */
-       job_t * job;
-
-       /**
-        * @brief Destroys a event_t object.
-        *
-        * @param event_t       calling object
-        * @returns                     always SUCCESS
-        */
-       status_t (*destroy) (event_t *event);
-};
-
-
-/**
- * @brief implements function destroy of event_t
- */
-static status_t event_destroy(event_t *event)
-{
-       allocator_free(event);
-       return SUCCESS;
-}
-
-/**
- * @brief Creates a event for a specific time
- *
- * @param time absolute time to fire the event
- * @param job  job to add to job-queue at specific time
- *
- * @returns
- *                             - created event_t object 
- *                             - NULL if memory allocation failed
- */
-static event_t *event_create(timeval_t time, job_t *job)
-{
-       event_t *this = allocator_alloc_thing(event_t);
-       if (this == NULL)
-       {
-               return this;
-       }
-
-       this->destroy = event_destroy;
-       this->time = time;
-       this->job = job;
-
-       return this;
-}
-
-
-/**
- * @brief Private Variables and Functions of event_queue_t class.
- *
- */
-typedef struct private_event_queue_s private_event_queue_t;
-
-
-struct private_event_queue_s {
-       /**
-        * Public part.
-        */
-       event_queue_t public;
-
-       /**
-        * The events are stored in a linked list of type linked_list_t.
-        */
-       linked_list_t *list;
-
-       /**
-        * Access to linked_list is locked through this mutex.
-        */
-       pthread_mutex_t mutex;
-
-       /**
-        * If the queue is empty or an event has not to be fired
-        * a thread has to wait.
-        * 
-        * This condvar is used to wake up such a thread.
-        */
-       pthread_cond_t condvar;
-};
-
-/**
- * Returns the difference of to timeval structs in microseconds
- *
- * @param end_time             end time
- * @param start_time   start time
- *
- * @warning this function is also defined in the tester class
- *                     In later improvements, this function can be added to a general
- *          class type!
- *
- * @return     difference in microseconds (end time - start time)
- */
-static long time_difference(struct timeval *end_time, struct timeval *start_time)
-{
-       long seconds, microseconds;
-
-       seconds = (end_time->tv_sec - start_time->tv_sec);
-       microseconds = (end_time->tv_usec - start_time->tv_usec);
-       return ((seconds * 1000000) + microseconds);
-}
-
-
-/**
- * Implements function get_count of event_queue_t.
- * See #event_queue_s.get_count for description.
- */
-static int get_count (private_event_queue_t *this)
-{
-       int count;
-       pthread_mutex_lock(&(this->mutex));
-       count = this->list->get_count(this->list);
-       pthread_mutex_unlock(&(this->mutex));
-       return count;
-}
-
-/**
- * Implements function get of event_queue_t.
- * See #event_queue_s.get for description.
- */
-static status_t get(private_event_queue_t *this, job_t **job)
-{
-       timespec_t timeout;
-       timeval_t current_time;
-       event_t * next_event;
-       int oldstate;
-
-       pthread_mutex_lock(&(this->mutex));
-
-       while (1)
-       {
-               while(this->list->get_count(this->list) == 0)
-               {
-                       /* add mutex unlock handler for cancellation, enable cancellation */
-                       pthread_cleanup_push((void(*)(void*))pthread_mutex_unlock, (void*)&(this->mutex));
-                       pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
-
-                       pthread_cond_wait( &(this->condvar), &(this->mutex));
-
-                       /* reset cancellation, remove mutex-unlock handler (without executing) */
-                       pthread_setcancelstate(oldstate, NULL);
-                       pthread_cleanup_pop(0);
-               }
-
-               this->list->get_first(this->list,(void **) &next_event);
-
-               gettimeofday(&current_time,NULL);
-               long difference = time_difference(&current_time,&(next_event->time));
-               if (difference <= 0)
-               {
-                       timeout.tv_sec = next_event->time.tv_sec;
-            timeout.tv_nsec = next_event->time.tv_usec * 1000;
-
-                       pthread_cond_timedwait( &(this->condvar), &(this->mutex),&timeout);
-               }
-               else
-               {
-                       /* event available */
-                       this->list->remove_first(this->list,(void **) &next_event);
-
-                       *job = next_event->job;
-
-                       next_event->destroy(next_event);
-                       break;
-               }
-
-       }
-       pthread_cond_signal( &(this->condvar));
-
-       pthread_mutex_unlock(&(this->mutex));
-
-       return SUCCESS;
-}
-
-/**
- * Implements function add_absolute of event_queue_t.
- * See #event_queue_s.add_absolute for description.
- */
-static status_t add_absolute(private_event_queue_t *this, job_t *job, timeval_t time)
-{
-       event_t *event = event_create(time,job);
-       event_t *current_event;
-       status_t status;
-
-       if (event == NULL)
-       {
-               return FAILED;
-       }
-       pthread_mutex_lock(&(this->mutex));
-
-       /* while just used to break out */
-       while(1)
-       {
-               if (this->list->get_count(this->list) == 0)
-               {
-                       status = this->list->insert_first(this->list,event);
-                       break;
-               }
-
-               /* check last entry */
-               this->list->get_last(this->list,(void **) &current_event);
-
-               if (time_difference(&(event->time), &(current_event->time)) >= 0)
-               {
-                       /* my event has to be fired after the last event in list */
-                       status = this->list->insert_last(this->list,event);
-                       break;
-               }
-
-               /* check first entry */
-               this->list->get_first(this->list,(void **) &current_event);
-
-               if (time_difference(&(event->time), &(current_event->time)) < 0)
-               {
-                       /* my event has to be fired before the first event in list */
-                       status = this->list->insert_first(this->list,event);
-                       break;
-               }
-
-               linked_list_iterator_t * iterator;
-
-               status = this->list->create_iterator(this->list,&iterator,TRUE);
-               if (status != SUCCESS)
-               {
-                       break;
-               }
-
-
-               iterator->has_next(iterator);
-               /* first element has not to be checked (already done) */
-
-               while(iterator->has_next(iterator))
-               {
-                       status = iterator->current(iterator,(void **) &current_event);
-
-                       if (time_difference(&(event->time), &(current_event->time)) <= 0)
-                       {
-                               /* my event has to be fired before the current event in list */
-                               status = this->list->insert_before(this->list,iterator,event);
-                               break;
-                       }
-               }
-               iterator->destroy(iterator);
-               break;
-       }
-
-       pthread_cond_signal( &(this->condvar));
-       pthread_mutex_unlock(&(this->mutex));
-
-       if (status != SUCCESS)
-       {
-               event->destroy(event);
-       }
-       return status;
-}
-
-/**
- * Implements function add_relative of event_queue_t.
- * See #event_queue_s.add_relative for description.
- */
-static status_t add_relative(event_queue_t *this, job_t *job, u_int32_t ms)
-{
-       timeval_t current_time;
-       timeval_t time;
-       int micros = ms * 1000;
-
-       gettimeofday(&current_time, NULL);
-
-       time.tv_usec = ((current_time.tv_usec + micros) % 1000000);
-       time.tv_sec = current_time.tv_sec + ((current_time.tv_usec + micros)/ 1000000);
-
-       return this->add_absolute(this, job, time);
-}
-
-
-/**
- * Implements function destroy of event_queue_t.
- * See #event_queue_s.destroy for description.
- */
-static status_t event_queue_destroy(private_event_queue_t *this)
-{
-       while (this->list->get_count(this->list) > 0)
-       {
-               event_t *event;
-
-               if (this->list->remove_first(this->list,(void *) &event) != SUCCESS)
-               {
-                       this->list->destroy(this->list);
-                       break;
-               }
-               event->job->destroy(event->job);
-               event->destroy(event);
-       }
-       this->list->destroy(this->list);
-
-       pthread_mutex_destroy(&(this->mutex));
-
-       pthread_cond_destroy(&(this->condvar));
-
-       allocator_free(this);
-       return SUCCESS;
-}
-
-/*
- * Documented in header
- */
-event_queue_t *event_queue_create()
-{
-       linked_list_t *linked_list = linked_list_create();
-       if (linked_list == NULL)
-       {
-               return NULL;
-       }
-
-       private_event_queue_t *this = allocator_alloc_thing(private_event_queue_t);
-       if (this == NULL)
-       {
-               linked_list->destroy(linked_list);
-               return NULL;
-       }
-
-       this->public.get_count = (int (*) (event_queue_t *event_queue)) get_count;
-       this->public.get = (status_t (*) (event_queue_t *event_queue, job_t **job)) get;
-       this->public.add_absolute = (status_t (*) (event_queue_t *event_queue, job_t *job, timeval_t time)) add_absolute;
-       this->public.add_relative = (status_t (*) (event_queue_t *event_queue, job_t *job, u_int32_t ms)) add_relative;
-       this->public.destroy = (status_t (*) (event_queue_t *event_queue)) event_queue_destroy;
-
-       this->list = linked_list;
-       pthread_mutex_init(&(this->mutex), NULL);
-       pthread_cond_init(&(this->condvar), NULL);
-
-       return (&this->public);
-}
diff --git a/Source/charon/event_queue.h b/Source/charon/event_queue.h
deleted file mode 100644 (file)
index 0fd6538..0000000
+++ /dev/null
@@ -1,114 +0,0 @@
-/**
- * @file event_queue.h
- *
- * @brief Event-Queue based on class linked_list_t
- *
- */
-
-/*
- * Copyright (C) 2005 Jan Hutter, Martin Willi
- * Hochschule fuer Technik Rapperswil
- *
- * This program 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 2 of the License, or (at your
- * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
- *
- * This program 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.
- */
-
-#ifndef EVENT_QUEUE_H_
-#define EVENT_QUEUE_H_
-
-#include <sys/time.h>
-
-#include "types.h"
-#include "job.h"
-
-/**
- * @brief Event-Queue used to store timed events.
- *
- * Although the event-queue is based on a linked_list_t
- * all access functions are thread-save implemented.
- */
-typedef struct event_queue_s event_queue_t;
-
-struct event_queue_s {
-
-       /**
-        * @brief Returns number of events in queue.
-        *
-        * @param event_queue   calling object
-        * @return                              number of events in queue
-        */
-       int (*get_count) (event_queue_t *event_queue);
-
-       /**
-        * @brief Get the next job from the event-queue.
-        *
-        * If no event is pending, this function blocks until a job can be returned.
-        *
-        * @param event_queue   calling object
-        * @param[out] job              pointer to a job pointer where to job is returned to
-        * @return                              - SUCCESS if succeeded
-        *                                              - FAILED otherwisesa
-        */
-       status_t (*get) (event_queue_t *event_queue, job_t **job);
-
-       /**
-        * @brief Adds a event to the queue, using a relative time.
-        *
-        * This function is non blocking and adds a job_t at a specific time to the list.
-        * The specific job object has to get destroyed by the thread which
-        * removes the job.
-        *
-        * @param event_queue   calling object
-        * @param[in] job               job to add to the queue (job is not copied)
-        * @param[in] time              relative time, when the event has to get fired
-        * @returns
-        *                                              - SUCCESS if succeeded
-        *                                              - FAILED otherwise
-        */
-       status_t (*add_relative) (event_queue_t *event_queue, job_t *job, u_int32_t ms);
-
-       /**
-        * @brief Adds a event to the queue, using an absolute time.
-        *
-        * This function is non blocking and adds a job_t at a specific time to the list.
-        * The specific job object has to get destroyed by the thread which
-        * removes the job.
-        *
-        * @param event_queue   calling object
-        * @param[in]                   job job to add to the queue (job is not copied)
-        * @param[in]                   absolute time time, when the event has to get fired
-        * @returns
-        *                                              - SUCCESS if succeeded
-        *                                              - FAILED otherwise
-        */
-       status_t (*add_absolute) (event_queue_t *event_queue, job_t *job, timeval_t time);
-
-       /**
-        * @brief Destroys a event_queue object.
-        *
-        * @warning The caller of this function has to make sure
-        * that no thread is going to add or get an event from the event_queue
-        * after calling this function.
-        *
-        * @param event_queue   calling object
-        * @returns                             always SUCCESS
-        */
-       status_t (*destroy) (event_queue_t *event_queue);
-};
-
-/**
- * @brief Creates an empty event_queue
- *
- * @returns
- *                     - Empty event_queue_t object
- *                     - NULL if memory allocation failed
- */
-event_queue_t *event_queue_create();
-#endif /*EVENT_QUEUE_H_*/
index 50742b2..d690277 100644 (file)
@@ -23,9 +23,9 @@
 #ifndef GLOBALS_H_
 #define GLOBALS_H_
 
-#include "send_queue.h"
-#include "job_queue.h"
-#include "event_queue.h"
+#include "queues/send_queue.h"
+#include "queues/job_queue.h"
+#include "queues/event_queue.h"
 #include "socket.h"
 #include "logger_manager.h"
 
index df77185..5afbce9 100644 (file)
@@ -23,7 +23,7 @@
 
 #include "allocator.h"
 #include "types.h"
-#include "linked_list.h"
+#include "utils/linked_list.h"
 #include "ike_sa.h"
 
 
index 5bb9035..0012cea 100644 (file)
@@ -25,7 +25,7 @@
 
 #include "allocator.h"
 #include "ike_sa_manager.h"
-#include "linked_list.h"
+#include "utils/linked_list.h"
 #include "ike_sa_id.h"
 
 /**
diff --git a/Source/charon/job_queue.c b/Source/charon/job_queue.c
deleted file mode 100644 (file)
index d14289b..0000000
+++ /dev/null
@@ -1,161 +0,0 @@
-/**
- * @file job_queue.c
- *
- * @brief Job-Queue based on linked_list_t
- *
- */
-
-/*
- * Copyright (C) 2005 Jan Hutter, Martin Willi
- * Hochschule fuer Technik Rapperswil
- *
- * This program 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 2 of the License, or (at your
- * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
- *
- * This program 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.
- */
-
-#include <stdlib.h>
-#include <pthread.h>
-
-#include "allocator.h"
-#include "job_queue.h"
-#include "linked_list.h"
-
-/**
- * @brief Private Variables and Functions of job_queue class
- *
- */
-typedef struct private_job_queue_s private_job_queue_t;
-
-
-struct private_job_queue_s {
-       job_queue_t public;
-
-       /**
-        * The jobs are stored in a linked list
-        */
-       linked_list_t *list;
-       /**
-        * access to linked_list is locked through this mutex
-        */
-       pthread_mutex_t mutex;
-
-       /**
-        * If the queue is empty a thread has to wait
-        * This condvar is used to wake up such a thread
-        */
-       pthread_cond_t condvar;
-};
-
-
-/**
- * @brief implements function get_count of job_queue_t
- */
-static int get_count(private_job_queue_t *this)
-{
-       int count;
-       pthread_mutex_lock(&(this->mutex));
-       count = this->list->get_count(this->list);
-       pthread_mutex_unlock(&(this->mutex));
-       return count;
-}
-
-/**
- * @brief implements function get of job_queue_t
- */
-static status_t get(private_job_queue_t *this, job_t **job)
-{
-       int oldstate;
-       pthread_mutex_lock(&(this->mutex));
-       /* go to wait while no jobs available */
-       while(this->list->get_count(this->list) == 0)
-       {
-               /* add mutex unlock handler for cancellation, enable cancellation */
-               pthread_cleanup_push((void(*)(void*))pthread_mutex_unlock, (void*)&(this->mutex));
-               pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
-
-               pthread_cond_wait( &(this->condvar), &(this->mutex));
-
-               /* reset cancellation, remove mutex-unlock handler (without executing) */
-               pthread_setcancelstate(oldstate, NULL);
-               pthread_cleanup_pop(0);
-       }
-       this->list->remove_first(this->list,(void **) job);
-       pthread_mutex_unlock(&(this->mutex));
-       return SUCCESS;
-}
-
-/**
- * @brief implements function add of job_queue_t
- */
-static status_t add(private_job_queue_t *this, job_t *job)
-{
-       pthread_mutex_lock(&(this->mutex));
-       this->list->insert_last(this->list,job);
-       pthread_cond_signal( &(this->condvar));
-       pthread_mutex_unlock(&(this->mutex));
-       return SUCCESS;
-}
-
-/**
- * @brief implements function destroy of job_queue_t
- *
- */
-static status_t job_queue_destroy (private_job_queue_t *this)
-{
-       while (this->list->get_count(this->list) > 0)
-       {
-               job_t *job;
-               if (this->list->remove_first(this->list,(void *) &job) != SUCCESS)
-               {
-                       this->list->destroy(this->list);
-                       break;
-               }
-               job->destroy(job);
-       }
-       this->list->destroy(this->list);
-
-       pthread_mutex_destroy(&(this->mutex));
-
-       pthread_cond_destroy(&(this->condvar));
-
-       allocator_free(this);
-       return SUCCESS;
-}
-
-/*
- *
- * Documented in header
- */
-job_queue_t *job_queue_create()
-{
-       linked_list_t *linked_list = linked_list_create();
-       if (linked_list == NULL)
-       {
-               return NULL;
-       }
-
-       private_job_queue_t *this = allocator_alloc_thing(private_job_queue_t);
-       if (this == NULL)
-       {
-               linked_list->destroy(linked_list);
-               return NULL;
-       }
-
-       this->public.get_count = (int(*)(job_queue_t*))get_count;
-       this->public.get = (status_t(*)(job_queue_t*, job_t**))get;
-       this->public.add = (status_t(*)(job_queue_t*, job_t*))add;
-       this->public.destroy = (status_t(*)(job_queue_t*))job_queue_destroy;
-
-       this->list = linked_list;
-       pthread_mutex_init(&(this->mutex), NULL);
-       pthread_cond_init(&(this->condvar), NULL);
-
-       return (&this->public);
-}
diff --git a/Source/charon/job_queue.h b/Source/charon/job_queue.h
deleted file mode 100644 (file)
index 62f9283..0000000
+++ /dev/null
@@ -1,92 +0,0 @@
-/**
- * @file job_queue.h
- *
- * @brief Job-Queue based on linked_list_t
- *
- */
-
-/*
- * Copyright (C) 2005 Jan Hutter, Martin Willi
- * Hochschule fuer Technik Rapperswil
- *
- * This program 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 2 of the License, or (at your
- * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
- *
- * This program 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.
- */
-
-#ifndef JOB_QUEUE_H_
-#define JOB_QUEUE_H_
-
-#include "types.h"
-#include "job.h"
-
-/**
- * @brief Job-Queue
- *
- * Although the job-queue is based on a linked_list_t
- * all access functions are thread-save implemented
- */
-typedef struct job_queue_s job_queue_t;
-
-struct job_queue_s {
-
-       /**
-        * @brief returns number of jobs in queue
-        *
-        * @param job_queue_t calling object
-        * @returns number of items in queue
-        */
-       int (*get_count) (job_queue_t *job_queue);
-
-       /**
-        * @brief get the next job from the queue
-        *
-        * If the queue is empty, this function blocks until a job can be returned.
-        *
-        * After using, the returned job has to get destroyed by the caller.
-        *
-        * @param job_queue_t calling object
-        * @param[out] job pointer to a job pointer where to job is returned to
-        * @returns SUCCESS if succeeded, FAILED otherwise
-        */
-       status_t (*get) (job_queue_t *job_queue, job_t **job);
-
-       /**
-        * @brief adds a job to the queue
-        *
-        * This function is non blocking and adds a job_t to the list.
-        * The specific job object has to get destroyed by the thread which
-        * removes the job.
-        *
-        * @param job_queue_t calling object
-        * @param[in] job job to add to the queue (job is not copied)
-        * @returns SUCCESS if succeeded, FAILED otherwise
-        */
-       status_t (*add) (job_queue_t *job_queue, job_t *job);
-
-       /**
-        * @brief destroys a job_queue object
-        *
-        * @warning The caller of this function has to make sure
-        * that no thread is going to add or get a job from the job_queue
-        * after calling this function.
-        *
-        * @param job_queue_t calling object
-        * @returns SUCCESS if succeeded, FAILED otherwise
-        */
-       status_t (*destroy) (job_queue_t *job_queue);
-};
-
-/**
- * @brief Creates an empty job_queue
- *
- * @return job_queue_t empty job_queue
- */
-job_queue_t *job_queue_create();
-#endif /*JOB_QUEUE_H_*/
diff --git a/Source/charon/linked_list.c b/Source/charon/linked_list.c
deleted file mode 100644 (file)
index e1a5157..0000000
+++ /dev/null
@@ -1,698 +0,0 @@
-/**
- * @file linked_list.c
- *
- * @brief Generic Double Linked List
- *
- */
-
-/*
- * Copyright (C) 2005 Jan Hutter, Martin Willi
- * Hochschule fuer Technik Rapperswil
- *
- * This program 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 2 of the License, or (at your
- * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
- *
- * This program 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.
- */
-
-#include <stdlib.h>
-
-#include "allocator.h"
-#include "linked_list.h"
-
-
-typedef struct linked_list_element_s linked_list_element_t;
-
-
-/**
- * @brief Element of the linked_list.
- *
- * This element holds a pointer to the value of the list item itself.
- */
-struct linked_list_element_s{
-       /**
-        * value of a list item
-        */
-       void *value;
-
-       /**
-        * @brief Destroys a linked_list_element object
-        *
-        * @param linked_list_element_t calling object
-        * @returns SUCCESS if succeeded, FAILED otherwise
-        */
-       status_t (*destroy) (linked_list_element_t *this);
-
-       /**
-        * previous list element
-        * NULL if first element in list
-        */
-       linked_list_element_t *previous;
-       /**
-        * next list element
-        * NULL if last element in list
-        */
-       linked_list_element_t *next;
-};
-
-/**
- * @brief implements function destroy of linked_list_item_t
- */
-static status_t linked_list_element_destroy(linked_list_element_t *this)
-{
-       if (this == NULL)
-       {
-               return FAILED;
-       }
-       allocator_free(this);
-       return SUCCESS;
-}
-
-/**
- * @brief Creates an empty linked list object
- *
- * @param[in] value value of item to be set
- *
- * @warning only the pointer to the value is stored
- *
- * @return linked_list_element object
- */
-
-linked_list_element_t *linked_list_element_create(void *value)
-{
-       linked_list_element_t *this = allocator_alloc_thing(linked_list_element_t);
-
-       if (this == NULL)
-       {
-               return NULL;
-       }
-
-       this->destroy = linked_list_element_destroy;
-
-       this->previous=NULL;
-       this->next=NULL;
-       this->value = value;
-
-       return (this);
-}
-
-/**
- * Private variables and functions of linked list
- *
- */
-typedef struct private_linked_list_s private_linked_list_t;
-
-struct private_linked_list_s{
-       /**
-        * Public part of linked list
-        */
-       linked_list_t public;
-
-       /**
-        * number of items in the list
-        */
-       int count;
-
-       /**
-        * First element in list
-        * NULL if no elements in list
-        */
-       linked_list_element_t *first;
-       /**
-        * Last element in list
-        * NULL if no elements in list
-        */
-       linked_list_element_t *last;
-};
-
-
-/**
- * Private variables and functions of linked list iterator
- *
- */
-typedef struct private_linked_list_iterator_s private_linked_list_iterator_t;
-
-struct private_linked_list_iterator_s{
-       /**
-        * Public part of linked list iterator
-        */
-       linked_list_iterator_t public;
-
-       /**
-        * associated linked list
-        */
-       private_linked_list_t * list;
-
-       /**
-        * current element of the iterator
-        */
-       linked_list_element_t *current;
-
-       /**
-        * direction of iterator
-        */
-       bool forward;
-};
-
-/**
- * Implements function has_next of linked_list_iteratr
- */
-bool iterator_has_next(private_linked_list_iterator_t *this)
-{
-       if (this->list->count == 0)
-       {
-               return FALSE;
-       }
-       if (this->current == NULL)
-       {
-               this->current = (this->forward) ? this->list->first : this->list->last;
-               return TRUE;
-       }
-       if (this->forward)
-       {
-               if (this->current->next == NULL)
-               {
-                       return FALSE;
-               }
-               this->current = this->current->next;
-               return TRUE;
-       }
-       /* backward */
-       if (this->current->previous == NULL)
-       {
-               return FALSE;
-       }
-       this->current = this->current->previous;
-       return TRUE;
-}
-
-/**
- * Implements function current of linked_list_iteratr
- */
-static status_t iterator_current(private_linked_list_iterator_t *this, void **value)
-{
-       if (this == NULL)
-       {
-               return FAILED;
-       }
-       if (this->current == NULL)
-       {
-               return FAILED;
-       }
-       *value = this->current->value;
-       return SUCCESS;
-}
-
-/**
- * Implements function current of linked_list_iteratr
- */
-static status_t iterator_reset(private_linked_list_iterator_t *this)
-{
-       if (this == NULL)
-       {
-               return FAILED;
-       }
-       this->current = NULL;
-       return SUCCESS;
-}
-
-/**
- * Implements function destroy of linked_list_iteratr
- */
-static status_t iterator_destroy(private_linked_list_iterator_t *this)
-{
-       if (this == NULL)
-       {
-               return FAILED;
-       }
-       allocator_free(this);
-       return SUCCESS;
-}
-
-/**
- * @brief implements function get_count of linked_list_t
- */
-static int get_count(private_linked_list_t *this)
-{
-       return this->count;
-}
-
-
-static status_t create_iterator (private_linked_list_t *linked_list, linked_list_iterator_t **iterator,bool forward)
-{
-       private_linked_list_iterator_t *this = allocator_alloc_thing(private_linked_list_iterator_t);
-
-       if (this == NULL)
-       {
-               return FAILED;
-       }
-
-       this->public.has_next = (bool (*) (linked_list_iterator_t *this)) iterator_has_next;
-       this->public.current = (status_t (*) (linked_list_iterator_t *this, void **value)) iterator_current;
-       this->public.reset = (status_t (*) (linked_list_iterator_t *this)) iterator_reset;
-       this->public.destroy = (status_t (*) (linked_list_iterator_t *this)) iterator_destroy;
-
-
-       this->forward = forward;
-       this->current = NULL;
-       this->list = linked_list;
-
-       *iterator = &(this->public);
-
-       return (SUCCESS);
-}
-
-
-/**
- * @brief implements function insert_first of linked_list_t
- */
-static status_t insert_first(private_linked_list_t *this, void *item)
-{
-       linked_list_element_t *element;
-
-       if (this == NULL)
-       {
-               return FAILED;
-       }
-
-       element =(linked_list_element_t *) linked_list_element_create(item);
-
-       if (element == NULL)
-       {
-               return FAILED;
-       }
-
-       if (this->count == 0)
-       {
-               /* first entry in list */
-               this->first = element;
-               this->last = element;
-               element->previous = NULL;
-               element->next = NULL;
-       }
-       else
-       {
-               if ((this->first == NULL) || (this->last == NULL))
-               {
-                       /* should never happen */
-                       element->destroy(element);
-                       return FAILED;
-               }
-               linked_list_element_t *old_first_element = this->first;
-               element->next = old_first_element;
-               element->previous = NULL;
-               old_first_element->previous = element;
-               this->first = element;
-       }
-
-       this->count++;
-
-       return SUCCESS;
-}
-
-/**
- * @brief implements function remove_first of linked_list_t
- */
-static status_t remove_first(private_linked_list_t *this, void **item)
-{
-       if (this == NULL)
-       {
-               return FAILED;
-       }
-
-       if (this->count == 0)
-       {
-               return FAILED;
-       }
-
-       if (this->first == NULL)
-       {
-               return FAILED;
-       }
-
-       linked_list_element_t *element = this->first;
-
-       if (element->next != NULL)
-       {
-               element->next->previous = NULL;
-       }
-       this->first = element->next;
-
-       *item = element->value;
-
-       this->count--;
-
-       return  (element->destroy(element));
-}
-
-/**
- * @brief implements function get_first of linked_list_t
- */
-static status_t get_first(private_linked_list_t *this, void **item)
-{
-       if (this == NULL)
-       {
-               return FAILED;
-       }
-
-       if (this->count == 0)
-       {
-               return FAILED;
-       }
-
-       if (this->first == NULL)
-       {
-               return FAILED;
-       }
-
-       *item = this->first->value;
-
-       return SUCCESS;
-}
-
-/**
- * @brief implements function insert_last of linked_list_t
- */
-static status_t insert_last(private_linked_list_t *this, void *item)
-{
-       if (this == NULL)
-       {
-               return FAILED;
-       }
-
-       linked_list_element_t *element = (linked_list_element_t *) linked_list_element_create(item);
-
-       if (element == NULL)
-       {
-               return FAILED;
-       }
-
-       if (this->count == 0)
-       {
-               /* first entry in list */
-               this->first = element;
-               this->last = element;
-               element->previous = NULL;
-               element->next = NULL;
-       }else
-       {
-               if ((this->first == NULL) || (this->last == NULL))
-               {
-                       /* should never happen */
-                       element->destroy(element);
-                       return FAILED;
-               }
-               linked_list_element_t *old_last_element = this->last;
-               element->previous = old_last_element;
-               element->next = NULL;
-               old_last_element->next = element;
-               this->last = element;
-       }
-
-       this->count++;
-
-       return SUCCESS;
-}
-
-/**
- * @brief implements function remove_last of linked_list_t
- */
-static status_t remove_last(private_linked_list_t *this, void **item)
-{
-       if (this == NULL)
-       {
-               return FAILED;
-       }
-
-       if (this->count == 0)
-       {
-               return FAILED;
-       }
-
-       if (this->last == NULL)
-       {
-               return FAILED;
-       }
-
-       linked_list_element_t *element = this->last;
-
-       if (element->previous != NULL)
-       {
-               element->previous->next = NULL;
-       }
-       this->last = element->previous;
-
-       *item = element->value;
-
-       this->count--;
-
-       return  (element->destroy(element));
-}
-
-/**
- * @brief implements function get_last of linked_list_t
- */
-static status_t get_last(private_linked_list_t *this, void **item)
-{
-       if (this == NULL)
-       {
-               return FAILED;
-       }
-
-       if (this->count == 0)
-       {
-               return FAILED;
-       }
-
-       if (this->last == NULL)
-       {
-               return FAILED;
-       }
-
-       *item = this->last->value;
-
-       return SUCCESS;
-}
-
-/**
- * @brief implements function insert_before of linked_list_t
- */
-static status_t insert_before(private_linked_list_t *this, private_linked_list_iterator_t * iterator, void *item)
-{
-       if ((this == NULL) || (iterator == NULL))
-       {
-               return FAILED;
-       }
-
-       if (this->count == 0)
-       {
-               return FAILED;
-       }
-
-       if (iterator->current == NULL)
-       {
-               return (this->public.insert_first(&this->public,item));
-       }
-
-       linked_list_element_t *element =(linked_list_element_t *) linked_list_element_create(item);
-
-       if (element == NULL)
-       {
-               return FAILED;
-       }
-
-       if (iterator->current->previous == NULL)
-       {
-               if (this->first != iterator->current)
-               {
-                       element->destroy(element);
-                       return FAILED;
-               }
-
-               iterator->current->previous = element;
-               element->next = iterator->current;
-               this->first = element;
-       }
-       else
-       {
-               iterator->current->previous->next = element;
-               element->previous = iterator->current->previous;
-               iterator->current->previous = element;
-               element->next = iterator->current;
-       }
-
-       this->count++;
-
-       return SUCCESS;
-}
-
-/**
- * @brief implements function insert_after of linked_list_t
- */
-static status_t insert_after(private_linked_list_t *this, private_linked_list_iterator_t * iterator, void *item)
-{
-       if ((this == NULL) || (iterator == NULL))
-       {
-               return FAILED;
-       }
-
-       if (this->count == 0)
-       {
-               return FAILED;
-       }
-
-       if (iterator->current == NULL)
-       {
-               return (this->public.insert_first(&this->public,item));
-       }
-
-       linked_list_element_t *element =(linked_list_element_t *) linked_list_element_create(item);
-
-       if (element == NULL)
-       {
-               return FAILED;
-       }
-
-       if (iterator->current->next == NULL)
-       {
-               if (this->last != iterator->current)
-               {
-                       element->destroy(element);
-                       return FAILED;
-               }
-
-               iterator->current->next = element;
-               element->previous = iterator->current;
-               this->last = element;
-       }
-       else
-       {
-               iterator->current->next->previous = element;
-               element->next = iterator->current->next;
-               iterator->current->next = element;
-               element->previous = iterator->current;
-       }
-
-       this->count++;
-       return SUCCESS;
-}
-
-/**
- * @brief implements function remove of linked_list_t
- */
-static status_t linked_list_remove(private_linked_list_t *this, private_linked_list_iterator_t * iterator)
-{
-       linked_list_element_t *new_current;
-
-       if ((this == NULL) || (iterator == NULL) || (iterator->current == NULL))
-       {
-               return FAILED;
-       }
-
-       if (this->count == 0)
-       {
-               return FAILED;
-       }
-       /* find out the new iterator position */
-       if (iterator->current->previous != NULL)
-       {
-               new_current = iterator->current->previous;
-       }
-       else if (iterator->current->next != NULL)
-       {
-               new_current = iterator->current->next;
-       }
-       else
-       {
-               new_current = NULL;
-       }
-
-       /* now delete the entry :-) */
-       if (iterator->current->previous == NULL)
-       {
-               if (iterator->current->next == NULL)
-               {
-                       this->first = NULL;
-                       this->last = NULL;
-               }
-               else
-               {
-                       iterator->current->next->previous = NULL;
-                       this->first = iterator->current->next;
-               }
-       }
-       else if (iterator->current->next == NULL)
-       {
-               iterator->current->previous->next = NULL;
-               this->last = iterator->current->previous;
-       }
-       else
-       {
-               iterator->current->previous->next = iterator->current->next;
-               iterator->current->next->previous = iterator->current->previous;
-       }
-
-       this->count--;
-       iterator->current->destroy(iterator->current);
-       /* set the new iterator position */
-       iterator->current = new_current;
-       return SUCCESS;
-}
-
-/**
- * @brief implements function destroy of linked_list_t
- */
-static status_t linked_list_destroy(private_linked_list_t *this)
-{
-       if (this == NULL)
-       {
-               return FAILED;
-       }
-
-       /* Remove all list items before destroying list */
-       while (this->count > 0)
-       {
-               void * value;
-               /* values are not destroyed so memory leaks are possible
-                * if list is not empty when deleting */
-               if (this->public.remove_first(&(this->public),&value) != SUCCESS)
-               {
-                       allocator_free(this);
-                       return FAILED;
-               }
-       }
-       allocator_free(this);
-       return SUCCESS;
-}
-
-/*
- * Described in header
- */
-linked_list_t *linked_list_create()
-{
-       private_linked_list_t *this = allocator_alloc_thing(private_linked_list_t);
-
-       this->public.get_count = (int (*) (linked_list_t *linked_list)) get_count;
-       this->public.create_iterator = (status_t (*) (linked_list_t *linked_list, linked_list_iterator_t **iterator,bool forward)) create_iterator;
-       this->public.get_first = (status_t (*) (linked_list_t *linked_list, void **item)) get_first;
-       this->public.get_last = (status_t (*) (linked_list_t *linked_list, void **item)) get_last;
-       this->public.insert_first = (status_t (*) (linked_list_t *linked_list, void *item)) insert_first;
-       this->public.insert_last = (status_t (*) (linked_list_t *linked_list, void *item)) insert_last;
-       this->public.insert_before = (status_t (*) (linked_list_t *linked_list, linked_list_iterator_t * element, void *item)) insert_before;
-       this->public.insert_after = (status_t (*) (linked_list_t *linked_list, linked_list_iterator_t * element, void *item)) insert_after;
-       this->public.remove = (status_t (*) (linked_list_t *linked_list, linked_list_iterator_t * element)) linked_list_remove;
-       this->public.remove_first = (status_t (*) (linked_list_t *linked_list, void **item)) remove_first;
-       this->public.remove_last = (status_t (*) (linked_list_t *linked_list, void **item)) remove_last;
-       this->public.destroy = (status_t (*) (linked_list_t *linked_list)) linked_list_destroy;
-
-       this->count = 0;
-       this->first = NULL;
-       this->last = NULL;
-
-       return (&(this->public));
-}
diff --git a/Source/charon/linked_list.h b/Source/charon/linked_list.h
deleted file mode 100644 (file)
index 2b900a4..0000000
+++ /dev/null
@@ -1,219 +0,0 @@
-/**
- * @file linked_list.h
- * 
- * @brief Generic Double Linked List
- * 
- */
-
-/*
- * Copyright (C) 2005 Jan Hutter, Martin Willi
- * Hochschule fuer Technik Rapperswil
- *
- * This program 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 2 of the License, or (at your
- * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
- *
- * This program 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.
- */
-
-#ifndef LINKED_LIST_H_
-#define LINKED_LIST_H_
-
-#include "types.h"
-
-/**
- * @brief Iterator for a linked list
- * 
- * This element holds a pointer to the current element in the linked list
- * 
- * @warning the iterator is NOT thread-save
- */
-typedef struct linked_list_iterator_s linked_list_iterator_t;
-
-struct linked_list_iterator_s {
-
-       /**
-        * @brief returns TRUE if more elements are available
-        * 
-        * @param this calling object
-        * @return if more elements are avaiable TRUE, FALSE otherwise
-        */
-       bool (*has_next) (linked_list_iterator_t *this);
-
-       /**
-        * @brief returns the current value at the iterator position
-        * 
-        * @param this calling object
-        * @param[out] value value is set to the current value at iterator position
-        * @return SUCCESS if succeeded, FAILED otherwise
-        */
-       status_t (*current) (linked_list_iterator_t *this, void **value);
-
-       /**
-        * @brief Resets a linked_list_iterator object
-        * 
-        * @param this calling object
-        * @return SUCCESS if succeeded, FAILED otherwise
-        */
-       status_t (*reset) (linked_list_iterator_t *this);
-
-       /**
-        * @brief Destroys a linked_list_iterator object
-        * 
-        * @param this calling object
-        * @return SUCCESS if succeeded, FAILED otherwise
-        */
-       status_t (*destroy) (linked_list_iterator_t *this);
-};
-
-/**
- * @brief Double Linked List (named only as linked list)
- *
- * @warning Access to an object of this type is not thread-save
- * 
- * @see job_queue_t
- * @see event_queue_t
- * @see send_queue_t
- */
-typedef struct linked_list_s linked_list_t;
-
-
-struct linked_list_s {
-
-       /**
-        * @brief gets the count of items in the list
-        * 
-        * @param linked_list calling object
-        * @return number of items in list
-        */
-       int (*get_count) (linked_list_t *linked_list);
-       
-       /**
-        * @brief creates a iterator for the given list
-        * 
-        * @warning has to get destroyed
-        * 
-        * @param linked_list calling object
-        * @param[out] iterator place where the iterator is written
-        * @param[in] forward iterator direction (TRUE: front to end)
-        * @return SUCCESS if succeeded, FAILED otherwise
-        */
-       status_t (*create_iterator) (linked_list_t *linked_list, linked_list_iterator_t **iterator,bool forward);
-
-       /**
-        * @brief inserts a new item at the beginning of the list
-        * 
-        * @param linked_list calling object
-        * @param[in] item value to insert in list
-        * @return SUCCESS if succeeded, FAILED otherwise
-        */
-       status_t (*insert_first) (linked_list_t *linked_list, void *item);
-       
-       /**
-        * @brief inserts a new item before the given iterator position
-        * 
-        * The iterator position is not changed after inserting
-        * 
-        * @param linked_list calling object
-        * @param iterator new element is inserted before this iterator
-        * @param[in] item value to insert in list
-        * @return SUCCESS if succeeded, FAILED otherwise
-        */
-       status_t (*insert_before) (linked_list_t *linked_list, linked_list_iterator_t *iterator, void *item);
-
-       /**
-        * @brief inserts a new item after the given iterator position
-        * 
-        * The iterator position is not changed after inserting
-        * 
-        * @param linked_list calling object
-        * @param iterator new element is inserted after this iterator
-        * @param[in] item value to insert in list
-        * @return SUCCESS if succeeded, FAILED otherwise
-        */
-       status_t (*insert_after) (linked_list_t *linked_list, linked_list_iterator_t *iterator, void *item);
-
-       /**
-        * @brief removes an element from list at the given iterator position
-        * 
-        * The position of the iterator is set in the following order:
-        * - to the item before, if available
-        * - otherwise to the item after, if available
-        * - otherwise it gets reseted
-        * 
-        * @param linked_list calling object
-        * @param iterator iterator holding the position of the element to remove
-        * @return SUCCESS if succeeded, FAILED otherwise
-        */
-       status_t (*remove) (linked_list_t *linked_list, linked_list_iterator_t *iterator);
-
-       /**
-        * @brief removes the first item in the list and returns its value
-        * 
-        * @param linked_list calling object
-        * @param[in] item returned value of first item
-        * @return SUCCESS if succeeded, FAILED otherwise
-        */
-       status_t (*remove_first) (linked_list_t *linked_list, void **item);
-
-       /**
-        * @brief returns the value of the first list item without removing it
-        * 
-        * @param linked_list calling object
-        * @param[out] item returned value of first item
-        * @return SUCCESS if succeeded, FAILED otherwise
-        */
-       status_t (*get_first) (linked_list_t *linked_list, void **item);
-
-       /**
-        * @brief inserts a new item at the end of the list
-        * 
-        * @param linked_list calling object
-        * @param[in] item value to insert into list
-        * @return SUCCESS if succeeded, FAILED otherwise
-        */
-       status_t (*insert_last) (linked_list_t *linked_list, void *item);
-       
-       /**
-        * @brief removes the last item in the list and returns its value
-        * 
-        * @param linked_list calling object
-        * @param[out] item returned value of last item
-        * @return SUCCESS if succeeded, FAILED otherwise
-        */
-       status_t (*remove_last) (linked_list_t *linked_list, void **item);
-
-       /**
-        * @brief Returns the value of the last list item without removing it
-        * 
-        * @param linked_list calling object
-        * @param[out] item returned value of last item
-        * @return SUCCESS if succeeded, FAILED otherwise
-        */
-       status_t (*get_last) (linked_list_t *linked_list, void **item);
-       
-       /**
-        * @brief Destroys a linked_list object
-        * 
-        * @warning all items are removed before deleting the list. The
-        *          associated values are NOT destroyed. 
-        *                      Destroying an list which is not empty may cause
-        *                      memory leaks!
-        * 
-        * @param linked_list calling object
-        * @return SUCCESS if succeeded, FAILED otherwise
-        */
-       status_t (*destroy) (linked_list_t *linked_list);
-};
-
-/**
- * @brief Creates an empty linked list object
- */
-linked_list_t *linked_list_create(void);
-
-
-#endif /*LINKED_LIST_H_*/
index 37fd146..9cf1ed4 100644 (file)
  * for more details.
  */
  
-#include "allocator.h"
 #include "logger_manager.h"
-#include "linked_list.h"
+#include "allocator.h"
+#include "utils/linked_list.h"
 
 /** 
  * Maximum length of a logger name
index 2683229..f6aa1fa 100644 (file)
 
 #include <stdlib.h>
 
+#include "message.h"
+
 #include "allocator.h"
 #include "types.h"
-#include "message.h"
 #include "ike_sa_id.h"
-#include "linked_list.h"
+#include "utils/linked_list.h"
 #include "encodings.h"
 
 /**
diff --git a/Source/charon/queues/event_queue.c b/Source/charon/queues/event_queue.c
new file mode 100644 (file)
index 0000000..7b0843a
--- /dev/null
@@ -0,0 +1,381 @@
+/**
+ * @file event_queue.c
+ *
+ * @brief Event-Queue based on class linked_list_t
+ *
+ */
+
+/*
+ * Copyright (C) 2005 Jan Hutter, Martin Willi
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program 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 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program 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.
+ */
+
+#include <pthread.h>
+#include <stdlib.h>
+
+#include "event_queue.h"
+
+#include "../allocator.h"
+#include "../types.h"
+#include "../utils/linked_list.h"
+
+
+
+/**
+ * @brief Represents an event as it is stored in the event queue.
+ *
+ * A event consists of a event time and an assigned job object.
+ *
+ */
+typedef struct event_s event_t;
+
+struct event_s{
+       /**
+        * Time to fire the event.
+        */
+       timeval_t time;
+
+       /**
+        * Every event has its assigned job.
+        */
+       job_t * job;
+
+       /**
+        * @brief Destroys a event_t object.
+        *
+        * @param event_t       calling object
+        * @returns                     always SUCCESS
+        */
+       status_t (*destroy) (event_t *event);
+};
+
+
+/**
+ * @brief implements function destroy of event_t
+ */
+static status_t event_destroy(event_t *event)
+{
+       allocator_free(event);
+       return SUCCESS;
+}
+
+/**
+ * @brief Creates a event for a specific time
+ *
+ * @param time absolute time to fire the event
+ * @param job  job to add to job-queue at specific time
+ *
+ * @returns
+ *                             - created event_t object 
+ *                             - NULL if memory allocation failed
+ */
+static event_t *event_create(timeval_t time, job_t *job)
+{
+       event_t *this = allocator_alloc_thing(event_t);
+       if (this == NULL)
+       {
+               return this;
+       }
+
+       this->destroy = event_destroy;
+       this->time = time;
+       this->job = job;
+
+       return this;
+}
+
+
+/**
+ * @brief Private Variables and Functions of event_queue_t class.
+ *
+ */
+typedef struct private_event_queue_s private_event_queue_t;
+
+
+struct private_event_queue_s {
+       /**
+        * Public part.
+        */
+       event_queue_t public;
+
+       /**
+        * The events are stored in a linked list of type linked_list_t.
+        */
+       linked_list_t *list;
+
+       /**
+        * Access to linked_list is locked through this mutex.
+        */
+       pthread_mutex_t mutex;
+
+       /**
+        * If the queue is empty or an event has not to be fired
+        * a thread has to wait.
+        * 
+        * This condvar is used to wake up such a thread.
+        */
+       pthread_cond_t condvar;
+};
+
+/**
+ * Returns the difference of to timeval structs in microseconds
+ *
+ * @param end_time             end time
+ * @param start_time   start time
+ *
+ * @warning this function is also defined in the tester class
+ *                     In later improvements, this function can be added to a general
+ *          class type!
+ *
+ * @return     difference in microseconds (end time - start time)
+ */
+static long time_difference(struct timeval *end_time, struct timeval *start_time)
+{
+       long seconds, microseconds;
+
+       seconds = (end_time->tv_sec - start_time->tv_sec);
+       microseconds = (end_time->tv_usec - start_time->tv_usec);
+       return ((seconds * 1000000) + microseconds);
+}
+
+
+/**
+ * Implements function get_count of event_queue_t.
+ * See #event_queue_s.get_count for description.
+ */
+static int get_count (private_event_queue_t *this)
+{
+       int count;
+       pthread_mutex_lock(&(this->mutex));
+       count = this->list->get_count(this->list);
+       pthread_mutex_unlock(&(this->mutex));
+       return count;
+}
+
+/**
+ * Implements function get of event_queue_t.
+ * See #event_queue_s.get for description.
+ */
+static status_t get(private_event_queue_t *this, job_t **job)
+{
+       timespec_t timeout;
+       timeval_t current_time;
+       event_t * next_event;
+       int oldstate;
+
+       pthread_mutex_lock(&(this->mutex));
+
+       while (1)
+       {
+               while(this->list->get_count(this->list) == 0)
+               {
+                       /* add mutex unlock handler for cancellation, enable cancellation */
+                       pthread_cleanup_push((void(*)(void*))pthread_mutex_unlock, (void*)&(this->mutex));
+                       pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
+
+                       pthread_cond_wait( &(this->condvar), &(this->mutex));
+
+                       /* reset cancellation, remove mutex-unlock handler (without executing) */
+                       pthread_setcancelstate(oldstate, NULL);
+                       pthread_cleanup_pop(0);
+               }
+
+               this->list->get_first(this->list,(void **) &next_event);
+
+               gettimeofday(&current_time,NULL);
+               long difference = time_difference(&current_time,&(next_event->time));
+               if (difference <= 0)
+               {
+                       timeout.tv_sec = next_event->time.tv_sec;
+            timeout.tv_nsec = next_event->time.tv_usec * 1000;
+
+                       pthread_cond_timedwait( &(this->condvar), &(this->mutex),&timeout);
+               }
+               else
+               {
+                       /* event available */
+                       this->list->remove_first(this->list,(void **) &next_event);
+
+                       *job = next_event->job;
+
+                       next_event->destroy(next_event);
+                       break;
+               }
+
+       }
+       pthread_cond_signal( &(this->condvar));
+
+       pthread_mutex_unlock(&(this->mutex));
+
+       return SUCCESS;
+}
+
+/**
+ * Implements function add_absolute of event_queue_t.
+ * See #event_queue_s.add_absolute for description.
+ */
+static status_t add_absolute(private_event_queue_t *this, job_t *job, timeval_t time)
+{
+       event_t *event = event_create(time,job);
+       event_t *current_event;
+       status_t status;
+
+       if (event == NULL)
+       {
+               return FAILED;
+       }
+       pthread_mutex_lock(&(this->mutex));
+
+       /* while just used to break out */
+       while(1)
+       {
+               if (this->list->get_count(this->list) == 0)
+               {
+                       status = this->list->insert_first(this->list,event);
+                       break;
+               }
+
+               /* check last entry */
+               this->list->get_last(this->list,(void **) &current_event);
+
+               if (time_difference(&(event->time), &(current_event->time)) >= 0)
+               {
+                       /* my event has to be fired after the last event in list */
+                       status = this->list->insert_last(this->list,event);
+                       break;
+               }
+
+               /* check first entry */
+               this->list->get_first(this->list,(void **) &current_event);
+
+               if (time_difference(&(event->time), &(current_event->time)) < 0)
+               {
+                       /* my event has to be fired before the first event in list */
+                       status = this->list->insert_first(this->list,event);
+                       break;
+               }
+
+               linked_list_iterator_t * iterator;
+
+               status = this->list->create_iterator(this->list,&iterator,TRUE);
+               if (status != SUCCESS)
+               {
+                       break;
+               }
+
+
+               iterator->has_next(iterator);
+               /* first element has not to be checked (already done) */
+
+               while(iterator->has_next(iterator))
+               {
+                       status = iterator->current(iterator,(void **) &current_event);
+
+                       if (time_difference(&(event->time), &(current_event->time)) <= 0)
+                       {
+                               /* my event has to be fired before the current event in list */
+                               status = this->list->insert_before(this->list,iterator,event);
+                               break;
+                       }
+               }
+               iterator->destroy(iterator);
+               break;
+       }
+
+       pthread_cond_signal( &(this->condvar));
+       pthread_mutex_unlock(&(this->mutex));
+
+       if (status != SUCCESS)
+       {
+               event->destroy(event);
+       }
+       return status;
+}
+
+/**
+ * Implements function add_relative of event_queue_t.
+ * See #event_queue_s.add_relative for description.
+ */
+static status_t add_relative(event_queue_t *this, job_t *job, u_int32_t ms)
+{
+       timeval_t current_time;
+       timeval_t time;
+       int micros = ms * 1000;
+
+       gettimeofday(&current_time, NULL);
+
+       time.tv_usec = ((current_time.tv_usec + micros) % 1000000);
+       time.tv_sec = current_time.tv_sec + ((current_time.tv_usec + micros)/ 1000000);
+
+       return this->add_absolute(this, job, time);
+}
+
+
+/**
+ * Implements function destroy of event_queue_t.
+ * See #event_queue_s.destroy for description.
+ */
+static status_t event_queue_destroy(private_event_queue_t *this)
+{
+       while (this->list->get_count(this->list) > 0)
+       {
+               event_t *event;
+
+               if (this->list->remove_first(this->list,(void *) &event) != SUCCESS)
+               {
+                       this->list->destroy(this->list);
+                       break;
+               }
+               event->job->destroy(event->job);
+               event->destroy(event);
+       }
+       this->list->destroy(this->list);
+
+       pthread_mutex_destroy(&(this->mutex));
+
+       pthread_cond_destroy(&(this->condvar));
+
+       allocator_free(this);
+       return SUCCESS;
+}
+
+/*
+ * Documented in header
+ */
+event_queue_t *event_queue_create()
+{
+       linked_list_t *linked_list = linked_list_create();
+       if (linked_list == NULL)
+       {
+               return NULL;
+       }
+
+       private_event_queue_t *this = allocator_alloc_thing(private_event_queue_t);
+       if (this == NULL)
+       {
+               linked_list->destroy(linked_list);
+               return NULL;
+       }
+
+       this->public.get_count = (int (*) (event_queue_t *event_queue)) get_count;
+       this->public.get = (status_t (*) (event_queue_t *event_queue, job_t **job)) get;
+       this->public.add_absolute = (status_t (*) (event_queue_t *event_queue, job_t *job, timeval_t time)) add_absolute;
+       this->public.add_relative = (status_t (*) (event_queue_t *event_queue, job_t *job, u_int32_t ms)) add_relative;
+       this->public.destroy = (status_t (*) (event_queue_t *event_queue)) event_queue_destroy;
+
+       this->list = linked_list;
+       pthread_mutex_init(&(this->mutex), NULL);
+       pthread_cond_init(&(this->condvar), NULL);
+
+       return (&this->public);
+}
diff --git a/Source/charon/queues/event_queue.h b/Source/charon/queues/event_queue.h
new file mode 100644 (file)
index 0000000..52e4c81
--- /dev/null
@@ -0,0 +1,114 @@
+/**
+ * @file event_queue.h
+ *
+ * @brief Event-Queue based on class linked_list_t
+ *
+ */
+
+/*
+ * Copyright (C) 2005 Jan Hutter, Martin Willi
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program 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 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program 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.
+ */
+
+#ifndef EVENT_QUEUE_H_
+#define EVENT_QUEUE_H_
+
+#include <sys/time.h>
+
+#include "../types.h"
+#include "../job.h"
+
+/**
+ * @brief Event-Queue used to store timed events.
+ *
+ * Although the event-queue is based on a linked_list_t
+ * all access functions are thread-save implemented.
+ */
+typedef struct event_queue_s event_queue_t;
+
+struct event_queue_s {
+
+       /**
+        * @brief Returns number of events in queue.
+        *
+        * @param event_queue   calling object
+        * @return                              number of events in queue
+        */
+       int (*get_count) (event_queue_t *event_queue);
+
+       /**
+        * @brief Get the next job from the event-queue.
+        *
+        * If no event is pending, this function blocks until a job can be returned.
+        *
+        * @param event_queue   calling object
+        * @param[out] job              pointer to a job pointer where to job is returned to
+        * @return                              - SUCCESS if succeeded
+        *                                              - FAILED otherwisesa
+        */
+       status_t (*get) (event_queue_t *event_queue, job_t **job);
+
+       /**
+        * @brief Adds a event to the queue, using a relative time.
+        *
+        * This function is non blocking and adds a job_t at a specific time to the list.
+        * The specific job object has to get destroyed by the thread which
+        * removes the job.
+        *
+        * @param event_queue   calling object
+        * @param[in] job               job to add to the queue (job is not copied)
+        * @param[in] time              relative time, when the event has to get fired
+        * @returns
+        *                                              - SUCCESS if succeeded
+        *                                              - FAILED otherwise
+        */
+       status_t (*add_relative) (event_queue_t *event_queue, job_t *job, u_int32_t ms);
+
+       /**
+        * @brief Adds a event to the queue, using an absolute time.
+        *
+        * This function is non blocking and adds a job_t at a specific time to the list.
+        * The specific job object has to get destroyed by the thread which
+        * removes the job.
+        *
+        * @param event_queue   calling object
+        * @param[in]                   job job to add to the queue (job is not copied)
+        * @param[in]                   absolute time time, when the event has to get fired
+        * @returns
+        *                                              - SUCCESS if succeeded
+        *                                              - FAILED otherwise
+        */
+       status_t (*add_absolute) (event_queue_t *event_queue, job_t *job, timeval_t time);
+
+       /**
+        * @brief Destroys a event_queue object.
+        *
+        * @warning The caller of this function has to make sure
+        * that no thread is going to add or get an event from the event_queue
+        * after calling this function.
+        *
+        * @param event_queue   calling object
+        * @returns                             always SUCCESS
+        */
+       status_t (*destroy) (event_queue_t *event_queue);
+};
+
+/**
+ * @brief Creates an empty event_queue
+ *
+ * @returns
+ *                     - Empty event_queue_t object
+ *                     - NULL if memory allocation failed
+ */
+event_queue_t *event_queue_create();
+#endif /*EVENT_QUEUE_H_*/
diff --git a/Source/charon/queues/job_queue.c b/Source/charon/queues/job_queue.c
new file mode 100644 (file)
index 0000000..46423a9
--- /dev/null
@@ -0,0 +1,162 @@
+/**
+ * @file job_queue.c
+ *
+ * @brief Job-Queue based on linked_list_t
+ *
+ */
+
+/*
+ * Copyright (C) 2005 Jan Hutter, Martin Willi
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program 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 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program 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.
+ */
+
+#include <stdlib.h>
+#include <pthread.h>
+
+#include "job_queue.h"
+
+#include "../allocator.h"
+#include "../utils/linked_list.h"
+
+/**
+ * @brief Private Variables and Functions of job_queue class
+ *
+ */
+typedef struct private_job_queue_s private_job_queue_t;
+
+
+struct private_job_queue_s {
+       job_queue_t public;
+
+       /**
+        * The jobs are stored in a linked list
+        */
+       linked_list_t *list;
+       /**
+        * access to linked_list is locked through this mutex
+        */
+       pthread_mutex_t mutex;
+
+       /**
+        * If the queue is empty a thread has to wait
+        * This condvar is used to wake up such a thread
+        */
+       pthread_cond_t condvar;
+};
+
+
+/**
+ * @brief implements function get_count of job_queue_t
+ */
+static int get_count(private_job_queue_t *this)
+{
+       int count;
+       pthread_mutex_lock(&(this->mutex));
+       count = this->list->get_count(this->list);
+       pthread_mutex_unlock(&(this->mutex));
+       return count;
+}
+
+/**
+ * @brief implements function get of job_queue_t
+ */
+static status_t get(private_job_queue_t *this, job_t **job)
+{
+       int oldstate;
+       pthread_mutex_lock(&(this->mutex));
+       /* go to wait while no jobs available */
+       while(this->list->get_count(this->list) == 0)
+       {
+               /* add mutex unlock handler for cancellation, enable cancellation */
+               pthread_cleanup_push((void(*)(void*))pthread_mutex_unlock, (void*)&(this->mutex));
+               pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
+
+               pthread_cond_wait( &(this->condvar), &(this->mutex));
+
+               /* reset cancellation, remove mutex-unlock handler (without executing) */
+               pthread_setcancelstate(oldstate, NULL);
+               pthread_cleanup_pop(0);
+       }
+       this->list->remove_first(this->list,(void **) job);
+       pthread_mutex_unlock(&(this->mutex));
+       return SUCCESS;
+}
+
+/**
+ * @brief implements function add of job_queue_t
+ */
+static status_t add(private_job_queue_t *this, job_t *job)
+{
+       pthread_mutex_lock(&(this->mutex));
+       this->list->insert_last(this->list,job);
+       pthread_cond_signal( &(this->condvar));
+       pthread_mutex_unlock(&(this->mutex));
+       return SUCCESS;
+}
+
+/**
+ * @brief implements function destroy of job_queue_t
+ *
+ */
+static status_t job_queue_destroy (private_job_queue_t *this)
+{
+       while (this->list->get_count(this->list) > 0)
+       {
+               job_t *job;
+               if (this->list->remove_first(this->list,(void *) &job) != SUCCESS)
+               {
+                       this->list->destroy(this->list);
+                       break;
+               }
+               job->destroy(job);
+       }
+       this->list->destroy(this->list);
+
+       pthread_mutex_destroy(&(this->mutex));
+
+       pthread_cond_destroy(&(this->condvar));
+
+       allocator_free(this);
+       return SUCCESS;
+}
+
+/*
+ *
+ * Documented in header
+ */
+job_queue_t *job_queue_create()
+{
+       linked_list_t *linked_list = linked_list_create();
+       if (linked_list == NULL)
+       {
+               return NULL;
+       }
+
+       private_job_queue_t *this = allocator_alloc_thing(private_job_queue_t);
+       if (this == NULL)
+       {
+               linked_list->destroy(linked_list);
+               return NULL;
+       }
+
+       this->public.get_count = (int(*)(job_queue_t*))get_count;
+       this->public.get = (status_t(*)(job_queue_t*, job_t**))get;
+       this->public.add = (status_t(*)(job_queue_t*, job_t*))add;
+       this->public.destroy = (status_t(*)(job_queue_t*))job_queue_destroy;
+
+       this->list = linked_list;
+       pthread_mutex_init(&(this->mutex), NULL);
+       pthread_cond_init(&(this->condvar), NULL);
+
+       return (&this->public);
+}
diff --git a/Source/charon/queues/job_queue.h b/Source/charon/queues/job_queue.h
new file mode 100644 (file)
index 0000000..c7ceaca
--- /dev/null
@@ -0,0 +1,92 @@
+/**
+ * @file job_queue.h
+ *
+ * @brief Job-Queue based on linked_list_t
+ *
+ */
+
+/*
+ * Copyright (C) 2005 Jan Hutter, Martin Willi
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program 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 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program 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.
+ */
+
+#ifndef JOB_QUEUE_H_
+#define JOB_QUEUE_H_
+
+#include "../types.h"
+#include "../job.h"
+
+/**
+ * @brief Job-Queue
+ *
+ * Although the job-queue is based on a linked_list_t
+ * all access functions are thread-save implemented
+ */
+typedef struct job_queue_s job_queue_t;
+
+struct job_queue_s {
+
+       /**
+        * @brief returns number of jobs in queue
+        *
+        * @param job_queue_t calling object
+        * @returns number of items in queue
+        */
+       int (*get_count) (job_queue_t *job_queue);
+
+       /**
+        * @brief get the next job from the queue
+        *
+        * If the queue is empty, this function blocks until a job can be returned.
+        *
+        * After using, the returned job has to get destroyed by the caller.
+        *
+        * @param job_queue_t calling object
+        * @param[out] job pointer to a job pointer where to job is returned to
+        * @returns SUCCESS if succeeded, FAILED otherwise
+        */
+       status_t (*get) (job_queue_t *job_queue, job_t **job);
+
+       /**
+        * @brief adds a job to the queue
+        *
+        * This function is non blocking and adds a job_t to the list.
+        * The specific job object has to get destroyed by the thread which
+        * removes the job.
+        *
+        * @param job_queue_t calling object
+        * @param[in] job job to add to the queue (job is not copied)
+        * @returns SUCCESS if succeeded, FAILED otherwise
+        */
+       status_t (*add) (job_queue_t *job_queue, job_t *job);
+
+       /**
+        * @brief destroys a job_queue object
+        *
+        * @warning The caller of this function has to make sure
+        * that no thread is going to add or get a job from the job_queue
+        * after calling this function.
+        *
+        * @param job_queue_t calling object
+        * @returns SUCCESS if succeeded, FAILED otherwise
+        */
+       status_t (*destroy) (job_queue_t *job_queue);
+};
+
+/**
+ * @brief Creates an empty job_queue
+ *
+ * @return job_queue_t empty job_queue
+ */
+job_queue_t *job_queue_create();
+#endif /*JOB_QUEUE_H_*/
diff --git a/Source/charon/queues/send_queue.c b/Source/charon/queues/send_queue.c
new file mode 100644 (file)
index 0000000..1b416f7
--- /dev/null
@@ -0,0 +1,167 @@
+/**
+ * @file send_queue.c
+ *
+ * @brief Send-Queue based on linked_list_t
+ *
+ */
+
+/*
+ * Copyright (C) 2005 Jan Hutter, Martin Willi
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program 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 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program 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.
+ */
+
+ #include <pthread.h>
+
+#include "send_queue.h"
+
+#include "../allocator.h"
+#include "../utils/linked_list.h"
+
+ /**
+ * @brief Private Variables and Functions of send_queue class
+ *
+ */
+typedef struct private_send_queue_s private_send_queue_t;
+
+
+struct private_send_queue_s {
+       /**
+        * Public part of the send_queue_t object
+        */
+       send_queue_t public;
+
+       /**
+        * The packets are stored in a linked list
+        */
+       linked_list_t *list;
+
+       /**
+        * access to linked_list is locked through this mutex
+        */
+       pthread_mutex_t mutex;
+
+       /**
+        * If the queue is empty a thread has to wait
+        * This condvar is used to wake up such a thread
+        */
+       pthread_cond_t condvar;
+};
+
+
+/**
+ * @brief implements function get_count of send_queue_t
+ */
+static int get_count(private_send_queue_t *this)
+{
+       int count;
+       pthread_mutex_lock(&(this->mutex));
+       count = this->list->get_count(this->list);
+       pthread_mutex_unlock(&(this->mutex));
+       return count;
+}
+
+ /**
+ * @brief implements function get of send_queue_t
+ */
+static status_t get(private_send_queue_t *this, packet_t **packet)
+{
+       int oldstate;
+       pthread_mutex_lock(&(this->mutex));
+       /* go to wait while no packets available */
+       
+       while(this->list->get_count(this->list) == 0)
+       {
+               /* add mutex unlock handler for cancellation, enable cancellation */
+               pthread_cleanup_push((void(*)(void*))pthread_mutex_unlock, (void*)&(this->mutex));
+               pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
+               pthread_cond_wait( &(this->condvar), &(this->mutex));
+
+               /* reset cancellation, remove mutex-unlock handler (without executing) */
+               pthread_setcancelstate(oldstate, NULL);
+               pthread_cleanup_pop(0);
+       }
+       this->list->remove_first(this->list,(void **) packet);
+       pthread_mutex_unlock(&(this->mutex));
+       return SUCCESS;
+}
+
+ /**
+ * @brief implements function add of send_queue_t
+ */
+static status_t add(private_send_queue_t *this, packet_t *packet)
+{
+       pthread_mutex_lock(&(this->mutex));
+       this->list->insert_last(this->list,packet);
+       pthread_cond_signal( &(this->condvar));
+       pthread_mutex_unlock(&(this->mutex));
+       return SUCCESS;
+}
+
+ /**
+ * @brief implements function destroy of send_queue_t
+ *
+ */
+static status_t destroy (private_send_queue_t *this)
+{
+
+       /* destroy all packets in list before destroying list */
+       while (this->list->get_count(this->list) > 0)
+       {
+               packet_t *packet;
+               if (this->list->remove_first(this->list,(void *) &packet) != SUCCESS)
+               {
+                       this->list->destroy(this->list);
+                       break;
+               }
+               packet->destroy(packet);
+       }
+       this->list->destroy(this->list);
+
+       pthread_mutex_destroy(&(this->mutex));
+
+       pthread_cond_destroy(&(this->condvar));
+
+       allocator_free(this);
+       return SUCCESS;
+}
+
+ /*
+ *
+ * Documented in header
+ */
+send_queue_t *send_queue_create()
+{
+       linked_list_t *linked_list = linked_list_create();
+       if (linked_list == NULL)
+       {
+               return NULL;
+       }
+
+       private_send_queue_t *this = allocator_alloc_thing(private_send_queue_t);
+       if (this == NULL)
+       {
+               linked_list->destroy(linked_list);
+               return NULL;
+       }
+
+       this->public.get_count = (int(*)(send_queue_t*)) get_count;
+       this->public.get = (status_t(*)(send_queue_t*, packet_t**)) get;
+       this->public.add = (status_t(*)(send_queue_t*, packet_t*)) add;
+       this->public.destroy = (status_t(*)(send_queue_t*)) destroy;
+
+       this->list = linked_list;
+       pthread_mutex_init(&(this->mutex), NULL);
+       pthread_cond_init(&(this->condvar), NULL);
+
+       return (&this->public);
+}
diff --git a/Source/charon/queues/send_queue.h b/Source/charon/queues/send_queue.h
new file mode 100644 (file)
index 0000000..072d2f9
--- /dev/null
@@ -0,0 +1,94 @@
+/**
+ * @file send_queue.h
+ *
+ * @brief Send-Queue based on linked_list_t
+ *
+ */
+
+/*
+ * Copyright (C) 2005 Jan Hutter, Martin Willi
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program 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 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program 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.
+ */
+
+#ifndef SEND_QUEUE_H_
+#define SEND_QUEUE_H_
+
+#include "../types.h"
+#include "../packet.h"
+
+/**
+ * @brief Send-Queue
+ *
+ * Although the send-queue is based on a linked_list_t
+ * all access functions are thread-save implemented
+ */
+typedef struct send_queue_s send_queue_t;
+
+struct send_queue_s {
+
+       /**
+        * @brief returns number of packets in queue
+        *
+        * @param send_queue_t calling object
+        * @param[out] count integer pointer to store the count in
+        * @returns number of items in queue
+        */
+       int (*get_count) (send_queue_t *send_queue);
+
+       /**
+        * @brief get the next packet from the queue
+        *
+        * If the queue is empty, this function blocks until a packet can be returned.
+        *
+        * After using, the returned packet has to get destroyed by the caller.
+        *
+        * @param send_queue_t calling object
+        * @param[out] packet pointer to a packet_t pointer where to packet is returned to
+        * @returns SUCCESS if succeeded, FAILED otherwise
+        */
+       status_t (*get) (send_queue_t *send_queue, packet_t **packet);
+
+       /**
+        * @brief adds a packet to the queue
+        *
+        * This function is non blocking and adds a packet_t to the list.
+        * The specific packet object has to get destroyed by the thread which
+        * removes the packet.
+        *
+        * @param send_queue_t calling object
+        * @param[in] packet packet_t to add to the queue (packet is not copied)
+        * @returns SUCCESS if succeeded, FAILED otherwise
+        */
+       status_t (*add) (send_queue_t *send_queue, packet_t *packet);
+
+       /**
+        * @brief destroys a send_queue object
+        *
+        * @warning The caller of this function has to make sure
+        * that no thread is going to add or get a packet from the send_queue
+        * after calling this function.
+        *
+        * @param send_queue_t calling object
+        * @returns SUCCESS if succeeded, FAILED otherwise
+        */
+       status_t (*destroy) (send_queue_t *send_queue);
+};
+
+/**
+ * @brief Creates an empty send_queue_t
+ *
+ * @return send_queue_t empty send_queue_t
+ */
+send_queue_t *send_queue_create();
+
+#endif /*SEND_QUEUE_H_*/
index bed6957..e3f60d7 100644 (file)
 #include <stdlib.h>
 #include <pthread.h>
 
-#include "allocator.h"
 #include "receiver.h"
+
+#include "allocator.h"
 #include "socket.h"
 #include "packet.h"
 #include "job.h"
-#include "job_queue.h"
+#include "queues/job_queue.h"
 #include "globals.h"
 
 /**
index 7947c34..e8ea4d4 100644 (file)
 #include <stdlib.h>
 #include <pthread.h>
 
-#include "allocator.h"
 #include "scheduler.h"
-#include "job_queue.h"
+
+#include "allocator.h"
+#include "queues/job_queue.h"
 #include "globals.h"
 
 /**
diff --git a/Source/charon/send_queue.c b/Source/charon/send_queue.c
deleted file mode 100644 (file)
index 8371692..0000000
+++ /dev/null
@@ -1,166 +0,0 @@
-/**
- * @file send_queue.c
- *
- * @brief Send-Queue based on linked_list_t
- *
- */
-
-/*
- * Copyright (C) 2005 Jan Hutter, Martin Willi
- * Hochschule fuer Technik Rapperswil
- *
- * This program 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 2 of the License, or (at your
- * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
- *
- * This program 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.
- */
-
- #include <pthread.h>
-
-#include "allocator.h"
- #include "send_queue.h"
- #include "linked_list.h"
-
- /**
- * @brief Private Variables and Functions of send_queue class
- *
- */
-typedef struct private_send_queue_s private_send_queue_t;
-
-
-struct private_send_queue_s {
-       /**
-        * Public part of the send_queue_t object
-        */
-       send_queue_t public;
-
-       /**
-        * The packets are stored in a linked list
-        */
-       linked_list_t *list;
-
-       /**
-        * access to linked_list is locked through this mutex
-        */
-       pthread_mutex_t mutex;
-
-       /**
-        * If the queue is empty a thread has to wait
-        * This condvar is used to wake up such a thread
-        */
-       pthread_cond_t condvar;
-};
-
-
-/**
- * @brief implements function get_count of send_queue_t
- */
-static int get_count(private_send_queue_t *this)
-{
-       int count;
-       pthread_mutex_lock(&(this->mutex));
-       count = this->list->get_count(this->list);
-       pthread_mutex_unlock(&(this->mutex));
-       return count;
-}
-
- /**
- * @brief implements function get of send_queue_t
- */
-static status_t get(private_send_queue_t *this, packet_t **packet)
-{
-       int oldstate;
-       pthread_mutex_lock(&(this->mutex));
-       /* go to wait while no packets available */
-       
-       while(this->list->get_count(this->list) == 0)
-       {
-               /* add mutex unlock handler for cancellation, enable cancellation */
-               pthread_cleanup_push((void(*)(void*))pthread_mutex_unlock, (void*)&(this->mutex));
-               pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
-               pthread_cond_wait( &(this->condvar), &(this->mutex));
-
-               /* reset cancellation, remove mutex-unlock handler (without executing) */
-               pthread_setcancelstate(oldstate, NULL);
-               pthread_cleanup_pop(0);
-       }
-       this->list->remove_first(this->list,(void **) packet);
-       pthread_mutex_unlock(&(this->mutex));
-       return SUCCESS;
-}
-
- /**
- * @brief implements function add of send_queue_t
- */
-static status_t add(private_send_queue_t *this, packet_t *packet)
-{
-       pthread_mutex_lock(&(this->mutex));
-       this->list->insert_last(this->list,packet);
-       pthread_cond_signal( &(this->condvar));
-       pthread_mutex_unlock(&(this->mutex));
-       return SUCCESS;
-}
-
- /**
- * @brief implements function destroy of send_queue_t
- *
- */
-static status_t destroy (private_send_queue_t *this)
-{
-
-       /* destroy all packets in list before destroying list */
-       while (this->list->get_count(this->list) > 0)
-       {
-               packet_t *packet;
-               if (this->list->remove_first(this->list,(void *) &packet) != SUCCESS)
-               {
-                       this->list->destroy(this->list);
-                       break;
-               }
-               packet->destroy(packet);
-       }
-       this->list->destroy(this->list);
-
-       pthread_mutex_destroy(&(this->mutex));
-
-       pthread_cond_destroy(&(this->condvar));
-
-       allocator_free(this);
-       return SUCCESS;
-}
-
- /*
- *
- * Documented in header
- */
-send_queue_t *send_queue_create()
-{
-       linked_list_t *linked_list = linked_list_create();
-       if (linked_list == NULL)
-       {
-               return NULL;
-       }
-
-       private_send_queue_t *this = allocator_alloc_thing(private_send_queue_t);
-       if (this == NULL)
-       {
-               linked_list->destroy(linked_list);
-               return NULL;
-       }
-
-       this->public.get_count = (int(*)(send_queue_t*)) get_count;
-       this->public.get = (status_t(*)(send_queue_t*, packet_t**)) get;
-       this->public.add = (status_t(*)(send_queue_t*, packet_t*)) add;
-       this->public.destroy = (status_t(*)(send_queue_t*)) destroy;
-
-       this->list = linked_list;
-       pthread_mutex_init(&(this->mutex), NULL);
-       pthread_cond_init(&(this->condvar), NULL);
-
-       return (&this->public);
-}
diff --git a/Source/charon/send_queue.h b/Source/charon/send_queue.h
deleted file mode 100644 (file)
index 5524c78..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-/**
- * @file send_queue.h
- *
- * @brief Send-Queue based on linked_list_t
- *
- */
-
-/*
- * Copyright (C) 2005 Jan Hutter, Martin Willi
- * Hochschule fuer Technik Rapperswil
- *
- * This program 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 2 of the License, or (at your
- * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
- *
- * This program 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.
- */
-
-#ifndef SEND_QUEUE_H_
-#define SEND_QUEUE_H_
-
-#include "types.h"
-#include "packet.h"
-
-/**
- * @brief Send-Queue
- *
- * Although the send-queue is based on a linked_list_t
- * all access functions are thread-save implemented
- */
-typedef struct send_queue_s send_queue_t;
-
-struct send_queue_s {
-
-       /**
-        * @brief returns number of packets in queue
-        *
-        * @param send_queue_t calling object
-        * @param[out] count integer pointer to store the count in
-        * @returns number of items in queue
-        */
-       int (*get_count) (send_queue_t *send_queue);
-
-       /**
-        * @brief get the next packet from the queue
-        *
-        * If the queue is empty, this function blocks until a packet can be returned.
-        *
-        * After using, the returned packet has to get destroyed by the caller.
-        *
-        * @param send_queue_t calling object
-        * @param[out] packet pointer to a packet_t pointer where to packet is returned to
-        * @returns SUCCESS if succeeded, FAILED otherwise
-        */
-       status_t (*get) (send_queue_t *send_queue, packet_t **packet);
-
-       /**
-        * @brief adds a packet to the queue
-        *
-        * This function is non blocking and adds a packet_t to the list.
-        * The specific packet object has to get destroyed by the thread which
-        * removes the packet.
-        *
-        * @param send_queue_t calling object
-        * @param[in] packet packet_t to add to the queue (packet is not copied)
-        * @returns SUCCESS if succeeded, FAILED otherwise
-        */
-       status_t (*add) (send_queue_t *send_queue, packet_t *packet);
-
-       /**
-        * @brief destroys a send_queue object
-        *
-        * @warning The caller of this function has to make sure
-        * that no thread is going to add or get a packet from the send_queue
-        * after calling this function.
-        *
-        * @param send_queue_t calling object
-        * @returns SUCCESS if succeeded, FAILED otherwise
-        */
-       status_t (*destroy) (send_queue_t *send_queue);
-};
-
-/**
- * @brief Creates an empty send_queue_t
- *
- * @return send_queue_t empty send_queue_t
- */
-send_queue_t *send_queue_create();
-
-#endif /*SEND_QUEUE_H_*/
index d72f7b1..cbef73e 100644 (file)
 #include <stdlib.h>
 #include <pthread.h>
 
-#include "allocator.h"
 #include "sender.h"
+
+#include "allocator.h"
 #include "socket.h"
 #include "packet.h"
-#include "send_queue.h"
+#include "queues/send_queue.h"
 #include "globals.h"
 
 /**
index 35e2443..05ff372 100644 (file)
@@ -26,7 +26,7 @@
 #include "../allocator.h"
 #include "event_queue_test.h"
 #include "../tester.h"
-#include "../event_queue.h"
+#include "../queues/event_queue.h"
 
 /**
  * Number of different times to insert per thread
index 63fbb45..5e6010f 100644 (file)
@@ -28,7 +28,7 @@
 #include "../allocator.h"
 #include "job_queue_test.h"
 #include "../tester.h"
-#include "../job_queue.h"
+#include "../queues/job_queue.h"
 
 
 typedef struct job_queue_test_s job_queue_test_t;
index bba2054..cf393fb 100644 (file)
@@ -23,7 +23,7 @@
 #include <string.h>
  
 #include "../tester.h"
-#include "../linked_list.h"
+#include "../utils/linked_list.h"
  
  /*
  * Description in header-file
index 2c3556d..d83581e 100644 (file)
@@ -29,8 +29,8 @@
 #include "../receiver.h"
 #include "../packet.h"
 #include "../socket.h"
-#include "../send_queue.h"
-#include "../job_queue.h"
+#include "../queues/send_queue.h"
+#include "../queues/job_queue.h"
 
 /**
  * Number of packets to send by sender-thread
index a67a446..ba312fc 100644 (file)
@@ -26,8 +26,8 @@
 #include "scheduler_test.h"
 #include "../globals.h"
 #include "../scheduler.h"
-#include "../event_queue.h"
-#include "../job_queue.h"
+#include "../queues/event_queue.h"
+#include "../queues/job_queue.h"
 
 
 /**
index 3096a3e..29aac88 100644 (file)
@@ -24,7 +24,7 @@
 
 #include "send_queue_test.h"
 #include "../tester.h"
-#include "../send_queue.h"
+#include "../queues/send_queue.h"
 
 
 /**
index 56a5d9c..67ba557 100644 (file)
@@ -28,8 +28,8 @@
 #include "../sender.h"
 #include "../packet.h"
 #include "../socket.h"
-#include "../send_queue.h"
-#include "../job_queue.h"
+#include "../queues/send_queue.h"
+#include "../queues/job_queue.h"
 
 /**
  * Number of packets to send by sender-thread
diff --git a/Source/charon/testcases/testcases.c b/Source/charon/testcases/testcases.c
new file mode 100644 (file)
index 0000000..eb3990f
--- /dev/null
@@ -0,0 +1,230 @@
+/**
+ * @file tests.c
+ * 
+ * @brief Main for all tests
+ * 
+ */
+
+/*
+ * Copyright (C) 2005 Jan Hutter, Martin Willi
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program 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 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program 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.
+ */
+#include <stdio.h>
+
+#include "../logger_manager.h"
+#include "../allocator.h"
+#include "../tester.h"
+#include "../queues/job_queue.h"
+#include "../queues/event_queue.h"
+#include "../queues/send_queue.h"
+#include "../socket.h"
+#include "linked_list_test.h"
+#include "thread_pool_test.h"
+#include "job_queue_test.h"
+#include "event_queue_test.h"
+#include "send_queue_test.h"
+#include "socket_test.h"
+#include "sender_test.h"
+#include "scheduler_test.h"
+#include "receiver_test.h"
+#include "ike_sa_id_test.h"
+#include "ike_sa_test.h"
+#include "ike_sa_manager_test.h"
+#include "generator_test.h"
+#include "parser_test.h"
+#include "packet_test.h"
+
+
+/* output for test messages */
+extern FILE * stderr;
+
+/**
+ * Test for linked_list_t
+ */
+test_t linked_list_test = {test_linked_list,"Linked List"};
+
+/**
+ * Test for linked_list_t with iterator
+ */
+test_t linked_list_iterator_test = {test_linked_list_iterator,"Linked List Iterator"};
+
+/**
+ * Test for linked_list_t insert and remove
+ */
+test_t linked_list_insert_and_remove_test = {test_linked_list_insert_and_remove,"Linked List Insert and remove"};
+
+/**
+ * Test for event_queue_t
+ */
+test_t event_queue_test = {test_event_queue,"Event-Queue"};
+
+/**
+ * Test 1 for job_queue_t
+ */
+test_t job_queue_test1 = {test_job_queue,"Job-Queue"};
+
+/**
+ * Test 1 for linked_list_t
+ */
+test_t send_queue_test = {test_send_queue,"Send-Queue"};
+
+/**
+ * Test for socket_t
+ */
+test_t socket_test = {test_socket,"Socket"};
+
+/**
+ * Test for thread_pool_t
+ */
+test_t thread_pool_test = {test_thread_pool,"Thread Pool"};
+
+/**
+ * Test for sender_t
+ */
+test_t sender_test = {test_sender,"Sender"};
+
+/**
+ * Test for scheduler_t
+ */
+test_t scheduler_test = {test_scheduler,"Scheduler"};
+
+/**
+ * Test for receiver_t
+ */
+test_t receiver_test = {test_receiver,"Receiver"};
+
+/**
+ * Test for ike_sa_id_t
+ */
+test_t ike_sa_id_test = {test_ike_sa_id,"IKE_SA-Identifier"};
+
+/**
+ * Test for ike_sa_t
+ */
+test_t ike_sa_test = {test_ike_sa,"IKE_SA"};
+
+
+/**
+ * Test for ike_sa_manager_t
+ */
+test_t ike_sa_manager_test = {test_ike_sa_manager, "IKE_SA-Manager"};
+
+/**
+ * Test for generator_t
+ */
+test_t generator_test1 = {test_generator_with_unsupported_payload,"Generator: unsupported payload"};
+
+/**
+ * Test 2 for generator_t
+ */
+test_t generator_test2 = {test_generator_with_header_payload,"Generator: header payload"};
+
+/**
+ * Test 2 for generator_t
+ */
+test_t parser_test = {test_parser_with_header_payload, "Parser: header payload"};
+
+
+/**
+ * Test for packet_t
+ */
+test_t packet_test = {test_packet,"Packet"};
+
+
+/**
+ * Global job-queue
+ */
+job_queue_t *global_job_queue;
+
+/**
+ * Global event-queue
+ */
+event_queue_t *global_event_queue;
+ /**
+  * Global send-queue
+  */
+send_queue_t *global_send_queue;
+
+ /**
+  * Global socket
+  */
+socket_t *global_socket;
+
+
+/**
+ * Global logger
+ */
+logger_manager_t *global_logger_manager;
+  
+ int main()
+{
+       FILE * test_output = stderr;
+       
+       test_t *all_tests[] ={
+       &linked_list_test,
+       &linked_list_iterator_test,
+       &linked_list_insert_and_remove_test,
+       &thread_pool_test,
+       &job_queue_test1,
+       &event_queue_test,
+       &send_queue_test,
+       &scheduler_test,
+       &socket_test,
+       &sender_test,
+       &receiver_test,
+       &ike_sa_id_test,
+       &ike_sa_test,
+       &generator_test1,
+       &generator_test2,
+       &parser_test,
+       &ike_sa_manager_test,
+       &packet_test,
+       NULL
+       };
+       global_logger_manager = logger_manager_create(CONTROL);
+       
+       global_socket = socket_create(4600);
+       
+       global_job_queue = job_queue_create();
+       global_event_queue = event_queue_create();
+       global_send_queue = send_queue_create();
+       
+
+               
+       tester_t *tester = tester_create(test_output, FALSE);
+
+       tester->perform_tests(tester,all_tests);
+/*     tester->perform_test(tester,&parser_test);   */
+       
+       tester->destroy(tester);
+
+
+       /* Destroy all queues */
+       global_job_queue->destroy(global_job_queue);
+       global_event_queue->destroy(global_event_queue);        
+       global_send_queue->destroy(global_send_queue);
+       
+       global_socket->destroy(global_socket);
+       
+       global_logger_manager->destroy(global_logger_manager);
+       
+#ifdef LEAK_DETECTIVE
+       /* Leaks are reported on stderr */
+       report_memory_leaks(void);
+#endif
+       
+       return 0;
+}
index 938ca46..b3bf3f0 100644 (file)
 #include <pthread.h>
 #include <sys/time.h>
 
-#include "allocator.h"
 #include "tester.h"
-#include "linked_list.h"
+
+#include "allocator.h"
+#include "utils/linked_list.h"
 #include "thread_pool.h"
-#include "job_queue.h"
+#include "queues/job_queue.h"
 
 /**
  * @brief Private Variables and Functions of tester class
diff --git a/Source/charon/tests.c b/Source/charon/tests.c
deleted file mode 100644 (file)
index ba6ccf8..0000000
+++ /dev/null
@@ -1,230 +0,0 @@
-/**
- * @file tests.c
- * 
- * @brief Main for all tests
- * 
- */
-
-/*
- * Copyright (C) 2005 Jan Hutter, Martin Willi
- * Hochschule fuer Technik Rapperswil
- *
- * This program 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 2 of the License, or (at your
- * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
- *
- * This program 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.
- */
-#include <stdio.h>
-
-#include "logger_manager.h"
-#include "allocator.h"
-#include "tester.h"
-#include "job_queue.h"
-#include "event_queue.h"
-#include "send_queue.h"
-#include "socket.h"
-#include "testcases/linked_list_test.h"
-#include "testcases/thread_pool_test.h"
-#include "testcases/job_queue_test.h"
-#include "testcases/event_queue_test.h"
-#include "testcases/send_queue_test.h"
-#include "testcases/socket_test.h"
-#include "testcases/sender_test.h"
-#include "testcases/scheduler_test.h"
-#include "testcases/receiver_test.h"
-#include "testcases/ike_sa_id_test.h"
-#include "testcases/ike_sa_test.h"
-#include "testcases/ike_sa_manager_test.h"
-#include "testcases/generator_test.h"
-#include "testcases/parser_test.h"
-#include "testcases/packet_test.h"
-
-
-/* output for test messages */
-extern FILE * stderr;
-
-/**
- * Test for linked_list_t
- */
-test_t linked_list_test = {test_linked_list,"Linked List"};
-
-/**
- * Test for linked_list_t with iterator
- */
-test_t linked_list_iterator_test = {test_linked_list_iterator,"Linked List Iterator"};
-
-/**
- * Test for linked_list_t insert and remove
- */
-test_t linked_list_insert_and_remove_test = {test_linked_list_insert_and_remove,"Linked List Insert and remove"};
-
-/**
- * Test for event_queue_t
- */
-test_t event_queue_test = {test_event_queue,"Event-Queue"};
-
-/**
- * Test 1 for job_queue_t
- */
-test_t job_queue_test1 = {test_job_queue,"Job-Queue"};
-
-/**
- * Test 1 for linked_list_t
- */
-test_t send_queue_test = {test_send_queue,"Send-Queue"};
-
-/**
- * Test for socket_t
- */
-test_t socket_test = {test_socket,"Socket"};
-
-/**
- * Test for thread_pool_t
- */
-test_t thread_pool_test = {test_thread_pool,"Thread Pool"};
-
-/**
- * Test for sender_t
- */
-test_t sender_test = {test_sender,"Sender"};
-
-/**
- * Test for scheduler_t
- */
-test_t scheduler_test = {test_scheduler,"Scheduler"};
-
-/**
- * Test for receiver_t
- */
-test_t receiver_test = {test_receiver,"Receiver"};
-
-/**
- * Test for ike_sa_id_t
- */
-test_t ike_sa_id_test = {test_ike_sa_id,"IKE_SA-Identifier"};
-
-/**
- * Test for ike_sa_t
- */
-test_t ike_sa_test = {test_ike_sa,"IKE_SA"};
-
-
-/**
- * Test for ike_sa_manager_t
- */
-test_t ike_sa_manager_test = {test_ike_sa_manager, "IKE_SA-Manager"};
-
-/**
- * Test for generator_t
- */
-test_t generator_test1 = {test_generator_with_unsupported_payload,"Generator: unsupported payload"};
-
-/**
- * Test 2 for generator_t
- */
-test_t generator_test2 = {test_generator_with_header_payload,"Generator: header payload"};
-
-/**
- * Test 2 for generator_t
- */
-test_t parser_test = {test_parser_with_header_payload, "Parser: header payload"};
-
-
-/**
- * Test for packet_t
- */
-test_t packet_test = {test_packet,"Packet"};
-
-
-/**
- * Global job-queue
- */
-job_queue_t *global_job_queue;
-
-/**
- * Global event-queue
- */
-event_queue_t *global_event_queue;
- /**
-  * Global send-queue
-  */
-send_queue_t *global_send_queue;
-
- /**
-  * Global socket
-  */
-socket_t *global_socket;
-
-
-/**
- * Global logger
- */
-logger_manager_t *global_logger_manager;
-  
- int main()
-{
-       FILE * test_output = stderr;
-       
-       test_t *all_tests[] ={
-       &linked_list_test,
-       &linked_list_iterator_test,
-       &linked_list_insert_and_remove_test,
-       &thread_pool_test,
-       &job_queue_test1,
-       &event_queue_test,
-       &send_queue_test,
-       &scheduler_test,
-       &socket_test,
-       &sender_test,
-       &receiver_test,
-       &ike_sa_id_test,
-       &ike_sa_test,
-       &generator_test1,
-       &generator_test2,
-       &parser_test,
-       &ike_sa_manager_test,
-       &packet_test,
-       NULL
-       };
-       global_logger_manager = logger_manager_create(CONTROL);
-       
-       global_socket = socket_create(4600);
-       
-       global_job_queue = job_queue_create();
-       global_event_queue = event_queue_create();
-       global_send_queue = send_queue_create();
-       
-
-               
-       tester_t *tester = tester_create(test_output, FALSE);
-
-       tester->perform_tests(tester,all_tests);
-/*     tester->perform_test(tester,&parser_test);   */
-       
-       tester->destroy(tester);
-
-
-       /* Destroy all queues */
-       global_job_queue->destroy(global_job_queue);
-       global_event_queue->destroy(global_event_queue);        
-       global_send_queue->destroy(global_send_queue);
-       
-       global_socket->destroy(global_socket);
-       
-       global_logger_manager->destroy(global_logger_manager);
-       
-#ifdef LEAK_DETECTIVE
-       /* Leaks are reported on stderr */
-       report_memory_leaks(void);
-#endif
-       
-       return 0;
-}
index c73317a..322e336 100644 (file)
 #include <pthread.h>
 #include <string.h>
 #include <errno.h>
+
+#include "thread_pool.h"
  
 #include "allocator.h"
 #include "logger.h"
-#include "thread_pool.h"
-#include "job_queue.h"
+#include "queues/job_queue.h"
 #include "globals.h"
 
 /**
diff --git a/Source/charon/utils/linked_list.c b/Source/charon/utils/linked_list.c
new file mode 100644 (file)
index 0000000..b842886
--- /dev/null
@@ -0,0 +1,699 @@
+/**
+ * @file linked_list.c
+ *
+ * @brief Generic Double Linked List
+ *
+ */
+
+/*
+ * Copyright (C) 2005 Jan Hutter, Martin Willi
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program 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 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program 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.
+ */
+
+#include <stdlib.h>
+
+#include "linked_list.h"
+
+#include "../allocator.h"
+
+
+typedef struct linked_list_element_s linked_list_element_t;
+
+
+/**
+ * @brief Element of the linked_list.
+ *
+ * This element holds a pointer to the value of the list item itself.
+ */
+struct linked_list_element_s{
+       /**
+        * value of a list item
+        */
+       void *value;
+
+       /**
+        * @brief Destroys a linked_list_element object
+        *
+        * @param linked_list_element_t calling object
+        * @returns SUCCESS if succeeded, FAILED otherwise
+        */
+       status_t (*destroy) (linked_list_element_t *this);
+
+       /**
+        * previous list element
+        * NULL if first element in list
+        */
+       linked_list_element_t *previous;
+       /**
+        * next list element
+        * NULL if last element in list
+        */
+       linked_list_element_t *next;
+};
+
+/**
+ * @brief implements function destroy of linked_list_item_t
+ */
+static status_t linked_list_element_destroy(linked_list_element_t *this)
+{
+       if (this == NULL)
+       {
+               return FAILED;
+       }
+       allocator_free(this);
+       return SUCCESS;
+}
+
+/**
+ * @brief Creates an empty linked list object
+ *
+ * @param[in] value value of item to be set
+ *
+ * @warning only the pointer to the value is stored
+ *
+ * @return linked_list_element object
+ */
+
+linked_list_element_t *linked_list_element_create(void *value)
+{
+       linked_list_element_t *this = allocator_alloc_thing(linked_list_element_t);
+
+       if (this == NULL)
+       {
+               return NULL;
+       }
+
+       this->destroy = linked_list_element_destroy;
+
+       this->previous=NULL;
+       this->next=NULL;
+       this->value = value;
+
+       return (this);
+}
+
+/**
+ * Private variables and functions of linked list
+ *
+ */
+typedef struct private_linked_list_s private_linked_list_t;
+
+struct private_linked_list_s{
+       /**
+        * Public part of linked list
+        */
+       linked_list_t public;
+
+       /**
+        * number of items in the list
+        */
+       int count;
+
+       /**
+        * First element in list
+        * NULL if no elements in list
+        */
+       linked_list_element_t *first;
+       /**
+        * Last element in list
+        * NULL if no elements in list
+        */
+       linked_list_element_t *last;
+};
+
+
+/**
+ * Private variables and functions of linked list iterator
+ *
+ */
+typedef struct private_linked_list_iterator_s private_linked_list_iterator_t;
+
+struct private_linked_list_iterator_s{
+       /**
+        * Public part of linked list iterator
+        */
+       linked_list_iterator_t public;
+
+       /**
+        * associated linked list
+        */
+       private_linked_list_t * list;
+
+       /**
+        * current element of the iterator
+        */
+       linked_list_element_t *current;
+
+       /**
+        * direction of iterator
+        */
+       bool forward;
+};
+
+/**
+ * Implements function has_next of linked_list_iteratr
+ */
+bool iterator_has_next(private_linked_list_iterator_t *this)
+{
+       if (this->list->count == 0)
+       {
+               return FALSE;
+       }
+       if (this->current == NULL)
+       {
+               this->current = (this->forward) ? this->list->first : this->list->last;
+               return TRUE;
+       }
+       if (this->forward)
+       {
+               if (this->current->next == NULL)
+               {
+                       return FALSE;
+               }
+               this->current = this->current->next;
+               return TRUE;
+       }
+       /* backward */
+       if (this->current->previous == NULL)
+       {
+               return FALSE;
+       }
+       this->current = this->current->previous;
+       return TRUE;
+}
+
+/**
+ * Implements function current of linked_list_iteratr
+ */
+static status_t iterator_current(private_linked_list_iterator_t *this, void **value)
+{
+       if (this == NULL)
+       {
+               return FAILED;
+       }
+       if (this->current == NULL)
+       {
+               return FAILED;
+       }
+       *value = this->current->value;
+       return SUCCESS;
+}
+
+/**
+ * Implements function current of linked_list_iteratr
+ */
+static status_t iterator_reset(private_linked_list_iterator_t *this)
+{
+       if (this == NULL)
+       {
+               return FAILED;
+       }
+       this->current = NULL;
+       return SUCCESS;
+}
+
+/**
+ * Implements function destroy of linked_list_iteratr
+ */
+static status_t iterator_destroy(private_linked_list_iterator_t *this)
+{
+       if (this == NULL)
+       {
+               return FAILED;
+       }
+       allocator_free(this);
+       return SUCCESS;
+}
+
+/**
+ * @brief implements function get_count of linked_list_t
+ */
+static int get_count(private_linked_list_t *this)
+{
+       return this->count;
+}
+
+
+static status_t create_iterator (private_linked_list_t *linked_list, linked_list_iterator_t **iterator,bool forward)
+{
+       private_linked_list_iterator_t *this = allocator_alloc_thing(private_linked_list_iterator_t);
+
+       if (this == NULL)
+       {
+               return FAILED;
+       }
+
+       this->public.has_next = (bool (*) (linked_list_iterator_t *this)) iterator_has_next;
+       this->public.current = (status_t (*) (linked_list_iterator_t *this, void **value)) iterator_current;
+       this->public.reset = (status_t (*) (linked_list_iterator_t *this)) iterator_reset;
+       this->public.destroy = (status_t (*) (linked_list_iterator_t *this)) iterator_destroy;
+
+
+       this->forward = forward;
+       this->current = NULL;
+       this->list = linked_list;
+
+       *iterator = &(this->public);
+
+       return (SUCCESS);
+}
+
+
+/**
+ * @brief implements function insert_first of linked_list_t
+ */
+static status_t insert_first(private_linked_list_t *this, void *item)
+{
+       linked_list_element_t *element;
+
+       if (this == NULL)
+       {
+               return FAILED;
+       }
+
+       element =(linked_list_element_t *) linked_list_element_create(item);
+
+       if (element == NULL)
+       {
+               return FAILED;
+       }
+
+       if (this->count == 0)
+       {
+               /* first entry in list */
+               this->first = element;
+               this->last = element;
+               element->previous = NULL;
+               element->next = NULL;
+       }
+       else
+       {
+               if ((this->first == NULL) || (this->last == NULL))
+               {
+                       /* should never happen */
+                       element->destroy(element);
+                       return FAILED;
+               }
+               linked_list_element_t *old_first_element = this->first;
+               element->next = old_first_element;
+               element->previous = NULL;
+               old_first_element->previous = element;
+               this->first = element;
+       }
+
+       this->count++;
+
+       return SUCCESS;
+}
+
+/**
+ * @brief implements function remove_first of linked_list_t
+ */
+static status_t remove_first(private_linked_list_t *this, void **item)
+{
+       if (this == NULL)
+       {
+               return FAILED;
+       }
+
+       if (this->count == 0)
+       {
+               return FAILED;
+       }
+
+       if (this->first == NULL)
+       {
+               return FAILED;
+       }
+
+       linked_list_element_t *element = this->first;
+
+       if (element->next != NULL)
+       {
+               element->next->previous = NULL;
+       }
+       this->first = element->next;
+
+       *item = element->value;
+
+       this->count--;
+
+       return  (element->destroy(element));
+}
+
+/**
+ * @brief implements function get_first of linked_list_t
+ */
+static status_t get_first(private_linked_list_t *this, void **item)
+{
+       if (this == NULL)
+       {
+               return FAILED;
+       }
+
+       if (this->count == 0)
+       {
+               return FAILED;
+       }
+
+       if (this->first == NULL)
+       {
+               return FAILED;
+       }
+
+       *item = this->first->value;
+
+       return SUCCESS;
+}
+
+/**
+ * @brief implements function insert_last of linked_list_t
+ */
+static status_t insert_last(private_linked_list_t *this, void *item)
+{
+       if (this == NULL)
+       {
+               return FAILED;
+       }
+
+       linked_list_element_t *element = (linked_list_element_t *) linked_list_element_create(item);
+
+       if (element == NULL)
+       {
+               return FAILED;
+       }
+
+       if (this->count == 0)
+       {
+               /* first entry in list */
+               this->first = element;
+               this->last = element;
+               element->previous = NULL;
+               element->next = NULL;
+       }else
+       {
+               if ((this->first == NULL) || (this->last == NULL))
+               {
+                       /* should never happen */
+                       element->destroy(element);
+                       return FAILED;
+               }
+               linked_list_element_t *old_last_element = this->last;
+               element->previous = old_last_element;
+               element->next = NULL;
+               old_last_element->next = element;
+               this->last = element;
+       }
+
+       this->count++;
+
+       return SUCCESS;
+}
+
+/**
+ * @brief implements function remove_last of linked_list_t
+ */
+static status_t remove_last(private_linked_list_t *this, void **item)
+{
+       if (this == NULL)
+       {
+               return FAILED;
+       }
+
+       if (this->count == 0)
+       {
+               return FAILED;
+       }
+
+       if (this->last == NULL)
+       {
+               return FAILED;
+       }
+
+       linked_list_element_t *element = this->last;
+
+       if (element->previous != NULL)
+       {
+               element->previous->next = NULL;
+       }
+       this->last = element->previous;
+
+       *item = element->value;
+
+       this->count--;
+
+       return  (element->destroy(element));
+}
+
+/**
+ * @brief implements function get_last of linked_list_t
+ */
+static status_t get_last(private_linked_list_t *this, void **item)
+{
+       if (this == NULL)
+       {
+               return FAILED;
+       }
+
+       if (this->count == 0)
+       {
+               return FAILED;
+       }
+
+       if (this->last == NULL)
+       {
+               return FAILED;
+       }
+
+       *item = this->last->value;
+
+       return SUCCESS;
+}
+
+/**
+ * @brief implements function insert_before of linked_list_t
+ */
+static status_t insert_before(private_linked_list_t *this, private_linked_list_iterator_t * iterator, void *item)
+{
+       if ((this == NULL) || (iterator == NULL))
+       {
+               return FAILED;
+       }
+
+       if (this->count == 0)
+       {
+               return FAILED;
+       }
+
+       if (iterator->current == NULL)
+       {
+               return (this->public.insert_first(&this->public,item));
+       }
+
+       linked_list_element_t *element =(linked_list_element_t *) linked_list_element_create(item);
+
+       if (element == NULL)
+       {
+               return FAILED;
+       }
+
+       if (iterator->current->previous == NULL)
+       {
+               if (this->first != iterator->current)
+               {
+                       element->destroy(element);
+                       return FAILED;
+               }
+
+               iterator->current->previous = element;
+               element->next = iterator->current;
+               this->first = element;
+       }
+       else
+       {
+               iterator->current->previous->next = element;
+               element->previous = iterator->current->previous;
+               iterator->current->previous = element;
+               element->next = iterator->current;
+       }
+
+       this->count++;
+
+       return SUCCESS;
+}
+
+/**
+ * @brief implements function insert_after of linked_list_t
+ */
+static status_t insert_after(private_linked_list_t *this, private_linked_list_iterator_t * iterator, void *item)
+{
+       if ((this == NULL) || (iterator == NULL))
+       {
+               return FAILED;
+       }
+
+       if (this->count == 0)
+       {
+               return FAILED;
+       }
+
+       if (iterator->current == NULL)
+       {
+               return (this->public.insert_first(&this->public,item));
+       }
+
+       linked_list_element_t *element =(linked_list_element_t *) linked_list_element_create(item);
+
+       if (element == NULL)
+       {
+               return FAILED;
+       }
+
+       if (iterator->current->next == NULL)
+       {
+               if (this->last != iterator->current)
+               {
+                       element->destroy(element);
+                       return FAILED;
+               }
+
+               iterator->current->next = element;
+               element->previous = iterator->current;
+               this->last = element;
+       }
+       else
+       {
+               iterator->current->next->previous = element;
+               element->next = iterator->current->next;
+               iterator->current->next = element;
+               element->previous = iterator->current;
+       }
+
+       this->count++;
+       return SUCCESS;
+}
+
+/**
+ * @brief implements function remove of linked_list_t
+ */
+static status_t linked_list_remove(private_linked_list_t *this, private_linked_list_iterator_t * iterator)
+{
+       linked_list_element_t *new_current;
+
+       if ((this == NULL) || (iterator == NULL) || (iterator->current == NULL))
+       {
+               return FAILED;
+       }
+
+       if (this->count == 0)
+       {
+               return FAILED;
+       }
+       /* find out the new iterator position */
+       if (iterator->current->previous != NULL)
+       {
+               new_current = iterator->current->previous;
+       }
+       else if (iterator->current->next != NULL)
+       {
+               new_current = iterator->current->next;
+       }
+       else
+       {
+               new_current = NULL;
+       }
+
+       /* now delete the entry :-) */
+       if (iterator->current->previous == NULL)
+       {
+               if (iterator->current->next == NULL)
+               {
+                       this->first = NULL;
+                       this->last = NULL;
+               }
+               else
+               {
+                       iterator->current->next->previous = NULL;
+                       this->first = iterator->current->next;
+               }
+       }
+       else if (iterator->current->next == NULL)
+       {
+               iterator->current->previous->next = NULL;
+               this->last = iterator->current->previous;
+       }
+       else
+       {
+               iterator->current->previous->next = iterator->current->next;
+               iterator->current->next->previous = iterator->current->previous;
+       }
+
+       this->count--;
+       iterator->current->destroy(iterator->current);
+       /* set the new iterator position */
+       iterator->current = new_current;
+       return SUCCESS;
+}
+
+/**
+ * @brief implements function destroy of linked_list_t
+ */
+static status_t linked_list_destroy(private_linked_list_t *this)
+{
+       if (this == NULL)
+       {
+               return FAILED;
+       }
+
+       /* Remove all list items before destroying list */
+       while (this->count > 0)
+       {
+               void * value;
+               /* values are not destroyed so memory leaks are possible
+                * if list is not empty when deleting */
+               if (this->public.remove_first(&(this->public),&value) != SUCCESS)
+               {
+                       allocator_free(this);
+                       return FAILED;
+               }
+       }
+       allocator_free(this);
+       return SUCCESS;
+}
+
+/*
+ * Described in header
+ */
+linked_list_t *linked_list_create()
+{
+       private_linked_list_t *this = allocator_alloc_thing(private_linked_list_t);
+
+       this->public.get_count = (int (*) (linked_list_t *linked_list)) get_count;
+       this->public.create_iterator = (status_t (*) (linked_list_t *linked_list, linked_list_iterator_t **iterator,bool forward)) create_iterator;
+       this->public.get_first = (status_t (*) (linked_list_t *linked_list, void **item)) get_first;
+       this->public.get_last = (status_t (*) (linked_list_t *linked_list, void **item)) get_last;
+       this->public.insert_first = (status_t (*) (linked_list_t *linked_list, void *item)) insert_first;
+       this->public.insert_last = (status_t (*) (linked_list_t *linked_list, void *item)) insert_last;
+       this->public.insert_before = (status_t (*) (linked_list_t *linked_list, linked_list_iterator_t * element, void *item)) insert_before;
+       this->public.insert_after = (status_t (*) (linked_list_t *linked_list, linked_list_iterator_t * element, void *item)) insert_after;
+       this->public.remove = (status_t (*) (linked_list_t *linked_list, linked_list_iterator_t * element)) linked_list_remove;
+       this->public.remove_first = (status_t (*) (linked_list_t *linked_list, void **item)) remove_first;
+       this->public.remove_last = (status_t (*) (linked_list_t *linked_list, void **item)) remove_last;
+       this->public.destroy = (status_t (*) (linked_list_t *linked_list)) linked_list_destroy;
+
+       this->count = 0;
+       this->first = NULL;
+       this->last = NULL;
+
+       return (&(this->public));
+}
diff --git a/Source/charon/utils/linked_list.h b/Source/charon/utils/linked_list.h
new file mode 100644 (file)
index 0000000..d48ba26
--- /dev/null
@@ -0,0 +1,219 @@
+/**
+ * @file linked_list.h
+ * 
+ * @brief Generic Double Linked List
+ * 
+ */
+
+/*
+ * Copyright (C) 2005 Jan Hutter, Martin Willi
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program 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 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program 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.
+ */
+
+#ifndef LINKED_LIST_H_
+#define LINKED_LIST_H_
+
+#include "../types.h"
+
+/**
+ * @brief Iterator for a linked list
+ * 
+ * This element holds a pointer to the current element in the linked list
+ * 
+ * @warning the iterator is NOT thread-save
+ */
+typedef struct linked_list_iterator_s linked_list_iterator_t;
+
+struct linked_list_iterator_s {
+
+       /**
+        * @brief returns TRUE if more elements are available
+        * 
+        * @param this calling object
+        * @return if more elements are avaiable TRUE, FALSE otherwise
+        */
+       bool (*has_next) (linked_list_iterator_t *this);
+
+       /**
+        * @brief returns the current value at the iterator position
+        * 
+        * @param this calling object
+        * @param[out] value value is set to the current value at iterator position
+        * @return SUCCESS if succeeded, FAILED otherwise
+        */
+       status_t (*current) (linked_list_iterator_t *this, void **value);
+
+       /**
+        * @brief Resets a linked_list_iterator object
+        * 
+        * @param this calling object
+        * @return SUCCESS if succeeded, FAILED otherwise
+        */
+       status_t (*reset) (linked_list_iterator_t *this);
+
+       /**
+        * @brief Destroys a linked_list_iterator object
+        * 
+        * @param this calling object
+        * @return SUCCESS if succeeded, FAILED otherwise
+        */
+       status_t (*destroy) (linked_list_iterator_t *this);
+};
+
+/**
+ * @brief Double Linked List (named only as linked list)
+ *
+ * @warning Access to an object of this type is not thread-save
+ * 
+ * @see job_queue_t
+ * @see event_queue_t
+ * @see send_queue_t
+ */
+typedef struct linked_list_s linked_list_t;
+
+
+struct linked_list_s {
+
+       /**
+        * @brief gets the count of items in the list
+        * 
+        * @param linked_list calling object
+        * @return number of items in list
+        */
+       int (*get_count) (linked_list_t *linked_list);
+       
+       /**
+        * @brief creates a iterator for the given list
+        * 
+        * @warning has to get destroyed
+        * 
+        * @param linked_list calling object
+        * @param[out] iterator place where the iterator is written
+        * @param[in] forward iterator direction (TRUE: front to end)
+        * @return SUCCESS if succeeded, FAILED otherwise
+        */
+       status_t (*create_iterator) (linked_list_t *linked_list, linked_list_iterator_t **iterator,bool forward);
+
+       /**
+        * @brief inserts a new item at the beginning of the list
+        * 
+        * @param linked_list calling object
+        * @param[in] item value to insert in list
+        * @return SUCCESS if succeeded, FAILED otherwise
+        */
+       status_t (*insert_first) (linked_list_t *linked_list, void *item);
+       
+       /**
+        * @brief inserts a new item before the given iterator position
+        * 
+        * The iterator position is not changed after inserting
+        * 
+        * @param linked_list calling object
+        * @param iterator new element is inserted before this iterator
+        * @param[in] item value to insert in list
+        * @return SUCCESS if succeeded, FAILED otherwise
+        */
+       status_t (*insert_before) (linked_list_t *linked_list, linked_list_iterator_t *iterator, void *item);
+
+       /**
+        * @brief inserts a new item after the given iterator position
+        * 
+        * The iterator position is not changed after inserting
+        * 
+        * @param linked_list calling object
+        * @param iterator new element is inserted after this iterator
+        * @param[in] item value to insert in list
+        * @return SUCCESS if succeeded, FAILED otherwise
+        */
+       status_t (*insert_after) (linked_list_t *linked_list, linked_list_iterator_t *iterator, void *item);
+
+       /**
+        * @brief removes an element from list at the given iterator position
+        * 
+        * The position of the iterator is set in the following order:
+        * - to the item before, if available
+        * - otherwise to the item after, if available
+        * - otherwise it gets reseted
+        * 
+        * @param linked_list calling object
+        * @param iterator iterator holding the position of the element to remove
+        * @return SUCCESS if succeeded, FAILED otherwise
+        */
+       status_t (*remove) (linked_list_t *linked_list, linked_list_iterator_t *iterator);
+
+       /**
+        * @brief removes the first item in the list and returns its value
+        * 
+        * @param linked_list calling object
+        * @param[in] item returned value of first item
+        * @return SUCCESS if succeeded, FAILED otherwise
+        */
+       status_t (*remove_first) (linked_list_t *linked_list, void **item);
+
+       /**
+        * @brief returns the value of the first list item without removing it
+        * 
+        * @param linked_list calling object
+        * @param[out] item returned value of first item
+        * @return SUCCESS if succeeded, FAILED otherwise
+        */
+       status_t (*get_first) (linked_list_t *linked_list, void **item);
+
+       /**
+        * @brief inserts a new item at the end of the list
+        * 
+        * @param linked_list calling object
+        * @param[in] item value to insert into list
+        * @return SUCCESS if succeeded, FAILED otherwise
+        */
+       status_t (*insert_last) (linked_list_t *linked_list, void *item);
+       
+       /**
+        * @brief removes the last item in the list and returns its value
+        * 
+        * @param linked_list calling object
+        * @param[out] item returned value of last item
+        * @return SUCCESS if succeeded, FAILED otherwise
+        */
+       status_t (*remove_last) (linked_list_t *linked_list, void **item);
+
+       /**
+        * @brief Returns the value of the last list item without removing it
+        * 
+        * @param linked_list calling object
+        * @param[out] item returned value of last item
+        * @return SUCCESS if succeeded, FAILED otherwise
+        */
+       status_t (*get_last) (linked_list_t *linked_list, void **item);
+       
+       /**
+        * @brief Destroys a linked_list object
+        * 
+        * @warning all items are removed before deleting the list. The
+        *          associated values are NOT destroyed. 
+        *                      Destroying an list which is not empty may cause
+        *                      memory leaks!
+        * 
+        * @param linked_list calling object
+        * @return SUCCESS if succeeded, FAILED otherwise
+        */
+       status_t (*destroy) (linked_list_t *linked_list);
+};
+
+/**
+ * @brief Creates an empty linked list object
+ */
+linked_list_t *linked_list_create(void);
+
+
+#endif /*LINKED_LIST_H_*/