Olivia_v2017/Olivia/Msmain.cpp

129 lines
2.7 KiB
C++

#include "StdAfx.h"
#include "Msmain.h"
#include "_log.h"
#include "olv.h"
//*******************************************************************************************
Msmain::Msmain(void)
{
pirate =false;
}
//*******************************************************************************************
Msmain::~Msmain(void)
{
}
//*******************************************************************************************
bool Msmain::Despacha_log()
{
StrArray msgs;
if(log.dame(msgs))
{
#if _DEBUG
//logea mensages();
for(int i = 0; i<msgs.n_i; i++)
//cout << "You entered " << iVar << endl;
{
TRACE(msgs.get(i));
char*st1, *st2=0;
st1 = msgs.get(i);
int n = (int)strlen(st1);
std::string ms;
for (int i =0; i<n; i++)
{
if(!st2 && st1[i])
st2 = &st1[i];
if(st1[i]== '\n')
{
st1[i] =0;
if(st2 && strlen(st2)>0)
{
ms = "echo " + std::string(st2);
system(ms.c_str());
}
st2 = 0;
}
}
if(st2)
{
ms = "echo " + std::string(st2);
system(ms.c_str());
}
}
#endif
return true;
}
return false;
}
//*******************************************************************************************
void Msmain::Despacha()
{
MSG msg;
while (!pirate)
{
while ( PeekMessage (&msg,NULL,NULL,NULL,
PM_NOREMOVE) )
{
PeekMessage (&msg,NULL,NULL,NULL,
PM_REMOVE);
TranslateMessage(&msg);
DispatchMessage(&msg);
}
if(!Despacha_log())
Sleep(100);
if(olv->isDebug && (olv->tarea == OLV_TAREA_FIN_SEC || olv->tarea == OLV_TAREA_FIN_PLANIF))
{
//C_log::log("Msmain", olv->msg_proce);
olv->cancela();
}
}
}
//*******************************************************************************************
void Msmain::log_ext( __time64_t tiemp, char *modulo, char *fmt )
{
char tiem[32];
char str[1024];
strftime(tiem, 20, "%Y-%m-%d %H:%M:%S", localtime(&tiemp));
sprintf_s(str,1024, "%s %-12s %s\r\n",
(char *) LPCTSTR (tiem),
(char *) LPCTSTR (modulo),
(char *) LPCTSTR (fmt));
log.pon(str);
}
//*******************************************************************************************
bool Cstr_Msg::dame( StrArray& stout )
{
if(n_i<=0)
return false;
if(stout.ind)
free(stout.ind);
if(stout.str)
free(stout.str);
lock_cola.entro();
stout.ind=ind;
stout.str=str;
stout.m_str=m_str;
stout.m_i=m_i;
stout.n_str=n_str;
stout.n_i=n_i;
m_str=m_i=n_i=n_str=0;
str=NULL;
ind=NULL;
lock_cola.salgo();
return true;
}
//************************************************************************************
void Cstr_Msg::pon( char* str)
{
lock_cola.entro();
add(str);
lock_cola.salgo();
}
//************************************************************************************