]> git.proxmox.com Git - mirror_smartmontools-debian.git/blame - dev_tunnelled.h
import smartmontools 7.0
[mirror_smartmontools-debian.git] / dev_tunnelled.h
CommitLineData
2127e193
GI
1/*
2 * dev_tunnelled.h
3 *
a86ec89e 4 * Home page of code is: http://www.smartmontools.org
2127e193 5 *
f9e10201 6 * Copyright (C) 2008 Christian Franke
2127e193 7 *
ff28b140 8 * SPDX-License-Identifier: GPL-2.0-or-later
2127e193
GI
9 */
10
11#ifndef DEV_TUNNELLED_H
12#define DEV_TUNNELLED_H
13
ff28b140 14#define DEV_TUNNELLED_H_CVSID "$Id: dev_tunnelled.h 4848 2018-12-05 18:30:46Z chrfranke $"
2127e193
GI
15
16#include "dev_interface.h"
17
18/////////////////////////////////////////////////////////////////////////////
19// tunnelled_device_base
20
21/// Common functionality for all tunnelled_device classes.
22
23class tunnelled_device_base
24: virtual public /*implements*/ smart_device
25{
26protected:
27 explicit tunnelled_device_base(smart_device * tunnel_dev);
28
29public:
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
42private:
43 smart_device * m_tunnel_base_dev;
44};
45
46
47/////////////////////////////////////////////////////////////////////////////
48// tunnelled_device
49
50/// Implement a device by tunneling through another device
51
52template <class BaseDev, class TunnelDev>
53class tunnelled_device
54: public BaseDev,
55 public tunnelled_device_base
56{
57public:
58 typedef TunnelDev tunnel_device_type;
59
60protected:
61 explicit tunnelled_device(tunnel_device_type * tunnel_dev)
62 : smart_device(smart_device::never_called),
63 tunnelled_device_base(tunnel_dev),
64 m_tunnel_dev(tunnel_dev)
65 { }
66
ff28b140
TL
67 // For nvme_device
68 explicit tunnelled_device(tunnel_device_type * tunnel_dev, unsigned nsid)
69 : smart_device(smart_device::never_called),
70 BaseDev(nsid),
71 tunnelled_device_base(tunnel_dev),
72 m_tunnel_dev(tunnel_dev)
73 { }
74
2127e193
GI
75public:
76 virtual void release(const smart_device * dev)
77 {
78 if (m_tunnel_dev == dev)
79 m_tunnel_dev = 0;
80 tunnelled_device_base::release(dev);
81 }
82
83 tunnel_device_type * get_tunnel_dev()
84 { return m_tunnel_dev; }
85
86 const tunnel_device_type * get_tunnel_dev() const
87 { return m_tunnel_dev; }
88
89private:
90 tunnel_device_type * m_tunnel_dev;
91};
92
93#endif // DEV_TUNNELLED_H