CyberMouseModule.cxx
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00042
00043
00044
00045 #include "../tool/disable4786.h"
00046
00047 #include "CyberMouseSource.h"
00048 #include "CyberMouseModule.h"
00049
00050 #ifdef USE_CYBERMOUSE
00051
00052 #include <stdio.h>
00053 #ifdef WIN32
00054 #include <iostream>
00055 #else
00056 #include <iostream.h>
00057 #endif
00058
00059 #include "freeddll.h"
00060
00061 #include <ace/Log_Msg.h>
00062
00063
00064
00065 #define SZ_Get_FREED_Info "Get_FREED_Info"
00066 #define SZ_OpenFREED "OpenFREED"
00067 #define SZ_CloseFREED "CloseFREED"
00068
00069 namespace ot {
00070
00071 typedef ULONG (FAR PASCAL *PFNGet_FREED_Info)(FREED_info *Info);
00072 extern PFNGet_FREED_Info lpfnGet_FREED_Info;
00073
00074 typedef ULONG (FAR PASCAL *PFNOpenFREED)(DWORD,HWND);
00075 extern PFNOpenFREED lpfnOpenFREED;
00076
00077 typedef ULONG (FAR PASCAL *PFNCloseFREED)();
00078 extern PFNCloseFREED lpfnCloseFREED;
00079
00080 PFNGet_FREED_Info lpfnGet_FREED_Info;
00081 PFNOpenFREED lpfnOpenFREED;
00082 PFNCloseFREED lpfnCloseFREED;
00083 FREED_info FREED_Info;
00084 WORD FREED_Opened;
00085
00086 HANDLE hLibrary;
00087 HWND hWndCyber;
00088
00089
00090 long FAR PASCAL WndProc (HWND hWndCyber, UINT uMsg, WPARAM wParam, LPARAM lParam)
00091 {
00092 return DefWindowProc(hWndCyber, uMsg, wParam, lParam);
00093 }
00094
00095
00096 CyberMouseModule::~CyberMouseModule()
00097 {
00098 nodes.clear();
00099 }
00100
00101
00102 Node * CyberMouseModule::createNode( const string& name, StringTable& attributes)
00103 {
00104 if( name.compare("CyberMouseSource") == 0 )
00105 {
00106 CyberMouseSource * source = new CyberMouseSource;
00107 source->event.getConfidence() = 1.0f;
00108 nodes.push_back( source );
00109 ACE_DEBUG((LM_INFO, ACE_TEXT("ot:Build CyberMouseSource node\n")));
00110 initialized = 1;
00111 return source;
00112 }
00113 return NULL;
00114 }
00115
00116
00117 void CyberMouseModule::start()
00118 {
00119 if( isInitialized() == 1 )
00120 {
00121 WNDCLASS wndclass ;
00122
00123
00124 wndclass.style = 0 ;
00125 wndclass.lpfnWndProc = WndProc ;
00126 wndclass.cbClsExtra = 0 ;
00127 wndclass.cbWndExtra = 0;
00128 wndclass.hInstance = NULL ;
00129 wndclass.hIcon = NULL;
00130 wndclass.hCursor = NULL;
00131 wndclass.hbrBackground = 0;
00132 wndclass.lpszMenuName = NULL ;
00133 wndclass.lpszClassName = "dummyClassCyberMouseModule";
00134
00135 RegisterClass(&wndclass) ;
00136
00137 hWndCyber = CreateWindow(
00138 "dummyClassCyberMouseModule",
00139 NULL,
00140 NULL,
00141 0,
00142 0,
00143 CW_USEDEFAULT,
00144 CW_USEDEFAULT,
00145 NULL,
00146 NULL,
00147 NULL,
00148 NULL
00149 );
00150
00151 if (!hWndCyber)
00152 {
00153 ACE_DEBUG((LM_ERROR, ACE_TEXT("ot:Could not create message-only window.\nFatal Error\n")));
00154 exit(1);
00155 }
00156
00157 if ((hLibrary = LoadLibrary("FREEDDLL.DLL")) == NULL) {
00158 ACE_DEBUG((LM_ERROR, ACE_TEXT("ot:Error Loading FREEDDLL.DLL.\nFatal Error\n")));
00159 exit(1);
00160 }
00161
00162 if ((lpfnGet_FREED_Info = (PFNGet_FREED_Info)GetProcAddress((HMODULE)hLibrary, SZ_Get_FREED_Info)) == NULL)
00163 exit(1);
00164 if ((lpfnOpenFREED = (PFNOpenFREED)GetProcAddress((HMODULE)hLibrary,SZ_OpenFREED)) == NULL)
00165 exit(1);
00166 if ((lpfnCloseFREED = (PFNCloseFREED)GetProcAddress((HMODULE)hLibrary,SZ_CloseFREED)) == NULL)
00167 exit(1);
00168
00169 if (lpfnOpenFREED != NULL) {
00170 lpfnOpenFREED(0,hWndCyber);
00171 FREED_Opened = TRUE;
00172 }
00173
00174
00175 if (lpfnGet_FREED_Info != NULL) lpfnGet_FREED_Info(&FREED_Info);
00176 }
00177 }
00178
00179
00180 void CyberMouseModule::close()
00181 {
00182 if( isInitialized() == 1 && lpfnCloseFREED != NULL) {
00183 FREED_Opened = FALSE;
00184 lpfnCloseFREED();
00185 }
00186 if (hLibrary != NULL) FreeLibrary((HMODULE)hLibrary);
00187 PostQuitMessage(0);
00188 }
00189
00190
00191 void CyberMouseModule::pushEvent()
00192 {
00193 if( isInitialized() == 1 )
00194 {
00195 lpfnGet_FREED_Info(&FREED_Info);
00196 if( ! (FREED_Info.Status & (NewPosition | NewButton_Status)))
00197 return;
00198 }
00199 for( NodeVector::iterator it = nodes.begin(); it != nodes.end(); it++ )
00200 {
00201 CyberMouseSource * source = (CyberMouseSource *)(*it);
00202 source->event.getPosition()[0] = FREED_Info.AbsX;
00203 source->event.getPosition()[1] = FREED_Info.AbsY;
00204 source->event.getPosition()[2] = FREED_Info.AbsZ;
00205
00206 source->event.getButton() = (FREED_Info.Status & 0x3);
00207 source->event.timeStamp();
00208 source->updateObservers( source->event );
00209 }
00210 }
00211
00212 }
00213
00214
00215 #else
00216 #pragma message(">>> no CyberMouse support")
00217 #endif
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233