Read about our upcoming Code of Conduct on this issue

This instance was upgraded to Heptapod 0.28.1 today

Commit 19464136 authored by Aleksandr Bakhshiev's avatar Aleksandr Bakhshiev
Browse files

1. Logger code refactoring.

2. Core interface code refactoring.

--HG--
branch : NewLogger
parent 34f391bb2828
......@@ -31,6 +31,7 @@ UApplication::UApplication(void)
Name="Application";
LastProjectsListMaxSize=10;
ProjectOpenFlag=false;
// DebugMode=false;
}
UApplication::~UApplication(void)
......@@ -92,7 +93,8 @@ bool UApplication::SetProjectPath(const std::string& value)
if(ProjectPath == value)
return true;
ProjectPath=value;
EngineControl->GetEngineStateThread()->SetLogPath(ProjectPath);
UpdateLoggers();
// EngineControl->GetEngineStateThread()->CloseEventsLogFile();
CalcAppCaption();
return true;
}
......@@ -158,6 +160,61 @@ const RDK::USerStorageXML& UApplication::GetInterfaceXml(void) const
return InterfaceXml;
}
///
std::string UApplication::GetLogDir(void) const
{
return Core_GetLogDir();
}
bool UApplication::SetLogDir(const std::string& value)
{
if(value == Core_GetLogDir())
return true;
// LogDir=value;
if(Core_SetLogDir(value.c_str()) == RDK_SUCCESS)
{
UpdateLoggers();
return true;
}
return false;
}
///
bool UApplication::GetDebugMode(void) const
{
return Core_GetDebugMode();
}
bool UApplication::SetDebugMode(bool value)
{
if(value == Core_GetDebugMode())
return true;
if(Core_SetDebugMode(value) == RDK_SUCCESS)
return true;
return true;
}
/// ( )
std::string UApplication::CalcCurrentLogDir(void) const
{
std::string log_dir;
if(Project && Project->GetConfig().OverrideLogParameters)
{
log_dir=ProjectPath+"EventsLog/";
}
else
{
log_dir=Core_GetLogDir();
if(log_dir.empty())
log_dir=WorkDirectory+"EventsLog/";
if(!log_dir.empty() && log_dir.find_last_of("\\/") != log_dir.size()-1)
log_dir+="/";
}
return log_dir;
}
// --------------------------
// --------------------------
......@@ -271,7 +328,7 @@ bool UApplication::Init(void)
std::string font_path=extract_file_path(ApplicationFileName);
SetSystemDir(font_path.c_str());
Core_SetLogDir(font_path.c_str());
// SetLogDir(font_path);
MLog_SetExceptionHandler(RDK_SYS_MESSAGE,(void*)ExceptionHandler);
MCore_ChannelInit(0,0,(void*)ExceptionHandler);
Engine_LoadFonts();
......@@ -349,14 +406,14 @@ bool UApplication::OpenProject(const std::string &filename)
ProjectXml.LoadFromFile(filename,"");
ProjectPath=extract_file_path(filename);
ProjectFileName=extract_file_name(filename);
Core_SetLogDir(ProjectPath.c_str());
Project->SetProjectPath(ProjectPath);
Project->ReadFromXml(ProjectXml);
UpdateLoggers();
TProjectConfig config=Project->GetConfig();
EngineControl->GetEngineStateThread()->SetLogFlag(config.EventsLogFlag);
EngineControl->GetEngineStateThread()->SetLogPath(ProjectPath);
EngineControl->GetEngineStateThread()->CloseEventsLogFile();
// EngineControl->GetEngineStateThread()->SetLogDir(ProjectPath);
EngineControl->SetThreadMode(config.MultiThreadingMode);
CalcAppCaption();
......@@ -366,7 +423,7 @@ try{
EngineControl->SetNumEngines(config.NumChannels);
ProjectXml.SelectNodeRoot("Project/MultiGeneral");
int selected_engine_index=ProjectXml.ReadInteger("SelectedEngineIndex",0);
int selected_channel_index=ProjectXml.ReadInteger("SelectedEngineIndex",0);
ProjectXml.SelectNodeRoot("Project/General");
......@@ -448,10 +505,10 @@ try{
Sleep(0);
}
if(selected_engine_index>=GetNumEngines())
selected_engine_index=0;
if(selected_channel_index>=GetNumEngines())
selected_channel_index=0;
SelectEngine(selected_engine_index);
SelectEngine(selected_channel_index);
InterfaceXml.Destroy();
if(!config.InterfaceFileName.empty())
......@@ -500,7 +557,7 @@ bool UApplication::SaveProject(void)
if(!ProjectOpenFlag)
return false;
int selected_engine_index=GetSelectedEngineIndex();
int selected_channel_index=GetSelectedEngineIndex();
Project->WriteToXml(ProjectXml);
......@@ -555,7 +612,7 @@ try
Sleep(0);
}
SelectEngine(selected_engine_index);
SelectEngine(selected_channel_index);
ProjectXml.SaveToFile(ProjectPath+ProjectFileName);
......@@ -862,36 +919,36 @@ bool UApplication::DeleteEngine(int index)
// --------------------------
//
// --------------------------
/// , , engine_index == -1
void UApplication::StartEngine(int engine_index)
/// , , channel_index == -1
void UApplication::StartEngine(int channel_index)
{
EngineControl->StartEngine(engine_index);
EngineControl->StartEngine(channel_index);
}
/// , , engine_index == -1
void UApplication::PauseEngine(int engine_index)
/// , , channel_index == -1
void UApplication::PauseEngine(int channel_index)
{
EngineControl->PauseEngine(engine_index);
EngineControl->PauseEngine(channel_index);
}
/// , , engine_index == -1
void UApplication::ResetEngine(int engine_index)
/// , , channel_index == -1
void UApplication::ResetEngine(int channel_index)
{
EngineControl->ResetEngine(engine_index);
EngineControl->ResetEngine(channel_index);
}
/// , , engine_index == -1
void UApplication::StepEngine(int engine_index)
/// , , channel_index == -1
void UApplication::StepEngine(int channel_index)
{
EngineControl->StepEngine(engine_index);
EngineControl->StepEngine(channel_index);
}
/// true
bool UApplication::IsEngineStarted(int engine_index)
bool UApplication::IsEngineStarted(int channel_index)
{
if(!EngineControl)
return false;
return EngineControl->CheckCalcState(engine_index);
return EngineControl->CheckCalcState(channel_index);
}
// --------------------------
......@@ -1121,6 +1178,14 @@ void UApplication::CalcAppCaption(void)
AppCaption=std::string("[")+Project->GetConfig().ProjectName+std::string(": ")+ProjectPath+ProjectFileName+"]";
}
///
void UApplication::UpdateLoggers(void)
{
DllManager.SetLogDir(CalcCurrentLogDir().c_str());
if(EngineControl && EngineControl->GetEngineStateThread())
EngineControl->GetEngineStateThread()->RecreateEventsLogFile();
}
///
bool UApplication::LoadFile(const std::string file_name, std::string &buffer) const
{
......
......@@ -51,6 +51,11 @@ std::list<std::string> LastProjectsList;
///
int LastProjectsListMaxSize;
///
//std::string LogDir;
///
//bool DebugMode;
protected: //
///
......@@ -122,6 +127,17 @@ const RDK::USerStorageXML& GetProjectXml(void) const;
//
const RDK::USerStorageXML& GetInterfaceXml(void) const;
/// ( )
std::string GetLogDir(void) const;
bool SetLogDir(const std::string& value);
///
bool GetDebugMode(void) const;
bool SetDebugMode(bool value);
/// ( )
std::string CalcCurrentLogDir(void) const;
// --------------------------
// --------------------------
......@@ -209,20 +225,20 @@ bool DeleteEngine(int index);
// --------------------------
//
// --------------------------
/// , , engine_index == -1
virtual void StartEngine(int engine_index);
/// , , channel_index == -1
virtual void StartEngine(int channel_index);
/// , , engine_index == -1
virtual void PauseEngine(int engine_index);
/// , , channel_index == -1
virtual void PauseEngine(int channel_index);
/// , , engine_index == -1
virtual void ResetEngine(int engine_index);
/// , , channel_index == -1
virtual void ResetEngine(int channel_index);
/// , , engine_index == -1
virtual void StepEngine(int engine_index);
/// , , channel_index == -1
virtual void StepEngine(int channel_index);
/// true
virtual bool IsEngineStarted(int engine_index);
virtual bool IsEngineStarted(int channel_index);
// --------------------------
// --------------------------
......@@ -260,6 +276,9 @@ protected:
///
void CalcAppCaption(void);
///
void UpdateLoggers(void);
///
bool LoadFile(const std::string file_name, std::string &buffer) const;
......
......@@ -72,50 +72,50 @@ void UEngineControl::SetUseControllersMode(int value)
}
//
int UEngineControl::GetCalculateMode(int engine_index) const
int UEngineControl::GetCalculateMode(int channel_index) const
{
if(int(EngineControlThreads.size())>engine_index)
return EngineControlThreads[engine_index]->GetCalculateMode();
if(int(EngineControlThreads.size())>channel_index)
return EngineControlThreads[channel_index]->GetCalculateMode();
return 0; // TODO:
}
void UEngineControl::SetCalculateMode(int engine_index,int value)
void UEngineControl::SetCalculateMode(int channel_index,int value)
{
if(int(EngineControlThreads.size())>engine_index)
EngineControlThreads[engine_index]->SetCalculateMode(value);
if(int(EngineControlThreads.size())>channel_index)
EngineControlThreads[channel_index]->SetCalculateMode(value);
}
///
/// 0 -
/// 1 -
int UEngineControl::GetCalculationTimeSource(int engine_index) const
int UEngineControl::GetCalculationTimeSource(int channel_index) const
{
if(engine_index>=int(EngineControlThreads.size()))
if(channel_index>=int(EngineControlThreads.size()))
return 0; // TODO:
return EngineControlThreads[engine_index]->GetCalculationTimeSource();
return EngineControlThreads[channel_index]->GetCalculationTimeSource();
}
bool UEngineControl::SetCalculationTimeSource(int engine_index, int value)
bool UEngineControl::SetCalculationTimeSource(int channel_index, int value)
{
if(engine_index>=int(EngineControlThreads.size()))
if(channel_index>=int(EngineControlThreads.size()))
return false; // TODO:
EngineControlThreads[engine_index]->SetCalculationTimeSource(value);
EngineControlThreads[channel_index]->SetCalculationTimeSource(value);
return true;
}
RDK::UTime UEngineControl::GetMinInterstepsInterval(int engine_index) const
RDK::UTime UEngineControl::GetMinInterstepsInterval(int channel_index) const
{
if(engine_index>=int(EngineControlThreads.size()))
if(channel_index>=int(EngineControlThreads.size()))
return 0; // TODO:
return EngineControlThreads[engine_index]->GetMinInterstepsInterval();
return EngineControlThreads[channel_index]->GetMinInterstepsInterval();
}
bool UEngineControl::SetMinInterstepsInterval(int engine_index, RDK::UTime value)
bool UEngineControl::SetMinInterstepsInterval(int channel_index, RDK::UTime value)
{
if(engine_index>=int(EngineControlThreads.size()))
if(channel_index>=int(EngineControlThreads.size()))
return false;
EngineControlThreads[engine_index]->SetMinInterstepsInterval(value);
EngineControlThreads[channel_index]->SetMinInterstepsInterval(value);
return true;
}
// --------------------------
......@@ -204,9 +204,9 @@ bool UEngineControl::IsInit(void) const
}
///
UEngineControlThread* UEngineControl::CreateEngineThread(UEngineControl* engine_control, int engine_index)
UEngineControlThread* UEngineControl::CreateEngineThread(UEngineControl* engine_control, int channel_index)
{
return new UEngineControlThread(engine_control, engine_index);
return new UEngineControlThread(engine_control, channel_index);
}
///
......@@ -216,26 +216,26 @@ UEngineStateThread* UEngineControl::CreateEngineStateThread(UEngineControl* engi
}
//
double UEngineControl::GetServerTimeStamp(int engine_index) const
double UEngineControl::GetServerTimeStamp(int channel_index) const
{
if(engine_index>=GetNumEngines())
if(channel_index>=GetNumEngines())
return 0.0;
return EngineControlThreads[engine_index]->GetServerTimeStamp();
return EngineControlThreads[channel_index]->GetServerTimeStamp();
}
void UEngineControl::SetServerTimeStamp(int engine_index, double stamp)
void UEngineControl::SetServerTimeStamp(int channel_index, double stamp)
{
if(engine_index>=GetNumEngines())
if(channel_index>=GetNumEngines())
return;
EngineControlThreads[engine_index]->SetServerTimeStamp(stamp);
EngineControlThreads[engine_index]->EnableCalculation();
EngineControlThreads[channel_index]->SetServerTimeStamp(stamp);
EngineControlThreads[channel_index]->EnableCalculation();
}
/// , , engine_index == -1
void UEngineControl::StartEngine(int engine_index)
/// , , channel_index == -1
void UEngineControl::StartEngine(int channel_index)
{
if(engine_index>=GetNumEngines())
if(channel_index>=GetNumEngines())
return;
EngineStateThread->RecreateEventsLogFile();
......@@ -253,7 +253,7 @@ void UEngineControl::StartEngine(int engine_index)
case 1:
// Timer->Interval=30;
// Timer->Enabled=true;
if(engine_index<0)
if(channel_index<0)
{
for(size_t i=0;i<EngineControlThreads.size();i++)
{
......@@ -265,9 +265,9 @@ void UEngineControl::StartEngine(int engine_index)
}
else
{
if(EngineControlThreads[engine_index])
if(EngineControlThreads[channel_index])
{
EngineControlThreads[engine_index]->Start();
EngineControlThreads[channel_index]->Start();
}
}
break;
......@@ -275,10 +275,10 @@ void UEngineControl::StartEngine(int engine_index)
}
/// , , engine_index == -1
void UEngineControl::PauseEngine(int engine_index)
/// , , channel_index == -1
void UEngineControl::PauseEngine(int channel_index)
{
if(engine_index>=GetNumEngines())
if(channel_index>=GetNumEngines())
return;
// if(Timer->Enabled == false)
......@@ -293,7 +293,7 @@ void UEngineControl::PauseEngine(int engine_index)
break;
case 1:
if(engine_index == -1)
if(channel_index == -1)
{
// Timer->Enabled=false;
......@@ -307,9 +307,9 @@ void UEngineControl::PauseEngine(int engine_index)
}
else
{
if(EngineControlThreads[engine_index])
if(EngineControlThreads[channel_index])
{
EngineControlThreads[engine_index]->Pause();
EngineControlThreads[channel_index]->Pause();
}
bool all_stopped=true;
......@@ -332,16 +332,17 @@ void UEngineControl::PauseEngine(int engine_index)
break;
}
EngineStateThread->RecreateEventsLogFile();
EngineStateThread->CloseEventsLogFile();
}
/// , , engine_index == -1
void UEngineControl::ResetEngine(int engine_index)
/// , , channel_index == -1
void UEngineControl::ResetEngine(int channel_index)
{
if(engine_index>=GetNumEngines())
if(channel_index>=GetNumEngines())
return;
if(engine_index == -1)
EngineStateThread->RecreateEventsLogFile();
if(channel_index == -1)
{
if(!Model_Check())
{
......@@ -361,33 +362,33 @@ void UEngineControl::ResetEngine(int engine_index)
}
else
{
if(!MModel_Check(engine_index))
if(!MModel_Check(channel_index))
{
RDK::UIVisualControllerStorage::UpdateInterface();
return;
}
RDK::UIVisualControllerStorage::BeforeReset();
RDK::UIControllerStorage::BeforeReset(engine_index);
EngineControlThreads[engine_index]->Reset();
RDK::UIControllerStorage::AfterReset(engine_index);
RDK::UIControllerStorage::BeforeReset(channel_index);
EngineControlThreads[channel_index]->Reset();
RDK::UIControllerStorage::AfterReset(channel_index);
RDK::UIVisualControllerStorage::AfterReset();
RDK::UIVisualControllerStorage::UpdateInterface();
}
}
/// , , engine_index == -1
void UEngineControl::StepEngine(int engine_index)
/// , , channel_index == -1
void UEngineControl::StepEngine(int channel_index)
{
if(engine_index>=GetNumEngines())
if(channel_index>=GetNumEngines())
return;
RDK::UIVisualControllerStorage::BeforeCalculate();
int use_controllers_mode=UseControllersMode;
if(use_controllers_mode == 0)
RDK::UIControllerStorage::BeforeCalculate(engine_index);
RDK::UIControllerStorage::BeforeCalculate(channel_index);
if(engine_index <0)
if(channel_index <0)
{
for(int i=0;i<GetNumEngines();i++)
{
......@@ -400,21 +401,21 @@ void UEngineControl::StepEngine(int engine_index)
}
else
{
if(MIsEngineInit(engine_index) && MModel_Check(engine_index))
if(MIsEngineInit(channel_index) && MModel_Check(channel_index))
{
EngineControlThreads[engine_index]->EnableCalculation();
EngineControlThreads[engine_index]->Calculate();
EngineControlThreads[channel_index]->EnableCalculation();
EngineControlThreads[channel_index]->Calculate();
}
}
if(use_controllers_mode == 0)
RDK::UIControllerStorage::AfterCalculate(engine_index);
RDK::UIControllerStorage::AfterCalculate(channel_index);
SendMetadata();
RDK::UIVisualControllerStorage::AfterCalculate();
RDK::UIVisualControllerStorage::ResetCalculationStepUpdatedFlag();
RDK::UIVisualControllerStorage::UpdateInterface();
if(engine_index <0)
if(channel_index <0)
{
for(int i=0;i<GetNumEngines();i++)
{
......@@ -423,7 +424,7 @@ void UEngineControl::StepEngine(int engine_index)
}
else
{
EngineControlThreads[engine_index]->GetProfiler()->Calculate();
EngineControlThreads[channel_index]->GetProfiler()->Calculate();
}
}
......
......@@ -73,18 +73,18 @@ int GetUseControllersMode(void) const;
void SetUseControllersMode(int value);
// Управление режимом расчетов
int GetCalculateMode(int engine_index) const;
void SetCalculateMode(int engine_index, int value);
int GetCalculateMode(int channel_index) const;
void SetCalculateMode(int channel_index, int value);
/// Режим использования времени для расчета
/// 0 - системное время
/// 1 - время источника данных
int GetCalculationTimeSource(int engine_index) const;
bool SetCalculationTimeSource(int engine_index, int value);
int GetCalculationTimeSource(int channel_index) const;
bool SetCalculationTimeSource(int channel_index, int value);
/// Минимальный интервал времени между итерациями расчета в режиме 0 и 2, мс
RDK::UTime GetMinInterstepsInterval(int engine_index) const;
bool SetMinInterstepsInterval(int engine_index, RDK::UTime value);
RDK::UTime GetMinInterstepsInterval(int channel_index) const;
bool SetMinInterstepsInterval(int channel_index, RDK::UTime value);
// --------------------------
// --------------------------
......@@ -117,26 +117,26 @@ virtual void UnInit(void);
bool IsInit(void) const;
/// Создание нового треда расчета
virtual UEngineControlThread* CreateEngineThread(UEngineControl* engine_control, int engine_index);
virtual UEngineControlThread* CreateEngineThread(UEngineControl* engine_control, int channel_index);
/// Создание нового треда расчета
virtual UEngineStateThread* CreateEngineStateThread(UEngineControl* engine_control);
// Управление временной меткой сервера
double GetServerTimeStamp(int engine_index) const;
void SetServerTimeStamp(int engine_index, double stamp);
double GetServerTimeStamp(int channel_index) const;
void SetServerTimeStamp(int channel_index, double stamp);
/// Запускает аналитику выбранного канала, или всех, если engine_index == -1
virtual void StartEngine(int engine_index);
/// Запускает аналитику выбранного канала, или всех, если channel_index == -1
virtual void StartEngine(int channel_index);
/// Останавливает аналитику выбранного канала, или всех, если engine_index == -1
virtual void PauseEngine(int engine_index);
/// Останавливает аналитику выбранного канала, или всех, если channel_index == -1
virtual void PauseEngine(int channel_index);
/// Сбрасывает аналитику выбранного канала, или всех, если engine_index == -1
virtual void ResetEngine(int engine_index);
/// Сбрасывает аналитику выбранного канала, или всех, если channel_index == -1
virtual void ResetEngine(int channel_index);
/// Делает шаг расчета выбранного канала, или всех, если engine_index == -1
virtual void StepEngine(int engine_index);
/// Делает шаг расчета выбранного канала, или всех, если channel_index == -1
virtual void StepEngine(int channel_index);