Migrated sqlite plugin to INIT/METHOD macros
authorAndreas Steffen <andreas.steffen@strongswan.org>
Sat, 4 Dec 2010 09:20:33 +0000 (10:20 +0100)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Sat, 4 Dec 2010 09:20:33 +0000 (10:20 +0100)
src/libstrongswan/plugins/sqlite/sqlite_database.c
src/libstrongswan/plugins/sqlite/sqlite_plugin.c

index 3e20dbb..7d2bd17 100644 (file)
@@ -213,10 +213,8 @@ static bool sqlite_enumerator_enumerate(sqlite_enumerator_t *this, ...)
        return TRUE;
 }
 
-/**
- * Implementation of database_t.query.
- */
-static enumerator_t* query(private_sqlite_database_t *this, char *sql, ...)
+METHOD(database_t, query, enumerator_t*,
+       private_sqlite_database_t *this, char *sql, ...)
 {
        sqlite3_stmt *stmt;
        va_list args;
@@ -248,10 +246,8 @@ static enumerator_t* query(private_sqlite_database_t *this, char *sql, ...)
        return (enumerator_t*)enumerator;
 }
 
-/**
- * Implementation of database_t.execute.
- */
-static int execute(private_sqlite_database_t *this, int *rowid, char *sql, ...)
+METHOD(database_t, execute, int,
+       private_sqlite_database_t *this, int *rowid, char *sql, ...)
 {
        sqlite3_stmt *stmt;
        int affected = -1;
@@ -283,10 +279,8 @@ static int execute(private_sqlite_database_t *this, int *rowid, char *sql, ...)
        return affected;
 }
 
-/**
- * Implementation of database_t.get_driver
- */
-static db_driver_t get_driver(private_sqlite_database_t *this)
+METHOD(database_t, get_driver, db_driver_t,
+       private_sqlite_database_t *this)
 {
        return DB_SQLITE;
 }
@@ -302,10 +296,8 @@ static int busy_handler(private_sqlite_database_t *this, int count)
        return 1;
 }
 
-/**
- * Implementation of database_t.destroy
- */
-static void destroy(private_sqlite_database_t *this)
+METHOD(database_t, destroy, void,
+       private_sqlite_database_t *this)
 {
        sqlite3_close(this->db);
        this->mutex->destroy(this->mutex);
@@ -329,14 +321,17 @@ sqlite_database_t *sqlite_database_create(char *uri)
        }
        file = uri + 9;
 
-       this = malloc_thing(private_sqlite_database_t);
-
-       this->public.db.query = (enumerator_t* (*)(database_t *this, char *sql, ...))query;
-       this->public.db.execute = (int (*)(database_t *this, int *rowid, char *sql, ...))execute;
-       this->public.db.get_driver = (db_driver_t(*)(database_t*))get_driver;
-       this->public.db.destroy = (void(*)(database_t*))destroy;
-
-       this->mutex = mutex_create(MUTEX_TYPE_RECURSIVE);
+       INIT(this,
+               .public = {
+                       .db = {
+                               .query = _query,
+                               .execute = _execute,
+                               .get_driver = _get_driver,
+                               .destroy = _destroy,
+                       },
+               },
+               .mutex = mutex_create(MUTEX_TYPE_RECURSIVE),
+       );
 
        if (sqlite3_open(file, &this->db) != SQLITE_OK)
        {
index 332d823..e0b8e6c 100644 (file)
@@ -31,10 +31,8 @@ struct private_sqlite_plugin_t {
        sqlite_plugin_t public;
 };
 
-/**
- * Implementation of plugin_t.destroy
- */
-static void destroy(private_sqlite_plugin_t *this)
+METHOD(plugin_t, destroy, void,
+       private_sqlite_plugin_t *this)
 {
        lib->db->remove_database(lib->db,
                                                         (database_constructor_t)sqlite_database_create);
@@ -46,9 +44,15 @@ static void destroy(private_sqlite_plugin_t *this)
  */
 plugin_t *sqlite_plugin_create()
 {
-       private_sqlite_plugin_t *this = malloc_thing(private_sqlite_plugin_t);
-
-       this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
+       private_sqlite_plugin_t *this;
+
+       INIT(this,
+               .public = {
+                       .plugin = {
+                               .destroy = _destroy,
+                       },
+               },
+       );
 
        lib->db->add_database(lib->db,
                                                  (database_constructor_t)sqlite_database_create);