Overte C++ Documentation
HFMFormatRegistry.h
1 //
2 // HFMFormatRegistry.h
3 // libraries/hfm/src/hfm
4 //
5 // Created by Sabrina Shanman on 2018/11/28.
6 // Copyright 2018 High Fidelity, Inc.
7 //
8 // Distributed under the Apache License, Version 2.0.
9 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10 //
11 
12 #ifndef hifi_HFMFormatRegistry_h
13 #define hifi_HFMFormatRegistry_h
14 
15 #include "HFMSerializer.h"
16 #include <shared/MediaTypeLibrary.h>
17 #include <shared/ReadWriteLockable.h>
18 
19 namespace hfm {
20 
21 class FormatRegistry {
22 public:
23  using MediaTypeID = MediaTypeLibrary::ID;
24  static const MediaTypeID INVALID_MEDIA_TYPE_ID { MediaTypeLibrary::INVALID_ID };
25 
26  MediaTypeID registerMediaType(const MediaType& mediaType, std::unique_ptr<Serializer::Factory> supportedFactory);
27  void unregisterMediaType(const MediaTypeID& id);
28 
29  std::shared_ptr<Serializer> getSerializerForMediaType(const hifi::ByteArray& data, const hifi::URL& url, const std::string& webMediaType) const;
30 
31 protected:
32  std::shared_ptr<Serializer> getSerializerForMediaTypeID(MediaTypeID id) const;
33 
34  MediaTypeLibrary _mediaTypeLibrary;
35  std::mutex _libraryLock;
36  class SupportedFormat {
37  public:
38  SupportedFormat(const MediaTypeID& mediaTypeID, std::unique_ptr<Serializer::Factory>& factory) :
39  mediaTypeID(mediaTypeID),
40  factory(std::move(factory)) {
41  }
42  MediaTypeID mediaTypeID;
43  std::unique_ptr<Serializer::Factory> factory;
44  };
45  std::vector<SupportedFormat> _supportedFormats;
46 };
47 
48 };
49 
50 #endif // hifi_HFMFormatRegistry_h