summaryrefslogtreecommitdiffstats
path: root/xbmc/storage/discs/IDiscDriveHandler.h
blob: a3b007a95e98ffd536ca74d5edf65f4d72e799d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
 *  Copyright (C) 2022 Team Kodi
 *  This file is part of Kodi - https://kodi.tv
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 *  See LICENSES/README.md for more information.
 */

#pragma once

#include <memory>
#include <string>

/*! \brief Represents the state of a disc (optical) drive */
enum class DriveState
{
  /*! The drive is open */
  OPEN,
  /*! The drive is not ready (happens when openning or closing) */
  NOT_READY,
  /*! The drive is ready */
  READY,
  /*! The drive is closed but no media could be detected in the drive */
  CLOSED_NO_MEDIA,
  /*! The drive is closed and there is media in the drive */
  CLOSED_MEDIA_PRESENT,
  /*! The system does not have an optical drive */
  NONE,
  /*! The drive is closed but we don't know yet if there's media there */
  CLOSED_MEDIA_UNDEFINED
};

/*! \brief Represents the state of the drive tray */
enum class TrayState
{
  /*!  The tray is in an undefined state, we don't know yet */
  UNDEFINED,
  /*!  The tray is open */
  OPEN,
  /*! The tray is closed and doesn't have any optical media */
  CLOSED_NO_MEDIA,
  /*! The tray is closed and contains optical media */
  CLOSED_MEDIA_PRESENT
};

/*! \brief Generic interface for platform disc drive handling
*/
class IDiscDriveHandler
{
public:
  /*! \brief Get the optical drive state provided its device path
  * \param devicePath the path for the device drive (e.g. /dev/sr0)
  * \return The drive state
  */
  virtual DriveState GetDriveState(const std::string& devicePath) = 0;

  /*! \brief Get the optical drive tray state provided the drive device path
  * \param devicePath the path for the device drive (e.g. /dev/sr0)
  * \return The drive state
  */
  virtual TrayState GetTrayState(const std::string& devicePath) = 0;

  /*! \brief Eject the provided drive device
  * \param devicePath the path for the device drive (e.g. /dev/sr0)
  */
  virtual void EjectDriveTray(const std::string& devicePath) = 0;

  /*! \brief Close the provided drive device
  * \note Some drives support closing appart from opening/eject
  * \param devicePath the path for the device drive (e.g. /dev/sr0)
  */
  virtual void CloseDriveTray(const std::string& devicePath) = 0;

  /*! \brief Toggle the state of a given drive device
  *
  * Will internally call EjectDriveTray or CloseDriveTray depending on
  * the internal state of the drive (i.e. if open -> CloseDriveTray /
  * if closed -> EjectDriveTray)
  *
  * \param devicePath the path for the device drive (e.g. /dev/sr0)
  */
  virtual void ToggleDriveTray(const std::string& devicePath) = 0;

  /*! \brief Called to create platform-specific disc drive handler
  *
  * This method is used to create platform-specific disc drive handler
  */
  static std::shared_ptr<IDiscDriveHandler> CreateInstance();

protected:
  virtual ~IDiscDriveHandler() = default;
  IDiscDriveHandler() = default;
};