<commit_before>//environment_policy.hpp    <NAME> 2017

#include <map>
//contrib
#include "ace/Log_Msg.h"
#include "ace/Signal.h"
#include "ace/Sig_Handler.h"

//cci
#include <cci_time_utils.h>
#include <cci_daemonize.h>

using namespace cpp_real_stream;

namespace
{
	void handle_pid()
	{
		
		if( ! remove_pid( cci_daemonize::path_pid ) ) 
		{ ACE_DEBUG(( LM_ERROR , "%D (%P) ....remove pid failed...s\n"  ) ); }
		else{ ACE_DEBUG(( LM_INFO , "%D (%P) ....removed pid file...\n"  ) ); }

	}
	
	class daemon_signal_handler : public ACE_Event_Handler
	{


		public :
			
			  daemon_signal_handler ( int signum ) : signum_( signum ) ,
								 m_tutils( std::make_unique<time_utils>()  )

			  {}

			  virtual ~daemon_signal_handler()
			  {}


			
		private :
			
		  	int 						signum_;
			std::unique_ptr<cpp_real_stream::time_utils> 	m_tutils;

		public:

		  //accessors-inspectors
		  cpp_real_stream::time_utils_ptr _t() { return m_tutils.get(); }

		  //services
		  virtual int handle_signal( int signum ,
                                             siginfo_t * = 0 , 
                                             ucontext_t * = 0 )
		  {
			    ACE_TRACE ( "daemon_signal_handler::handle_signal" );

			    _t()->color( stamp_color::red );
	 		    _t()->null_stamp();


			    ACE_ASSERT( signum == this->signum_ );
				
			    switch( signum_ ) 
			    {
			     	case SIGTERM :
			
			    		ACE_DEBUG ( ( LM_DEBUG, ACE_TEXT ( "%D %P sigterm occurred....shutting down server\n" )  ) );
					_t()->clear_color();
					
					handle_pid();
					

					exit( 1 );

				case SIGINT :
						
					ACE_DEBUG ( ( LM_DEBUG, ACE_TEXT ( "%D %P sigint occurred...shutting down server..\n" )  ) );
					_t()->clear_color();

					
					handle_pid();

					exit( 0 );
					
				default :
					_t()->clear_color();

					return 0;
			  }					    			    
		  }

	};
	
	
				
}

namespace cci_policy
{
	
	//
	//environment policies
	//
	template<typename T>
	class default_environment_context
	{

	
		public :<commit_msg>cci-meta-daemon<commit_after>//environment_policy.hpp    <NAME> 2017

#include <map>
//contrib
#include "ace/Log_Msg.h"
#include "ace/Signal.h"
#include "ace/Sig_Handler.h"

//cci
#include <cci_time_utils.h>
#include <cci_daemonize.h>

using namespace cpp_real_stream;

namespace
{
	void handle_pid()
	{
		
		if( ! remove_pid( cci_daemonize::path_pid ) ) 
		{ ACE_DEBUG(( LM_ERROR , "%D (%P) ....remove pid failed...s\n"  ) ); }
		else{ ACE_DEBUG(( LM_INFO , "%D (%P) ....removed pid file...\n"  ) ); }

	}
	
	class daemon_signal_handler : public ACE_Event_Handler
	{


		public :
			
			  daemon_signal_handler ( int signum ) : signum_( signum ) ,
								 m_tutils( std::make_unique<time_utils>()  )

			  {}

			  virtual ~daemon_signal_handler()
			  {}


			
		private :
			
		  	int 						signum_;
			std::unique_ptr<cpp_real_stream::time_utils> 	m_tutils;

		public:

		  //accessors-inspectors
		  cpp_real_stream::time_utils_ptr _t() { return m_tutils.get(); }

		  //services
		  virtual int handle_signal( int signum ,
                                             siginfo_t * = 0 , 
                                             ucontext_t * = 0 )
		  {
			    ACE_TRACE ( "daemon_signal_handler::handle_signal" );

			    _t()->color( stamp_color::red );
	 		    _t()->null_stamp();


			    ACE_ASSERT( signum == this->signum_ );
				
			    switch( signum_ ) 
			    {
			     	case SIGTERM :
			
			    		ACE_DEBUG ( ( LM_DEBUG, ACE_TEXT ( "%D %P sigterm occurred....shutting down server\n" )  ) );
					_t()->clear_color();
					
					handle_pid();
					

					exit( 1 );

				case SIGINT :
						
					ACE_DEBUG ( ( LM_DEBUG, ACE_TEXT ( "%D %P sigint occurred...shutting down server..\n" )  ) );
					_t()->clear_color();

					
					handle_pid();

					exit( 0 );

				case SIGSEGV :
						
					ACE_DEBUG ( ( LM_DEBUG, ACE_TEXT ( "%D %P sigsev occurred...shutting down server..\n" )  ) );
					_t()->clear_color();

					
					handle_pid();

					exit( 0 );

					
				default :
					_t()->clear_color();

					return 0;
			  }					    			    
		  }

	};
	
	
				
}

namespace cci_policy
{
	
	//
	//environment policies
	//
	template<typename T>
	class default_environment_context
	{

	
		public :
{'fraction_non_alphanumeric': 0.13752362948960303, 'fraction_numerical': 0.0044896030245746696, 'mean_word_length': 1.9375433726578766, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4889184', 'n_tokens_mistral': 1926, 'n_tokens_neox': 1435, 'n_words': 273}