RulbusDevice.h

00001 /*
00002  * RulbusDevice.h - class RulbusDevice.
00003  *
00004  * This file is part of the Rulbus Device Class Library (RDCL).
00005  *
00006  * Copyright (C) 2003-2004, Leiden University.
00007  *
00008  * This library is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * The library is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with mngdriver; if not, write to the Free Software
00020  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  *
00022  * $Id: RulbusDevice.h 2 2004-10-12 11:54:15Z moene $
00023  */
00024 
00025 #ifndef __RULBUSDEVICE_H
00026 #define __RULBUSDEVICE_H
00027 
00028 #ifndef __COMMON_H
00029    #include "Common.h"
00030 #endif
00031 
00032 #include <iosfwd>               // for std::ostream
00033 
00034 namespace Rulbus
00035 {
00036    DECLARE_CLASS( RulbusDevice );
00037    DECLARE_CLASS( TheRulbusInterface );
00038 
00039    /* - <em>provide %Rulbus Interface creation</em> -- the class provides
00040     * methods createInterface() and destroyInterface() to create and destroy
00041     * the proper %Rulbus Interface; to this end it uses the
00042     * RulbusInterfaceFactory Singleton(127)
00043     */
00044 
00067    class RulbusDevice
00068    {
00069    public:                                         // P U B L I C
00072 
00073       RulbusDevice( Name aName, Addr aAddr, Addr aWidth, Rack aRack );
00074 //      RulbusDevice( Name aName = "(empty)", Addr aAddr = 0xFF, Addr aWidth = 0, Rack aRack = 0 );
00075 
00076       virtual ~RulbusDevice();
00077 
00081 
00082       Name          name () const;
00083       Rack          rack () const;
00084       Addr          addr () const;
00085       Addr          width() const;
00086 
00090 
00091       bool          eqRack( RulbusDeviceCref rhs ) const;
00092       bool          eqAddr( RulbusDeviceCref rhs ) const;
00093 
00097 
00098       void          setRack( Rack aRack );
00099       void          setAddr( Addr aAddr );
00100 
00104 
00105       virtual int   printOn( std::ostream& stream ) const;
00106 
00110 
00111       int           getByte( int offset           ) const;
00112       int           putByte( int offset, int byte ) const;
00113 
00115 
00116 /*
00117       static  void  createInterface();
00118       static  void  destroyInterface();
00119       static  int   printInterface();
00120 */
00121 
00122    protected:                                           // P R O T E C T E D
00125 
00126       RulbusDevice( );                                  
00127       RulbusDevice( RulbusDeviceCref );                 
00128       RulbusDeviceRef operator= ( RulbusDeviceCref );   
00129 
00133 
00134       void   checkValidAddress( int offset = 0       ) const;
00135       void   checkBusViolation( int offset, int byte ) const;
00136 
00140 
00141       static TheRulbusInterfaceRef theRulbus();
00142 
00144 
00145    public:
00146       static const int ANY_RACK = 0xF;          
00147       static const int DEF_RACK = ANY_RACK;     
00148 
00149 
00150    private:                                     // P R I V A T E
00151       Name   theName;                           
00152       Rack   theRack;                           
00153       Addr   theAddr;                           
00154       Addr   theWidth;                          
00155 
00156 //      static RulbusInterfaceCptr theInterface;  ///< the %Rulbus Interface implementation
00157    };
00158 
00163    inline Name RulbusDevice::name() const
00164    {
00165       return theName;
00166    }
00167 
00172    inline Rack RulbusDevice::rack() const
00173    {
00174       return theRack;
00175    }
00176 
00181    inline Addr RulbusDevice::addr() const
00182    {
00183       return theAddr;
00184    }
00185 
00190    inline Addr RulbusDevice::width() const
00191    {
00192       return theWidth;
00193    }
00194 
00199    inline bool RulbusDevice::eqRack( RulbusDeviceCref rhs ) const
00200    {
00201       return rack() == ANY_RACK || rhs.rack() == ANY_RACK || rack() == rhs.rack();
00202    }
00203 
00208    inline bool RulbusDevice::eqAddr( RulbusDeviceCref rhs ) const
00209    {
00210       return         eqRack( rhs )
00211       && (         addr() == rhs.addr()
00212           || (     addr() <  rhs.addr() &&     addr() +     width() > rhs.addr() )
00213           || ( rhs.addr() <      addr() && rhs.addr() + rhs.width() >     addr() ) );
00214    }
00215 
00220    inline RulbusDeviceRef to_rb( RulbusDevicePtr p )
00221    {
00222       return PROXY_CAST<RulbusDeviceRef>( *p );
00223    }
00224 
00229    inline RulbusDevicePtr to_rb_ptr( RulbusDevicePtr p )
00230    {
00231       return PROXY_CAST<RulbusDevicePtr>( p );
00232    }
00233 
00234 }       // namespace Rulbus
00235 
00236 /*------------------------------------------------------------------------
00237  * convenience functions
00238  *------------------------------------------------------------------------
00239  */
00240 
00241 inline std::ostream& operator<< ( std::ostream& stream, const Rulbus::RulbusDevice& aDevice )
00242 {
00243    aDevice.printOn( stream );
00244    return stream;
00245 }
00246 
00247 inline std::ostream& operator<< ( std::ostream& stream, Rulbus::RulbusDeviceCptr aDevicePtr )
00248 {
00249    aDevicePtr->printOn( stream );
00250    return stream;
00251 }
00252 
00253 #endif  // __RULBUSDEVICE_H
00254 
00255 /*
00256  * end of file
00257  */

Generated on Tue Oct 12 14:11:58 2004 for Rulbus Device Class Library for Microsoft Windows by doxygen 1.3.4