Moved bus_t to METHOD/INIT macros

This commit is contained in:
Martin Willi
2010-07-13 10:26:07 +02:00
parent 1c8c924610
commit 88fa56b1ad
+68 -107
View File
@@ -102,20 +102,16 @@ static void entry_destroy(entry_t *entry)
free(entry); free(entry);
} }
/** METHOD(bus_t, add_listener, void,
* Implementation of bus_t.add_listener. private_bus_t *this, listener_t *listener)
*/
static void add_listener(private_bus_t *this, listener_t *listener)
{ {
this->mutex->lock(this->mutex); this->mutex->lock(this->mutex);
this->listeners->insert_last(this->listeners, entry_create(listener, FALSE)); this->listeners->insert_last(this->listeners, entry_create(listener, FALSE));
this->mutex->unlock(this->mutex); this->mutex->unlock(this->mutex);
} }
/** METHOD(bus_t, remove_listener, void,
* Implementation of bus_t.remove_listener. private_bus_t *this, listener_t *listener)
*/
static void remove_listener(private_bus_t *this, listener_t *listener)
{ {
enumerator_t *enumerator; enumerator_t *enumerator;
entry_t *entry; entry_t *entry;
@@ -156,10 +152,8 @@ static void listener_cleanup(cleanup_data_t *data)
entry_destroy(data->entry); entry_destroy(data->entry);
} }
/** METHOD(bus_t, listen_, void,
* Implementation of bus_t.listen. private_bus_t *this, listener_t *listener, job_t *job)
*/
static void listen_(private_bus_t *this, listener_t *listener, job_t *job)
{ {
bool old; bool old;
cleanup_data_t data; cleanup_data_t data;
@@ -184,18 +178,14 @@ static void listen_(private_bus_t *this, listener_t *listener, job_t *job)
entry_destroy(data.entry); entry_destroy(data.entry);
} }
/** METHOD(bus_t, set_sa, void,
* Implementation of bus_t.set_sa. private_bus_t *this, ike_sa_t *ike_sa)
*/
static void set_sa(private_bus_t *this, ike_sa_t *ike_sa)
{ {
this->thread_sa->set(this->thread_sa, ike_sa); this->thread_sa->set(this->thread_sa, ike_sa);
} }
/** METHOD(bus_t, get_sa, ike_sa_t*,
* Implementation of bus_t.get_sa private_bus_t *this)
*/
static ike_sa_t* get_sa(private_bus_t *this)
{ {
return this->thread_sa->get(this->thread_sa); return this->thread_sa->get(this->thread_sa);
} }
@@ -252,11 +242,9 @@ static bool log_cb(entry_t *entry, log_data_t *data)
return FALSE; return FALSE;
} }
/** METHOD(bus_t, vlog, void,
* Implementation of bus_t.vlog. private_bus_t *this, debug_t group, level_t level,
*/ char* format, va_list args)
static void vlog(private_bus_t *this, debug_t group, level_t level,
char* format, va_list args)
{ {
log_data_t data; log_data_t data;
@@ -276,11 +264,8 @@ static void vlog(private_bus_t *this, debug_t group, level_t level,
va_end(data.args); va_end(data.args);
} }
/** METHOD(bus_t, log_, void,
* Implementation of bus_t.log. private_bus_t *this, debug_t group, level_t level, char* format, ...)
*/
static void log_(private_bus_t *this, debug_t group, level_t level,
char* format, ...)
{ {
va_list args; va_list args;
@@ -307,10 +292,8 @@ static void unregister_listener(private_bus_t *this, entry_t *entry,
this->listeners->remove_at(this->listeners, enumerator); this->listeners->remove_at(this->listeners, enumerator);
} }
/** METHOD(bus_t, alert, void,
* Implementation of bus_t.alert private_bus_t *this, alert_t alert, ...)
*/
static void alert(private_bus_t *this, alert_t alert, ...)
{ {
enumerator_t *enumerator; enumerator_t *enumerator;
ike_sa_t *ike_sa; ike_sa_t *ike_sa;
@@ -342,11 +325,8 @@ static void alert(private_bus_t *this, alert_t alert, ...)
this->mutex->unlock(this->mutex); this->mutex->unlock(this->mutex);
} }
/** METHOD(bus_t, ike_state_change, void,
* Implementation of bus_t.ike_state_change private_bus_t *this, ike_sa_t *ike_sa, ike_sa_state_t state)
*/
static void ike_state_change(private_bus_t *this, ike_sa_t *ike_sa,
ike_sa_state_t state)
{ {
enumerator_t *enumerator; enumerator_t *enumerator;
entry_t *entry; entry_t *entry;
@@ -372,11 +352,8 @@ static void ike_state_change(private_bus_t *this, ike_sa_t *ike_sa,
this->mutex->unlock(this->mutex); this->mutex->unlock(this->mutex);
} }
/** METHOD(bus_t, child_state_change, void,
* Implementation of bus_t.child_state_change private_bus_t *this, child_sa_t *child_sa, child_sa_state_t state)
*/
static void child_state_change(private_bus_t *this, child_sa_t *child_sa,
child_sa_state_t state)
{ {
enumerator_t *enumerator; enumerator_t *enumerator;
ike_sa_t *ike_sa; ike_sa_t *ike_sa;
@@ -406,10 +383,8 @@ static void child_state_change(private_bus_t *this, child_sa_t *child_sa,
this->mutex->unlock(this->mutex); this->mutex->unlock(this->mutex);
} }
/** METHOD(bus_t, message, void,
* Implementation of bus_t.message private_bus_t *this, message_t *message, bool incoming)
*/
static void message(private_bus_t *this, message_t *message, bool incoming)
{ {
enumerator_t *enumerator; enumerator_t *enumerator;
ike_sa_t *ike_sa; ike_sa_t *ike_sa;
@@ -439,12 +414,9 @@ static void message(private_bus_t *this, message_t *message, bool incoming)
this->mutex->unlock(this->mutex); this->mutex->unlock(this->mutex);
} }
/** METHOD(bus_t, ike_keys, void,
* Implementation of bus_t.ike_keys private_bus_t *this, ike_sa_t *ike_sa, diffie_hellman_t *dh,
*/ chunk_t nonce_i, chunk_t nonce_r, ike_sa_t *rekey)
static void ike_keys(private_bus_t *this, ike_sa_t *ike_sa,
diffie_hellman_t *dh, chunk_t nonce_i, chunk_t nonce_r,
ike_sa_t *rekey)
{ {
enumerator_t *enumerator; enumerator_t *enumerator;
entry_t *entry; entry_t *entry;
@@ -471,11 +443,9 @@ static void ike_keys(private_bus_t *this, ike_sa_t *ike_sa,
this->mutex->unlock(this->mutex); this->mutex->unlock(this->mutex);
} }
/** METHOD(bus_t, child_keys, void,
* Implementation of bus_t.child_keys private_bus_t *this, child_sa_t *child_sa, diffie_hellman_t *dh,
*/ chunk_t nonce_i, chunk_t nonce_r)
static void child_keys(private_bus_t *this, child_sa_t *child_sa,
diffie_hellman_t *dh, chunk_t nonce_i, chunk_t nonce_r)
{ {
enumerator_t *enumerator; enumerator_t *enumerator;
ike_sa_t *ike_sa; ike_sa_t *ike_sa;
@@ -505,10 +475,8 @@ static void child_keys(private_bus_t *this, child_sa_t *child_sa,
this->mutex->unlock(this->mutex); this->mutex->unlock(this->mutex);
} }
/** METHOD(bus_t, child_updown, void,
* Implementation of bus_t.child_updown private_bus_t *this, child_sa_t *child_sa, bool up)
*/
static void child_updown(private_bus_t *this, child_sa_t *child_sa, bool up)
{ {
enumerator_t *enumerator; enumerator_t *enumerator;
ike_sa_t *ike_sa; ike_sa_t *ike_sa;
@@ -538,10 +506,8 @@ static void child_updown(private_bus_t *this, child_sa_t *child_sa, bool up)
this->mutex->unlock(this->mutex); this->mutex->unlock(this->mutex);
} }
/** METHOD(bus_t, child_rekey, void,
* Implementation of bus_t.child_rekey private_bus_t *this, child_sa_t *old, child_sa_t *new)
*/
static void child_rekey(private_bus_t *this, child_sa_t *old, child_sa_t *new)
{ {
enumerator_t *enumerator; enumerator_t *enumerator;
ike_sa_t *ike_sa; ike_sa_t *ike_sa;
@@ -570,10 +536,8 @@ static void child_rekey(private_bus_t *this, child_sa_t *old, child_sa_t *new)
this->mutex->unlock(this->mutex); this->mutex->unlock(this->mutex);
} }
/** METHOD(bus_t, ike_updown, void,
* Implementation of bus_t.ike_updown private_bus_t *this, ike_sa_t *ike_sa, bool up)
*/
static void ike_updown(private_bus_t *this, ike_sa_t *ike_sa, bool up)
{ {
enumerator_t *enumerator; enumerator_t *enumerator;
entry_t *entry; entry_t *entry;
@@ -613,10 +577,8 @@ static void ike_updown(private_bus_t *this, ike_sa_t *ike_sa, bool up)
} }
} }
/** METHOD(bus_t, ike_rekey, void,
* Implementation of bus_t.ike_rekey private_bus_t *this, ike_sa_t *old, ike_sa_t *new)
*/
static void ike_rekey(private_bus_t *this, ike_sa_t *old, ike_sa_t *new)
{ {
enumerator_t *enumerator; enumerator_t *enumerator;
entry_t *entry; entry_t *entry;
@@ -642,10 +604,8 @@ static void ike_rekey(private_bus_t *this, ike_sa_t *old, ike_sa_t *new)
this->mutex->unlock(this->mutex); this->mutex->unlock(this->mutex);
} }
/** METHOD(bus_t, authorize, bool,
* Implementation of bus_t.authorize private_bus_t *this, bool final)
*/
static bool authorize(private_bus_t *this, bool final)
{ {
enumerator_t *enumerator; enumerator_t *enumerator;
ike_sa_t *ike_sa; ike_sa_t *ike_sa;
@@ -680,10 +640,8 @@ static bool authorize(private_bus_t *this, bool final)
return success; return success;
} }
/** METHOD(bus_t, destroy, void,
* Implementation of bus_t.destroy. private_bus_t *this)
*/
static void destroy(private_bus_t *this)
{ {
this->thread_sa->destroy(this->thread_sa); this->thread_sa->destroy(this->thread_sa);
this->mutex->destroy(this->mutex); this->mutex->destroy(this->mutex);
@@ -696,31 +654,34 @@ static void destroy(private_bus_t *this)
*/ */
bus_t *bus_create() bus_t *bus_create()
{ {
private_bus_t *this = malloc_thing(private_bus_t); private_bus_t *this;
this->public.add_listener = (void(*)(bus_t*,listener_t*))add_listener; INIT(this,
this->public.remove_listener = (void(*)(bus_t*,listener_t*))remove_listener; .public = {
this->public.listen = (void(*)(bus_t*, listener_t *listener, job_t *job))listen_; .add_listener = _add_listener,
this->public.set_sa = (void(*)(bus_t*,ike_sa_t*))set_sa; .remove_listener = _remove_listener,
this->public.get_sa = (ike_sa_t*(*)(bus_t*))get_sa; .listen = _listen_,
this->public.log = (void(*)(bus_t*,debug_t,level_t,char*,...))log_; .set_sa = _set_sa,
this->public.vlog = (void(*)(bus_t*,debug_t,level_t,char*,va_list))vlog; .get_sa = _get_sa,
this->public.alert = (void(*)(bus_t*, alert_t alert, ...))alert; .log = _log_,
this->public.ike_state_change = (void(*)(bus_t*,ike_sa_t*,ike_sa_state_t))ike_state_change; .vlog = _vlog,
this->public.child_state_change = (void(*)(bus_t*,child_sa_t*,child_sa_state_t))child_state_change; .alert = _alert,
this->public.message = (void(*)(bus_t*, message_t *message, bool incoming))message; .ike_state_change = _ike_state_change,
this->public.ike_keys = (void(*)(bus_t*, ike_sa_t *ike_sa, diffie_hellman_t *dh, chunk_t nonce_i, chunk_t nonce_r, ike_sa_t *rekey))ike_keys; .child_state_change = _child_state_change,
this->public.child_keys = (void(*)(bus_t*, child_sa_t *child_sa, diffie_hellman_t *dh, chunk_t nonce_i, chunk_t nonce_r))child_keys; .message = _message,
this->public.ike_updown = (void(*)(bus_t*, ike_sa_t *ike_sa, bool up))ike_updown; .ike_keys = _ike_keys,
this->public.ike_rekey = (void(*)(bus_t*, ike_sa_t *old, ike_sa_t *new))ike_rekey; .child_keys = _child_keys,
this->public.child_updown = (void(*)(bus_t*, child_sa_t *child_sa, bool up))child_updown; .ike_updown = _ike_updown,
this->public.child_rekey = (void(*)(bus_t*, child_sa_t *old, child_sa_t *new))child_rekey; .ike_rekey = _ike_rekey,
this->public.authorize = (bool(*)(bus_t*, bool final))authorize; .child_updown = _child_updown,
this->public.destroy = (void(*)(bus_t*)) destroy; .child_rekey = _child_rekey,
.authorize = _authorize,
this->listeners = linked_list_create(); .destroy = _destroy,
this->mutex = mutex_create(MUTEX_TYPE_RECURSIVE); },
this->thread_sa = thread_value_create(NULL); .listeners = linked_list_create(),
.mutex = mutex_create(MUTEX_TYPE_RECURSIVE),
.thread_sa = thread_value_create(NULL),
);
return &this->public; return &this->public;
} }