Files
EgtInterface/API_General.cpp
T
Dario Sassi 4bb71f5578 EgtInterface 1.6c9 :
- EgtGraphics, EgtExchange ed EgtMachKernel sono caricabili opzionalmente.
2015-03-30 06:52:19 +00:00

346 lines
9.5 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 "API.h"
#include "LUA_Base.h"
#include "DllGraphics.h"
#include "DllExchange.h"
#include "DllMachKernel.h"
#include "/EgtDev/Include/EInAPI.h"
#include "/EgtDev/Include/EInDllMain.h"
#include "/EgtDev/Include/EGnDllMain.h"
#include "/EgtDev/Include/ENkDllMain.h"
#include "/EgtDev/Include/EGkDllMain.h"
#include "/EgtDev/Include/EGnStringUtils.h"
#include "/EgtDev/Include/EGnStringConverter.h"
#include "/EgtDev/Include/EGnPcInfo.h"
#include "/EgtDev/Include/EgtLogger.h"
#include <fstream>
using namespace std ;
using namespace egtlogger ;
//----------------------------------------------------------------------------
static Logger* s_pGenLog = nullptr ;
static Logger* s_pCmdLog = nullptr ;
static bool s_bCmdLog = false ;
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtInit( int nDebug, const wchar_t* sLogFile, const wchar_t* 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( sLogFile), true) ;
// lo passo alle DLL
SetEGnLogger( s_pGenLog) ;
SetENkLogger( s_pGenLog) ;
SetEGkLogger( s_pGenLog) ;
// carico librerie opzionali
LoadGraphicsDll() ;
MySetEGrLogger( s_pGenLog) ;
LoadExchangeDll() ;
MySetEExLogger( s_pGenLog) ;
LoadMachKernelDll() ;
MySetEMkLogger( s_pGenLog) ;
// dichiaro inizio programma
LOG_DATETIME( s_pGenLog, " Init")
// eventuale messaggio dall'applicazione
if ( sLogMsg != nullptr && sLogMsg[0] != L'\0')
LOG_INFO( s_pGenLog, LPSTR( WtoA( sLogMsg)))
// versione di interfaccia e componenti
string sVer ;
EgtGetVersionInfo( sVer, "\n") ;
LOG_INFO( s_pGenLog, sVer.c_str())
// 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())
// inizializzo l'interprete LUA
LuaInit() ;
return TRUE ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtExit( 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
__stdcall EgtSetKey( const wchar_t* swKey)
{
string sKey = WtoA( swKey) ;
SetEGkKey( sKey) ;
MySetEGrKey( sKey) ;
MySetEExKey( sKey) ;
MySetEMkKey( sKey) ;
return TRUE ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtSetFont( const wchar_t* wsNfeFontDir, const wchar_t* wsDefaultFont)
{
// inizializzazioni gestore font Nfe
InitFontManager( LPSTR( WtoA( wsNfeFontDir)), LPSTR( WtoA( wsDefaultFont))) ;
return TRUE ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtGetNfeFontDir( wchar_t*& wsNfeFontDir)
{
if ( &wsNfeFontDir == nullptr)
return false ;
// recupero il nome del font di default
string sNfeFontDir = GetNfeFontDir() ;
wsNfeFontDir = _wcsdup( stringtoW( sNfeFontDir)) ;
return (( wsNfeFontDir == nullptr) ? FALSE : TRUE) ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtGetDefaultFont( wchar_t*& wsDefaultFont)
{
if ( &wsDefaultFont == nullptr)
return false ;
// recupero il nome del font di default
string sDefaultFont = GetDefaultFont() ;
wsDefaultFont = _wcsdup( stringtoW( sDefaultFont)) ;
return (( wsDefaultFont == nullptr) ? FALSE : TRUE) ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtSetLuaLibs( const wchar_t* wsLuaLibsDir)
{
if ( LuaSetLuaLibsDir( LPSTR( WtoA( wsLuaLibsDir))))
return TRUE ;
else
return FALSE ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtSetCommandLogger( const wchar_t* 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( 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 TRUE ;
}
//-----------------------------------------------------------------------------
void
__stdcall EgtEnableCommandLogger( void)
{
SetCmdLog( true) ;
}
//-----------------------------------------------------------------------------
void
__stdcall EgtDisableCommandLogger( void)
{
SetCmdLog( false) ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtGetVersionInfo( wchar_t*& wsVer)
{
// recupero le informazioni sulle DLL
string sVer ;
if ( ! EgtGetVersionInfo( sVer, "\r\n"))
return FALSE ;
wsVer = _wcsdup( stringtoW( sVer)) ;
return (( wsVer == nullptr) ? FALSE : TRUE) ;
}
//-----------------------------------------------------------------------------
bool
EgtGetVersionInfo( string& sVer, const char* szNewLine)
{
// verifico il parametro
if ( &sVer == nullptr)
return false ;
// recupero le informazioni sulle DLL sempre presenti
sVer += GetEInVersion() ;
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() ;
}
string sEMkVer = MyGetEMkVersion() ;
if ( ! sEMkVer.empty()) {
sVer += szNewLine ;
sVer += sEMkVer ;
}
return true ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtGetOsInfo( wchar_t*& wsOs)
{
// recupero le informazioni sul sistema operativo
string sOs ;
if ( ! GetOsInfo( sOs))
return FALSE ;
wsOs = _wcsdup( stringtoW( sOs)) ;
return (( wsOs == nullptr) ? FALSE : TRUE) ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtGetCpuInfo( wchar_t*& wsCpu)
{
// recupero le informazioni sulla Cpu
string sCpu ;
if ( ! GetCpuInfo( sCpu))
return FALSE ;
wsCpu = _wcsdup( stringtoW( sCpu)) ;
return (( wsCpu == nullptr) ? FALSE : TRUE) ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtGetMemoryInfo( wchar_t*& wsMem)
{
// recupero le informazioni sulla memoria presente
string sMem ;
if ( ! GetMemoryInfo( sMem))
return FALSE ;
wsMem = _wcsdup( stringtoW( sMem)) ;
return (( wsMem == nullptr) ? FALSE : TRUE) ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtFreeMemory( void* pMem)
{
if ( pMem == nullptr)
return FALSE ;
free( pMem) ;
return TRUE ;
}
//-----------------------------------------------------------------------------
BOOL
__stdcall EgtOutLog( const wchar_t* sMsg)
{
LOG_INFO( s_pGenLog, LPSTR( WtoA( sMsg)))
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 ;
}