Migrated backend_manager_t to INIT/METHOD macros
authorAndreas Steffen <andreas.steffen@strongswan.org>
Thu, 25 Nov 2010 21:43:19 +0000 (22:43 +0100)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Thu, 25 Nov 2010 21:43:19 +0000 (22:43 +0100)
src/libcharon/config/backend_manager.c

index 90ef585..7b69eda 100644 (file)
@@ -128,11 +128,8 @@ static ike_cfg_match_t get_ike_match(ike_cfg_t *cand, host_t *me, host_t *other)
        return match;
 }
 
-/**
- * implements backend_manager_t.get_ike_cfg.
- */
-static ike_cfg_t *get_ike_cfg(private_backend_manager_t *this,
-                                                         host_t *me, host_t *other)
+METHOD(backend_manager_t, get_ike_cfg, ike_cfg_t*,
+       private_backend_manager_t *this, host_t *me, host_t *other)
 {
        ike_cfg_t *current, *found = NULL;
        enumerator_t *enumerator;
@@ -308,12 +305,9 @@ static void insert_sorted(match_entry_t *entry, linked_list_t *list,
        }
 }
 
-/**
- * Implements backend_manager_t.create_peer_cfg_enumerator.
- */
-static enumerator_t *create_peer_cfg_enumerator(private_backend_manager_t *this,
-                                                       host_t *me, host_t *other, identification_t *my_id,
-                                                       identification_t *other_id)
+METHOD(backend_manager_t, create_peer_cfg_enumerator, enumerator_t*,
+       private_backend_manager_t *this, host_t *me, host_t *other,
+       identification_t *my_id, identification_t *other_id)
 {
        enumerator_t *enumerator;
        peer_data_t *data;
@@ -372,10 +366,8 @@ static enumerator_t *create_peer_cfg_enumerator(private_backend_manager_t *this,
                                                                        (void*)peer_enum_filter_destroy);
 }
 
-/**
- * implements backend_manager_t.get_peer_cfg_by_name.
- */
-static peer_cfg_t *get_peer_cfg_by_name(private_backend_manager_t *this, char *name)
+METHOD(backend_manager_t, get_peer_cfg_by_name, peer_cfg_t*,
+       private_backend_manager_t *this, char *name)
 {
        backend_t *backend;
        peer_cfg_t *config = NULL;
@@ -392,30 +384,24 @@ static peer_cfg_t *get_peer_cfg_by_name(private_backend_manager_t *this, char *n
        return config;
 }
 
-/**
- * Implementation of backend_manager_t.remove_backend.
- */
-static void remove_backend(private_backend_manager_t *this, backend_t *backend)
+METHOD(backend_manager_t, remove_backend, void,
+       private_backend_manager_t *this, backend_t *backend)
 {
        this->lock->write_lock(this->lock);
        this->backends->remove(this->backends, backend, NULL);
        this->lock->unlock(this->lock);
 }
 
-/**
- * Implementation of backend_manager_t.add_backend.
- */
-static void add_backend(private_backend_manager_t *this, backend_t *backend)
+METHOD(backend_manager_t, add_backend, void,
+       private_backend_manager_t *this, backend_t *backend)
 {
        this->lock->write_lock(this->lock);
        this->backends->insert_last(this->backends, backend);
        this->lock->unlock(this->lock);
 }
 
-/**
- * Implementation of backend_manager_t.destroy.
- */
-static void destroy(private_backend_manager_t *this)
+METHOD(backend_manager_t, destroy, void,
+       private_backend_manager_t *this)
 {
        this->backends->destroy(this->backends);
        this->lock->destroy(this->lock);
@@ -424,20 +410,24 @@ static void destroy(private_backend_manager_t *this)
 
 /*
  * Described in header-file
+
  */
 backend_manager_t *backend_manager_create()
 {
-       private_backend_manager_t *this = malloc_thing(private_backend_manager_t);
-
-       this->public.get_ike_cfg = (ike_cfg_t* (*)(backend_manager_t*, host_t*, host_t*))get_ike_cfg;
-       this->public.get_peer_cfg_by_name = (peer_cfg_t* (*)(backend_manager_t*,char*))get_peer_cfg_by_name;
-       this->public.create_peer_cfg_enumerator = (enumerator_t* (*)(backend_manager_t*,host_t*,host_t*,identification_t*,identification_t*))create_peer_cfg_enumerator;
-       this->public.add_backend = (void(*)(backend_manager_t*, backend_t *backend))add_backend;
-       this->public.remove_backend = (void(*)(backend_manager_t*, backend_t *backend))remove_backend;
-       this->public.destroy = (void (*)(backend_manager_t*))destroy;
+       private_backend_manager_t *this;
 
-       this->backends = linked_list_create();
-       this->lock = rwlock_create(RWLOCK_TYPE_DEFAULT);
+       INIT(this,
+               .public = {
+                       .get_ike_cfg = _get_ike_cfg,
+                       .get_peer_cfg_by_name = _get_peer_cfg_by_name,
+                       .create_peer_cfg_enumerator = _create_peer_cfg_enumerator,
+                       .add_backend = _add_backend,
+                       .remove_backend = _remove_backend,
+                       .destroy = _destroy,
+               },
+               .backends = linked_list_create(),
+               .lock = rwlock_create(RWLOCK_TYPE_DEFAULT),
+       );
 
        return &this->public;
 }