mirror of
https://github.com/overte-org/overte.git
synced 2025-08-07 13:30:33 +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"
|
||||
|
||||
MIMETypeLibrary::ID MIMETypeLibrary::registerMIMEType(const MIMEType& mimeType) {
|
||||
ID id;
|
||||
withWriteLock([&](){
|
||||
id = nextID++;
|
||||
ID id = nextID++;
|
||||
_mimeTypes.emplace_back(id, mimeType);
|
||||
});
|
||||
return id;
|
||||
}
|
||||
|
||||
void MIMETypeLibrary::unregisterMIMEType(const MIMETypeLibrary::ID& id) {
|
||||
withWriteLock([&](){
|
||||
for (auto it = _mimeTypes.begin(); it != _mimeTypes.end(); it++) {
|
||||
if ((*it).id == id) {
|
||||
_mimeTypes.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
MIMEType MIMETypeLibrary::getMIMEType(const MIMETypeLibrary::ID& id) const {
|
||||
return resultWithReadLock<MIMEType>([&](){
|
||||
for (auto& supportedFormat : _mimeTypes) {
|
||||
if (supportedFormat.id == id) {
|
||||
return supportedFormat.mimeType;
|
||||
}
|
||||
}
|
||||
return MIMEType::NONE;
|
||||
});
|
||||
}
|
||||
|
||||
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
|
||||
for (auto& mimeType : _mimeTypes) {
|
||||
for (auto& fileSignature : mimeType.mimeType.fileSignatures) {
|
||||
|
@ -81,5 +73,4 @@ MIMETypeLibrary::ID MIMETypeLibrary::findMatchingMIMEType(const hifi::ByteArray&
|
|||
|
||||
// Supported file type not found.
|
||||
return INVALID_ID;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
|
||||
#include "HifiTypes.h"
|
||||
|
||||
#include "ReadWriteLockable.h"
|
||||
|
||||
// A short sequence of bytes, typically at the beginning of the file, which identifies the file format
|
||||
class FileSignature {
|
||||
public:
|
||||
|
@ -61,7 +59,7 @@ public:
|
|||
|
||||
MIMEType MIMEType::NONE = MIMEType("");
|
||||
|
||||
class MIMETypeLibrary : ReadWriteLockable {
|
||||
class MIMETypeLibrary {
|
||||
public:
|
||||
using ID = unsigned int;
|
||||
static const ID INVALID_ID { 0 };
|
||||
|
|
Loading…
Reference in a new issue