Annotation of embedaddon/smartmontools/dev_tunnelled.h, revision 1.1.1.1

1.1       misho       1: /*
                      2:  * dev_tunnelled.h
                      3:  *
                      4:  * Home page of code is: http://smartmontools.sourceforge.net
                      5:  *
                      6:  * Copyright (C) 2008 Christian Franke <smartmontools-support@lists.sourceforge.net>
                      7:  *
                      8:  * This program is free software; you can redistribute it and/or modify
                      9:  * it under the terms of the GNU General Public License as published by
                     10:  * the Free Software Foundation; either version 2, or (at your option)
                     11:  * any later version.
                     12:  *
                     13:  * You should have received a copy of the GNU General Public License
                     14:  * (for example COPYING); If not, see <http://www.gnu.org/licenses/>.
                     15:  *
                     16:  */
                     17: 
                     18: #ifndef DEV_TUNNELLED_H
                     19: #define DEV_TUNNELLED_H
                     20: 
                     21: #define DEV_TUNNELLED_H_CVSID "$Id: dev_tunnelled.h,v 1.1 2008/07/25 21:16:00 chrfranke Exp $\n"
                     22: 
                     23: #include "dev_interface.h"
                     24: 
                     25: /////////////////////////////////////////////////////////////////////////////
                     26: // tunnelled_device_base
                     27: 
                     28: /// Common functionality for all tunnelled_device classes.
                     29: 
                     30: class tunnelled_device_base
                     31: : virtual public /*implements*/ smart_device
                     32: {
                     33: protected:
                     34:   explicit tunnelled_device_base(smart_device * tunnel_dev);
                     35: 
                     36: public:
                     37:   virtual ~tunnelled_device_base() throw();
                     38: 
                     39:   virtual bool is_open() const;
                     40: 
                     41:   virtual bool open();
                     42: 
                     43:   virtual bool close();
                     44: 
                     45:   virtual bool owns(const smart_device * dev) const;
                     46: 
                     47:   virtual void release(const smart_device * dev);
                     48: 
                     49: private:
                     50:   smart_device * m_tunnel_base_dev;
                     51: };
                     52: 
                     53: 
                     54: /////////////////////////////////////////////////////////////////////////////
                     55: // tunnelled_device
                     56: 
                     57: /// Implement a device by tunneling through another device
                     58: 
                     59: template <class BaseDev, class TunnelDev>
                     60: class tunnelled_device
                     61: : public BaseDev,
                     62:   public tunnelled_device_base
                     63: {
                     64: public:
                     65:   typedef TunnelDev tunnel_device_type;
                     66: 
                     67: protected:
                     68:   explicit tunnelled_device(tunnel_device_type * tunnel_dev)
                     69:     : smart_device(smart_device::never_called),
                     70:       tunnelled_device_base(tunnel_dev),
                     71:       m_tunnel_dev(tunnel_dev)
                     72:     { }
                     73: 
                     74: public:
                     75:   virtual void release(const smart_device * dev)
                     76:     {
                     77:       if (m_tunnel_dev == dev)
                     78:         m_tunnel_dev = 0;
                     79:       tunnelled_device_base::release(dev);
                     80:     }
                     81: 
                     82:   tunnel_device_type * get_tunnel_dev()
                     83:     { return m_tunnel_dev; }
                     84: 
                     85:   const tunnel_device_type * get_tunnel_dev() const
                     86:     { return m_tunnel_dev; }
                     87: 
                     88: private:
                     89:   tunnel_device_type * m_tunnel_dev;
                     90: };
                     91: 
                     92: #endif // DEV_TUNNELLED_H

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>