[DEV] update new ETK

This commit is contained in:
Edouard DUPIN 2017-09-26 15:51:25 +02:00
parent c8a9290648
commit a02d121421
21 changed files with 295 additions and 427 deletions

View File

@ -115,11 +115,11 @@ ETK_EXPORT_API void SERVICE_IO_peridic_call() {
return;
}
// try lock mutex:
if (g_mutex.try_lock() == false) {
if (g_mutex.tryLock() == false) {
return;
}
store_db();
g_mutex.unlock();
g_mutex.unLock();
}

View File

@ -176,7 +176,7 @@ bool pushVideoFile(zeus::service::ProxyVideo& _srv, etk::String _path, etk::Map<
continue;
}
haveDate = true;
_basicKey.insert(etk::Pair<etk::String,etk::String>("date", it));
_basicKey.set("date", it);
} else {
if (haveTitle == true) {
APPL_INFO(" '" << fileName << "'");
@ -185,16 +185,16 @@ bool pushVideoFile(zeus::service::ProxyVideo& _srv, etk::String _path, etk::Map<
}
haveTitle = true;
// Other title
_basicKey.insert(etk::Pair<etk::String,etk::String>("title2", it));
_basicKey.set("title2", it);
}
}
// remove unneeded date
if (haveDate == false) {
_basicKey.insert(etk::Pair<etk::String,etk::String>("date", ""));
_basicKey.set("date", "");
}
// remove unneeded title 2
if (haveTitle == false) {
_basicKey.insert(etk::Pair<etk::String,etk::String>("title2", ""));
_basicKey.set("title2", "");
}
// Remove the actors [XXX YYY][EEE TTT]...
etk::Vector<etk::String> acthors;
@ -208,7 +208,7 @@ bool pushVideoFile(zeus::service::ProxyVideo& _srv, etk::String _path, etk::Map<
}
actorList += itActor;
}
_basicKey.insert(etk::Pair<etk::String,etk::String>("acthors", actorList));
_basicKey.set("acthors", actorList);
}
// remove extention
@ -239,7 +239,7 @@ bool pushVideoFile(zeus::service::ProxyVideo& _srv, etk::String _path, etk::Map<
}
if (listElement.size() == 1) {
// nothing to do , it might be a film ...
_basicKey.insert(etk::Pair<etk::String,etk::String>("title", etk::toString(listElement[0])));
_basicKey.set("title", etk::toString(listElement[0]));
} else {
/*
for (auto &itt : listElement) {
@ -254,12 +254,12 @@ bool pushVideoFile(zeus::service::ProxyVideo& _srv, etk::String _path, etk::Map<
int32_t episode = -1;
etk::String seriesName = listElement[0];
_basicKey.insert(etk::Pair<etk::String,etk::String>("series-name", etk::toString(seriesName)));
_basicKey.set("series-name", etk::toString(seriesName));
etk::String fullEpisodeName = listElement[3];
for (int32_t yyy=4; yyy<listElement.size(); ++yyy) {
fullEpisodeName += "-" + listElement[yyy];
}
_basicKey.insert(etk::Pair<etk::String,etk::String>("title", etk::toString(fullEpisodeName)));
_basicKey.set("title", etk::toString(fullEpisodeName));
if (etk::String(&listElement[1][1]) == "XX") {
// saison unknow ... ==> nothing to do ...
} else {
@ -270,7 +270,7 @@ bool pushVideoFile(zeus::service::ProxyVideo& _srv, etk::String _path, etk::Map<
} else {
episode = etk::string_to_int32_t(&listElement[2][1]);
_basicKey.insert(etk::Pair<etk::String,etk::String>("episode", etk::toString(episode)));
_basicKey.set("episode", etk::toString(episode));
}
APPL_INFO("Find a internal mode series: :");
APPL_INFO(" origin : '" << fileName << "'");
@ -280,19 +280,19 @@ bool pushVideoFile(zeus::service::ProxyVideo& _srv, etk::String _path, etk::Map<
// nothing to do
} else if(saison < 10) {
saisonPrint = "0" + etk::toString(saison);
_basicKey.insert(etk::Pair<etk::String,etk::String>("saison", etk::toString(saison)));
_basicKey.set("saison", etk::toString(saison));
} else {
saisonPrint = etk::toString(saison);
_basicKey.insert(etk::Pair<etk::String,etk::String>("saison", etk::toString(saison)));
_basicKey.set("saison", etk::toString(saison));
}
if (episode < 0) {
// nothing to do
} else if(episode < 10) {
episodePrint = "0" + etk::toString(episode);
_basicKey.insert(etk::Pair<etk::String,etk::String>("episode", etk::toString(episode)));
_basicKey.set("episode", etk::toString(episode));
} else {
episodePrint = etk::toString(episode);
_basicKey.insert(etk::Pair<etk::String,etk::String>("episode", etk::toString(episode)));
_basicKey.set("episode", etk::toString(episode));
}
APPL_PRINT(" ==> '" << seriesName << "-s" << saisonPrint << "-e" << episodePrint << "-" << fullEpisodeName << "'");
}
@ -320,87 +320,87 @@ void installVideoPath(zeus::service::ProxyVideo& _srv, etk::String _path, etk::M
if (basicKeyTmp.size() == 0) {
APPL_INFO("find A '" << lastPathName << "' " << basicKeyTmp.size());
if (lastPathName == "film") {
basicKeyTmp.insert(etk::Pair<etk::String,etk::String>("type", "film"));
basicKeyTmp.insert(etk::Pair<etk::String,etk::String>("production-methode", "picture"));
basicKeyTmp.set("type", "film");
basicKeyTmp.set("production-methode", "picture");
} else if (lastPathName == "film-annimation") {
basicKeyTmp.insert(etk::Pair<etk::String,etk::String>("type", "film"));
basicKeyTmp.insert(etk::Pair<etk::String,etk::String>("production-methode", "draw"));
basicKeyTmp.set("type", "film");
basicKeyTmp.set("production-methode", "draw");
} else if (lastPathName == "film-short") { // short films
basicKeyTmp.insert(etk::Pair<etk::String,etk::String>("type", "film"));
basicKeyTmp.insert(etk::Pair<etk::String,etk::String>("production-methode", "short"));
basicKeyTmp.set("type", "film");
basicKeyTmp.set("production-methode", "short");
} else if (lastPathName == "tv-show") {
basicKeyTmp.insert(etk::Pair<etk::String,etk::String>("type", "tv-show"));
basicKeyTmp.insert(etk::Pair<etk::String,etk::String>("production-methode", "picture"));
basicKeyTmp.set("type", "tv-show");
basicKeyTmp.set("production-methode", "picture");
} else if (lastPathName == "tv-show-annimation") {
basicKeyTmp.insert(etk::Pair<etk::String,etk::String>("type", "tv-show"));
basicKeyTmp.insert(etk::Pair<etk::String,etk::String>("production-methode", "draw"));
basicKeyTmp.set("type", "tv-show");
basicKeyTmp.set("production-methode", "draw");
} else if (lastPathName == "theater") {
basicKeyTmp.insert(etk::Pair<etk::String,etk::String>("type", "theater"));
basicKeyTmp.set("type", "theater");
} else if (lastPathName == "one-man") {
basicKeyTmp.insert(etk::Pair<etk::String,etk::String>("type", "one-man"));
basicKeyTmp.set("type", "one-man");
}
} else {
APPL_INFO("find B '" << lastPathName << "' " << basicKeyTmp.size());
if (lastPathName == "saison_01") {
basicKeyTmp.insert(etk::Pair<etk::String,etk::String>("saison", "1"));
basicKeyTmp.set("saison", "1");
} else if (lastPathName == "saison_02") {
basicKeyTmp.insert(etk::Pair<etk::String,etk::String>("saison", "2"));
basicKeyTmp.set("saison", "2");
} else if (lastPathName == "saison_03") {
basicKeyTmp.insert(etk::Pair<etk::String,etk::String>("saison", "3"));
basicKeyTmp.set("saison", "3");
} else if (lastPathName == "saison_04") {
basicKeyTmp.insert(etk::Pair<etk::String,etk::String>("saison", "4"));
basicKeyTmp.set("saison", "4");
} else if (lastPathName == "saison_05") {
basicKeyTmp.insert(etk::Pair<etk::String,etk::String>("saison", "5"));
basicKeyTmp.set("saison", "5");
} else if (lastPathName == "saison_06") {
basicKeyTmp.insert(etk::Pair<etk::String,etk::String>("saison", "6"));
basicKeyTmp.set("saison", "6");
} else if (lastPathName == "saison_07") {
basicKeyTmp.insert(etk::Pair<etk::String,etk::String>("saison", "7"));
basicKeyTmp.set("saison", "7");
} else if (lastPathName == "saison_08") {
basicKeyTmp.insert(etk::Pair<etk::String,etk::String>("saison", "8"));
basicKeyTmp.set("saison", "8");
} else if (lastPathName == "saison_09") {
basicKeyTmp.insert(etk::Pair<etk::String,etk::String>("saison", "9"));
basicKeyTmp.set("saison", "9");
} else if (lastPathName == "saison_10") {
basicKeyTmp.insert(etk::Pair<etk::String,etk::String>("saison", "10"));
basicKeyTmp.set("saison", "10");
} else if (lastPathName == "saison_11") {
basicKeyTmp.insert(etk::Pair<etk::String,etk::String>("saison", "11"));
basicKeyTmp.set("saison", "11");
} else if (lastPathName == "saison_12") {
basicKeyTmp.insert(etk::Pair<etk::String,etk::String>("saison", "12"));
basicKeyTmp.set("saison", "12");
} else if (lastPathName == "saison_13") {
basicKeyTmp.insert(etk::Pair<etk::String,etk::String>("saison", "13"));
basicKeyTmp.set("saison", "13");
} else if (lastPathName == "saison_14") {
basicKeyTmp.insert(etk::Pair<etk::String,etk::String>("saison", "14"));
basicKeyTmp.set("saison", "14");
} else if (lastPathName == "saison_15") {
basicKeyTmp.insert(etk::Pair<etk::String,etk::String>("saison", "15"));
basicKeyTmp.set("saison", "15");
} else if (lastPathName == "saison_16") {
basicKeyTmp.insert(etk::Pair<etk::String,etk::String>("saison", "16"));
basicKeyTmp.set("saison", "16");
} else if (lastPathName == "saison_17") {
basicKeyTmp.insert(etk::Pair<etk::String,etk::String>("saison", "17"));
basicKeyTmp.set("saison", "17");
} else if (lastPathName == "saison_18") {
basicKeyTmp.insert(etk::Pair<etk::String,etk::String>("saison", "18"));
basicKeyTmp.set("saison", "18");
} else if (lastPathName == "saison_19") {
basicKeyTmp.insert(etk::Pair<etk::String,etk::String>("saison", "19"));
basicKeyTmp.set("saison", "19");
} else if (lastPathName == "saison_20") {
basicKeyTmp.insert(etk::Pair<etk::String,etk::String>("saison", "20"));
basicKeyTmp.set("saison", "20");
} else if (lastPathName == "saison_21") {
basicKeyTmp.insert(etk::Pair<etk::String,etk::String>("saison", "21"));
basicKeyTmp.set("saison", "21");
} else if (lastPathName == "saison_22") {
basicKeyTmp.insert(etk::Pair<etk::String,etk::String>("saison", "22"));
basicKeyTmp.set("saison", "22");
} else if (lastPathName == "saison_23") {
basicKeyTmp.insert(etk::Pair<etk::String,etk::String>("saison", "23"));
basicKeyTmp.set("saison", "23");
} else if (lastPathName == "saison_24") {
basicKeyTmp.insert(etk::Pair<etk::String,etk::String>("saison", "24"));
basicKeyTmp.set("saison", "24");
} else if (lastPathName == "saison_25") {
basicKeyTmp.insert(etk::Pair<etk::String,etk::String>("saison", "25"));
basicKeyTmp.set("saison", "25");
} else if (lastPathName == "saison_26") {
basicKeyTmp.insert(etk::Pair<etk::String,etk::String>("saison", "26"));
basicKeyTmp.set("saison", "26");
} else if (lastPathName == "saison_27") {
basicKeyTmp.insert(etk::Pair<etk::String,etk::String>("saison", "27"));
basicKeyTmp.set("saison", "27");
} else if (lastPathName == "saison_28") {
basicKeyTmp.insert(etk::Pair<etk::String,etk::String>("saison", "28"));
basicKeyTmp.set("saison", "28");
} else if (lastPathName == "saison_29") {
basicKeyTmp.insert(etk::Pair<etk::String,etk::String>("saison", "29"));
basicKeyTmp.set("saison", "29");
} else {
basicKeyTmp.insert(etk::Pair<etk::String,etk::String>("series-name", lastPathName));
basicKeyTmp.set("series-name", lastPathName);
}
}
installVideoPath(_srv, itPath, basicKeyTmp);
@ -549,9 +549,13 @@ int main(int _argc, const char *_argv[]) {
APPL_ERROR("get media error");
return -1;
}
APPL_DEBUG(" Get title ...");
etk::String name = media.getMetadata("title").wait().get();
APPL_DEBUG(" Get series-name ...");
etk::String serie = media.getMetadata("series-name").wait().get();
APPL_DEBUG(" Get episode ...");
etk::String episode = media.getMetadata("episode").wait().get();
APPL_DEBUG(" Get saison ...");
etk::String saison = media.getMetadata("saison").wait().get();
etk::String outputDesc = "";
if (serie != "") {
@ -564,7 +568,7 @@ int main(int _argc, const char *_argv[]) {
outputDesc += "e" + episode + "-";
}
outputDesc += name;
APPL_PRINT("[" << it << "] " << outputDesc);
APPL_PRINT("[" << it << "] '" << outputDesc << "'");
}
}
APPL_PRINT("============================================");

View File

@ -9,6 +9,7 @@
#include <enet/TcpServer.hpp>
#include <appl/DirectInterface.hpp>
#include <appl/RouterInterface.hpp>
#include <etk/Exception.hpp>
namespace appl {
@ -32,7 +33,7 @@ namespace appl {
m_interface.link();
m_threadRunning = true;
APPL_INFO("Start waiting on " << _host << " " << _port);
m_thread = new ethread::Thread([&](void *){ this->threadCallback();}, nullptr);
m_thread = new ethread::Thread([&](){ threadCallback();}, "GatewayListening");
if (m_thread == nullptr) {
m_threadRunning = false;
APPL_ERROR("creating callback thread!");
@ -125,7 +126,7 @@ void appl::GateWay::start() {
m_routerClient = ememory::makeShared<appl::RouterInterface>(*propertyRouterIp, *propertyRouterPort, *propertyUserName, this);
if (m_routerClient->isAlive() == false) {
APPL_ERROR("Can not connect the Router (if it is the normal case, use option '--no-router'");
throw std::runtime_error("Can not connect router");
throw etk::exception::RuntimeError("Can not connect router");
}
}
m_interfaceNewService->start(*propertyServiceIp, *propertyServicePort);

View File

@ -222,7 +222,7 @@ int main(int _argc, const char *_argv[]) {
etk::Vector<etk::String> listServices = dataPath.folderGetSub(false, true, ".*\\.srv");
for (auto &it2: listServices) {
etk::String nameFileSrv = etk::FSNode(it2).getNameFile();
etk::Vector<etk::String> spl = etk::split(etk::String(nameFileSrv.begin(), nameFileSrv.end()-4), "-service-");
etk::Vector<etk::String> spl = etk::String(nameFileSrv.begin(), nameFileSrv.end()-4).split("-service-");
if (spl.size() != 2) {
APPL_ERROR("reject service, wrong format ... '" << it2 << "' missing XXX-service-SERVICE-NAME.srv");
continue;
@ -304,7 +304,7 @@ int main(int _argc, const char *_argv[]) {
APPL_WARNING("Router is Dead or Timeout");
} else {
elog::flush();
ethread::sleepMilliSeconds(std::chrono::seconds(1));
ethread::sleepMilliSeconds(1000);
APPL_INFO("gateway in waiting ... " << iii << "/inf");
}
iii++;

View File

@ -179,7 +179,7 @@ int main(int _argc, const char *_argv[]) {
for (auto &it: listElements) {
it->peridic_call();
}
ethread::sleepMilliSeconds(std::chrono::seconds(1));
ethread::sleepMilliSeconds(1000);
APPL_INFO("service in waiting ... " << iii << "/inf");
iii++;
}

View File

@ -84,7 +84,7 @@ namespace appl {
m_interface.setPort(_port);
m_interface.link();
m_threadRunning = true;
m_thread = new ethread::Thread([&](void *){ this->threadCallback();}, nullptr);
m_thread = new ethread::Thread([&](){ threadCallback();}, "routerListener");
if (m_thread == nullptr) {
m_threadRunning = false;
ZEUS_ERROR("creating callback thread!");

View File

@ -106,7 +106,7 @@ namespace appl {
}
}
if (find == false) {
throw std::invalid_argument("Wrong file name ...");
throw etk::exception::InvalidArgument("Wrong file name ...");
}
return zeus::File::create(g_basePath + property.m_fileName + "." + zeus::getExtention(property.m_mineType), "", property.m_mineType);
}
@ -135,7 +135,7 @@ namespace appl {
APPL_DEBUG("move temporay file in : " << g_basePath << sha512String);
if (etk::FSNodeGetSize(tmpFileName) == 0) {
APPL_ERROR("try to store an empty file");
throw std::runtime_error("file size == 0");
throw etk::exception::RuntimeError("file size == 0");
}
etk::FSNodeMove(tmpFileName, g_basePath + sha512String + "." + zeus::getExtention(futType.get()));
FileProperty property;
@ -167,7 +167,7 @@ namespace appl {
}
}
if (find == false) {
throw std::invalid_argument("Wrong file name ...");
throw etk::exception::InvalidArgument("Wrong file name ...");
}
// Remove media in all Album ...
for (auto &it : m_listAlbum) {
@ -184,7 +184,7 @@ namespace appl {
// Real Remove definitly the file
// TODO : Set it in a trash ... For a while ...
if (etk::FSNodeRemove(g_basePath + property.m_fileName + "." + zeus::getExtention(property.m_mineType)) == false) {
throw std::runtime_error("Can not remove file ...");
throw etk::exception::RuntimeError("Can not remove file ...");
}
}
@ -198,7 +198,7 @@ namespace appl {
return out;
}
}
throw std::invalid_argument("Wrong Album ID ...");
throw etk::exception::InvalidArgument("Wrong Album ID ...");
}
etk::String mediaMetadataGetKey(uint32_t _mediaId, etk::String _key) override {
etk::Vector<etk::String> out;
@ -211,21 +211,16 @@ namespace appl {
return "";
}
}
throw std::invalid_argument("Wrong Album ID ...");
throw etk::exception::InvalidArgument("Wrong Album ID ...");
}
void mediaMetadataSetKey(uint32_t _mediaId, etk::String _key, etk::String _value) override {
for (auto &it : m_listFile) {
if (it.m_id == _mediaId) {
auto itM = it.m_metadata.find(_key);
if (itM != it.m_metadata.end()) {
itM->second = _value;
} else {
it.m_metadata.insert(etk::makePair(_key, _value));
}
it.m_metadata.set(_key, _value);
return;
}
}
throw std::invalid_argument("Wrong Album ID ...");
throw etk::exception::InvalidArgument("Wrong Album ID ...");
}
uint32_t albumCreate(etk::String _albumName) override {
ethread::UniqueLock lock(g_mutex);
@ -255,7 +250,7 @@ namespace appl {
}
++it;
}
throw std::invalid_argument("Wrong Album ID ...");
throw etk::exception::InvalidArgument("Wrong Album ID ...");
}
etk::Vector<uint32_t> albumGetList() override {
ethread::UniqueLock lock(g_mutex);
@ -272,7 +267,7 @@ namespace appl {
return it.m_name;
}
}
throw std::invalid_argument("Wrong Album ID ...");
throw etk::exception::InvalidArgument("Wrong Album ID ...");
return "";
}
void albumNameSet(uint32_t _albumId, etk::String _albumName) override {
@ -283,7 +278,7 @@ namespace appl {
return;
}
}
throw std::invalid_argument("Wrong Album ID ...");
throw etk::exception::InvalidArgument("Wrong Album ID ...");
}
etk::String albumDescriptionGet(uint32_t _albumId) override {
ethread::UniqueLock lock(g_mutex);
@ -292,7 +287,7 @@ namespace appl {
return it.m_description;
}
}
throw std::invalid_argument("Wrong Album ID ...");
throw etk::exception::InvalidArgument("Wrong Album ID ...");
return "";
}
void albumDescriptionSet(uint32_t _albumId, etk::String _desc) override {
@ -303,7 +298,7 @@ namespace appl {
return;
}
}
throw std::invalid_argument("Wrong Album ID ...");
throw etk::exception::InvalidArgument("Wrong Album ID ...");
}
void albumMediaAdd(uint32_t _albumId, uint32_t _mediaId) override {
ethread::UniqueLock lock(g_mutex);
@ -319,7 +314,7 @@ namespace appl {
return;
}
}
throw std::invalid_argument("Wrong Album ID ...");
throw etk::exception::InvalidArgument("Wrong Album ID ...");
}
void albumMediaRemove(uint32_t _albumId, uint32_t _mediaId) override {
ethread::UniqueLock lock(g_mutex);
@ -338,7 +333,7 @@ namespace appl {
return;
}
}
throw std::invalid_argument("Wrong Album ID ...");
throw etk::exception::InvalidArgument("Wrong Album ID ...");
}
uint32_t albumMediaCount(uint32_t _albumId) override {
ethread::UniqueLock lock(g_mutex);
@ -347,7 +342,7 @@ namespace appl {
return it.m_listMedia.size();
}
}
throw std::invalid_argument("Wrong Album ID ...");
throw etk::exception::InvalidArgument("Wrong Album ID ...");
return 0;
}
etk::Vector<uint32_t> albumMediaIdGet(uint32_t _albumId, uint32_t _start, uint32_t _stop) override {
@ -364,7 +359,7 @@ namespace appl {
return out;
}
}
throw std::invalid_argument("Wrong Album ID ...");
throw etk::exception::InvalidArgument("Wrong Album ID ...");
}
void albumParentSet(uint32_t _albumId, uint32_t _albumParentId) override {
ethread::UniqueLock lock(g_mutex);
@ -374,7 +369,7 @@ namespace appl {
return;
}
}
throw std::invalid_argument("Wrong Album ID ...");
throw etk::exception::InvalidArgument("Wrong Album ID ...");
}
void albumParentRemove(uint32_t _albumId) override {
ethread::UniqueLock lock(g_mutex);
@ -384,7 +379,7 @@ namespace appl {
return;
}
}
throw std::invalid_argument("Wrong Album ID ...");
throw etk::exception::InvalidArgument("Wrong Album ID ...");
}
uint32_t albumParentGet(uint32_t _albumId) override {
ethread::UniqueLock lock(g_mutex);
@ -393,7 +388,7 @@ namespace appl {
return it.m_parentId;
}
}
throw std::invalid_argument("Wrong Album ID ...");
throw etk::exception::InvalidArgument("Wrong Album ID ...");
}
};
}
@ -463,7 +458,7 @@ static void load_db() {
for (auto itValue = tmpObj.begin();
itValue != tmpObj.end();
++itValue) {
property.m_metadata.insert(etk::makePair(itValue.getKey(), (*itValue).toString().get()));
property.m_metadata.set(itValue.getKey(), (*itValue).toString().get());
}
}
if (property.m_fileName == "") {
@ -511,11 +506,11 @@ ETK_EXPORT_API void SERVICE_IO_peridic_call() {
return;
}
// try lock mutex:
if (g_mutex.try_lock() == false) {
if (g_mutex.tryLock() == false) {
return;
}
store_db();
g_mutex.unlock();
g_mutex.unLock();
}

View File

@ -159,7 +159,7 @@ namespace appl {
return m_listFile[iii]->getUniqueId();
}
}
throw std::invalid_argument("sha512 not find...");
throw etk::exception::InvalidArgument("sha512 not find...");
}
// Return a File Data (might be a video .tiff/.png/.jpg)
@ -175,7 +175,7 @@ namespace appl {
return it;
}
}
throw std::invalid_argument("Wrong file ID ...");
throw etk::exception::InvalidArgument("Wrong file ID ...");
//
}
uint32_t add(zeus::ActionNotification<etk::String>& _notifs, zeus::ProxyFile _dataFile) override {
@ -218,7 +218,7 @@ namespace appl {
APPL_DEBUG("move temporay file in : " << g_basePath << sha512String);
if (etk::FSNodeGetSize(tmpFileName) == 0) {
APPL_ERROR("try to store an empty file");
throw std::runtime_error("file size == 0");
throw etk::exception::RuntimeError("file size == 0");
}
if (zeus::getExtention(futType.get()) != "") {
ethread::UniqueLock lock(g_mutex);
@ -264,26 +264,26 @@ namespace appl {
g_needToStore = true;
}
if (find == false) {
throw std::invalid_argument("Wrong file name ...");
throw etk::exception::InvalidArgument("Wrong file name ...");
}
// Real Remove definitly the file
// TODO : Set it in a trash ... For a while ...
if (property->erase() == false) {
throw std::runtime_error("Can not remove file ...");
throw etk::exception::RuntimeError("Can not remove file ...");
}
}
etk::Vector<etk::Vector<etk::String>> interpreteSQLRequest(const etk::String& _sqlLikeRequest) {
etk::Vector<etk::Vector<etk::String>> out;
if (_sqlLikeRequest != "*") {
etk::Vector<etk::String> listAnd = etk::split(_sqlLikeRequest, "AND");
etk::Vector<etk::String> listAnd = _sqlLikeRequest.split("AND");
APPL_INFO("Find list AND : ");
for (auto &it : listAnd) {
it = removeSpaceOutQuote(it);
etk::Vector<etk::String> elements = splitAction(it);
if (elements.size() != 3) {
APPL_ERROR("element : '" + it + "' have wrong spliting " << elements);
throw std::invalid_argument("element : \"" + it + "\" have wrong spliting");
throw etk::exception::InvalidArgument("element : \"" + it + "\" have wrong spliting");
}
if ( elements[1] != "=="
&& elements[1] != "!="
@ -291,7 +291,7 @@ namespace appl {
&& elements[1] != "<="
&& elements[1] != ">"
&& elements[1] != "<") {
throw std::invalid_argument("action invalid : '" + elements[1] + "' only availlable : [==,!=,<=,>=,<,>]");
throw etk::exception::InvalidArgument("action invalid : '" + elements[1] + "' only availlable : [==,!=,<=,>=,<,>]");
}
APPL_INFO(" - '" << elements[0] << "' action='" << elements[1] << "' with='" << elements[2] << "'");
out.pushBack(elements);
@ -350,7 +350,7 @@ namespace appl {
etk::Vector<uint32_t> getSQL(etk::String _sqlLikeRequest) override {
etk::Vector<uint32_t> out;
if (_sqlLikeRequest == "") {
throw std::invalid_argument("empty request");
throw etk::exception::InvalidArgument("empty request");
}
APPL_DEBUG("check : " << _sqlLikeRequest);
etk::Vector<etk::Vector<etk::String>> listAndParsed = interpreteSQLRequest(_sqlLikeRequest);
@ -372,7 +372,7 @@ namespace appl {
etk::Vector<etk::String> getMetadataValuesWhere(etk::String _keyName, etk::String _sqlLikeRequest) override {
etk::Vector<etk::String> out;
if (_sqlLikeRequest == "") {
throw std::invalid_argument("empty request");
throw etk::exception::InvalidArgument("empty request");
}
etk::Vector<etk::Vector<etk::String>> listAndParsed = interpreteSQLRequest(_sqlLikeRequest);
ethread::UniqueLock lock(g_mutex);
@ -410,7 +410,7 @@ namespace appl {
if (etk::FSNodeExist(_baseName + _mediaString + ".png") == true) {
return zeus::File::create(_baseName + _mediaString + ".png");
}
throw std::runtime_error("No cover availlable");
throw etk::exception::RuntimeError("No cover availlable");
}
void internalSetCover(const etk::String& _baseName, zeus::ActionNotification<etk::String>& _notifs, zeus::ProxyFile _cover, etk::String _mediaString) {
@ -425,11 +425,11 @@ namespace appl {
futType.wait();
if (etk::FSNodeGetSize(tmpFileName) == 0) {
APPL_ERROR("try to store an empty file");
throw std::runtime_error("file size == 0");
throw etk::exception::RuntimeError("file size == 0");
}
if (etk::FSNodeGetSize(tmpFileName) > 1024*1024) {
APPL_ERROR("try to store a Bigger file");
throw std::runtime_error("file size > 1Mo");
throw etk::exception::RuntimeError("file size > 1Mo");
}
if (futType.get() == "image/png") {
ethread::UniqueLock lock(g_mutex);
@ -441,7 +441,7 @@ namespace appl {
etk::FSNodeMove(tmpFileName, _baseName + _mediaString + ".jpg");
} else {
APPL_ERROR("try to store a file with the wrong format");
throw std::runtime_error("wrong foramt :" + futType.get() + " support only image/jpeg, image/png");
throw etk::exception::RuntimeError("wrong foramt :" + futType.get() + " support only image/jpeg, image/png");
}
}
@ -529,11 +529,11 @@ ETK_EXPORT_API void SERVICE_IO_peridic_call() {
return;
}
// try lock mutex:
if (g_mutex.try_lock() == false) {
if (g_mutex.tryLock() == false) {
return;
}
store_db();
g_mutex.unlock();
g_mutex.unLock();
}

View File

@ -10,6 +10,7 @@
#include <zeus/AbstractFunction.hpp>
#include <zeus/mineType.hpp>
#include <zeus/ActionNotification.hpp>
#include <etk/Exception.hpp>
namespace zeus {
@ -227,54 +228,9 @@ namespace zeus {
try {
// execute cmd:
zeus::executeClassCall(_interfaceClient, _obj, tmpClass, m_function);
} catch (const std::invalid_argument& eee) {
} catch (const etk::Exception& eee) {
_interfaceClient->addAsync([=](WebServer* _interface) {
_interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "INVALID-ARGUMENT", eee.what());
return true;
});
} catch (const std::domain_error& eee) {
_interfaceClient->addAsync([=](WebServer* _interface) {
_interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "DOMAIN-ERROR", eee.what());
return true;
});
} catch (const std::length_error& eee) {
_interfaceClient->addAsync([=](WebServer* _interface) {
_interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "LENGTH-ERROR", eee.what());
return true;
});
} catch (const std::out_of_range& eee) {
_interfaceClient->addAsync([=](WebServer* _interface) {
_interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "OUT-OF-RANGE", eee.what());
return true;
});
} catch (const std::range_error& eee) {
_interfaceClient->addAsync([=](WebServer* _interface) {
_interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "RANGE-ERROR", eee.what());
return true;
});
} catch (const std::overflow_error& eee) {
_interfaceClient->addAsync([=](WebServer* _interface) {
_interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "OVERFLOW-ERROR", eee.what());
return true;
});
} catch (const std::underflow_error& eee) {
_interfaceClient->addAsync([=](WebServer* _interface) {
_interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "UNDERFLOW-ERROR", eee.what());
return true;
});
} catch (const std::logic_error& eee) {
_interfaceClient->addAsync([=](WebServer* _interface) {
_interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "LOGIC-ERROR", eee.what());
return true;
});
} catch (const std::runtime_error& eee) {
_interfaceClient->addAsync([=](WebServer* _interface) {
_interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "RUNTIME-ERROR", eee.what());
return true;
});
} catch ( ... ) {
_interfaceClient->addAsync([=](WebServer* _interface) {
_interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "?-ERROR", "catch unknow error");
_interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), eee.which(), eee.what());
return true;
});
}
@ -361,54 +317,9 @@ namespace zeus {
try {
// execute cmd:
zeus::executeClassCall(_interfaceClient, _obj, tmpClass, m_function);
} catch (const std::invalid_argument& eee) {
} catch (const etk::Exception& eee) {
_interfaceClient->addAsync([=](WebServer* _interface) {
_interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "INVALID-ARGUMENT", eee.what());
return true;
});
} catch (const std::domain_error& eee) {
_interfaceClient->addAsync([=](WebServer* _interface) {
_interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "DOMAIN-ERROR", eee.what());
return true;
});
} catch (const std::length_error& eee) {
_interfaceClient->addAsync([=](WebServer* _interface) {
_interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "LENGTH-ERROR", eee.what());
return true;
});
} catch (const std::out_of_range& eee) {
_interfaceClient->addAsync([=](WebServer* _interface) {
_interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "OUT-OF-RANGE", eee.what());
return true;
});
} catch (const std::range_error& eee) {
_interfaceClient->addAsync([=](WebServer* _interface) {
_interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "RANGE-ERROR", eee.what());
return true;
});
} catch (const std::overflow_error& eee) {
_interfaceClient->addAsync([=](WebServer* _interface) {
_interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "OVERFLOW-ERROR", eee.what());
return true;
});
} catch (const std::underflow_error& eee) {
_interfaceClient->addAsync([=](WebServer* _interface) {
_interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "UNDERFLOW-ERROR", eee.what());
return true;
});
} catch (const std::logic_error& eee) {
_interfaceClient->addAsync([=](WebServer* _interface) {
_interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "LOGIC-ERROR", eee.what());
return true;
});
} catch (const std::runtime_error& eee) {
_interfaceClient->addAsync([=](WebServer* _interface) {
_interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "RUNTIME-ERROR", eee.what());
return true;
});
} catch ( ... ) {
_interfaceClient->addAsync([=](WebServer* _interface) {
_interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "?-ERROR", "catch unknow error");
_interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), eee.which(), eee.what());
return true;
});
}

View File

@ -8,6 +8,7 @@
#include <zeus/WebServer.hpp>
#include <zeus/debug.hpp>
#include <zeus/AbstractFunction.hpp>
#include <etk/Exception.hpp>
namespace zeus {
/**
@ -146,54 +147,9 @@ namespace zeus {
try {
// execute cmd:
zeus::executeCall(_interfaceClient, _obj, m_function);
} catch (const std::invalid_argument& eee) {
} catch (const etk::Exception& eee) {
_interfaceClient->addAsync([=](WebServer* _interface) {
_interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "INVALID-ARGUMENT", eee.what());
return true;
});
} catch (const std::domain_error& eee) {
_interfaceClient->addAsync([=](WebServer* _interface) {
_interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "DOMAIN-ERROR", eee.what());
return true;
});
} catch (const std::length_error& eee) {
_interfaceClient->addAsync([=](WebServer* _interface) {
_interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "LENGTH-ERROR", eee.what());
return true;
});
} catch (const std::out_of_range& eee) {
_interfaceClient->addAsync([=](WebServer* _interface) {
_interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "OUT-OF-RANGE", eee.what());
return true;
});
} catch (const std::range_error& eee) {
_interfaceClient->addAsync([=](WebServer* _interface) {
_interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "RANGE-ERROR", eee.what());
return true;
});
} catch (const std::overflow_error& eee) {
_interfaceClient->addAsync([=](WebServer* _interface) {
_interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "OVERFLOW-ERROR", eee.what());
return true;
});
} catch (const std::underflow_error& eee) {
_interfaceClient->addAsync([=](WebServer* _interface) {
_interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "UNDERFLOW-ERROR", eee.what());
return true;
});
} catch (const std::logic_error& eee) {
_interfaceClient->addAsync([=](WebServer* _interface) {
_interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "LOGIC-ERROR", eee.what());
return true;
});
} catch (const std::runtime_error& eee) {
_interfaceClient->addAsync([=](WebServer* _interface) {
_interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "RUNTIME-ERROR", eee.what());
return true;
});
} catch ( ... ) {
_interfaceClient->addAsync([=](WebServer* _interface) {
_interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), "?-ERROR", "catch unknow error");
_interface->answerError(_obj->getTransactionId(), _obj->getDestination(), _obj->getSource(), eee.which(), eee.what());
return true;
});
}

View File

@ -120,7 +120,7 @@ void zeus::Client::onClientData(ememory::SharedPtr<zeus::Message> _value) {
m_interfaceWeb->answerError(transactionId, _value->getDestination(), _value->getSource(), "TRANSFER-OWNERSHIP-ERROR");
return;
} else if (callFunction == "removeInterface") {
ZEUS_VERBOSE("Remove Object : " << callObj);
//ZEUS_VERBOSE("Remove Object : " << callObj);
m_interfaceWeb->interfaceRemoved(callObj->getParameter<etk::Vector<uint16_t>>(0));
return;
}
@ -143,7 +143,7 @@ bool zeus::Client::serviceAdd(const etk::String& _serviceName, factoryService _f
ZEUS_ERROR("Can not provide a new sevice ... '" << futValidate.getErrorType() << "' help:" << futValidate.getErrorHelp());
return false;
}
m_listServicesAvaillable.insert(etk::makePair(_serviceName, _factory));
m_listServicesAvaillable.add(_serviceName, _factory);
return true;
}

View File

@ -29,7 +29,7 @@ void zeus::FutureGroup::waitUntil(echrono::Steady _endTime) const {
allIsFinished = false;
}
}
ethread::sleepMilliSeconds(echrono::milliseconds(10));
ethread::sleepMilliSeconds(10);
}
if (allIsFinished == false) {
ZEUS_WARNING("Group Wait timeout ...");

View File

@ -245,7 +245,7 @@ bool zeus::Promise::isFinished() const {
void zeus::Promise::wait() const {
while (isFinished() == false) {
// TODO : Do it better ... like messaging/mutex_locked ...
ethread::sleepMilliSeconds(echrono::milliseconds(10));
ethread::sleepMilliSeconds(10);
}
}
@ -254,7 +254,7 @@ void zeus::Promise::waitFor(echrono::Duration _delta) const {
while ( echrono::Steady::now() - start < _delta
&& isFinished() == false) {
// TODO : Do it better ... like messaging/mutex_locked ...
ethread::sleepMilliSeconds(echrono::milliseconds(10));
ethread::sleepMilliSeconds(10);
}
if (isFinished() == false) {
ZEUS_WARNING("Wait timeout ... " << _delta);
@ -266,7 +266,7 @@ void zeus::Promise::waitUntil(echrono::Steady _endTime) const {
while ( echrono::Steady::now() < _endTime
&& isFinished() == false) {
// TODO : Do it better ... like messaging/mutex_locked ...
ethread::sleepMilliSeconds(echrono::milliseconds(10));
ethread::sleepMilliSeconds(10);
}
if (isFinished() == false) {
ZEUS_WARNING("Wait timeout ..." << _endTime);

View File

@ -5,6 +5,7 @@
*/
#pragma once
#include <etk/types.hpp>
#include <etk/Vector.hpp>
namespace zeus {

View File

@ -177,7 +177,7 @@ bool zeus::WebServer::isActive() const {
void zeus::WebServer::connect(bool _async){
ZEUS_DEBUG("connect [START]");
m_threadAsyncRunning = true;
m_threadAsync = new ethread::Thread([&](void *){ this->threadAsyncCallback();}, nullptr);
m_threadAsync = new ethread::Thread([&](){ threadAsyncCallback();}, "webServerAsync");
if (m_threadAsync == nullptr) {
m_threadAsyncRunning = false;
ZEUS_ERROR("creating async sender thread!");
@ -228,7 +228,7 @@ class SendAsyncBinary {
}
// TODO : Use shared ptr instaed of pointer ....
bool operator() (zeus::WebServer* _interface){
bool operator() (zeus::WebServer* _interface) {
auto it = m_async.begin();
while (it != m_async.end()) {
bool ret = (*it)(_interface, m_source, m_destination, m_transactionId, m_partId);
@ -273,7 +273,10 @@ int32_t zeus::WebServer::writeBinary(ememory::SharedPtr<zeus::Message> _obj) {
ZEUS_LOG_INPUT_OUTPUT("Send :" << _obj);
if (_obj->writeOn(m_connection) == true) {
if (_obj->haveAsync() == true) {
addAsync(SendAsyncBinary(_obj->getTransactionId(), _obj->getSource(), _obj->getDestination(), etk::move(_obj->moveAsync())));
addAsync(SendAsyncBinary(_obj->getTransactionId(),
_obj->getSource(),
_obj->getDestination(),
etk::move(_obj->moveAsync())));
}
return 1;
}
@ -625,7 +628,7 @@ void zeus::WebServer::threadAsyncCallback() {
}
auto it = m_threadAsyncList.begin();
while (it != m_threadAsyncList.end()) {
ZEUS_INFO(" send DATA ... ");
ZEUS_VERBOSE(" send DATA ... ");
bool ret = (*it)(this);
if (ret == true) {
// Remove it ...

View File

@ -64,7 +64,7 @@ void zeus::Message::clear() {
m_header.flags = ZEUS_BUFFER_FLAG_FINISH;
}
etk::Stream& zeus::operator <<(etk::Stream& _os, ememory::SharedPtr<zeus::Message> _obj) {
etk::Stream& zeus::operator <<(etk::Stream& _os, const ememory::SharedPtr<zeus::Message>& _obj) {
_os << "zeus::Message: ";
if (_obj == nullptr) {
_os << "nullptr";

View File

@ -313,7 +313,7 @@ namespace zeus {
* @value[in] _obj Message to display
* @return a reference of the stream
*/
etk::Stream& operator <<(etk::Stream& _os, ememory::SharedPtr<zeus::Message> _obj);
etk::Stream& operator <<(etk::Stream& _os, const ememory::SharedPtr<zeus::Message>& _obj);
namespace message {
// internal:

View File

@ -57,7 +57,7 @@ void zeus::message::Parameter::composeWith(const uint8_t* _buffer, uint32_t _len
data.resize(sizeParam);
memcpy(&data[0], &_buffer[offset], data.size() * sizeof(uint8_t));
offset += data.size() * sizeof(uint8_t);
m_parameter[nbParameters].second = data;
etk::swap(m_parameter[nbParameters].second, data);
nbParameters++;
}
}

View File

@ -6,154 +6,153 @@
#include <zeus/mineType.hpp>
#include <zeus/debug.hpp>
#include <etk/Pair.hpp>
static etk::Vector<etk::Pair<etk::String, etk::String>> mineList = {
/* Video files */
{ "webm", "video/webm"},
{ "asf", "video/x-ms-asf"},
{ "avi", "video/avi"},
{ "avc", "video/avi"},
{ "dv", "video/x-dv"},
{ "divx", "video/avi"},
{ "wmv", "video/x-ms-wmv"},
{ "mjpg", "video/x-motion-jpeg"},
{ "mjpeg", "video/x-motion-jpeg"},
{ "mpeg", "video/mpeg"},
{ "mpg", "video/mpeg"},
{ "mpe", "video/mpeg"},
{ "mp2p", "video/mp2p"},
{ "vob", "video/mp2p"},
{ "mp2t", "video/mp2t"},
{ "m1v", "video/mpeg"},
{ "m2v", "video/mpeg2"},
{ "mpg2", "video/mpeg2"},
{ "mpeg2", "video/mpeg2"},
{ "m4v", "video/mp4"},
{ "m4p", "video/mp4"},
{ "mp4ps", "video/x-nerodigital-ps"},
{ "ts", "video/mpeg2-ts"},
{ "ogm", "video/mpeg"},
{ "mkv", "video/x-matroska"},
{ "rmvb", "video/mpeg"},
{ "mov", "video/quicktime"},
{ "hdmov", "video/quicktime"},
{ "qt", "video/quicktime"},
/* Audio files */
{ "weba", "audio/webm"},
{ "3gp", "audio/3gpp"},
{ "aac", "audio/x-aac"},
{ "ac3", "audio/x-ac3"},
{ "aif", "audio/aiff"},
{ "aiff", "audio/aiff"},
{ "at3p", "audio/x-atrac3"},
{ "au", "audio/basic"},
{ "snd", "audio/basic"},
{ "dts", "audio/x-dts"},
{ "rmi", "audio/midi"},
{ "mid", "audio/midi"},
{ "mp1", "audio/mp1"},
{ "mp2", "audio/mp2"},
{ "mp3", "audio/mpeg"},
{ "mp4", "audio/mp4"},
{ "m4a", "audio/mp4"},
{ "mka", "audio/x-matroska"},
{ "ogg", "audio/x-ogg"},
{ "wav", "audio/wav"},
{ "pcm", "audio/l16"},
{ "lpcm", "audio/l16"},
{ "l16", "audio/l16"},
{ "wma", "audio/x-ms-wma"},
{ "mka", "audio/x-matroska"},
{ "ra", "audio/x-pn-realaudio"},
{ "rm", "audio/x-pn-realaudio"},
{ "ram", "audio/x-pn-realaudio"},
{ "flac", "audio/x-flac"},
/* Images files */
{ "webp", "image/webp"},
{ "bmp", "image/bmp"},
{ "ico", "image/x-icon"},
{ "gif", "image/gif"},
{ "jpg", "image/jpeg"},
{ "jpeg", "image/jpeg"},
{ "jpe", "image/jpeg"},
{ "pcd", "image/x-ms-bmp"},
{ "png", "image/png"},
{ "pnm", "image/x-portable-anymap"},
{ "ppm", "image/x-portable-pixmap"},
{ "qti", "image/x-quicktime"},
{ "qtf", "image/x-quicktime"},
{ "qtif", "image/x-quicktime"},
{ "tif", "image/tiff"},
{ "tiff", "image/tiff"},
/* Playlist files */
{ "pls", "audio/x-scpls"},
{ "m3u", "audio/mpegurl"},
{ "asx", "video/x-ms-asf"},
/* Subtitle Text files */
{ "srt", "text/srt"}, /* SubRip */
{ "ssa", "text/ssa"}, /* SubStation Alpha */
{ "stl", "text/srt"}, /* Spruce */
{ "psb", "text/psb"}, /* PowerDivX */
{ "pjs", "text/pjs"}, /* Phoenix Japanim */
{ "sub", "text/sub"}, /* MicroDVD */
{ "idx", "text/idx"}, /* VOBsub */
{ "dks", "text/dks"}, /* DKS */
{ "scr", "text/scr"}, /* MACsub */
{ "tts", "text/tts"}, /* TurboTitler */
{ "vsf", "text/vsf"}, /* ViPlay */
{ "zeg", "text/zeg"}, /* ZeroG */
{ "mpl", "text/mpl"}, /* MPL */
/* Miscellaneous text files */
{ "bup", "text/bup"}, /* DVD backup */
{ "ifo", "text/ifo"}, /* DVD information */
/* Some Raw format for images */
{ "yuv422", "image/x-raw/yuv422"},
{ "yuv420", "image/x-raw/yuv420"},
{ "yuv411", "image/x-raw/yuv411"},
{ "rgb", "image/x-raw/r8g8b8"},
{ "rgba", "image/x-raw/r8g8b8a8"},
{ "js", "application/javascript"},
{ "raw", "application/octet-stream"},
{ "ogg", "application/ogg"},
{ "pdf", "application/pdf"},
{ "xhtml", "application/xhtml+xml"},
{ "flw", "application/x-shockwave-flash"},
{ "json", "application/json"},
{ "xml", "application/xml"},
{ "zip", "application/zip"},
{ "gz", "application/gzip"},
{ "rar", "application/rar"},
{ "css", "text/css"},
{ "csv", "text/csv"},
{ "html", "text/html"},
{ "js", "text/javascript"}, // DEPRECATED application/javascript.
{ "txt", "text/plain"},
{ "xml", "text/xml"},
{ "json", "text/json"},
{ "yml", "text/yml"},
{ "c", "code/c"},
{ "h", "header/c"},
{ "cpp", "code/c++"},
{ "hpp", "header/c++"},
{ "c#", "code/c#"},
{ "py", "code/python"},
{ "java", "code/java"},
{ "js", "code/javascript"},
static etk::Vector<etk::Pair<etk::String, etk::String>> getMimeList() {
static etk::Vector<etk::Pair<etk::String, etk::String>> mineList;
if (mineList.size() != 0) {
return mineList;
}
/* Video files */
mineList.pushBack(etk::makePair("webm", "video/webm"));
mineList.pushBack(etk::makePair("asf", "video/x-ms-asf"));
mineList.pushBack(etk::makePair("avi", "video/avi"));
mineList.pushBack(etk::makePair("avc", "video/avi"));
mineList.pushBack(etk::makePair("dv", "video/x-dv"));
mineList.pushBack(etk::makePair("divx", "video/avi"));
mineList.pushBack(etk::makePair("wmv", "video/x-ms-wmv"));
mineList.pushBack(etk::makePair("mjpg", "video/x-motion-jpeg"));
mineList.pushBack(etk::makePair("mjpeg", "video/x-motion-jpeg"));
mineList.pushBack(etk::makePair("mpeg", "video/mpeg"));
mineList.pushBack(etk::makePair("mpg", "video/mpeg"));
mineList.pushBack(etk::makePair("mpe", "video/mpeg"));
mineList.pushBack(etk::makePair("mp2p", "video/mp2p"));
mineList.pushBack(etk::makePair("vob", "video/mp2p"));
mineList.pushBack(etk::makePair("mp2t", "video/mp2t"));
mineList.pushBack(etk::makePair("m1v", "video/mpeg"));
mineList.pushBack(etk::makePair("m2v", "video/mpeg2"));
mineList.pushBack(etk::makePair("mpg2", "video/mpeg2"));
mineList.pushBack(etk::makePair("mpeg2", "video/mpeg2"));
mineList.pushBack(etk::makePair("m4v", "video/mp4"));
mineList.pushBack(etk::makePair("m4p", "video/mp4"));
mineList.pushBack(etk::makePair("mp4ps", "video/x-nerodigital-ps"));
mineList.pushBack(etk::makePair("ts", "video/mpeg2-ts"));
mineList.pushBack(etk::makePair("ogm", "video/mpeg"));
mineList.pushBack(etk::makePair("mkv", "video/x-matroska"));
mineList.pushBack(etk::makePair("rmvb", "video/mpeg"));
mineList.pushBack(etk::makePair("mov", "video/quicktime"));
mineList.pushBack(etk::makePair("hdmov", "video/quicktime"));
mineList.pushBack(etk::makePair("qt", "video/quicktime"));
/* Audio files */
mineList.pushBack(etk::makePair("weba", "audio/webm"));
mineList.pushBack(etk::makePair("3gp", "audio/3gpp"));
mineList.pushBack(etk::makePair("aac", "audio/x-aac"));
mineList.pushBack(etk::makePair("ac3", "audio/x-ac3"));
mineList.pushBack(etk::makePair("aif", "audio/aiff"));
mineList.pushBack(etk::makePair("aiff", "audio/aiff"));
mineList.pushBack(etk::makePair("at3p", "audio/x-atrac3"));
mineList.pushBack(etk::makePair("au", "audio/basic"));
mineList.pushBack(etk::makePair("snd", "audio/basic"));
mineList.pushBack(etk::makePair("dts", "audio/x-dts"));
mineList.pushBack(etk::makePair("rmi", "audio/midi"));
mineList.pushBack(etk::makePair("mid", "audio/midi"));
mineList.pushBack(etk::makePair("mp1", "audio/mp1"));
mineList.pushBack(etk::makePair("mp2", "audio/mp2"));
mineList.pushBack(etk::makePair("mp3", "audio/mpeg"));
mineList.pushBack(etk::makePair("mp4", "audio/mp4"));
mineList.pushBack(etk::makePair("m4a", "audio/mp4"));
mineList.pushBack(etk::makePair("mka", "audio/x-matroska"));
mineList.pushBack(etk::makePair("ogg", "audio/x-ogg"));
mineList.pushBack(etk::makePair("wav", "audio/wav"));
mineList.pushBack(etk::makePair("pcm", "audio/l16"));
mineList.pushBack(etk::makePair("lpcm", "audio/l16"));
mineList.pushBack(etk::makePair("l16", "audio/l16"));
mineList.pushBack(etk::makePair("wma", "audio/x-ms-wma"));
mineList.pushBack(etk::makePair("mka", "audio/x-matroska"));
mineList.pushBack(etk::makePair("ra", "audio/x-pn-realaudio"));
mineList.pushBack(etk::makePair("rm", "audio/x-pn-realaudio"));
mineList.pushBack(etk::makePair("ram", "audio/x-pn-realaudio"));
mineList.pushBack(etk::makePair("flac", "audio/x-flac"));
/* Images files */
mineList.pushBack(etk::makePair("webp", "image/webp"));
mineList.pushBack(etk::makePair("bmp", "image/bmp"));
mineList.pushBack(etk::makePair("ico", "image/x-icon"));
mineList.pushBack(etk::makePair("gif", "image/gif"));
mineList.pushBack(etk::makePair("jpg", "image/jpeg"));
mineList.pushBack(etk::makePair("jpeg", "image/jpeg"));
mineList.pushBack(etk::makePair("jpe", "image/jpeg"));
mineList.pushBack(etk::makePair("pcd", "image/x-ms-bmp"));
mineList.pushBack(etk::makePair("png", "image/png"));
mineList.pushBack(etk::makePair("pnm", "image/x-portable-anymap"));
mineList.pushBack(etk::makePair("ppm", "image/x-portable-pixmap"));
mineList.pushBack(etk::makePair("qti", "image/x-quicktime"));
mineList.pushBack(etk::makePair("qtf", "image/x-quicktime"));
mineList.pushBack(etk::makePair("qtif", "image/x-quicktime"));
mineList.pushBack(etk::makePair("tif", "image/tiff"));
mineList.pushBack(etk::makePair("tiff", "image/tiff"));
/* Playlist files */
mineList.pushBack(etk::makePair("pls", "audio/x-scpls"));
mineList.pushBack(etk::makePair("m3u", "audio/mpegurl"));
mineList.pushBack(etk::makePair("asx", "video/x-ms-asf"));
/* Subtitle Text files */
mineList.pushBack(etk::makePair("srt", "text/srt")); /* SubRip */
mineList.pushBack(etk::makePair("ssa", "text/ssa")); /* SubStation Alpha */
mineList.pushBack(etk::makePair("stl", "text/srt")); /* Spruce */
mineList.pushBack(etk::makePair("psb", "text/psb")); /* PowerDivX */
mineList.pushBack(etk::makePair("pjs", "text/pjs")); /* Phoenix Japanim */
mineList.pushBack(etk::makePair("sub", "text/sub")); /* MicroDVD */
mineList.pushBack(etk::makePair("idx", "text/idx")); /* VOBsub */
mineList.pushBack(etk::makePair("dks", "text/dks")); /* DKS */
mineList.pushBack(etk::makePair("scr", "text/scr")); /* MACsub */
mineList.pushBack(etk::makePair("tts", "text/tts")); /* TurboTitler */
mineList.pushBack(etk::makePair("vsf", "text/vsf")); /* ViPlay */
mineList.pushBack(etk::makePair("zeg", "text/zeg")); /* ZeroG */
mineList.pushBack(etk::makePair("mpl", "text/mpl")); /* MPL */
/* Miscellaneous text files */
mineList.pushBack(etk::makePair("bup", "text/bup")); /* DVD backup */
mineList.pushBack(etk::makePair("ifo", "text/ifo")); /* DVD information */
/* Some Raw format for images */
mineList.pushBack(etk::makePair("yuv422", "image/x-raw/yuv422"));
mineList.pushBack(etk::makePair("yuv420", "image/x-raw/yuv420"));
mineList.pushBack(etk::makePair("yuv411", "image/x-raw/yuv411"));
mineList.pushBack(etk::makePair("rgb", "image/x-raw/r8g8b8"));
mineList.pushBack(etk::makePair("rgba", "image/x-raw/r8g8b8a8"));
mineList.pushBack(etk::makePair("js", "application/javascript"));
mineList.pushBack(etk::makePair("raw", "application/octet-stream"));
mineList.pushBack(etk::makePair("ogg", "application/ogg"));
mineList.pushBack(etk::makePair("pdf", "application/pdf"));
mineList.pushBack(etk::makePair("xhtml", "application/xhtml+xml"));
mineList.pushBack(etk::makePair("flw", "application/x-shockwave-flash"));
mineList.pushBack(etk::makePair("json", "application/json"));
mineList.pushBack(etk::makePair("xml", "application/xml"));
mineList.pushBack(etk::makePair("zip", "application/zip"));
mineList.pushBack(etk::makePair("gz", "application/gzip"));
mineList.pushBack(etk::makePair("rar", "application/rar"));
mineList.pushBack(etk::makePair("css", "text/css"));
mineList.pushBack(etk::makePair("csv", "text/csv"));
mineList.pushBack(etk::makePair("html", "text/html"));
mineList.pushBack(etk::makePair("js", "text/javascript")); // DEPRECATED application/javascript.
mineList.pushBack(etk::makePair("txt", "text/plain"));
mineList.pushBack(etk::makePair("xml", "text/xml"));
mineList.pushBack(etk::makePair("json", "text/json"));
mineList.pushBack(etk::makePair("yml", "text/yml"));
mineList.pushBack(etk::makePair("c", "code/c"));
mineList.pushBack(etk::makePair("h", "header/c"));
mineList.pushBack(etk::makePair("cpp", "code/c++"));
mineList.pushBack(etk::makePair("hpp", "header/c++"));
mineList.pushBack(etk::makePair("c#", "code/c#"));
mineList.pushBack(etk::makePair("py", "code/python"));
mineList.pushBack(etk::makePair("java", "code/java"));
mineList.pushBack(etk::makePair("js", "code/javascript"));
return mineList;
};
etk::String zeus::getMineType(etk::String _extention) {
_extention = etk::tolower(_extention);
for (auto &it : mineList) {
for (auto &it : getMimeList()) {
if (it.first == _extention) {
return it.second;
}
@ -166,7 +165,7 @@ etk::String zeus::getMineType(etk::String _extention) {
etk::String zeus::getExtention(etk::String _mineType) {
_mineType = etk::tolower(_mineType);
for (auto &it : mineList) {
for (auto &it : getMimeList()) {
if (it.second == _mineType) {
return it.first;
}

View File

@ -9,6 +9,7 @@
#include <zeus/mineType.hpp>
#include <algue/sha512.hpp>
#include <etk/os/FSNode.hpp>
#include <etk/Exception.hpp>
#include "debug.hpp"
@ -92,22 +93,22 @@ etk::String zeus::FileImpl::getMineType() {
zeus::Raw zeus::FileImpl::getPart(uint64_t _start, uint64_t _stop) {
if ((_stop - _start) > 25*1024*1024) {
ZEUS_ERROR("REQUEST more that 25 Mo in a part file ...");
throw std::invalid_argument("REQUEST more that 25 Mo in a part file ..." + etk::toString(_stop - _start) + " Bytes");
throw etk::exception::InvalidArgument("REQUEST more that 25 Mo in a part file ..." + etk::toString(_stop - _start) + " Bytes");
return zeus::Raw();
}
if (_start >= m_size) {
throw std::invalid_argument("REQUEST start position out of file size" + etk::toString(_start) + " > " + etk::toString(m_size));
throw etk::exception::InvalidArgument("REQUEST start position out of file size" + etk::toString(_start) + " > " + etk::toString(m_size));
}
if (m_node.fileIsOpen() == false) {
m_node.fileOpenRead();
}
m_gettedData += (_stop - _start);
//ZEUS_PRINT("Reading file : " << m_gettedData << "/" << m_size << " ==> " << float(m_gettedData)/float(m_size)*100.0f << "%");
std::cout << "Reading file : " << m_gettedData << "/" << m_size << " ==> " << float(m_gettedData)/float(m_size)*100.0f << "% \r";
printf("Reading file : %d/%d ==> %f \r", int(m_gettedData), int(m_size), float(m_gettedData)/float(m_size)*100.0f);
zeus::Raw tmp(_stop - _start);
if (m_node.fileSeek(_start, etk::seekNode_start) == false) {
ZEUS_ERROR("REQUEST seek error ...");
throw std::runtime_error("Seek in the file error");
throw etk::exception::RuntimeError("Seek in the file error");
return zeus::Raw();
}
int64_t sizeCopy = m_node.fileRead(tmp.writeData(), 1, _stop-_start);
@ -142,7 +143,7 @@ etk::String zeus::storeInFileNotify(zeus::ProxyFile _file, etk::String _filename
auto futData = _file.getPart(offset, offset + nbElement);
futData.wait();
if (futData.hasError() == true) {
throw std::runtime_error("Error when loading data");
throw etk::exception::RuntimeError("Error when loading data");
}
zeus::Raw buffer = futData.get();
shaCtx.update(buffer.data(), buffer.size());
@ -159,7 +160,7 @@ etk::String zeus::storeInFileNotify(zeus::ProxyFile _file, etk::String _filename
if (sha512String != futSha.get()) {
ZEUS_ERROR("get wrong Sha512 local : '" << sha512String << "'");
ZEUS_ERROR("get wrong Sha512 remote: '" << futSha.get() << "'");
throw std::runtime_error("SHA-512 error check");
throw etk::exception::RuntimeError("SHA-512 error check");
}
return sha512String;
}
@ -184,7 +185,7 @@ etk::Vector<uint8_t> zeus::storeInMemory(zeus::ProxyFile _file) {
auto futData = _file.getPart(offset, offset + nbElement);
futData.wait();
if (futData.hasError() == true) {
throw std::runtime_error("Error when loading data");
throw etk::exception::RuntimeError("Error when loading data");
}
zeus::Raw buffer = futData.get();
shaCtx.update(buffer.data(), buffer.size());

View File

@ -39,7 +39,8 @@ zeus::MediaImpl::MediaImpl(const etk::String& _basePath, ejson::Object _property
for (auto itValue = tmpObj.begin();
itValue != tmpObj.end();
++itValue) {
m_metadata.insert(etk::makePair(itValue.getKey(), (*itValue).toString().get()));
ZEUS_INFO(" Add metadata: " << itValue.getKey() << ":" << (*itValue).toString().get() << " " << *itValue);
m_metadata.add(itValue.getKey(), (*itValue).toString().get());
}
}
}
@ -76,7 +77,7 @@ etk::String zeus::MediaImpl::getMineType() {
etk::String zeus::MediaImpl::getSha512() {
try {
return getMetadata("sha512");
} catch (std::invalid_argument _eee) {
} catch (etk::exception::InvalidArgument _eee) {
// Nothing to do ...
}
etk::String sha512;
@ -103,7 +104,7 @@ etk::String zeus::MediaImpl::getDecoratedName() {
if (out != "") {
return out;
}
} catch (std::invalid_argument _eee) {
} catch (etk::exception::InvalidArgument _eee) {
// Nothing to do ...
}
// Store the metadat to not calculated it all the time ...
@ -124,32 +125,28 @@ ememory::SharedPtr<zeus::File> zeus::MediaImpl::getFile() {
etk::Vector<etk::String> zeus::MediaImpl::getMetadataKeys() {
etk::Vector<etk::String> out;
for (auto &it : m_metadata) {
// TODO: add filter ...
out.pushBack(it.first);
}
return out;
}
etk::String zeus::MediaImpl::getMetadata(etk::String _key) {
ZEUS_WARNING("Get metadata: " << _key);
auto it = m_metadata.find(_key);
if (it != m_metadata.end()) {
ZEUS_WARNING(" Value='" << it->second << "'");
return it->second;
}
throw std::invalid_argument("KEY '" + _key + "' Does not exist");
throw etk::exception::InvalidArgument("KEY '" + _key + "' Does not exist");
}
void zeus::MediaImpl::setMetadata(etk::String _key, etk::String _value) {
ZEUS_INFO("metadataSetKey: '" << _key << "' value='" << _value << "'");
auto it = m_metadata.find(_key);
if (it != m_metadata.end()) {
if (_value == "") {
m_metadata.erase(it);
} else if (it->second == _value) {
return;
} else {
it->second = _value;
}
if (_value == "") {
m_metadata.erase(_key);
} else {
m_metadata.insert(etk::makePair(_key, _value));
m_metadata.set(_key, _value);
}
// hook to remove some case that does not call the callback ==> can change many times ...
if ( _key == "sha512"