mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 00:36:47 +02:00
Remove locks from MIMETypeLibrary
This commit is contained in:
parent
bf1c5f2fa5
commit
6ec0e42ded
2 changed files with 42 additions and 53 deletions
|
@ -12,38 +12,30 @@
|
||||||
#include "MIMETypeLibrary.h"
|
#include "MIMETypeLibrary.h"
|
||||||
|
|
||||||
MIMETypeLibrary::ID MIMETypeLibrary::registerMIMEType(const MIMEType& mimeType) {
|
MIMETypeLibrary::ID MIMETypeLibrary::registerMIMEType(const MIMEType& mimeType) {
|
||||||
ID id;
|
ID id = nextID++;
|
||||||
withWriteLock([&](){
|
|
||||||
id = nextID++;
|
|
||||||
_mimeTypes.emplace_back(id, mimeType);
|
_mimeTypes.emplace_back(id, mimeType);
|
||||||
});
|
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MIMETypeLibrary::unregisterMIMEType(const MIMETypeLibrary::ID& id) {
|
void MIMETypeLibrary::unregisterMIMEType(const MIMETypeLibrary::ID& id) {
|
||||||
withWriteLock([&](){
|
|
||||||
for (auto it = _mimeTypes.begin(); it != _mimeTypes.end(); it++) {
|
for (auto it = _mimeTypes.begin(); it != _mimeTypes.end(); it++) {
|
||||||
if ((*it).id == id) {
|
if ((*it).id == id) {
|
||||||
_mimeTypes.erase(it);
|
_mimeTypes.erase(it);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MIMEType MIMETypeLibrary::getMIMEType(const MIMETypeLibrary::ID& id) const {
|
MIMEType MIMETypeLibrary::getMIMEType(const MIMETypeLibrary::ID& id) const {
|
||||||
return resultWithReadLock<MIMEType>([&](){
|
|
||||||
for (auto& supportedFormat : _mimeTypes) {
|
for (auto& supportedFormat : _mimeTypes) {
|
||||||
if (supportedFormat.id == id) {
|
if (supportedFormat.id == id) {
|
||||||
return supportedFormat.mimeType;
|
return supportedFormat.mimeType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return MIMEType::NONE;
|
return MIMEType::NONE;
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MIMETypeLibrary::ID MIMETypeLibrary::findMatchingMIMEType(const hifi::ByteArray& data, const hifi::VariantHash& mapping, const hifi::URL& url, const std::string& webMediaType) const {
|
MIMETypeLibrary::ID MIMETypeLibrary::findMatchingMIMEType(const hifi::ByteArray& data, const hifi::VariantHash& mapping, const hifi::URL& url, const std::string& webMediaType) const {
|
||||||
return resultWithReadLock<MIMETypeLibrary::ID>([&](){
|
|
||||||
// Check file contents
|
// Check file contents
|
||||||
for (auto& mimeType : _mimeTypes) {
|
for (auto& mimeType : _mimeTypes) {
|
||||||
for (auto& fileSignature : mimeType.mimeType.fileSignatures) {
|
for (auto& fileSignature : mimeType.mimeType.fileSignatures) {
|
||||||
|
@ -81,5 +73,4 @@ MIMETypeLibrary::ID MIMETypeLibrary::findMatchingMIMEType(const hifi::ByteArray&
|
||||||
|
|
||||||
// Supported file type not found.
|
// Supported file type not found.
|
||||||
return INVALID_ID;
|
return INVALID_ID;
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,6 @@
|
||||||
|
|
||||||
#include "HifiTypes.h"
|
#include "HifiTypes.h"
|
||||||
|
|
||||||
#include "ReadWriteLockable.h"
|
|
||||||
|
|
||||||
// A short sequence of bytes, typically at the beginning of the file, which identifies the file format
|
// A short sequence of bytes, typically at the beginning of the file, which identifies the file format
|
||||||
class FileSignature {
|
class FileSignature {
|
||||||
public:
|
public:
|
||||||
|
@ -61,7 +59,7 @@ public:
|
||||||
|
|
||||||
MIMEType MIMEType::NONE = MIMEType("");
|
MIMEType MIMEType::NONE = MIMEType("");
|
||||||
|
|
||||||
class MIMETypeLibrary : ReadWriteLockable {
|
class MIMETypeLibrary {
|
||||||
public:
|
public:
|
||||||
using ID = unsigned int;
|
using ID = unsigned int;
|
||||||
static const ID INVALID_ID { 0 };
|
static const ID INVALID_ID { 0 };
|
||||||
|
|
Loading…
Reference in a new issue