00001 /* 00002 * $RCSfile: USBDeviceManager.hpp,v $ 00003 * $Revision: 1.6 $ 00004 * $Date: 2009/11/26 22:06:44 $ 00005 * jEdit:tabSize=4:indentSize=4:collapseFolds=1: 00006 * 00007 * class DeviceList, USBDeviceManager, OperationFailedException, IllegalArgumentException declarations 00008 */ 00009 00010 00011 #if ! defined( USBDeviceManager_hpp ) 00012 #define USBDeviceManager_hpp 00013 00014 // {{{ includes 00015 #include <iostream> 00016 #include <stdexcept> 00017 #include <string> 00018 #include <vector> 00019 #include <aiousb.h> 00020 // }}} 00021 00022 namespace AIOUSB { 00023 00024 // {{{ class DeviceList declarations 00025 00026 class USBDevice; 00027 00028 class DeviceList : public std::vector<USBDevice*> { 00029 }; // class DeviceList 00030 00031 // }}} 00032 00033 // {{{ class USBDeviceManager declarations 00034 00035 class USBDeviceManager { 00036 public: 00037 const std::string VERSION_NUMBER; 00038 const std::string VERSION_DATE; 00039 00040 protected: 00041 const std::string MESSAGE_NOT_OPEN; 00042 const unsigned long OPEN_PATTERN; // unique, random value 00043 unsigned long openStatus; // if openStatus == OPEN_PATTERN, module is initialized 00044 DeviceList deviceList; // contains all the ACCES devices found on the bus 00045 00046 void emptyDeviceList(); 00047 00048 public: 00049 USBDeviceManager(); 00050 virtual ~USBDeviceManager(); 00051 00052 /* 00053 * properties 00054 */ 00055 00056 virtual std::ostream &print( std::ostream &out ); 00057 USBDeviceManager &printDevices(); 00058 00059 std::string getAIOUSBVersion() const { 00060 return AIOUSB_GetVersion(); 00061 } // getAIOUSBVersion() 00062 00063 std::string getAIOUSBVersionDate() const { 00064 return AIOUSB_GetVersionDate(); 00065 } // getAIOUSBVersionDate() 00066 00067 /* 00068 * operations 00069 */ 00070 00071 void listDevices() const { 00072 AIOUSB_ListDevices(); 00073 } // listDevices() 00074 00075 static std::string getResultCodeAsString( int result ) { 00076 return AIOUSB_GetResultCodeAsString( result ); 00077 } // getResultCodeAsString() 00078 00079 bool isOpen() const { 00080 return openStatus == OPEN_PATTERN; 00081 } // isOpen() 00082 00083 USBDeviceManager &open(); 00084 USBDeviceManager &close(); 00085 USBDeviceManager &scanForDevices(); 00086 DeviceList getDeviceByProductID( int productID ) const; 00087 DeviceList getDeviceByProductID( int minProductID, int maxProductID ) const; 00088 DeviceList getDeviceBySerialNumber( __uint64_t serialNumber ) const; 00089 }; // class USBDeviceManager 00090 00091 // }}} 00092 00093 // {{{ class OperationFailedException declarations 00094 00095 class OperationFailedException : public std::runtime_error { 00096 public: 00097 OperationFailedException( const std::string &message ) : std::runtime_error( message ) {} 00098 OperationFailedException( int result ) : std::runtime_error( USBDeviceManager::getResultCodeAsString( result ) ) {} 00099 }; // class OperationFailedException 00100 00101 // }}} 00102 00103 // {{{ class IllegalArgumentException declarations 00104 00105 class IllegalArgumentException : public std::invalid_argument { 00106 public: 00107 IllegalArgumentException( const std::string &message ) : std::invalid_argument( message ) {} 00108 }; // class IllegalArgumentException 00109 00110 // }}} 00111 00112 } // namespace AIOUSB 00113 00114 #endif 00115 00116 00117 /* end of file */