Home Libraries Author Links

device.hpp

Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is the SysToMath IO C++ Libraries package (LibStmIo).
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Tom Michaelis, SysToMath.
00018  * Portions created by the Initial Developer are Copyright (C) 2006-2007
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *
00023  * Alternatively, the contents of this file may be used under the terms of
00024  * either the GNU General Public License Version 2 or later (the "GPL"), or
00025  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00026  * in which case the provisions of the GPL or the LGPL are applicable instead
00027  * of those above. If you wish to allow use of your version of this file only
00028  * under the terms of either the GPL or the LGPL, and not to allow others to
00029  * use your version of this file under the terms of the MPL, indicate your
00030  * decision by deleting the provisions above and replace them with the notice
00031  * and other provisions required by the GPL or the LGPL. If you do not delete
00032  * the provisions above, a recipient may use your version of this file under
00033  * the terms of any one of the MPL, the GPL or the LGPL.
00034  *
00035  * ***** END LICENSE BLOCK ***** */
00036 
00037 /******************************************************************************
00038  *                       First Release 2006-04-30
00039  ******************************************************************************/
00040 
00041 
00082 #ifndef STM_DEVICE_HPP
00083 #define STM_DEVICE_HPP
00084 
00085 
00086 // Include header files for implementation.
00087 #include <stm/impl/xdevice.hpp>
00088 
00089 
00298 namespace stm
00299 {
00300 
00301 
00305 
00306 
00307 struct StmDllSpec Uuid
00308 {
00310     static const size_t Size = 16;
00311 
00313     Uuid ();
00314 
00316     explicit Uuid (const unsigned char array [Size]);
00317 
00320     Uuid
00321     (
00322         unsigned long l,
00323         unsigned short w1,
00324         unsigned short w2,
00325         unsigned char b1,
00326         unsigned char b2,
00327         unsigned char b3,
00328         unsigned char b4,
00329         unsigned char b5,
00330         unsigned char b6,
00331         unsigned char b7,
00332         unsigned char b8
00333     );
00334 
00336     Uuid (const Uuid &other);
00337 
00339     Uuid &operator= (const Uuid &other);
00340 
00342     std::string string () const;
00343 
00346     bool isNull () const;
00347 
00349     bool operator== (const Uuid &other) const;
00350 
00352     bool operator!= (const Uuid &other) const;
00353 
00355     bool operator<  (const Uuid &other) const;
00356 
00358     bool operator>  (const Uuid &other) const;
00359 
00361     bool operator<= (const Uuid &other) const;
00362 
00364     bool operator>= (const Uuid &other) const;
00365 
00373     unsigned char octet [Size];
00374 };
00375 
00376 
00380 }  // namespace stm.
00381 
00382 
00383 // Include stm::Device base class implementation.
00384 #include <stm/impl/xdevice.hpp>
00385 
00386 
00387 namespace stm
00388 {
00389 
00390 
00394 
00395 
00396 
00397 
00398 class StmDllSpec Device :
00399     private local::xDevice  // Implementation DeviceImpl.
00400 {
00401 public:
00405     enum OpenMode
00406     {
00407         NoAccess        = 0x00000000,       
00408         ReadAccess      = 0x00000001,       
00409         WriteAccess     = 0x00000002,       
00410         ReadWriteAccess = ReadAccess | WriteAccess  
00411     };
00412 
00416     enum ErrorState
00417     {
00418         NoError          = 0,   
00419         ReadError        = 1,   
00420         WriteError       = 2,   
00421         ControlError     = 3,   
00422         ResourceError    = 4,   
00423         OpenError        = 5,   
00424         CloseError       = 6,   
00425         SeekError        = 7,   
00426 
00427         ArgumentError    = 8,   
00428         UnknownError     = 9    
00429     };
00430 
00432     enum ErrorFlags
00433     {
00434         ErrorFlagMask    = 0x7fff0000,   
00435 
00436         SystemError      = 0x00010000    
00437 
00438 
00439     };
00440 
00442     enum
00443     {
00444         NoFlags          = 0x00000000,   
00445         AcceptTimeout    = 0x00000001    
00446     };
00447 
00451     enum DescribeFlags
00452     {
00457         IndentMask        = 0x0000000f,
00458 
00462         IndentFirst       = IndentMask + 1,
00463 
00466         NoPropertyNames   = IndentFirst << 1,
00467 
00469         DefaultProperties = NoPropertyNames << 1,
00470 
00473         VerboseProperties = DefaultProperties << 1 | DefaultProperties,
00474 
00476         AllProperties     = ~ ((DefaultProperties << 2) - 1),
00477 
00479         DeviceType        = DefaultProperties << 2,
00480 
00482         DeviceUuid        = DeviceType << 1,
00483 
00485         DriverVersion     = DeviceUuid << 1
00486     };
00487 
00489     enum Timeout
00490     {
00491         DefaultTimeout  = -1,      
00492         Forever         = INT_MAX  
00493     };
00494 
00495     // Forward reference.
00496     struct Version;
00497 
00502     struct Descriptor : public std::pair<void *, void (*) ()>
00503     {
00506         Descriptor (void *d = NULL, void (*f) () = NULL);
00507 
00509         operator const void * () const;
00510     };
00511 
00519     Device
00520     (
00521         const Uuid &uuid = Uuid (),
00522         const std::string type = std::string (),
00523         int defaultTimeout = Forever,
00524         const Descriptor &descr = Descriptor ()
00525     );
00526 
00529     Device
00530     (
00531         int defaultTimeout,
00532         const Descriptor &descr = Descriptor ()
00533     );
00534 
00540     Device
00541     (
00542         const Uuid &uuid,
00543         const std::string type,
00544         const Version &version,
00545         int defaultTimeout = Forever,
00546         const Descriptor &descr = Descriptor ()
00547     );
00548 
00553     Device (const Device &other);
00554 
00559     Device &operator= (const Device &other);
00560 
00563     virtual ~Device ();
00564 
00568     virtual const Uuid &uuid () const;
00569 
00572     virtual void setUuid (const Uuid &uuid);
00573 
00576     const std::string &property (const std::string &name) const;
00577 
00579     void setProperty (const std::string &name, const std::string &value);
00580 
00583     bool unsetProperty (const std::string &name);
00584 
00587     bool hasProperty (const std::string &name);
00588 
00592     virtual const std::string &type () const;
00593 
00597     virtual void setType (const std::string &type);
00598 
00602     virtual Version version () const;
00603 
00607     virtual void setVersion (const Version &version);
00608 
00612     virtual int defaultTimeout () const;
00613 
00618     virtual void setDefaultTimeout (int defaultTimeout = Forever);
00619 
00630     virtual const Descriptor &descr () const;
00631 
00642     virtual void setDescr (const Descriptor &descr) = 0;
00643 
00655     virtual bool canRead () const;
00656 
00668     virtual bool canWrite () const;
00669 
00680     virtual bool canControl () const;
00681 
00694     virtual bool canSeek () const;
00695 
00704     virtual int error () const;
00705 
00727     virtual void setError (int error,
00728                            const std::string &msg = std::string ()) const;
00729 
00741     virtual void clearError () const;
00742 
00757     virtual std::string errorString (bool msgOnly = false) const;
00758 
00774     virtual void augmentErrorString
00775     (
00776         const std::string &prefix,
00777         const std::string &suffix = std::string ()
00778     ) const;
00779 
00785     virtual bool isOpen () const;
00786 
00790     virtual unsigned int openMode () const;
00791 
00800     virtual bool open (unsigned int openMode = ReadWriteAccess);
00801 
00809     virtual bool close ();
00810 
00819     virtual int64_t read (void *data, int64_t maxLen,
00820                           int timeout = DefaultTimeout,
00821                           unsigned int flags = NoFlags);
00822 
00831     virtual int64_t write (const void *data, int64_t len,
00832                            int timeout = DefaultTimeout,
00833                            unsigned int flags = NoFlags);
00834 
00846     virtual int64_t control (unsigned int request,
00847                              const void *inData, int64_t inLen,
00848                              void *outData, int64_t maxOutLen,
00849                              int timeout = DefaultTimeout,
00850                              unsigned int flags = NoFlags) const;
00851 
00857     virtual int64_t size () const;
00858 
00864     virtual int64_t pos () const;
00865 
00873     virtual bool seek (int64_t pos);
00874 
00879     virtual bool reset ();
00880 
00889     virtual std::ostream &describe
00890     (
00891         std::ostream &os,
00892         unsigned int flags = DefaultProperties
00893     ) const;
00894 
00895 private:
00904 
00907     virtual Device *proxy ();
00908 
00910     virtual const Device *proxy () const;
00912 };
00913 
00914 
00918 std::ostream &operator<< (std::ostream &os, const Device &device);
00919 
00920 
00922 struct Device::Version
00923 {
00926     enum Parts
00927     {
00928         Major = 3,  
00929         Minor = 2,  
00930         Micro = 1,  
00931         Nano  = 0   
00932     };
00933 
00935     Version ();
00936 
00939     Version (unsigned short major, unsigned minor,
00940              unsigned micro = 0, unsigned nano = 0);
00941 
00943     Version (const Version &other);
00944 
00946     Version &operator= (const Version &other);
00947 
00949     std::string string () const;
00950 
00953     bool isNull () const;
00954 
00956     bool operator== (const Version &other) const;
00957 
00959     bool operator!= (const Version &other) const;
00960 
00962     bool operator<  (const Version &other) const;
00963 
00965     bool operator>  (const Version &other) const;
00966 
00968     bool operator<= (const Version &other) const;
00969 
00971     bool operator>= (const Version &other) const;
00972 
00976     unsigned short part [4];
00977 };
00978 
00982 }  // namespace stm.
00983 
00984 
00985 // Include inline implementation.
00986 #include <stm/impl/xdevice.hpp>
00987 
00988 
00989 #endif  // STM_DEVICE_HPP

© Copyright Tom Michaelis 2002-2007

Distributed under the SysToMath Software License (See the accompanying file license.txt or a copy at www.SysToMath.com).