LCOV - code coverage report
Current view: top level - src/detail - ppg_context_detail.c (source / functions) Hit Total Coverage
Test: coverage.info.cleaned Lines: 48 48 100.0 %
Date: 2018-01-08 Functions: 6 6 100.0 %

          Line data    Source code
       1             : /* Copyright 2017 noseglasses <shinynoseglasses@gmail.com>
       2             :  *
       3             :  * This program is free software: you can redistribute it and/or modify
       4             :  * it under the terms of the GNU Lesser General Public License as published by
       5             :  * the Free Software Foundation, either version 3 of the License, or
       6             :  * (at your option) any later version.
       7             :  *
       8             :  * This program is distributed in the hope that it will be useful,
       9             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      10             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      11             :  * GNU Lesser General Public License for more details.
      12             :  *
      13             :  * You should have received a copy of the GNU Lesser General Public License
      14             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
      15             :  */
      16             : 
      17             : #include "detail/ppg_context_detail.h"
      18             : #include "detail/ppg_input_detail.h"
      19             : #include "ppg_statistics.h"
      20             : #include "ppg_debug.h"
      21             : 
      22             : #include <assert.h>
      23             : 
      24             : PPG_Context *ppg_context = NULL;
      25             : 
      26             : /** @brief This function initializes a signal callback
      27             :  *
      28             :  * @param cb A pointer to the callback struct
      29             :  */
      30             : inline
      31          41 : static void ppg_signal_callback_init(PPG_Signal_Callback *cb)
      32             : {
      33          41 :    cb->func = NULL;
      34          41 :    cb->user_data = NULL;
      35          41 : }
      36             : 
      37          41 : void ppg_global_initialize_context(PPG_Context *context) {
      38             :    
      39             : //    PPG_LOG("Initializing context\n");
      40             :    
      41          41 :    ppg_event_buffer_init(&context->event_buffer);
      42          41 :    ppg_furcation_stack_init(&context->furcation_stack);
      43          41 :    ppg_active_tokens_init(&context->active_tokens);
      44             :    
      45             : //    ppg_bitfield_init(&context->active_inputs);
      46             :    
      47          41 :    context->properties.timeout_enabled = true;
      48          41 :    context->properties.papageno_enabled = true;
      49             :       
      50             :    #if PPG_HAVE_LOGGING
      51          41 :    context->properties.logging_enabled = true;
      52             :    #endif
      53             :    
      54          41 :    context->properties.destruction_enabled = true;
      55             :    
      56          41 :    context->tree_depth = 0;
      57          41 :    context->layer = 0;
      58          41 :    ppg_global_init_input(&context->abort_input);
      59          41 :    context->time_last_event = 0;
      60          41 :    context->event_timeout = 0;
      61          41 :    context->event_processor = NULL;
      62             :    
      63          41 :    ppg_time_manager_init(&context->time_manager);
      64             :    
      65          41 :    ppg_signal_callback_init(&context->signal_callback);
      66             :    
      67          41 :    context->pattern_root = ppg_token_alloc();
      68             : 
      69             :    /* Initialize the pattern root
      70             :    */
      71          41 :    ppg_token_new(context->pattern_root);
      72             :    
      73          41 :    context->pattern_root->misc.state = PPG_Token_Initialized;
      74             :    
      75          41 :    context->current_token = NULL;
      76             :    
      77             :    #if PPG_HAVE_STATISTICS
      78             :    ppg_statistics_clear(&context->statistics);
      79             :    #endif
      80          41 : };
      81             : 
      82          18 : size_t ppg_context_get_size_requirements(PPG_Context *context)
      83             : {
      84             :    PPG_UNUSED(context);
      85          18 :    return sizeof(PPG_Context);
      86             : }
      87             : 
      88          18 : char *ppg_context_copy(PPG_Context *context, void *target__)
      89             : {
      90             :    PPG_UNUSED(context);
      91             :    
      92          18 :    char *target = target__;
      93             :    
      94          18 :    PPG_Context *target_context = (PPG_Context*)target;
      95             :    
      96          18 :    *target_context = *ppg_context;
      97             :    
      98          18 :    target += sizeof(PPG_Context);
      99             :    
     100          18 :    return target;
     101             : }
     102             : 
     103           9 : void ppg_restore_context(PPG_Context *context)
     104             : {
     105           9 :    PPG_LOG("rst ctxt\n");
     106           9 :    PPG_ASSERT(context);
     107             :    
     108             :    // Restore the members buffer, which means to let them allocated their
     109             :    // dynamically allocated data structures
     110             : 
     111           9 :    ppg_event_buffer_restore(&context->event_buffer);
     112             : 
     113           9 :    ppg_furcation_stack_restore(&context->furcation_stack);
     114             :    
     115           9 :    ppg_active_tokens_restore(&context->active_tokens);
     116             :    
     117           9 :    ppg_print_context(context);
     118           9 : }
     119             : 
     120           9 : void ppg_print_context(PPG_Context *context)
     121             : {
     122             :    // The following is necessary as the PPG_LOG macros might be
     123             :    // defined empty.
     124             :    //
     125             :    PPG_UNUSED(context);
     126             :    
     127           9 :    PPG_LOG("tree_depth: %d\n", (int)context->tree_depth);
     128           9 :    PPG_LOG("layer: %d\n", (int)context->layer);
     129           9 :    PPG_LOG("abort_input: %d\n", (int)context->abort_input);
     130           9 :    PPG_LOG("time_last_event: %d\n", (int)context->time_last_event);
     131           9 :    PPG_LOG("event_timeout: %d\n", (int)context->event_timeout);
     132           9 : }

Generated by: LCOV version 1.10