LCOV - code coverage report
Current view: top level - src - ppg_global.c (source / functions) Hit Total Coverage
Test: coverage.info.cleaned Lines: 50 64 78.1 %
Date: 2018-01-08 Functions: 12 18 66.7 %

          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 "ppg_global.h"
      18             : #include "ppg_token.h"
      19             : #include "ppg_debug.h"
      20             : #include "ppg_context.h"
      21             : #include "ppg_action_flags.h"
      22             : #include "detail/ppg_context_detail.h"
      23             : #include "detail/ppg_global_detail.h"
      24             : #include "detail/ppg_event_buffer_detail.h"
      25             : #include "detail/ppg_signal_detail.h"
      26             : #include "detail/ppg_pattern_detail.h"
      27             : 
      28             : #include <stdlib.h>
      29             : #include <stddef.h>
      30             : #include <inttypes.h>
      31             : #include <stdarg.h>
      32             : 
      33         844 : void ppg_global_init(void) {
      34             : 
      35         844 :    if(!ppg_context) {
      36             :       
      37          40 :       ppg_context = (PPG_Context *)ppg_context_create();
      38             :    }
      39         844 : }
      40             : 
      41          32 : void ppg_global_compile(void)
      42             : {
      43          32 :    ppg_context->tree_depth = ppg_pattern_tree_depth();
      44             :    
      45             :    // Initialize the furcation buffer to ensure correct size (the maximum
      46             :    // search tree depth)
      47             :    //
      48          32 :    ppg_furcation_stack_restore(&ppg_context->furcation_stack);
      49          32 : }
      50             : 
      51          40 : void ppg_global_finalize(void) {
      52             :    
      53          40 :    if(!ppg_context) { return; }
      54             :    
      55          40 :    ppg_context_destroy(ppg_context);
      56             :    
      57          40 :    ppg_context = NULL;
      58             : }
      59             : 
      60           0 : void ppg_global_reset(void)
      61             : {
      62           0 :    ppg_global_finalize();
      63             :    
      64           0 :    ppg_context = (PPG_Context *)ppg_context_create();
      65           0 : }
      66             : 
      67             : /* Use this function to define a input that always aborts a pattern
      68             :  */
      69           4 : PPG_Input_Id ppg_global_set_abort_trigger(PPG_Input_Id input)
      70             : {
      71           4 :    PPG_Input_Id old_input = ppg_context->abort_input;
      72             :    
      73           4 :    ppg_context->abort_input = input;
      74             :    
      75           4 :    return old_input;
      76             : }
      77             : 
      78           0 : PPG_Input_Id ppg_global_get_abort_trigger(void)
      79             : {
      80           0 :    return ppg_context->abort_input;
      81             : }
      82             : 
      83          41 : PPG_Time ppg_global_set_timeout(PPG_Time timeout)
      84             : {
      85          41 :    PPG_Time old_value = ppg_context->event_timeout;
      86             :    
      87          41 :    ppg_context->event_timeout = timeout;
      88             :    
      89          41 :    return old_value;
      90             : }
      91             : 
      92           0 : PPG_Time ppg_global_get_timeout(void)
      93             : {
      94           0 :    return ppg_context->event_timeout;
      95             : }
      96             : 
      97          41 : PPG_Event_Processor_Fun ppg_global_set_default_event_processor(PPG_Event_Processor_Fun event_processor)
      98             : {
      99          41 :    PPG_Event_Processor_Fun old_event_processor = ppg_context->event_processor;
     100             :    
     101          41 :    ppg_context->event_processor = event_processor;
     102             :    
     103          41 :    return old_event_processor;
     104             : }
     105             : 
     106           2 : bool ppg_global_set_enabled(bool state)
     107             : {
     108           2 :    bool old_state = ppg_context->properties.papageno_enabled;
     109             :    
     110           2 :    ppg_context->properties.papageno_enabled = state;
     111             : 
     112           2 :    return old_state;
     113             : }
     114             : 
     115           6 : bool ppg_global_set_timeout_enabled(bool state)
     116             : {
     117           6 :    bool previous_state = ppg_context->properties.timeout_enabled;
     118             :    
     119           6 :    ppg_context->properties.timeout_enabled = state;
     120             :    
     121           6 :    return previous_state;
     122             : }
     123             : 
     124           0 : bool ppg_global_get_timeout_enabled(void)
     125             : {
     126           0 :    return ppg_context->properties.timeout_enabled;
     127             : }
     128             : 
     129           6 : PPG_Layer ppg_global_set_layer(PPG_Layer layer)
     130             : {
     131           6 :    PPG_Layer previous_layer = ppg_context->layer;
     132             :    
     133           6 :    if(previous_layer != layer) {
     134           6 :       if(ppg_context->current_token) {
     135           2 :          ppg_global_abort_pattern_matching();
     136             :       }
     137             :    }
     138             :    
     139           6 :    ppg_context->layer = layer;
     140             :    
     141           6 :    return previous_layer;
     142             : }
     143             : 
     144           0 : PPG_Layer ppg_global_get_layer(void)
     145             : {
     146           0 :    return ppg_context->layer;
     147             : }
     148             : 
     149          41 : PPG_Signal_Callback ppg_global_set_signal_callback(PPG_Signal_Callback callback)
     150             : {
     151          41 :    PPG_Signal_Callback previous_callback = ppg_context->signal_callback;
     152             :    
     153          41 :    ppg_context->signal_callback = callback;
     154             :    
     155          41 :    return previous_callback;
     156             : }
     157             : 
     158           0 : PPG_Signal_Callback ppg_global_get_signal_callback(void)
     159             : {
     160           0 :    return ppg_context->signal_callback;
     161             : }
     162             : 
     163           4 : void ppg_global_abort_pattern_matching(void)
     164             : {     
     165           4 :    if(!ppg_context->current_token) { return; }
     166             :    
     167             : //    PPG_LOG("Abrt pttrn\n");
     168             : 
     169             :    // Note: It is on the user to read back any 
     170             :    //       events that were stored from the PPG_On_Abort signal callback
     171             :          
     172           4 :    ppg_signal(PPG_On_Abort);
     173             :    
     174           4 :    ppg_delete_stored_events();
     175             :    
     176           4 :    ppg_reset_pattern_matching_engine();
     177             : }
     178             : 
     179             : #if PPG_HAVE_DEBUGGING
     180             : 
     181         105 : bool ppg_global_check_consistency(void)
     182             : {
     183         105 :    return false;//ppg_token_recurse_check_initialized(&ppg_context->pattern_root);
     184             : }
     185             : 
     186             : #endif

Generated by: LCOV version 1.10