Ocean
media/Library.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_MEDIA_LIBRARY_H
9 #define META_OCEAN_MEDIA_LIBRARY_H
10 
11 #include "ocean/media/Media.h"
12 #include "ocean/media/MediumRef.h"
13 #include "ocean/media/Recorder.h"
14 
15 #include <set>
16 #include <string>
17 
18 namespace Ocean
19 {
20 
21 namespace Media
22 {
23 
24 // Forward declaration.
25 class Library;
26 
27 /**
28  * Definition of a object reference holding a library object.
29  * @see ObjectRef, Library.
30  * @ingroup media
31  */
33 
34 /**
35  * This class is the base class for all media libraries.
36  * Any derived library providing individual types of media objects must implement a library class which must be registered at the Manager object of the base media library.<br>
37  * A derived library may implement only one type of media object, all types of media objects or a subset of the media objects.
38  * @see Manager.
39  * @ingroup media
40  */
41 class OCEAN_MEDIA_EXPORT Library
42 {
43  friend class Manager;
44  friend class ObjectRef<Library>;
45 
46  public:
47 
48  /**
49  * Class combining the url, type, library of a medium, and a unique identifier.
50  */
51  class Definition
52  {
53  public:
54 
55  /**
56  * Default constructor.
57  */
58  Definition() = default;
59 
60  /**
61  * Creates a new definition object.
62  * @param url The URL of the medium
63  * @param type The type of the medium
64  * @param library The name of the library to which the medium belongs
65  * @param uniqueIdentifier Optional unique identifier of the medium (e.g., in case the medium is a USB device).
66  */
67  inline Definition(std::string url, const Medium::Type type, std::string library, std::string uniqueIdentifier = std::string());
68 
69  /**
70  * Returns the URL of the medium definition.
71  * @retrn The medium's URL
72  */
73  inline const std::string& url() const;
74 
75  /**
76  * Returns the type of the medium.
77  * @return The medium's type
78  */
79  inline Medium::Type type() const;
80 
81  /**
82  * Returns the name of the library to which the medium belongs.
83  * @return The medium's library
84  */
85  inline const std::string& library() const;
86 
87  /**
88  * Returns the optional unique identifier of the medium.
89  * @return The medium's unique identifier, empty if unknown
90  */
91  inline const std::string& uniqueIdentifier() const;
92 
93  protected:
94 
95  /// Url of the medium.
96  std::string url_;
97 
98  /// Type of the medium.
100 
101  /// Name of the library.
102  std::string library_;
103 
104  /// Optional unique identifier of the medium, e.g., a device name or a serial number.
105  std::string uniqueIdentifier_;
106  };
107 
108  /**
109  * Definition of a vector holding medium definition objects.
110  */
111  typedef std::vector<Definition> Definitions;
112 
113  protected:
114 
115  /**
116  * Definition of a set holding file extensions.
117  */
118  typedef std::set<std::string> ExtensionSet;
119 
120  public:
121 
122  /**
123  * Returns the name of the library.
124  * @return Library name
125  */
126  inline const std::string& name() const;
127 
128  /**
129  * Creates a new medium by a given url.
130  * @param url Url to create the medium from
131  * @param useExclusive Determines whether the caller would like to use this medium exclusively
132  * @return Reference to the medium
133  */
134  virtual MediumRef newMedium(const std::string& url, bool useExclusive = false) = 0;
135 
136  /**
137  * Creates a new medium by a given url and an expected type.
138  * If no medium can be created an empty reference is returned.
139  * @param url Url of the medium
140  * @param type The type of the expected medium
141  * @param useExclusive Determines whether the caller would like to use this medium exclusively
142  * @return Reference to the new medium
143  */
144  virtual MediumRef newMedium(const std::string& url, const Medium::Type type, bool useExclusive = false) = 0;
145 
146  /**
147  * Creates a new recorder specified by the recorder type.
148  * @param type The type of the recorder to return
149  * @return Reference to the new recorder
150  */
151  virtual RecorderRef newRecorder(const Recorder::Type type) = 0;
152 
153  /**
154  * Returns a list of selectable mediums.
155  * @return Selectable mediums
156  */
157  virtual Definitions selectableMedia() const;
158 
159  /**
160  * Returns a list of specific selectable mediums.
161  * @param type The type of the selectable mediums
162  * @return Selectable mediums
163  */
164  virtual Definitions selectableMedia(const Medium::Type type) const;
165 
166  /**
167  * Returns whether the library supports a given medium type.
168  * @param type Medium type to check
169  * @return True, if so
170  */
171  bool supports(const Medium::Type type) const;
172 
173  /**
174  * Returns the supported medium types.
175  * @return Supported medium types
176  */
177  virtual Medium::Type supportedTypes() const;
178 
179  /**
180  * Returns whether a given file extension is not supported by this library.
181  * @param extension File extension to check with lower case
182  * @return True, if so
183  */
184  bool notSupported(const std::string& extension) const;
185 
186  /**
187  * Converts a medium definition to one string.
188  * @param definition Medium definition to convert
189  * @return String of the definition
190  */
191  static std::string convertDefinition(const Definition& definition);
192 
193  /**
194  * Converts a string to a medium definition.
195  * @param string The string of the medium definition
196  * @return Medium definition
197  */
198  static Definition convertDefinition(const std::string& string);
199 
200  protected:
201 
202  /**
203  * Disabled copy constructor.
204  * @param library Object which would be copied
205  */
206  Library(const Library& library) = delete;
207 
208  /**
209  * Creates a new Library object.
210  * @param name The name of the library
211  * @param priority The priority of this library, libraries with higher priority will be privileged compared to libraries with lower priority
212  */
213  Library(const std::string& name, const unsigned int priority);
214 
215  /**
216  * Destructs a library.
217  */
218  virtual ~Library();
219 
220  /**
221  * Returns the priority of this library.
222  * @return Library priority
223  */
224  inline unsigned int priority() const;
225 
226  /**
227  * Registers file extensions not supported by this library.
228  * @param extension Not supported file extension
229  */
230  void registerNotSupportedExtension(const std::string& extension);
231 
232  /**
233  * Disabled copy operator.
234  * @param library Object which would be copied
235  * @return Reference to this object
236  */
237  Library& operator=(const Library& library) = delete;
238 
239  protected:
240 
241  /// The name of the library.
242  std::string libraryName;
243 
244  /// Priority of this library, the higher the value, the higher the priority.
245  unsigned int libraryPriority;
246 
247  /// Library lock.
248  mutable Lock lock;
249 
250  private:
251 
252  /// Set holding file extensions which are not supported by this library.
254 };
255 
256 inline Library::Definition::Definition(std::string url, const Medium::Type type, std::string library, std::string uniqueIdentifier) :
257  url_(std::move(url)),
258  type_(type),
259  library_(library),
260  uniqueIdentifier_(std::move(uniqueIdentifier))
261 {
262  // nothing to do here
263 }
264 
265 inline const std::string& Library::Definition::url() const
266 {
267  return url_;
268 }
269 
271 {
272  return type_;
273 }
274 
275 inline const std::string& Library::Definition::library() const
276 {
277  return library_;
278 }
279 
280 inline const std::string& Library::Definition::uniqueIdentifier() const
281 {
282  return uniqueIdentifier_;
283 }
284 
285 inline const std::string& Library::name() const
286 {
287  return libraryName;
288 }
289 
290 inline unsigned int Library::priority() const
291 {
292  return libraryPriority;
293 }
294 
295 }
296 
297 }
298 
299 #endif // META_OCEAN_MEDIA_LIBRARY_H
This class implements a recursive lock object.
Definition: Lock.h:31
Class combining the url, type, library of a medium, and a unique identifier.
Definition: media/Library.h:52
std::string uniqueIdentifier_
Optional unique identifier of the medium, e.g., a device name or a serial number.
Definition: media/Library.h:105
std::string url_
Url of the medium.
Definition: media/Library.h:96
Definition()=default
Default constructor.
Medium::Type type() const
Returns the type of the medium.
Definition: media/Library.h:270
const std::string & library() const
Returns the name of the library to which the medium belongs.
Definition: media/Library.h:275
std::string library_
Name of the library.
Definition: media/Library.h:102
const std::string & url() const
Returns the URL of the medium definition.
Definition: media/Library.h:265
const std::string & uniqueIdentifier() const
Returns the optional unique identifier of the medium.
Definition: media/Library.h:280
This class is the base class for all media libraries.
Definition: media/Library.h:42
virtual ~Library()
Destructs a library.
Library(const std::string &name, const unsigned int priority)
Creates a new Library object.
unsigned int priority() const
Returns the priority of this library.
Definition: media/Library.h:290
void registerNotSupportedExtension(const std::string &extension)
Registers file extensions not supported by this library.
static std::string convertDefinition(const Definition &definition)
Converts a medium definition to one string.
bool supports(const Medium::Type type) const
Returns whether the library supports a given medium type.
bool notSupported(const std::string &extension) const
Returns whether a given file extension is not supported by this library.
virtual Definitions selectableMedia() const
Returns a list of selectable mediums.
Lock lock
Library lock.
Definition: media/Library.h:248
virtual MediumRef newMedium(const std::string &url, const Medium::Type type, bool useExclusive=false)=0
Creates a new medium by a given url and an expected type.
std::set< std::string > ExtensionSet
Definition of a set holding file extensions.
Definition: media/Library.h:118
virtual RecorderRef newRecorder(const Recorder::Type type)=0
Creates a new recorder specified by the recorder type.
virtual Definitions selectableMedia(const Medium::Type type) const
Returns a list of specific selectable mediums.
const std::string & name() const
Returns the name of the library.
Definition: media/Library.h:285
unsigned int libraryPriority
Priority of this library, the higher the value, the higher the priority.
Definition: media/Library.h:245
std::string libraryName
The name of the library.
Definition: media/Library.h:242
Library & operator=(const Library &library)=delete
Disabled copy operator.
virtual Medium::Type supportedTypes() const
Returns the supported medium types.
Library(const Library &library)=delete
Disabled copy constructor.
std::vector< Definition > Definitions
Definition of a vector holding medium definition objects.
Definition: media/Library.h:111
virtual MediumRef newMedium(const std::string &url, bool useExclusive=false)=0
Creates a new medium by a given url.
ExtensionSet notSupportedExtensionSet
Set holding file extensions which are not supported by this library.
Definition: media/Library.h:253
static Definition convertDefinition(const std::string &string)
Converts a string to a medium definition.
This class is the manager for all media objects.
Definition: media/Manager.h:34
Type
Definition of different medium types.
Definition: Medium.h:57
@ MEDIUM
Simple medium.
Definition: Medium.h:59
Type
Definition of different recorder types.
Definition: Recorder.h:46
This template class implements a object reference with an internal reference counter.
Definition: base/ObjectRef.h:58
ObjectRef< Library > LibraryRef
Definition of a object reference holding a library object.
Definition: media/Library.h:25
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15