Debian Codegraph @

xbmc/storage/discs/IDiscDriveHandler.h

raw
1 /*
2 * Copyright (C) 2022 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
8
9 #pragma once
10
11 #include <memory>
12 #include <string>
13
14 /*! \brief Represents the state of a disc (optical) drive */
15 enum class DriveState
16 {
17 /*! The drive is open */
18 OPEN,
19 /*! The drive is not ready (happens when openning or closing) */
20 NOT_READY,
21 /*! The drive is ready */
22 READY,
23 /*! The drive is closed but no media could be detected in the drive */
24 CLOSED_NO_MEDIA,
25 /*! The drive is closed and there is media in the drive */
26 CLOSED_MEDIA_PRESENT,
27 /*! The system does not have an optical drive */
28 NONE,
29 /*! The drive is closed but we don't know yet if there's media there */
30 CLOSED_MEDIA_UNDEFINED
31 };
32
33 /*! \brief Represents the state of the drive tray */
34 enum class TrayState
35 {
36 /*! The tray is in an undefined state, we don't know yet */
37 UNDEFINED,
38 /*! The tray is open */
39 OPEN,
40 /*! The tray is closed and doesn't have any optical media */
41 CLOSED_NO_MEDIA,
42 /*! The tray is closed and contains optical media */
43 CLOSED_MEDIA_PRESENT
44 };
45
46 /*! \brief Generic interface for platform disc drive handling
47 */
48 class IDiscDriveHandler
49 {
50 public:
51 /*! \brief Get the optical drive state provided its device path
52 * \param devicePath the path for the device drive (e.g. /dev/sr0)
53 * \return The drive state
54 */
55 virtual DriveState GetDriveState(const std::string& devicePath) = 0;
56
57 /*! \brief Get the optical drive tray state provided the drive device path
58 * \param devicePath the path for the device drive (e.g. /dev/sr0)
59 * \return The drive state
60 */
61 virtual TrayState GetTrayState(const std::string& devicePath) = 0;
62
63 /*! \brief Eject the provided drive device
64 * \param devicePath the path for the device drive (e.g. /dev/sr0)
65 */
66 virtual void EjectDriveTray(const std::string& devicePath) = 0;
67
68 /*! \brief Close the provided drive device
69 * \note Some drives support closing appart from opening/eject
70 * \param devicePath the path for the device drive (e.g. /dev/sr0)
71 */
72 virtual void CloseDriveTray(const std::string& devicePath) = 0;
73
74 /*! \brief Toggle the state of a given drive device
75 *
76 * Will internally call EjectDriveTray or CloseDriveTray depending on
77 * the internal state of the drive (i.e. if open -> CloseDriveTray /
78 * if closed -> EjectDriveTray)
79 *
80 * \param devicePath the path for the device drive (e.g. /dev/sr0)
81 */
82 virtual void ToggleDriveTray(const std::string& devicePath) = 0;
83
84 /*! \brief Called to create platform-specific disc drive handler
85 *
86 * This method is used to create platform-specific disc drive handler
87 */
88 static std::shared_ptr<IDiscDriveHandler> CreateInstance();
89
90 protected:
91 virtual ~IDiscDriveHandler() = default;
92 IDiscDriveHandler() = default;
93 };