smartmontools SVN Rev 5640
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: https://www.smartmontools.org
5 *
6 * Copyright (C) 2008-21 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 5198 2021-02-01 20:36:02Z 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{
26protected:
27 explicit tunnelled_device_base(smart_device * tunnel_dev);
28
29public:
30 virtual ~tunnelled_device_base();
31
32 virtual bool is_open() const override;
33
34 virtual bool open() override;
35
36 virtual bool close() override;
37
38 virtual bool owns(const smart_device * dev) const override;
39
40 virtual void release(const smart_device * dev) override;
41
42private:
44};
45
46
47/////////////////////////////////////////////////////////////////////////////
48// tunnelled_device
49
50/// Implement a device by tunneling through another device
51
52template <class BaseDev, class TunnelDev>
54: public BaseDev,
56{
57public:
58 typedef TunnelDev tunnel_device_type;
59
60protected:
61 explicit tunnelled_device(tunnel_device_type * tunnel_dev)
63 tunnelled_device_base(tunnel_dev),
64 m_tunnel_dev(tunnel_dev)
65 { }
66
67 // For nvme_device
68 explicit tunnelled_device(tunnel_device_type * tunnel_dev, unsigned nsid)
71 tunnelled_device_base(tunnel_dev),
72 m_tunnel_dev(tunnel_dev)
73 { }
74
75public:
76 virtual void release(const smart_device * dev) override
77 {
78 if (m_tunnel_dev == dev)
79 m_tunnel_dev = 0;
81 }
82
84 { return m_tunnel_dev; }
85
87 { return m_tunnel_dev; }
88
89private:
91};
92
93#endif // DEV_TUNNELLED_H
Base class for all devices.
Definition: dev_interface.h:33
Common functionality for all tunnelled_device classes.
Definition: dev_tunnelled.h:25
virtual bool open() override
Open device, return false on error.
virtual bool owns(const smart_device *dev) const override
Return true if other device is owned by this device.
virtual void release(const smart_device *dev) override
Release ownership of other device.
smart_device * m_tunnel_base_dev
Definition: dev_tunnelled.h:43
virtual ~tunnelled_device_base()
virtual bool is_open() const override
Return true if device is open.
virtual bool close() override
Close device, return false on error.
Implement a device by tunneling through another device.
Definition: dev_tunnelled.h:56
const tunnel_device_type * get_tunnel_dev() const
Definition: dev_tunnelled.h:86
tunnelled_device(tunnel_device_type *tunnel_dev)
Definition: dev_tunnelled.h:61
tunnelled_device(tunnel_device_type *tunnel_dev, unsigned nsid)
Definition: dev_tunnelled.h:68
virtual void release(const smart_device *dev) override
Release ownership of other device.
Definition: dev_tunnelled.h:76
TunnelDev tunnel_device_type
Definition: dev_tunnelled.h:58
tunnel_device_type * get_tunnel_dev()
Definition: dev_tunnelled.h:83
tunnel_device_type * m_tunnel_dev
Definition: dev_tunnelled.h:90
uint32_t nsid