- renamed EVENT_THREAD to SCHEDULER_THREAD
[strongswan.git] / Source / charon / utils / logger_manager.c
index 26635d9..657d2e3 100644 (file)
  
 #include "allocator.h"
 #include "linked_list.h"
+#include "../definitions.h"
+
+mapping_t logger_context_t_mappings[] = {
+       {PARSER, "PARSER"},
+       {GENERATOR, "GENERATOR"},
+       {IKE_SA, "IKE_SA"},
+       {IKE_SA_MANAGER, "IKE_SA_MANAGER"},
+       {MESSAGE, "MESSAGE"},
+       {THREAD_POOL, "THREAD_POOL"},
+       {WORKER_THREAD, "WORKER_THREAD"},
+       {SCHEDULER_THREAD, "SCHEDULER_THREAD"},
+       {SENDER_THREAD, "SENDER_THREAD"},
+       {RECEIVER_THREAD, "RECEIVER_THREAD"},
+       {TESTER, "TESTER"},
+       {DAEMON, "DAEMON"},
+};
 
 /** 
  * Maximum length of a logger name
@@ -106,42 +122,15 @@ static logger_t *create_logger(private_logger_manager_t *this, logger_context_t
 
        switch(context)
        {
-               case PARSER:
-                       context_name = "PARSER";
-                       break;
-               case GENERATOR:
-                       context_name = "GENERATOR";
-                       break;
-               case IKE_SA:
-                       context_name = "IKE_SA";
-                       break;
-               case MESSAGE:
-                       context_name = "MESSAGE";
-                       break;
-               case WORKER_THREAD:
-                       context_name = "WORKER_THREAD";
-                       break;
-               case EVENT_THREAD:
-                       context_name = "EVENT_THREAD";
-                       break;
-               case SENDER_THREAD:
-                       context_name = "SENDER_THREAD";
-                       break;
-               case RECEIVER_THREAD:
-                       context_name = "RECEIVER_THREAD";
-                       break;
-               case THREAD_POOL:
-                       context_name = "THREAD_POOL";
-                       break;
                case TESTER:
                        context_name = "TESTER";
                        output = stdout;
                        break;
                default:
-                       context_name = "NO CONTEXT";
+                       context_name = mapping_find(logger_context_t_mappings,context);
                        break;          
        }
-       
+       /* logger manager is thread save */
        pthread_mutex_lock(&(this->mutex));
        if (name != NULL)
        {
@@ -186,9 +175,14 @@ static logger_t *create_logger(private_logger_manager_t *this, logger_context_t
        
 }
 
+/**
+ * Implements logger_manager_t-function get_logger_level.
+ * @see logger_manager_s.get_logger_level.
+ */
 static logger_level_t get_logger_level (private_logger_manager_t *this, logger_context_t context)
 {
        linked_list_iterator_t *iterator;
+       /* set logger_level to default logger_level */
        logger_level_t logger_level = this->default_log_level;
 
        pthread_mutex_lock(&(this->mutex));
@@ -198,6 +192,8 @@ static logger_level_t get_logger_level (private_logger_manager_t *this, logger_c
                pthread_mutex_unlock(&(this->mutex));
                return logger_level;
        }
+       
+       /* check for existing logger_level entry */
        while (iterator->has_next(iterator))
        {
                
@@ -266,7 +262,6 @@ static status_t destroy_logger (private_logger_manager_t *this,logger_t *logger)
  */
 static status_t set_logger_level (private_logger_manager_t *this, logger_context_t context,logger_level_t logger_level,bool enable)
 {
-       
        linked_list_iterator_t *iterator;
        status_t status;
        
@@ -278,6 +273,7 @@ static status_t set_logger_level (private_logger_manager_t *this, logger_context
        }
 
        status = NOT_FOUND;
+       /* find existing logger_level entry */
        while (iterator->has_next(iterator))
        {       
                logger_levels_entry_t * entry;
@@ -308,7 +304,7 @@ static status_t set_logger_level (private_logger_manager_t *this, logger_context
        
        if (status == NOT_FOUND)
        {
-
+               /* logger_levels entry not existing for current context */
                logger_levels_entry_t *entry = allocator_alloc_thing(logger_levels_entry_t);
                if (entry == NULL)
                {
@@ -316,11 +312,12 @@ static status_t set_logger_level (private_logger_manager_t *this, logger_context
                        return OUT_OF_RES;
                }
                entry->context = context;
-               entry->level =  (enable) ? logger_level : this->default_log_level;
+               entry->level =  (enable) ? logger_level : (this->default_log_level & (~logger_level));
 
                status = this->logger_levels->insert_last(this->logger_levels,entry);
                if (status != SUCCESS)
                {
+                       allocator_free(entry);
                        pthread_mutex_unlock(&(this->mutex));
                        return status;
                }