smartmontools  SVN Rev 4092
Utility to control and monitor storage systems with "S.M.A.R.T."
dev_tunnelled.h
Go to the documentation of this file.
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 
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:
51 };
52 
53 
54 /////////////////////////////////////////////////////////////////////////////
55 // tunnelled_device
56 
57 /// Implement a device by tunneling through another device
58 
59 template <class BaseDev, class TunnelDev>
61 : public BaseDev,
63 {
64 public:
65  typedef TunnelDev tunnel_device_type;
66 
67 protected:
68  explicit tunnelled_device(tunnel_device_type * tunnel_dev)
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;
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
virtual void release(const smart_device *dev)
Release ownership of other device.
tunnelled_device_base(smart_device *tunnel_dev)
tunnel_device_type * m_tunnel_dev
Definition: dev_tunnelled.h:89
virtual void release(const smart_device *dev)
Release ownership of other device.
Definition: dev_tunnelled.h:75
virtual bool open()
Open device, return false on error.
tunnelled_device(tunnel_device_type *tunnel_dev)
Definition: dev_tunnelled.h:68
TunnelDev tunnel_device_type
Definition: dev_tunnelled.h:65
virtual bool owns(const smart_device *dev) const
Return true if other device is owned by this device.
virtual ~tunnelled_device_base()
Implement a device by tunneling through another device.
Definition: dev_tunnelled.h:60
const tunnel_device_type * get_tunnel_dev() const
Definition: dev_tunnelled.h:85
Base class for all devices.
Definition: dev_interface.h:38
smart_device * m_tunnel_base_dev
Definition: dev_tunnelled.h:50
tunnel_device_type * get_tunnel_dev()
Definition: dev_tunnelled.h:82
virtual bool close()
Close device, return false on error.
Common functionality for all tunnelled_device classes.
Definition: dev_tunnelled.h:30
virtual bool is_open() const
Return true if device is open.