smartmontools SVN Rev 3317
Utility to control and monitor storage systems with "S.M.A.R.T."
dev_tunnelled.h
Go to the documentation of this file.
00001 /*
00002  * dev_tunnelled.h
00003  *
00004  * Home page of code is: http://smartmontools.sourceforge.net
00005  *
00006  * Copyright (C) 2008 Christian Franke <smartmontools-support@lists.sourceforge.net>
00007  *
00008  * This program 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, or (at your option)
00011  * any later version.
00012  *
00013  * You should have received a copy of the GNU General Public License
00014  * (for example COPYING); If not, see <http://www.gnu.org/licenses/>.
00015  *
00016  */
00017 
00018 #ifndef DEV_TUNNELLED_H
00019 #define DEV_TUNNELLED_H
00020 
00021 #define DEV_TUNNELLED_H_CVSID "$Id: dev_tunnelled.h,v 1.1 2008/07/25 21:16:00 chrfranke Exp $\n"
00022 
00023 #include "dev_interface.h"
00024 
00025 /////////////////////////////////////////////////////////////////////////////
00026 // tunnelled_device_base
00027 
00028 /// Common functionality for all tunnelled_device classes.
00029 
00030 class tunnelled_device_base
00031 : virtual public /*implements*/ smart_device
00032 {
00033 protected:
00034   explicit tunnelled_device_base(smart_device * tunnel_dev);
00035 
00036 public:
00037   virtual ~tunnelled_device_base() throw();
00038 
00039   virtual bool is_open() const;
00040 
00041   virtual bool open();
00042 
00043   virtual bool close();
00044 
00045   virtual bool owns(const smart_device * dev) const;
00046 
00047   virtual void release(const smart_device * dev);
00048 
00049 private:
00050   smart_device * m_tunnel_base_dev;
00051 };
00052 
00053 
00054 /////////////////////////////////////////////////////////////////////////////
00055 // tunnelled_device
00056 
00057 /// Implement a device by tunneling through another device
00058 
00059 template <class BaseDev, class TunnelDev>
00060 class tunnelled_device
00061 : public BaseDev,
00062   public tunnelled_device_base
00063 {
00064 public:
00065   typedef TunnelDev tunnel_device_type;
00066 
00067 protected:
00068   explicit tunnelled_device(tunnel_device_type * tunnel_dev)
00069     : smart_device(smart_device::never_called),
00070       tunnelled_device_base(tunnel_dev),
00071       m_tunnel_dev(tunnel_dev)
00072     { }
00073 
00074 public:
00075   virtual void release(const smart_device * dev)
00076     {
00077       if (m_tunnel_dev == dev)
00078         m_tunnel_dev = 0;
00079       tunnelled_device_base::release(dev);
00080     }
00081 
00082   tunnel_device_type * get_tunnel_dev()
00083     { return m_tunnel_dev; }
00084 
00085   const tunnel_device_type * get_tunnel_dev() const
00086     { return m_tunnel_dev; }
00087 
00088 private:
00089   tunnel_device_type * m_tunnel_dev;
00090 };
00091 
00092 #endif // DEV_TUNNELLED_H