summaryrefslogtreecommitdiffstats
path: root/xbmc/storage/IStorageProvider.h
blob: aa9ecaf6524e508a1b61c1b09798144fc863216d (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
94
95
/*
 *  Copyright (C) 2005-2018 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 "MediaSource.h"

#include <memory>
#include <string>
#include <vector>
#ifdef HAS_DVD_DRIVE
#include "cdioSupport.h"
#endif

namespace MEDIA_DETECT
{
namespace STORAGE
{
/*! \brief Abstracts a generic storage device type*/
enum class Type
{
  UNKNOWN, /*!< the storage type is unknown */
  OPTICAL /*!< an optical device (e.g. DVD or Bluray) */
};

/*! \brief Abstracts a generic storage device */
struct StorageDevice
{
  /*! Device name/label */
  std::string label{};
  /*! Device mountpoint/path */
  std::string path{};
  /*! The storage type (e.g. OPTICAL) */
  STORAGE::Type type{STORAGE::Type::UNKNOWN};
};
} // namespace STORAGE
} // namespace MEDIA_DETECT

class IStorageEventsCallback
{
public:
  virtual ~IStorageEventsCallback() = default;

  /*! \brief Callback executed when a new storage device is added
    * @param device the storage device
    */
  virtual void OnStorageAdded(const MEDIA_DETECT::STORAGE::StorageDevice& device) = 0;

  /*! \brief Callback executed when a new storage device is safely removed
    * @param device the storage device
    */
  virtual void OnStorageSafelyRemoved(const MEDIA_DETECT::STORAGE::StorageDevice& device) = 0;

  /*! \brief Callback executed when a new storage device is unsafely removed
    * @param device the storage device
    */
  virtual void OnStorageUnsafelyRemoved(const MEDIA_DETECT::STORAGE::StorageDevice& device) = 0;
};

class IStorageProvider
{
public:
  virtual ~IStorageProvider() = default;

  virtual void Initialize() = 0;
  virtual void Stop() = 0;

  virtual void GetLocalDrives(VECSOURCES &localDrives) = 0;
  virtual void GetRemovableDrives(VECSOURCES &removableDrives) = 0;
  virtual std::string GetFirstOpticalDeviceFileName()
  {
#ifdef HAS_DVD_DRIVE
    return std::string(MEDIA_DETECT::CLibcdio::GetInstance()->GetDeviceFileName());
#else
    return "";
#endif
  }

  virtual bool Eject(const std::string& mountpath) = 0;

  virtual std::vector<std::string> GetDiskUsage() = 0;

  virtual bool PumpDriveChangeEvents(IStorageEventsCallback *callback) = 0;

  /**\brief Called by media manager to create platform storage provider
  *
  * This method used to create platform specified storage provider
  */
  static std::unique_ptr<IStorageProvider> CreateInstance();
};