Files
EgtExecutor/EXE_General.cpp
T
Dario Sassi e2b54a993b EgtExecutor :
- librerie opzionali caricate solo se bit chiave lo 
- punto notevole endpoint su tip di vettore
- aggiornamenti.
2015-05-31 14:11:40 +00:00

320 lines
8.6 KiB
C++

//----------------------------------------------------------------------------
// EgalTech 2014-2014
//----------------------------------------------------------------------------
// File : API_General.cpp Data : 01.09.14 Versione : 1.5i1
// Contenuto : Funzioni generali per API.
//
//
//
// Modifiche : 01.09.14 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
//--------------------------- Include ----------------------------------------
#include "stdafx.h"
#include "EXE.h"
#include "LUA_Base.h"
#include "DllGraphics.h"
#include "DllExchange.h"
#include "DllMachKernel.h"
#include "/EgtDev/Include/EXeExecutor.h"
#include "/EgtDev/Include/EXeDllMain.h"
#include "/EgtDev/Include/EGnDllMain.h"
#include "/EgtDev/Include/ENkDllMain.h"
#include "/EgtDev/Include/EGkDllMain.h"
#include "/EgtDev/Include/EGkObjUserFactory.h"
#include "/EgtDev/Include/EGnStringUtils.h"
#include "/EgtDev/Include/EGnPcInfo.h"
#include "/EgtDev/Include/EgtLogger.h"
#include "/EgtDev/Include/EgtStringConverter.h"
#include <fstream>
using namespace std ;
using namespace egtlogger ;
//----------------------------------------------------------------------------
static Logger* s_pGenLog = nullptr ;
static bool s_bCmdLog = false ;
static Logger* s_pCmdLog = nullptr ;
static string s_sKey ;
//-----------------------------------------------------------------------------
bool
ExeInit( int nDebug, const string& sLogFile, const string& sLogMsg)
{
// cancello eventuali vecchi contesti
ClearAllGseContexts() ;
// cancello eventuale vecchio logger
if ( s_pGenLog != nullptr)
delete s_pGenLog ;
// creo il logger generale
s_pGenLog = new Logger( ( nDebug > 0 ? LL_DEBUG : LL_INFO), "EgtInterface") ;
if ( s_pGenLog == nullptr)
return false ;
// assegno il file
s_pGenLog->AddOutputStream( new ofstream( stringtoW( sLogFile)), true) ;
// lo passo alle DLL
SetEGnLogger( s_pGenLog) ;
SetENkLogger( s_pGenLog) ;
SetEGkLogger( s_pGenLog) ;
// dichiaro inizio programma
LOG_DATETIME( s_pGenLog, " Init")
// eventuale messaggio dall'applicazione
if ( &sLogMsg != nullptr && ! sLogMsg.empty())
LOG_INFO( s_pGenLog, sLogMsg.c_str())
// versione di interfaccia e componenti
string sVer ;
ExeGetVersionInfo( sVer, "\n") ;
LOG_INFO( s_pGenLog, sVer.c_str())
// imposto la chiave di protezione sulle librerie di base
SetEGkKey( s_sKey) ;
// carico libreria grafica opzionale
if ( LoadGraphicsDll( s_pGenLog, s_sKey))
LOG_INFO( s_pGenLog, MyGetEGrVersion())
// carico libreria exchange opzionale
if ( LoadExchangeDll( s_pGenLog, s_sKey))
LOG_INFO( s_pGenLog, MyGetEExVersion())
// carico libreria di lavorazione opzionale
if ( LoadMachKernelDll( s_pGenLog, s_sKey))
LOG_INFO( s_pGenLog, MyGetEMkVersion())
// Info sul sistema
string sTmp ;
if ( GetOsInfo( sTmp))
LOG_INFO( s_pGenLog, sTmp.c_str())
if ( GetCpuInfo( sTmp))
LOG_INFO( s_pGenLog, sTmp.c_str())
if ( GetMemoryInfo( sTmp))
LOG_INFO( s_pGenLog, sTmp.c_str())
// Info su gestori ObjUser caricati
STRVECTOR vsOuMgr ;
if ( OBJUSER_GETLIST( vsOuMgr)) {
LOG_INFO( s_pGenLog, "ObjUser Managers :")
for ( size_t i = 0 ; i < vsOuMgr.size() ; ++ i)
LOG_INFO( s_pGenLog, vsOuMgr[i].c_str())
}
// inizializzo l'interprete LUA
LuaInit() ;
return true ;
}
//-----------------------------------------------------------------------------
bool
ExeExit( void)
{
// cancello tutti i contesti
ClearAllGseContexts() ;
// termino l'interprete LUA
LuaExit() ;
// libero le librerie opzionali
FreeMachKernelDll() ;
FreeExchangeDll() ;
FreeGraphicsDll() ;
// fine programma
LOG_DATETIME( s_pGenLog, " Exit")
// cancello il logger dei comandi
if ( s_pCmdLog != nullptr) {
delete s_pCmdLog ;
s_pCmdLog = nullptr ;
}
// cancello il logger generale
if ( s_pGenLog != nullptr) {
delete s_pGenLog ;
s_pGenLog = nullptr ;
}
return true ;
}
//-----------------------------------------------------------------------------
bool
ExeSetKey( const string& sKey)
{
s_sKey = sKey ;
return true ;
}
//-----------------------------------------------------------------------------
bool
ExeSetFont( const string& sNfeFontDir, const string& sDefaultFont)
{
// inizializzazioni gestore font Nfe
InitFontManager( sNfeFontDir, sDefaultFont) ;
return true ;
}
//-----------------------------------------------------------------------------
bool
ExeGetNfeFontDir( string& sNfeFontDir)
{
if ( &sNfeFontDir == nullptr)
return false ;
// recupero il nome del font di default
sNfeFontDir = GetNfeFontDir() ;
return true ;
}
//-----------------------------------------------------------------------------
bool
ExeGetDefaultFont( string& sDefaultFont)
{
if ( &sDefaultFont == nullptr)
return false ;
// recupero il nome del font di default
sDefaultFont = GetDefaultFont() ;
return true ;
}
//-----------------------------------------------------------------------------
bool
ExeSetLuaLibs( const string& sLuaLibsDir)
{
return LuaSetLuaLibsDir( sLuaLibsDir) ;
}
//-----------------------------------------------------------------------------
bool
ExeSetCommandLogger( const string& sLogFile)
{
// cancello eventuale vecchio logger e disabilito output
if ( s_pCmdLog != nullptr)
delete s_pCmdLog ;
s_bCmdLog = false ;
// creo il logger dei comandi
s_pCmdLog = new Logger( LL_INFO, "EgtCommandLog") ;
if ( s_pCmdLog == nullptr)
return false ;
// assegno il file
ofstream* pLogFile = new ofstream( stringtoW( sLogFile)) ;
if ( pLogFile == nullptr || pLogFile->bad())
return false ;
s_pCmdLog->AddOutputStream( pLogFile, true) ;
// scrivo intestazione
string sOut = "-- " + CurrDateTime() + " EgtCommandLog" ;
LOG_INFO( s_pCmdLog, sOut.c_str())
return false ;
}
//-----------------------------------------------------------------------------
void
ExeEnableCommandLogger( void)
{
SetCmdLog( true) ;
}
//-----------------------------------------------------------------------------
void
ExeDisableCommandLogger( void)
{
SetCmdLog( false) ;
}
//-----------------------------------------------------------------------------
bool
ExeGetVersionInfo( string& sVer, const char* szNewLine)
{
// verifico il parametro
if ( &sVer == nullptr)
return false ;
// recupero le informazioni sulle DLL sempre presenti
sVer += GetEXeVersion() ;
sVer += szNewLine ;
sVer += GetEGnVersion() ;
sVer += szNewLine ;
sVer += GetENkVersion() ;
sVer += szNewLine ;
sVer += GetEGkVersion() ;
// recupero le informazioni sulle DLL opzionali
if ( IsLoadedGraphicsDll()) {
sVer += szNewLine ;
sVer += MyGetEGrVersion() ;
}
if ( IsLoadedExchangeDll()) {
sVer += szNewLine ;
sVer += MyGetEExVersion() ;
}
if ( IsLoadedMachKernelDll()) {
sVer += szNewLine ;
sVer += MyGetEMkVersion() ;
}
return true ;
}
//-----------------------------------------------------------------------------
bool
ExeGetOsInfo( string& sOs)
{
// recupero le informazioni sul sistema operativo
return GetOsInfo( sOs) ;
}
//-----------------------------------------------------------------------------
bool
ExeGetCpuInfo( string& sCpu)
{
// recupero le informazioni sulla Cpu
return GetCpuInfo( sCpu) ;
}
//-----------------------------------------------------------------------------
bool
ExeGetMemoryInfo( string& sMem)
{
// recupero le informazioni sulla memoria presente
return GetMemoryInfo( sMem) ;
}
//-----------------------------------------------------------------------------
bool
ExeOutLog( const string& sMsg)
{
LOG_INFO( s_pGenLog, sMsg.c_str())
return ( s_pGenLog != nullptr) ;
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
ILogger*
GetLogger( void)
{
return s_pGenLog ;
}
//-----------------------------------------------------------------------------
ILogger*
GetCmdLogger( void)
{
return s_pCmdLog ;
}
//-----------------------------------------------------------------------------
bool
SetCmdLog( bool bVal)
{
swap( bVal, s_bCmdLog) ;
return bVal ;
}
//-----------------------------------------------------------------------------
bool
IsCmdLog( void)
{
return s_bCmdLog ;
}