OpenTracker

An Open Architecture for Reconfigurable Tracking based on XML | Contact

CyberMouseModule.cxx

Go to the documentation of this file.
00001 /* ========================================================================
00002  * Copyright (c) 2006,
00003  * Institute for Computer Graphics and Vision
00004  * Graz University of Technology
00005  * All rights reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions are
00009  * met:
00010  *
00011  * Redistributions of source code must retain the above copyright notice,
00012  * this list of conditions and the following disclaimer.
00013  *
00014  * Redistributions in binary form must reproduce the above copyright
00015  * notice, this list of conditions and the following disclaimer in the
00016  * documentation and/or other materials provided with the distribution.
00017  *
00018  * Neither the name of the Graz University of Technology nor the names of
00019  * its contributors may be used to endorse or promote products derived from
00020  * this software without specific prior written permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
00023  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
00024  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00025  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
00026  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00027  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00028  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00029  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00030  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00031  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00032  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033  * ========================================================================
00034  * PROJECT: OpenTracker
00035  * ======================================================================== */
00042 /* ======================================================================= */
00043 
00044 // this will remove the warning 4786
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>    // VisualC++ uses STL based IOStream lib
00055 #else
00056 #include <iostream.h>
00057 #endif
00058 
00059 #include "freeddll.h"
00060 
00061 #include <ace/Log_Msg.h>
00062 
00063 //using namespace std;
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     // Destructor method
00096     CyberMouseModule::~CyberMouseModule()
00097     {
00098         nodes.clear();
00099     }
00100 
00101     // This method is called to construct a new Node.
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     // opens CyberMouse library
00117     void CyberMouseModule::start()
00118     {
00119         if( isInitialized() == 1 )
00120         {
00121             WNDCLASS  wndclass ;
00122 
00123             // register FREED window class
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             // get initial FREED information
00175             if (lpfnGet_FREED_Info != NULL) lpfnGet_FREED_Info(&FREED_Info);
00176         }
00177     }
00178 
00179     // closes CyberMouse library
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     // pushes events into the tracker tree.
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             //middle button = 1, second button = 2, both = 3
00206             source->event.getButton() = (FREED_Info.Status & 0x3);
00207             source->event.timeStamp();
00208             source->updateObservers( source->event );
00209         }
00210     }
00211 
00212 } // namespace ot
00213 
00214 
00215 #else
00216 #pragma message(">>> no CyberMouse support")
00217 #endif
00218 
00219 /* 
00220  * ------------------------------------------------------------
00221  *   End of CyberMouseModule.cxx
00222  * ------------------------------------------------------------
00223  *   Automatic Emacs configuration follows.
00224  *   Local Variables:
00225  *   mode:c++
00226  *   c-basic-offset: 4
00227  *   eval: (c-set-offset 'substatement-open 0)
00228  *   eval: (c-set-offset 'case-label '+)
00229  *   eval: (c-set-offset 'statement 'c-lineup-runin-statements)
00230  *   eval: (setq indent-tabs-mode nil)
00231  *   End:
00232  * ------------------------------------------------------------ 
00233  */

copyright (c) 2006 Graz University of Technology