<commit_before>//
//  JdEnvironment.h
//  Jigidesign
//
//  Created by <NAME> on 8/24/16.
//  Copyright © 2016 Jigidesign. All rights reserved.
//

#ifndef JdEnvironment_h
#define JdEnvironment_h


//#include "JdLibraryManager.h"
#include "JdServer.h"
#include "JdLibraryFactory.h"

#include "IJdBroadcaster.h"
#include "IJdTimers.h"


class JdEnvironment
{
	public:
	
	JdEnvironment				(bool i_enableTimers = false, bool i_deferSetup = false)
	:
	m_server					(m_libraries),
	m_timersEnabled				(i_enableTimers)
	{
		if (not i_deferSetup)
			Setup ();
	}
	
	virtual ~ JdEnvironment		()
	{
		Teardown ();
	}
	
	
	void DisableModules (cstr_t i_disabledModules)
	{
		if (i_disabledModules)
			m_disabledModules = Jd::SplitString (i_disabledModules, ",");
	}
	
	
	JdResult Setup (EpigramRef i_configuration = Epigram ())
	{
		JdResult result;
		
		if (not m_initialized)
		{
			result = m_server.Setup ();
			
			if (not result)
			{
				m_libraries.ParseLibraries (& JdLibraryFactory::Get ());
				
				if (i_configuration)
					m_server.SetConfiguration (i_configuration);
				
				for (auto moduleName : m_disabledModules)
				{
					//epilog_(normal,  "disable: %s", epistr (moduleName));
					
					m_libraries.DisableModule (moduleName);
				}
				
				if (m_timersEnabled)
				{
					result = jd_timers.Bind (& m_server);

					try
					{
//						jd_broadcaster.Bind (& m_server); // This is the notification delivery module
					}
					
					catch (...)
					{
						
					}
					
//					auto timers = JdPlatform::Get <IJdPlatform::Notification> ();
//					m_timer = timers->ScheduleTimer (10, this, 0);
				}
				
				if (not result)
				{
					auto scheduler = m_server.GetScheduler ();
					
					if (m_timersEnabled)
					{
						auto driver = jd_timers.Cast <IJdTimerDriver> ();
						
						scheduler->AddTimerThread (driver);
					}
	//				else
	//				scheduler->AddThreads (1);
					
					scheduler->Start ();
				}
				<commit_msg>no message<commit_after>//
//  JdEnvironment.h
//  Jigidesign
//
//  Created by <NAME> on 8/24/16.
//  Copyright © 2016 Jigidesign. All rights reserved.
//

#ifndef JdEnvironment_h
#define JdEnvironment_h


//#include "JdLibraryManager.h"
#include "JdServer.h"
#include "JdLibraryFactory.h"

#include "IJdBroadcaster.h"
#include "IJdTimers.h"


class JdEnvironment
{
	public:
	
	JdEnvironment				(bool i_enableTimers = false, bool i_deferSetup = false)
	:
	m_server					(m_libraries),
	m_timersEnabled				(i_enableTimers)
	{
		if (not i_deferSetup)
			Setup ();
	}
	
	virtual ~ JdEnvironment		()
	{
		Teardown ();
	}
	
	
	void DisableModules (cstr_t i_disabledModules)
	{
		if (i_disabledModules)
			m_disabledModules = Jd::SplitString (i_disabledModules, ",");
	}
	
	
	JdResult Setup (EpigramRef i_configuration = Epigram ())
	{
		JdResult result;
		
		if (not m_initialized)
		{
			result = m_server.Setup ();
			
			if (not result)
			{
				m_libraries.ParseLibraries (& JdLibraryFactory::Get ());
				
				if (i_configuration)
					m_server.SetConfiguration (i_configuration);
				
				for (auto moduleName : m_disabledModules)
				{
					//epilog_(normal,  "disable: %s", epistr (moduleName));
					
					m_libraries.DisableModule (moduleName);
				}
				
				if (m_timersEnabled)
				{
					result = jd_timers.Bind (& m_server);

					try
					{
//						jd_broadcaster.Bind (& m_server); // This is the notification delivery module
					}
					
					catch (...)
					{
						
					}
					
//					auto timers = JdPlatform::Get <IJdPlatform::Notification> ();
//					m_timer = timers->ScheduleTimer (10, this, 0);
				}
				
				if (not result)
				{
					auto scheduler = m_server.GetScheduler ();
					
					if (m_timersEnabled)
					{
						auto driver = jd_timers.Cast <IJdTimerDriver> ();
						
						scheduler->AddTimerThread (driver);
					}
					else scheduler->AddThreads (1);
					
					scheduler->Start ();
				}
				
{'fraction_non_alphanumeric': 0.12171222279525529, 'fraction_numerical': 0.006704486848891181, 'mean_word_length': 2.516772438803264, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2254414', 'n_tokens_mistral': 1818, 'n_tokens_neox': 1368, 'n_words': 267}