4 * Home page of code is: http://www.smartmontools.org
6 * Copyright (C) 2008 Christian Franke
8 * SPDX-License-Identifier: GPL-2.0-or-later
11 #ifndef DEV_TUNNELLED_H
12 #define DEV_TUNNELLED_H
14 #define DEV_TUNNELLED_H_CVSID "$Id: dev_tunnelled.h 4848 2018-12-05 18:30:46Z chrfranke $"
16 #include "dev_interface.h"
18 /////////////////////////////////////////////////////////////////////////////
19 // tunnelled_device_base
21 /// Common functionality for all tunnelled_device classes.
23 class tunnelled_device_base
24 : virtual public /*implements*/ smart_device
27 explicit tunnelled_device_base(smart_device
* tunnel_dev
);
30 virtual ~tunnelled_device_base() throw();
32 virtual bool is_open() const;
38 virtual bool owns(const smart_device
* dev
) const;
40 virtual void release(const smart_device
* dev
);
43 smart_device
* m_tunnel_base_dev
;
47 /////////////////////////////////////////////////////////////////////////////
50 /// Implement a device by tunneling through another device
52 template <class BaseDev
, class TunnelDev
>
53 class tunnelled_device
55 public tunnelled_device_base
58 typedef TunnelDev tunnel_device_type
;
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
)
68 explicit tunnelled_device(tunnel_device_type
* tunnel_dev
, unsigned nsid
)
69 : smart_device(smart_device::never_called
),
71 tunnelled_device_base(tunnel_dev
),
72 m_tunnel_dev(tunnel_dev
)
76 virtual void release(const smart_device
* dev
)
78 if (m_tunnel_dev
== dev
)
80 tunnelled_device_base::release(dev
);
83 tunnel_device_type
* get_tunnel_dev()
84 { return m_tunnel_dev
; }
86 const tunnel_device_type
* get_tunnel_dev() const
87 { return m_tunnel_dev
; }
90 tunnel_device_type
* m_tunnel_dev
;
93 #endif // DEV_TUNNELLED_H