Migrated file_logger_t to INIT/METHOD macros.
authorTobias Brunner <tobias@strongswan.org>
Tue, 3 May 2011 08:21:03 +0000 (10:21 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 3 May 2011 08:21:03 +0000 (10:21 +0200)
src/libcharon/bus/listeners/file_logger.c

index 157436a..36d1861 100644 (file)
@@ -53,11 +53,9 @@ struct private_file_logger_t {
        bool ike_name;
 };
 
-/**
- * Implementation of bus_listener_t.log.
- */
-static bool log_(private_file_logger_t *this, debug_t group, level_t level,
-                                int thread, ike_sa_t* ike_sa, char *format, va_list args)
+METHOD(listener_t, log_, bool,
+          private_file_logger_t *this, debug_t group, level_t level, int thread,
+          ike_sa_t* ike_sa, char *format, va_list args)
 {
        if (level <= this->levels[group])
        {
@@ -118,10 +116,8 @@ static bool log_(private_file_logger_t *this, debug_t group, level_t level,
        return TRUE;
 }
 
-/**
- * Implementation of file_logger_t.set_level.
- */
-static void set_level(private_file_logger_t *this, debug_t group, level_t level)
+METHOD(file_logger_t, set_level, void,
+          private_file_logger_t *this, debug_t group, level_t level)
 {
        if (group < DBG_ANY)
        {
@@ -136,10 +132,8 @@ static void set_level(private_file_logger_t *this, debug_t group, level_t level)
        }
 }
 
-/**
- * Implementation of file_logger_t.destroy.
- */
-static void destroy(private_file_logger_t *this)
+METHOD(file_logger_t, destroy, void,
+          private_file_logger_t *this)
 {
        if (this->out != stdout && this->out != stderr)
        {
@@ -153,18 +147,21 @@ static void destroy(private_file_logger_t *this)
  */
 file_logger_t *file_logger_create(FILE *out, char *time_format, bool ike_name)
 {
-       private_file_logger_t *this = malloc_thing(private_file_logger_t);
-
-       /* public functions */
-       memset(&this->public.listener, 0, sizeof(listener_t));
-       this->public.listener.log = (bool(*)(listener_t*,debug_t,level_t,int,ike_sa_t*,char*,va_list))log_;
-       this->public.set_level = (void(*)(file_logger_t*,debug_t,level_t))set_level;
-       this->public.destroy = (void(*)(file_logger_t*))destroy;
-
-       /* private variables */
-       this->out = out;
-       this->time_format = time_format;
-       this->ike_name = ike_name;
+       private_file_logger_t *this;
+
+       INIT(this,
+               .public = {
+                       .listener = {
+                               .log = _log_,
+                       },
+                       .set_level = _set_level,
+                       .destroy = _destroy,
+               },
+               .out = out,
+               .time_format = time_format,
+               .ike_name = ike_name,
+       );
+
        set_level(this, DBG_ANY, LEVEL_SILENT);
 
        return &this->public;