Tightened up how the API is opened.

master
Pacman Ghost 7 years ago
parent 9735b7d047
commit 9f7c4b0401
  1. 50
      MainApp/MouseDll.cs
  2. 45
      MouseDll/api.cpp
  3. 15
      MouseDll/api.hpp
  4. 68
      MouseDll/core.cpp

@ -12,16 +12,7 @@ namespace MouseInterception
[DllImport( @DLL_NAME , CallingConvention=CallingConvention.Cdecl )]
[return: MarshalAs(UnmanagedType.BStr)]
private static extern string open_api(
ref AppConfig.ApiSettings pAppSettings ,
[MarshalAs(UnmanagedType.LPArray)] AppConfig.ApiDevice[] pDevices , int nDevices ,
[MarshalAs(UnmanagedType.LPArray)] AppConfig.ApiDeviceConfig[] pDeviceConfigs , int nDeviceConfigs ,
[MarshalAs(UnmanagedType.LPArray)] AppConfig.ApiAppProfile[] pAppProfiles , int nAppProfiles ,
[MarshalAs(UnmanagedType.LPArray)] AppConfig.ApiEvent[] pEvents , int nEvents ,
[MarshalAs(UnmanagedType.LPArray)] AppConfig.ApiAction[] pActions , int nActions ,
ref DebugConfig.ApiSettings pDebugSettings ,
int initConsole
) ;
private static extern string open_api( ref DebugConfig.ApiSettings pDebugSettings , int initConsole ) ;
[DllImport( @DLL_NAME , CallingConvention=CallingConvention.Cdecl )]
[return: MarshalAs(UnmanagedType.BStr)]
@ -35,32 +26,21 @@ namespace MouseInterception
[MarshalAs(UnmanagedType.LPArray)] AppConfig.ApiDeviceConfig[] pDeviceConfigs , int nDeviceConfigs ,
[MarshalAs(UnmanagedType.LPArray)] AppConfig.ApiAppProfile[] pAppProfiles , int nAppProfiles ,
[MarshalAs(UnmanagedType.LPArray)] AppConfig.ApiEvent[] pEvents , int nEvents ,
[MarshalAs(UnmanagedType.LPArray)] AppConfig.ApiAction[] pActions , int nActions ,
ref DebugConfig.ApiSettings pDebugSettings
[MarshalAs(UnmanagedType.LPArray)] AppConfig.ApiAction[] pActions , int nActions
) ;
[DllImport( @DLL_NAME , CallingConvention=CallingConvention.Cdecl )]
[return: MarshalAs(UnmanagedType.BStr)]
private static extern string reload_debug_config( ref DebugConfig.ApiSettings pDebugSettings ) ;
public MouseDll( bool initConsole )
{
// open the mouse API
AppConfig.ApiSettings appSettings = Program.appConfig.settings ;
AppConfig.ApiDevice[] devices = Program.appConfig.devices ;
AppConfig.ApiDeviceConfig[] deviceConfigs = Program.appConfig.deviceConfigs ;
AppConfig.ApiAppProfile[] appProfiles = Program.appConfig.appProfiles ;
AppConfig.ApiEvent[] events = Program.appConfig.events ;
AppConfig.ApiAction[] actions = Program.appConfig.actions ;
DebugConfig.ApiSettings debugSettings = Program.debugConfig.settings ;
string errorMsg = open_api(
ref appSettings ,
devices , devices.Length ,
deviceConfigs , deviceConfigs.Length ,
appProfiles , appProfiles.Length ,
events , events.Length ,
actions , actions.Length ,
ref debugSettings ,
initConsole ? 1 : 0
) ;
string errorMsg = open_api( ref debugSettings , initConsole?1:0 ) ;
if ( errorMsg != null )
throw new Exception( errorMsg ) ;
reloadConfig() ;
}
~MouseDll()
@ -80,18 +60,26 @@ namespace MouseInterception
AppConfig.ApiAppProfile[] appProfiles = Program.appConfig.appProfiles ;
AppConfig.ApiEvent[] events = Program.appConfig.events ;
AppConfig.ApiAction[] actions = Program.appConfig.actions ;
DebugConfig.ApiSettings debugSettings = Program.debugConfig.settings ;
string errorMsg = reload_config(
ref appSettings ,
devices , devices.Length ,
deviceConfigs , deviceConfigs.Length ,
appProfiles , appProfiles.Length ,
events , events.Length ,
actions , actions.Length ,
ref debugSettings
actions , actions.Length
) ;
if ( errorMsg != null )
throw new Exception( errorMsg ) ;
}
public void reloadDebugConfig()
{
// reload the debug config
DebugConfig.ApiSettings debugSettings = Program.debugConfig.settings ;
string errorMsg = reload_debug_config( ref debugSettings ) ;
if ( errorMsg != null )
throw new Exception( errorMsg ) ;
}
}
}

@ -8,30 +8,12 @@ using namespace std ;
// ---------------------------------------------------------------------
extern "C" __declspec(dllexport) BSTR
open_api(
const ApiAppConfig* pAppConfig ,
const ApiDevice* pDevices , int nDevices ,
const ApiDeviceConfig* pDeviceConfigs , int nDeviceConfigs ,
const ApiAppProfile* pAppProfiles , int nAppProfiles ,
const ApiEvent* pEvents , int nEvents ,
const ApiAction* pActions , int nActions ,
const ApiDebugConfig* pDebugConfig ,
int initConsole
)
open_api( const ApiDebugConfig* pDebugConfig , int initConsole )
{
// open the API
try
{
openApi(
pAppConfig ,
pDevices , nDevices ,
pDeviceConfigs , nDeviceConfigs ,
pAppProfiles , nAppProfiles ,
pEvents , nEvents ,
pActions , nActions ,
pDebugConfig ,
initConsole != 0
) ;
openApi( pDebugConfig , initConsole != 0 ) ;
return NULL ;
}
catch ( exception& xcptn )
@ -66,8 +48,7 @@ reload_config(
const ApiDeviceConfig* pDeviceConfigs , int nDeviceConfigs ,
const ApiAppProfile* pAppProfiles , int nAppProfiles ,
const ApiEvent* pEvents , int nEvents ,
const ApiAction* pActions , int nActions ,
const ApiDebugConfig* pDebugConfig
const ApiAction* pActions , int nActions
)
{
// reload the config
@ -79,8 +60,7 @@ reload_config(
pDeviceConfigs , nDeviceConfigs ,
pAppProfiles , nAppProfiles ,
pEvents , nEvents ,
pActions , nActions ,
pDebugConfig
pActions , nActions
) ;
return NULL ;
}
@ -89,3 +69,20 @@ reload_config(
return SysAllocString( fromUtf8( MAKE_STRING( xcptn.what() ) ).c_str() ) ;
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
extern "C" __declspec(dllexport) BSTR
reload_debug_config( const ApiDebugConfig* pDebugConfig )
{
// reload the debug config
try
{
reloadDebugConfig( pDebugConfig ) ;
return NULL ;
}
catch ( exception& xcptn )
{
return SysAllocString( fromUtf8( MAKE_STRING( xcptn.what() ) ).c_str() ) ;
}
}

@ -57,16 +57,7 @@ struct ApiDebugConfig
// IMPORTANT! The definitions here must be kept in sync with their C# equivalents in MouseDll.cs.
extern void openApi(
const ApiAppConfig* pAppConfig ,
const ApiDevice* pDevices , int nDevices ,
const ApiDeviceConfig* pDeviceConfigs , int nDeviceConfigs ,
const ApiAppProfile* pAppProfiles , int nAppProfiles ,
const ApiEvent* pEvents , int nEvents ,
const ApiAction* pActions , int nActions ,
const ApiDebugConfig* pDebugConfig ,
bool initConsole
) ;
extern void openApi( const ApiDebugConfig* pDebugConfig , bool initConsole ) ;
extern void closeApi() ;
extern void reloadConfig(
@ -75,9 +66,9 @@ extern void reloadConfig(
const ApiDeviceConfig* pDeviceConfigs , int nDeviceConfigs ,
const ApiAppProfile* pAppProfiles , int nAppProfiles ,
const ApiEvent* pEvents , int nEvents ,
const ApiAction* pActions , int nActions ,
const ApiDebugConfig* pDebugConfig
const ApiAction* pActions , int nActions
) ;
extern void reloadDebugConfig( const ApiDebugConfig* pDebugConfig ) ;
// ---------------------------------------------------------------------

@ -7,32 +7,15 @@ using namespace std ;
// ---------------------------------------------------------------------
void
openApi(
const ApiAppConfig* pAppConfig ,
const ApiDevice* pDevices , int nDevices ,
const ApiDeviceConfig* pDeviceConfigs , int nDeviceConfigs ,
const ApiAppProfile* pAppProfiles , int nAppProfiles ,
const ApiEvent* pEvents , int nEvents ,
const ApiAction* pActions , int nActions ,
const ApiDebugConfig* pDebugConfig ,
bool initConsole
)
openApi( const ApiDebugConfig* pDebugConfig , bool initConsole )
{
// check if we are open
if ( ghInterceptionDll != NULL )
throw runtime_error( "API is already open." ) ;
// initialize
reloadDebugConfig( pDebugConfig ) ;
gEnableConsole = initConsole ;
reloadConfig(
pAppConfig ,
pDevices , nDevices ,
pDeviceConfigs , nDeviceConfigs ,
pAppProfiles , nAppProfiles ,
pEvents , nEvents ,
pActions , nActions ,
pDebugConfig
) ;
// load Interception
wchar_t buf[ _MAX_PATH+1 ] ;
@ -76,8 +59,7 @@ reloadConfig(
const ApiDeviceConfig* pDeviceConfigs , int nDeviceConfigs ,
const ApiAppProfile* pAppProfiles , int nAppProfiles ,
const ApiEvent* pEvents , int nEvents ,
const ApiAction* pActions , int nActions ,
const ApiDebugConfig* pDebugConfig
const ApiAction* pActions , int nActions
)
{
// validate the parameters
@ -103,24 +85,6 @@ reloadConfig(
throw runtime_error( "Missing Action's." ) ;
if ( nActions < 0 )
throw runtime_error( "Invalid Action count." ) ;
if ( pDebugConfig == NULL )
throw runtime_error( "Missing DebugConfig." ) ;
const wchar_t* pLogFilename = pDebugConfig->mpLogFilename ;
if ( pLogFilename == NULL )
pLogFilename = L"" ;
// initialize the log file
if ( _wcsicmp( gLogFilename.c_str() , pLogFilename ) != 0 )
{
if ( gLogFile.is_open() )
gLogFile.close() ;
if ( pLogFilename[0] != L'\0' )
{
gLogFile.open( pLogFilename ) ;
gLogFilename = pLogFilename ;
}
}
initLogging( pDebugConfig->mpLogging ) ;
// load the Device's
gDeviceTable.deleteAll() ;
@ -179,3 +143,29 @@ reloadConfig(
LOG_MSG( buf.str() ) ;
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void
reloadDebugConfig( const ApiDebugConfig* pDebugConfig )
{
// validate the parameters
if ( pDebugConfig == NULL )
throw runtime_error( "Missing DebugConfig." ) ;
// initialize the log file
const wchar_t* pLogFilename = pDebugConfig->mpLogFilename ;
if ( pLogFilename == NULL )
pLogFilename = L"" ;
if ( _wcsicmp( gLogFilename.c_str() , pLogFilename ) != 0 )
{
if ( gLogFile.is_open() )
gLogFile.close() ;
if ( pLogFilename[0] != L'\0' )
{
gLogFile.open( pLogFilename ) ;
gLogFilename = pLogFilename ;
}
}
initLogging( pDebugConfig->mpLogging ) ;
}

Loading…
Cancel
Save