smartmontools  SVN Rev 4814
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://www.smartmontools.org
5  *
6  * Copyright (C) 2008 Christian Franke
7  *
8  * SPDX-License-Identifier: GPL-2.0-or-later
9  */
10 
11 #ifndef DEV_TUNNELLED_H
12 #define DEV_TUNNELLED_H
13 
14 #define DEV_TUNNELLED_H_CVSID "$Id: dev_tunnelled.h 4760 2018-08-19 18:45:53Z chrfranke $"
15 
16 #include "dev_interface.h"
17 
18 /////////////////////////////////////////////////////////////////////////////
19 // tunnelled_device_base
20 
21 /// Common functionality for all tunnelled_device classes.
22 
24 : virtual public /*implements*/ smart_device
25 {
26 protected:
27  explicit tunnelled_device_base(smart_device * tunnel_dev);
28 
29 public:
30  virtual ~tunnelled_device_base() throw();
31 
32  virtual bool is_open() const;
33 
34  virtual bool open();
35 
36  virtual bool close();
37 
38  virtual bool owns(const smart_device * dev) const;
39 
40  virtual void release(const smart_device * dev);
41 
42 private:
44 };
45 
46 
47 /////////////////////////////////////////////////////////////////////////////
48 // tunnelled_device
49 
50 /// Implement a device by tunneling through another device
51 
52 template <class BaseDev, class TunnelDev>
54 : public BaseDev,
56 {
57 public:
58  typedef TunnelDev tunnel_device_type;
59 
60 protected:
61  explicit tunnelled_device(tunnel_device_type * tunnel_dev)
63  tunnelled_device_base(tunnel_dev),
64  m_tunnel_dev(tunnel_dev)
65  { }
66 
67 public:
68  virtual void release(const smart_device * dev)
69  {
70  if (m_tunnel_dev == dev)
71  m_tunnel_dev = 0;
73  }
74 
75  tunnel_device_type * get_tunnel_dev()
76  { return m_tunnel_dev; }
77 
78  const tunnel_device_type * get_tunnel_dev() const
79  { return m_tunnel_dev; }
80 
81 private:
82  tunnel_device_type * m_tunnel_dev;
83 };
84 
85 #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:82
virtual void release(const smart_device *dev)
Release ownership of other device.
Definition: dev_tunnelled.h:68
virtual bool open()
Open device, return false on error.
tunnelled_device(tunnel_device_type *tunnel_dev)
Definition: dev_tunnelled.h:61
TunnelDev tunnel_device_type
Definition: dev_tunnelled.h:58
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:53
const tunnel_device_type * get_tunnel_dev() const
Definition: dev_tunnelled.h:78
Base class for all devices.
Definition: dev_interface.h:32
smart_device * m_tunnel_base_dev
Definition: dev_tunnelled.h:43
tunnel_device_type * get_tunnel_dev()
Definition: dev_tunnelled.h:75
virtual bool close()
Close device, return false on error.
Common functionality for all tunnelled_device classes.
Definition: dev_tunnelled.h:23
virtual bool is_open() const
Return true if device is open.