00001 /* 00002 * $RCSfile: USBDeviceManager.hpp,v $ 00003 * $Revision: 1.10 $ 00004 * $Date: 2009/12/23 22:39:10 $ 00005 * jEdit:tabSize=4:indentSize=4:collapseFolds=1: 00006 * 00007 * class USBDeviceManager, OperationFailedException, IllegalArgumentException declarations 00008 */ 00009 00010 #if ! defined( USBDeviceManager_hpp ) 00011 #define USBDeviceManager_hpp 00012 00013 // {{{ includes 00014 #include <iostream> 00015 #include <stdexcept> 00016 #include <string> 00017 #include <vector> 00018 #include <aiousb.h> 00019 #include <USBDevice.hpp> 00020 // }}} 00021 00022 namespace AIOUSB { 00023 00030 class USBDeviceManager { 00031 00032 // {{{ public constants 00033 public: 00035 static const std::string VERSION_NUMBER; 00036 00038 static const std::string VERSION_DATE; 00039 00040 static const int MIN_PRODUCT_ID = 0; 00041 static const int MAX_PRODUCT_ID = 0xffff; 00042 // }}} 00043 00044 // {{{ protected members 00045 protected: 00046 USBDeviceArray deviceList; // contains all the ACCES devices found on the bus 00047 static const unsigned long OPEN_PATTERN = 0x786938f5; // unique, random value 00048 unsigned long openStatus; // if openStatus == OPEN_PATTERN, module is initialized 00049 static const std::string MESSAGE_NOT_OPEN; 00050 // }}} 00051 00052 // {{{ protected methods 00053 protected: 00054 void emptyDeviceList(); 00055 // }}} 00056 00057 // {{{ public methods 00058 public: 00059 USBDeviceManager(); 00060 virtual ~USBDeviceManager(); 00061 00062 /* 00063 * properties 00064 */ 00065 00066 virtual std::ostream &print( std::ostream &out ); 00067 USBDeviceManager &printDevices(); 00068 00074 std::string getAIOUSBVersion() const { 00075 return AIOUSB_GetVersion(); 00076 } // getAIOUSBVersion() 00077 00083 std::string getAIOUSBVersionDate() const { 00084 return AIOUSB_GetVersionDate(); 00085 } // getAIOUSBVersionDate() 00086 00087 /* 00088 * utilities 00089 */ 00090 00091 static std::string productIDToName( int productID ); 00092 static StringArray productIDToName( const IntArray &productID ); 00093 static int productNameToID( const std::string &productName ); 00094 static IntArray productNameToID( const StringArray &productName ); 00095 00096 /* 00097 * operations 00098 */ 00099 00107 void listDevices() const { 00108 AIOUSB_ListDevices(); 00109 } // listDevices() 00110 00124 static std::string getResultCodeAsString( int result ) { 00125 return AIOUSB_GetResultCodeAsString( result ); 00126 } // getResultCodeAsString() 00127 00134 bool isOpen() const { 00135 return openStatus == OPEN_PATTERN; 00136 } // isOpen() 00137 00138 USBDeviceManager &open(); 00139 USBDeviceManager &close(); 00140 USBDeviceManager &scanForDevices(); 00141 USBDeviceArray getDeviceByProductID( int productID ) const; 00142 USBDeviceArray getDeviceByProductID( int minProductID, int maxProductID ) const; 00143 USBDeviceArray getDeviceByProductID( const IntArray &productIDs ) const; 00144 USBDeviceArray getDeviceBySerialNumber( __uint64_t serialNumber ) const; 00145 00146 // }}} 00147 00148 }; // class USBDeviceManager 00149 00150 // {{{ class OperationFailedException declarations 00151 00158 class OperationFailedException : public std::runtime_error { 00159 public: 00160 00166 OperationFailedException( int result ) 00167 : std::runtime_error( USBDeviceManager::getResultCodeAsString( result ) ) { 00168 } // OperationFailedException() 00169 00175 OperationFailedException( const std::string &message ) 00176 : std::runtime_error( message ) { 00177 } // OperationFailedException() 00178 00179 }; // class OperationFailedException 00180 00181 // }}} 00182 00183 // {{{ class IllegalArgumentException declarations 00184 00189 class IllegalArgumentException : public std::invalid_argument { 00190 public: 00191 00197 IllegalArgumentException( const std::string &message ) 00198 : std::invalid_argument( message ) { 00199 } // IllegalArgumentException() 00200 00201 }; // class IllegalArgumentException 00202 00203 // }}} 00204 00205 } // namespace AIOUSB 00206 00207 #endif 00208 00209 /* end of file */