Notify the UI when new devices are seen.

master
Pacman Ghost 7 years ago
parent 42bd9fae04
commit 3a1b91f74d
  1. 1
      MainApp/MouseDll.cs
  2. 3
      MainApp/Program.cs
  3. 1
      MouseDll/api.hpp
  4. 1
      MouseDll/core.cpp
  5. 51
      MouseDll/core2.cpp
  6. 3
      MouseDll/globals.cpp
  7. 11
      MouseDll/globals.hpp

@ -15,6 +15,7 @@ namespace MouseInterception
public const int CBTYPE_STARTED = 1 ;
public const int CBTYPE_STOPPED = 2 ;
public const int CBTYPE_FATAL_ERROR = 3 ;
public const int CBTYPE_NEW_DEVICE = 10 ;
[DllImport( @DLL_NAME , CallingConvention=CallingConvention.Cdecl )]
[return: MarshalAs(UnmanagedType.BStr)]

@ -116,6 +116,9 @@ namespace MouseInterception
Program.showErrorMsg( errorMsg ) ;
Application.Exit() ;
break ;
case MouseDll.CBTYPE_NEW_DEVICE:
System.Console.WriteLine( String.Format( "NEW DEVICE: {0}" , callbackMsg ) ) ;
break ;
default:
Debug.Assert( false ) ;
System.Console.WriteLine( String.Format( "UNKNOWN CALLBACK {0}: {1}" , callbackType , callbackMsg ) ) ;

@ -61,6 +61,7 @@ typedef int (__stdcall *PCALLBACKFN)( int callbackType , const char* pCallbackMs
#define CBTYPE_STARTED 1
#define CBTYPE_STOPPED 2
#define CBTYPE_FATAL_ERROR 3
#define CBTYPE_NEW_DEVICE 10
extern void openApi( PCALLBACKFN pCallbackFn , const ApiDebugConfig* pDebugConfig ) ;
extern void closeApi() ;

@ -95,6 +95,7 @@ reloadConfig(
(*it).second->dumpDevice( buf , " " ) ;
LOG_MSG( buf.str() ) ;
}
gUnknownDevices.clear() ;
// load the DeviceConfig's
gDeviceConfigTable.deleteAll() ;

@ -1,5 +1,3 @@
#include "interception.h"
#include "globals.hpp"
using namespace std ;
@ -8,6 +6,7 @@ using namespace std ;
// local functions:
static void doRunMainLoop( int* pExitFlag ) ;
static bool findDevice( InterceptionDevice hDevice , Device** ppDevice ) ;
// ---------------------------------------------------------------------
@ -116,6 +115,35 @@ doRunMainLoop( int* pExitFlag )
) ;
}
// find the device that generated the event
Device* pDevice ;
if ( ! findDevice( hDevice , &pDevice ) )
{
// can't find the the device - check if we've seen it before
if ( gUnknownDevices.find( hDevice ) == gUnknownDevices.end() )
{
// nope - notify the front-end about the new device
// NOTE: We seem to get multiple hardware ID's back, but the first one seems to be the one we want :shrug:
WideCharVector buf( 4*1024 ) ;
size_t nChars = interception_get_hardware_id( hContext , hDevice , &buf[0] , buf.size()*sizeof(wchar_t) ) ;
(*gpCallbackFn)( CBTYPE_NEW_DEVICE , MAKE_CSTRING(hDevice << "|" << toUtf8(&buf[0],nChars)) ) ;
gUnknownDevices.insert( hDevice ) ;
}
// forward the event on (for normal processing)
interception_send( hContext , hDevice ,&stroke , 1 ) ;
continue ;
}
// check if the device is enabled
if ( ! pDevice->isEnabled() )
{
// nope - just forward the event (for normal processing)
interception_send( hContext , hDevice ,&stroke , 1 ) ;
continue ;
}
// FIXME! handle the event
interception_send( hContext , hDevice ,&stroke , 1 ) ;
}
@ -125,3 +153,22 @@ doRunMainLoop( int* pExitFlag )
LOG_CMSG( "system" , "Main loop ended." ) ;
}
// ---------------------------------------------------------------------
static bool
findDevice( InterceptionDevice hDevice , Device** ppDevice )
{
// find the specified device
for( DeviceTable::iterator it=gDeviceTable.begin() ; it != gDeviceTable.end() ; ++it )
{
Device* pDevice = (*it).second ;
// FIXME! have to check HID as well
if ( pDevice->deviceNumber() == hDevice )
{
*ppDevice = pDevice ;
return true ;
}
}
return false ;
}

@ -1,4 +1,3 @@
#include <set>
#include <ctime>
#include "globals.hpp"
@ -17,6 +16,7 @@ HMODULE ghInterceptionDll = NULL ;
DeviceTable gDeviceTable ;
DeviceConfigTable gDeviceConfigTable ;
InterceptionDeviceSet gUnknownDevices ;
PCALLBACKFN gpCallbackFn = NULL ;
@ -25,7 +25,6 @@ ofstream gLogFile ;
// ---------------------------------------------------------------------
typedef set<string> StringSet ;
static StringSet gLogging ;
void initLogging( const wchar_t* pLogging )

@ -4,12 +4,20 @@
#include <windows.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include "interception.h"
#include "device.hpp"
#include "deviceConfig.hpp"
#include "api.hpp"
#include "utils.hpp"
typedef std::vector<char> CharVector ;
typedef std::vector<wchar_t> WideCharVector ;
typedef std::set<int> IntSet ;
typedef std::set<std::string> StringSet ;
// ---------------------------------------------------------------------
extern HMODULE ghInterceptionDll ;
@ -20,6 +28,9 @@ extern DeviceTable gDeviceTable ;
typedef IntPtrMap<DeviceConfig> DeviceConfigTable ;
extern DeviceConfigTable gDeviceConfigTable ;
typedef std::set<InterceptionDevice> InterceptionDeviceSet ;
extern InterceptionDeviceSet gUnknownDevices ;
extern PCALLBACKFN gpCallbackFn ;
// ---------------------------------------------------------------------

Loading…
Cancel
Save