From 6ea4769173d2000f92a0d9a1962a89d1591434dc Mon Sep 17 00:00:00 2001 From: sabrina-shanman Date: Thu, 6 Dec 2018 13:38:57 -0800 Subject: [PATCH] Re-name MIMETypeLibrary to MediaTypeLibrary and update related references --- libraries/fbx/src/FBXSerializer.cpp | 12 ++--- libraries/fbx/src/GLTFSerializer.cpp | 12 ++--- libraries/fbx/src/OBJSerializer.cpp | 10 ++-- libraries/hfm/src/hfm/HFMFormatRegistry.cpp | 30 ++++++------ libraries/hfm/src/hfm/HFMFormatRegistry.h | 22 ++++----- libraries/hfm/src/hfm/HFMSimpleFormat.h | 14 +++--- .../src/model-networking/ModelLoader.cpp | 2 +- ...METypeLibrary.cpp => MediaTypeLibrary.cpp} | 44 ++++++++--------- .../{MIMETypeLibrary.h => MediaTypeLibrary.h} | 48 +++++++++---------- 9 files changed, 97 insertions(+), 97 deletions(-) rename libraries/shared/src/shared/{MIMETypeLibrary.cpp => MediaTypeLibrary.cpp} (53%) rename libraries/shared/src/shared/{MIMETypeLibrary.h => MediaTypeLibrary.h} (57%) diff --git a/libraries/fbx/src/FBXSerializer.cpp b/libraries/fbx/src/FBXSerializer.cpp index b57ff183a0..ccbda9af33 100644 --- a/libraries/fbx/src/FBXSerializer.cpp +++ b/libraries/fbx/src/FBXSerializer.cpp @@ -1834,14 +1834,14 @@ HFMModel* FBXSerializer::extractHFMModel(const QVariantHash& mapping, const QStr return hfmModelPtr; } -MIMEType getFBXMIMEType() { - MIMEType mimeType("fbx"); - mimeType.extensions.push_back("fbx"); - mimeType.fileSignatures.emplace_back("Kaydara FBX Binary \x00", 0); - return mimeType; +MediaType getFBXMediaType() { + MediaType mediaType("fbx"); + mediaType.extensions.push_back("fbx"); + mediaType.fileSignatures.emplace_back("Kaydara FBX Binary \x00", 0); + return mediaType; } -std::shared_ptr FBXSerializer::FORMAT = std::make_shared>(getFBXMIMEType()); +std::shared_ptr FBXSerializer::FORMAT = std::make_shared>(getFBXMediaType()); HFMModel::Pointer FBXSerializer::read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url) { QBuffer buffer(const_cast(&data)); diff --git a/libraries/fbx/src/GLTFSerializer.cpp b/libraries/fbx/src/GLTFSerializer.cpp index b841226a9e..cfa2124c5d 100644 --- a/libraries/fbx/src/GLTFSerializer.cpp +++ b/libraries/fbx/src/GLTFSerializer.cpp @@ -906,14 +906,14 @@ bool GLTFSerializer::buildGeometry(HFMModel& hfmModel, const QUrl& url) { return true; } -MIMEType getGLTFMIMEType() { - MIMEType mimeType("gltf"); - mimeType.extensions.push_back("gltf"); - mimeType.webMediaTypes.push_back("model/gltf+json"); - return mimeType; +MediaType getGLTFMediaType() { + MediaType mediaType("gltf"); + mediaType.extensions.push_back("gltf"); + mediaType.webMediaTypes.push_back("model/gltf+json"); + return mediaType; } -std::shared_ptr GLTFSerializer::FORMAT = std::make_shared>(getGLTFMIMEType()); +std::shared_ptr GLTFSerializer::FORMAT = std::make_shared>(getGLTFMediaType()); HFMModel::Pointer GLTFSerializer::read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url) { diff --git a/libraries/fbx/src/OBJSerializer.cpp b/libraries/fbx/src/OBJSerializer.cpp index 62b33e3690..b85ca7ebca 100644 --- a/libraries/fbx/src/OBJSerializer.cpp +++ b/libraries/fbx/src/OBJSerializer.cpp @@ -652,13 +652,13 @@ done: return result; } -MIMEType getOBJMIMEType() { - MIMEType mimeType("obj"); - mimeType.extensions.push_back("obj"); - return mimeType; +MediaType getOBJMediaType() { + MediaType mediaType("obj"); + mediaType.extensions.push_back("obj"); + return mediaType; } -std::shared_ptr OBJSerializer::FORMAT = std::make_shared>(getOBJMIMEType()); +std::shared_ptr OBJSerializer::FORMAT = std::make_shared>(getOBJMediaType()); HFMModel::Pointer OBJSerializer::read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url) { PROFILE_RANGE_EX(resource_parse, __FUNCTION__, 0xffff0000, nullptr); diff --git a/libraries/hfm/src/hfm/HFMFormatRegistry.cpp b/libraries/hfm/src/hfm/HFMFormatRegistry.cpp index 8ff11d851d..60606bc018 100644 --- a/libraries/hfm/src/hfm/HFMFormatRegistry.cpp +++ b/libraries/hfm/src/hfm/HFMFormatRegistry.cpp @@ -13,53 +13,53 @@ namespace hfm { -FormatRegistry::MIMETypeID FormatRegistry::registerMIMEType(const MIMEType& mimeType, std::unique_ptr supportedFactory) { +FormatRegistry::MediaTypeID FormatRegistry::registerMediaType(const MediaType& mediaType, std::unique_ptr supportedFactory) { std::lock_guard lock(_libraryLock); - MIMETypeID id = _mimeTypeLibrary.registerMIMEType(mimeType); + MediaTypeID id = _mediaTypeLibrary.registerMediaType(mediaType); _supportedFormats.emplace_back(id, supportedFactory); return id; } -void FormatRegistry::unregisterMIMEType(const MIMETypeID& mimeTypeID) { +void FormatRegistry::unregisterMediaType(const MediaTypeID& mediaTypeID) { std::lock_guard lock(_libraryLock); for (auto it = _supportedFormats.begin(); it != _supportedFormats.end(); it++) { - if ((*it).mimeTypeID == mimeTypeID) { + if ((*it).mediaTypeID == mediaTypeID) { _supportedFormats.erase(it); break; } } - _mimeTypeLibrary.unregisterMIMEType(mimeTypeID); + _mediaTypeLibrary.unregisterMediaType(mediaTypeID); } -std::shared_ptr FormatRegistry::getSerializerForMIMETypeID(FormatRegistry::MIMETypeID mimeTypeID) const { +std::shared_ptr FormatRegistry::getSerializerForMediaTypeID(FormatRegistry::MediaTypeID mediaTypeID) const { // TODO: shared_lock in C++14 std::lock_guard lock(*const_cast(&_libraryLock)); for (auto it = _supportedFormats.begin(); it != _supportedFormats.end(); it++) { - if ((*it).mimeTypeID == mimeTypeID) { + if ((*it).mediaTypeID == mediaTypeID) { return (*it).factory->get(); } } return std::shared_ptr(); } -std::shared_ptr FormatRegistry::getSerializerForMIMEType(const hifi::ByteArray& data, const hifi::URL& url, const std::string& webMediaType) const { - MIMETypeID id; +std::shared_ptr FormatRegistry::getSerializerForMediaType(const hifi::ByteArray& data, const hifi::URL& url, const std::string& webMediaType) const { + MediaTypeID id; { // TODO: shared_lock in C++14 std::lock_guard lock(*const_cast(&_libraryLock)); - id = _mimeTypeLibrary.findMIMETypeForData(data); - if (id == INVALID_MIME_TYPE_ID) { - id = _mimeTypeLibrary.findMIMETypeForURL(url); + id = _mediaTypeLibrary.findMediaTypeForData(data); + if (id == INVALID_MEDIA_TYPE_ID) { + id = _mediaTypeLibrary.findMediaTypeForURL(url); } - if (id == INVALID_MIME_TYPE_ID) { - id = _mimeTypeLibrary.findMIMETypeForMediaType(webMediaType); + if (id == INVALID_MEDIA_TYPE_ID) { + id = _mediaTypeLibrary.findMediaTypeForWebID(webMediaType); } } - return getSerializerForMIMETypeID(id); + return getSerializerForMediaTypeID(id); } }; diff --git a/libraries/hfm/src/hfm/HFMFormatRegistry.h b/libraries/hfm/src/hfm/HFMFormatRegistry.h index 92076e814c..203c5f5743 100644 --- a/libraries/hfm/src/hfm/HFMFormatRegistry.h +++ b/libraries/hfm/src/hfm/HFMFormatRegistry.h @@ -13,32 +13,32 @@ #define hifi_HFMFormatRegistry_h #include "HFMSerializer.h" -#include +#include #include namespace hfm { class FormatRegistry { public: - using MIMETypeID = MIMETypeLibrary::ID; - static const MIMETypeID INVALID_MIME_TYPE_ID { MIMETypeLibrary::INVALID_ID }; + using MediaTypeID = MediaTypeLibrary::ID; + static const MediaTypeID INVALID_MEDIA_TYPE_ID { MediaTypeLibrary::INVALID_ID }; - MIMETypeID registerMIMEType(const MIMEType& mimeType, std::unique_ptr supportedFactory); - void unregisterMIMEType(const MIMETypeID& id); + MediaTypeID registerMediaType(const MediaType& mediaType, std::unique_ptr supportedFactory); + void unregisterMediaType(const MediaTypeID& id); - std::shared_ptr getSerializerForMIMEType(const hifi::ByteArray& data, const hifi::URL& url, const std::string& webMediaType) const; - std::shared_ptr getSerializerForMIMETypeID(MIMETypeID id) const; + std::shared_ptr getSerializerForMediaType(const hifi::ByteArray& data, const hifi::URL& url, const std::string& webMediaType) const; + std::shared_ptr getSerializerForMediaTypeID(MediaTypeID id) const; protected: - MIMETypeLibrary _mimeTypeLibrary; + MediaTypeLibrary _mediaTypeLibrary; std::mutex _libraryLock; class SupportedFormat { public: - SupportedFormat(const MIMETypeID& mimeTypeID, std::unique_ptr& factory) : - mimeTypeID(mimeTypeID), + SupportedFormat(const MediaTypeID& mediaTypeID, std::unique_ptr& factory) : + mediaTypeID(mediaTypeID), factory(std::move(factory)) { } - MIMETypeID mimeTypeID; + MediaTypeID mediaTypeID; std::unique_ptr factory; }; std::vector _supportedFormats; diff --git a/libraries/hfm/src/hfm/HFMSimpleFormat.h b/libraries/hfm/src/hfm/HFMSimpleFormat.h index c12a7233bf..0ab6636e7d 100644 --- a/libraries/hfm/src/hfm/HFMSimpleFormat.h +++ b/libraries/hfm/src/hfm/HFMSimpleFormat.h @@ -26,21 +26,21 @@ namespace hfm { template // T is an implementation of hfm::Serializer class SimpleFormat : public Format { public: - SimpleFormat(const MIMEType& mimeType) : Format(), - _mimeType(mimeType) { + SimpleFormat(const MediaType& mediaType) : Format(), + _mediaType(mediaType) { } void registerFormat(FormatRegistry& registry) override { - _mimeTypeID = registry.registerMIMEType(_mimeType, std::make_unique>()); + _mediaTypeID = registry.registerMediaType(_mediaType, std::make_unique>()); } void unregisterFormat(FormatRegistry& registry) override { - registry.unregisterMIMEType(_mimeTypeID); - _mimeTypeID = hfm::FormatRegistry::INVALID_MIME_TYPE_ID; + registry.unregisterMediaType(_mediaTypeID); + _mediaTypeID = hfm::FormatRegistry::INVALID_MEDIA_TYPE_ID; } protected: - MIMEType _mimeType; - hfm::FormatRegistry::MIMETypeID _mimeTypeID; + MediaType _mediaType; + hfm::FormatRegistry::MediaTypeID _mediaTypeID; }; }; diff --git a/libraries/model-networking/src/model-networking/ModelLoader.cpp b/libraries/model-networking/src/model-networking/ModelLoader.cpp index a69559ad38..1ef8e8ae85 100644 --- a/libraries/model-networking/src/model-networking/ModelLoader.cpp +++ b/libraries/model-networking/src/model-networking/ModelLoader.cpp @@ -16,7 +16,7 @@ hfm::Model::Pointer ModelLoader::load(const hifi::ByteArray& data, const hifi::VariantHash& mapping, const hifi::URL& url, const std::string& webMediaType) const { - auto serializer = DependencyManager::get()->getSerializerForMIMEType(data, url, webMediaType); + auto serializer = DependencyManager::get()->getSerializerForMediaType(data, url, webMediaType); if (!serializer) { return hfm::Model::Pointer(); } diff --git a/libraries/shared/src/shared/MIMETypeLibrary.cpp b/libraries/shared/src/shared/MediaTypeLibrary.cpp similarity index 53% rename from libraries/shared/src/shared/MIMETypeLibrary.cpp rename to libraries/shared/src/shared/MediaTypeLibrary.cpp index 5ae4016c54..790897c3e2 100644 --- a/libraries/shared/src/shared/MIMETypeLibrary.cpp +++ b/libraries/shared/src/shared/MediaTypeLibrary.cpp @@ -1,5 +1,5 @@ // -// MIMETypeLibrary.cpp +// MediaTypeLibrary.cpp // libraries/shared/src/shared // // Created by Sabrina Shanman on 2018/11/29. @@ -9,41 +9,41 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include "MIMETypeLibrary.h" +#include "MediaTypeLibrary.h" -MIMEType MIMEType::NONE = MIMEType(""); +MediaType MediaType::NONE = MediaType(""); -MIMETypeLibrary::ID MIMETypeLibrary::registerMIMEType(const MIMEType& mimeType) { +MediaTypeLibrary::ID MediaTypeLibrary::registerMediaType(const MediaType& mediaType) { ID id = nextID++; - _mimeTypes.emplace_back(id, mimeType); + _mediaTypes.emplace_back(id, mediaType); return id; } -void MIMETypeLibrary::unregisterMIMEType(const MIMETypeLibrary::ID& id) { - for (auto it = _mimeTypes.begin(); it != _mimeTypes.end(); it++) { +void MediaTypeLibrary::unregisterMediaType(const MediaTypeLibrary::ID& id) { + for (auto it = _mediaTypes.begin(); it != _mediaTypes.end(); it++) { if ((*it).id == id) { - _mimeTypes.erase(it); + _mediaTypes.erase(it); break; } } } -MIMEType MIMETypeLibrary::getMIMEType(const MIMETypeLibrary::ID& id) const { - for (auto& supportedFormat : _mimeTypes) { +MediaType MediaTypeLibrary::getMediaType(const MediaTypeLibrary::ID& id) const { + for (auto& supportedFormat : _mediaTypes) { if (supportedFormat.id == id) { - return supportedFormat.mimeType; + return supportedFormat.mediaType; } } - return MIMEType::NONE; + return MediaType::NONE; } -MIMETypeLibrary::ID MIMETypeLibrary::findMIMETypeForData(const hifi::ByteArray& data) const { +MediaTypeLibrary::ID MediaTypeLibrary::findMediaTypeForData(const hifi::ByteArray& data) const { // Check file contents - for (auto& mimeType : _mimeTypes) { - for (auto& fileSignature : mimeType.mimeType.fileSignatures) { + for (auto& mediaType : _mediaTypes) { + for (auto& fileSignature : mediaType.mediaType.fileSignatures) { auto testBytes = data.mid(fileSignature.byteOffset, (int)fileSignature.bytes.size()).toStdString(); if (testBytes == fileSignature.bytes) { - return mimeType.id; + return mediaType.id; } } } @@ -51,14 +51,14 @@ MIMETypeLibrary::ID MIMETypeLibrary::findMIMETypeForData(const hifi::ByteArray& return INVALID_ID; } -MIMETypeLibrary::ID MIMETypeLibrary::findMIMETypeForURL(const hifi::URL& url) const { +MediaTypeLibrary::ID MediaTypeLibrary::findMediaTypeForURL(const hifi::URL& url) const { // Check file extension std::string urlString = url.path().toStdString(); std::size_t extensionSeparator = urlString.rfind('.'); if (extensionSeparator != std::string::npos) { std::string detectedExtension = urlString.substr(extensionSeparator + 1); - for (auto& supportedFormat : _mimeTypes) { - for (auto& extension : supportedFormat.mimeType.extensions) { + for (auto& supportedFormat : _mediaTypes) { + for (auto& extension : supportedFormat.mediaType.extensions) { if (extension == detectedExtension) { return supportedFormat.id; } @@ -69,11 +69,11 @@ MIMETypeLibrary::ID MIMETypeLibrary::findMIMETypeForURL(const hifi::URL& url) co return INVALID_ID; } -MIMETypeLibrary::ID MIMETypeLibrary::findMIMETypeForMediaType(const std::string& webMediaType) const { +MediaTypeLibrary::ID MediaTypeLibrary::findMediaTypeForWebID(const std::string& webMediaType) const { // Check web media type if (webMediaType != "") { - for (auto& supportedFormat : _mimeTypes) { - for (auto& candidateWebMediaType : supportedFormat.mimeType.webMediaTypes) { + for (auto& supportedFormat : _mediaTypes) { + for (auto& candidateWebMediaType : supportedFormat.mediaType.webMediaTypes) { if (candidateWebMediaType == webMediaType) { return supportedFormat.id; } diff --git a/libraries/shared/src/shared/MIMETypeLibrary.h b/libraries/shared/src/shared/MediaTypeLibrary.h similarity index 57% rename from libraries/shared/src/shared/MIMETypeLibrary.h rename to libraries/shared/src/shared/MediaTypeLibrary.h index 5066e859fb..c87da01fa1 100644 --- a/libraries/shared/src/shared/MIMETypeLibrary.h +++ b/libraries/shared/src/shared/MediaTypeLibrary.h @@ -1,5 +1,5 @@ // -// MIMETypeLibrary.h +// MediaTypeLibrary.h // libraries/shared/src/shared // // Created by Sabrina Shanman on 2018/11/28. @@ -9,8 +9,8 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#ifndef hifi_MIMETypeLibrary_h -#define hifi_MIMETypeLibrary_h +#ifndef hifi_MediaTypeLibrary_h +#define hifi_MediaTypeLibrary_h #include #include @@ -36,20 +36,20 @@ public: }; // A named file extension with a list of known ways to positively identify the file type -class MIMEType { +class MediaType { public: - MIMEType(const std::string& name) : + MediaType(const std::string& name) : name(name) { } - MIMEType() {}; - MIMEType(const MIMEType& mimeType) : - name(mimeType.name), - extensions(mimeType.extensions), - webMediaTypes(mimeType.webMediaTypes), - fileSignatures(mimeType.fileSignatures) { + MediaType() {}; + MediaType(const MediaType& mediaType) : + name(mediaType.name), + extensions(mediaType.extensions), + webMediaTypes(mediaType.webMediaTypes), + fileSignatures(mediaType.fileSignatures) { } - static MIMEType NONE; + static MediaType NONE; std::string name; std::vector extensions; @@ -57,34 +57,34 @@ public: std::vector fileSignatures; }; -class MIMETypeLibrary { +class MediaTypeLibrary { public: using ID = unsigned int; static const ID INVALID_ID { 0 }; - ID registerMIMEType(const MIMEType& mimeType); - void unregisterMIMEType(const ID& id); + ID registerMediaType(const MediaType& mediaType); + void unregisterMediaType(const ID& id); - MIMEType getMIMEType(const ID& id) const; + MediaType getMediaType(const ID& id) const; - ID findMIMETypeForData(const hifi::ByteArray& data) const; - ID findMIMETypeForURL(const hifi::URL& url) const; - ID findMIMETypeForMediaType(const std::string& webMediaType) const; + ID findMediaTypeForData(const hifi::ByteArray& data) const; + ID findMediaTypeForURL(const hifi::URL& url) const; + ID findMediaTypeForWebID(const std::string& webMediaType) const; protected: ID nextID { 1 }; class Entry { public: - Entry(const ID& id, const MIMEType& mimeType) : + Entry(const ID& id, const MediaType& mediaType) : id(id), - mimeType(mimeType) { + mediaType(mediaType) { } ID id; - MIMEType mimeType; + MediaType mediaType; }; - std::vector _mimeTypes; + std::vector _mediaTypes; }; -#endif // hifi_MIMETypeLibrary_h +#endif // hifi_MeidaTypeLibrary_h