added connection management to TNCCS manager

This commit is contained in:
Andreas Steffen
2010-11-09 20:43:50 +01:00
parent fe5ce8f3a2
commit e7da87f942
2 changed files with 88 additions and 2 deletions
+72 -2
View File
@@ -15,11 +15,13 @@
#include "tnccs_manager.h"
#include <debug.h>
#include <utils/linked_list.h>
#include <threading/rwlock.h>
typedef struct private_tnccs_manager_t private_tnccs_manager_t;
typedef struct tnccs_entry_t tnccs_entry_t;
typedef struct tnccs_connection_entry_t tnccs_connection_entry_t;
/**
* TNCCS constructor entry
@@ -37,6 +39,22 @@ struct tnccs_entry_t {
tnccs_constructor_t constructor;
};
/**
* TNCCS connection entry
*/
struct tnccs_connection_entry_t {
/**
* TNCCS connection ID
*/
TNC_ConnectionID id;
/**
* TNCCS instance
*/
tnccs_t *tnccs;
};
/**
* private data of tnccs_manager
*/
@@ -48,14 +66,25 @@ struct private_tnccs_manager_t {
tnccs_manager_t public;
/**
* list of tnccs_entry_t's
* list of TNCCS protocol entries
*/
linked_list_t *protocols;
/**
* rwlock to lock methods
* connection ID counter
*/
TNC_ConnectionID connection_id;
/**
* list of TNCCS connection entries
*/
linked_list_t *connections;
/**
* rwlock to lock TNCCS protocol and connection entries
*/
rwlock_t *lock;
};
METHOD(tnccs_manager_t, add_method, void,
@@ -117,10 +146,48 @@ METHOD(tnccs_manager_t, create_instance, tnccs_t*,
return protocol;
}
METHOD(tnccs_manager_t, create_connection, TNC_ConnectionID,
private_tnccs_manager_t *this, tnccs_t *tnccs)
{
tnccs_connection_entry_t *entry = malloc_thing(tnccs_connection_entry_t);
entry->id = ++this->connection_id;
entry->tnccs = tnccs;
this->lock->write_lock(this->lock);
this->connections->insert_last(this->connections, entry);
this->lock->unlock(this->lock);
DBG1(DBG_TNC, "assigned TNCCS Connection ID %u", entry->id);
return entry->id;
}
METHOD(tnccs_manager_t, remove_connection, void,
private_tnccs_manager_t *this, TNC_ConnectionID id)
{
enumerator_t *enumerator;
tnccs_connection_entry_t *entry;
this->lock->write_lock(this->lock);
enumerator = this->connections->create_enumerator(this->connections);
while (enumerator->enumerate(enumerator, &entry))
{
if (id == entry->id)
{
this->connections->remove_at(this->connections, enumerator);
free(entry);
DBG1(DBG_TNC, "removed TNCCS Connection ID %u", id);
}
}
enumerator->destroy(enumerator);
this->lock->unlock(this->lock);
}
METHOD(tnccs_manager_t, destroy, void,
private_tnccs_manager_t *this)
{
this->protocols->destroy_function(this->protocols, free);
this->connections->destroy_function(this->connections, free);
this->lock->destroy(this->lock);
free(this);
}
@@ -137,9 +204,12 @@ tnccs_manager_t *tnccs_manager_create()
.add_method = _add_method,
.remove_method = _remove_method,
.create_instance = _create_instance,
.create_connection = _create_connection,
.remove_connection = _remove_connection,
.destroy = _destroy,
},
.protocols = linked_list_create(),
.connections = linked_list_create(),
.lock = rwlock_create(RWLOCK_TYPE_DEFAULT),
);
+16
View File
@@ -22,6 +22,7 @@
#define TNCCS_MANAGER_H_
#include "tnccs.h"
#include "tncif.h"
typedef struct tnccs_manager_t tnccs_manager_t;
@@ -60,6 +61,21 @@ struct tnccs_manager_t {
tnccs_t* (*create_instance)(tnccs_manager_t *this, tnccs_type_t type,
bool is_server);
/**
* Create a TNCCS connection and assign a unique connection ID
*
* @param tnccs TNCCS connection instance
* @result assigned connection ID
*/
TNC_ConnectionID (*create_connection)(tnccs_manager_t *this, tnccs_t *tnccs);
/**
* Remove a TNCCS connection using its connection ID.
*
* @param id connection ID of the connection to be removed
*/
void (*remove_connection)(tnccs_manager_t *this, TNC_ConnectionID id);
/**
* Destroy a tnccs_manager instance.
*/