[DEV] continue integration of service-picture

This commit is contained in:
Edouard DUPIN 2016-12-13 22:58:01 +01:00
parent 3e8524feb2
commit 325c740290
20 changed files with 350 additions and 264 deletions

View File

@ -506,7 +506,7 @@ class ServiceDefinition:
out += " " + namespace + "register" + self.name[-1] + "(*obj);\n"
out += " obj->addRemote(getDestination());\n"
out += " m_iface->addWebObj(obj);\n"
out += " ZEUS_INFO(\"Create object ID : \" << idObj);\n"
out += " ZEUS_DEBUG(\"Create object ID : \" << idObj);\n"
out += " fullId = (uint32_t(id)<<16)+idObj;\n"
out += " }\n"
# return Object ID and interface adress
@ -616,9 +616,9 @@ class ServiceDefinition:
space += " "
out += space + 'ZEUS_INFO("===========================================================");\n';
out += space + 'ZEUS_INFO("== Instanciate service: ' + self.name[-1] + '");\n';
out += space + 'ZEUS_INFO("===========================================================");\n';
out += space + 'ZEUS_VERBOSE("===========================================================");\n';
out += space + 'ZEUS_VERBOSE("== Instanciate service: ' + self.name[-1] + '");\n';
out += space + 'ZEUS_VERBOSE("===========================================================");\n';
#out += space + '_serviceInterface.propertyNameService.set("' + self.name[-1].lower() + '");\n'
if self.brief != "":
out += space + '_interface.setDescription("' + self.brief + '");\n';
@ -663,9 +663,9 @@ class ServiceDefinition:
out += space + 'func->setReturn("' + elem.return_brief + '");\n'
space = space[:-1]
out += space + '}\n'
out += space + 'ZEUS_INFO("===========================================================");\n';
out += space + 'ZEUS_INFO("== Instanciate service: ' + self.name[-1] + ' [DONE]");\n';
out += space + 'ZEUS_INFO("===========================================================");\n';
out += space + 'ZEUS_VERBOSE("===========================================================");\n';
out += space + 'ZEUS_VERBOSE("== Instanciate service: ' + self.name[-1] + ' [DONE]");\n';
out += space + 'ZEUS_VERBOSE("===========================================================");\n';
out += "}\n"
out += "\n"

View File

@ -21,6 +21,49 @@
#include <zeus/ObjectRemote.hpp>
#include <echrono/Steady.hpp>
void installPath(zeus::service::ProxyPicture& _srv, std::string _path, uint32_t _albumID) {
etk::FSNode node(_path);
APPL_INFO("Parse : '" << _path << "'");
std::vector<std::string> listSubPath = node.folderGetSub(true, false, "*");
for (auto &itPath : listSubPath) {
APPL_INFO("Create Album : '" << itPath << "'");
std::string albumName = etk::split(itPath, '/').back();
uint32_t albumId = _srv.albumCreate(albumName).wait().get();
_srv.albumDescriptionSet(albumId, itPath).wait();
if (_albumID != 0) {
_srv.albumParentSet(albumId, _albumID).wait();
}
installPath(_srv, itPath, albumId);
}
std::vector<std::string> listSubFile = node.folderGetSub(false, true, "*");
for (auto &itFile : listSubFile) {
APPL_INFO("Add media : '" << itFile << "' in " << _albumID);
std::string extention = etk::tolower(std::string(itFile.begin()+itFile.size() -3, itFile.end()));
if ( extention == "jpg"
|| extention == "png"
|| extention == "gif"
|| extention == "bmp"
|| extention == "avi"
|| extention == "ogg"
|| extention == "mp3"
|| extention == "mkv"
|| extention == "mka"
|| extention == "tga"
|| extention == "mp2") {
uint32_t mediaId = _srv.mediaAdd(zeus::File::create(itFile)).wait().get();
if (mediaId == 0) {
APPL_ERROR("Get media ID = 0 With no error");
}
if (_albumID != 0) {
_srv.albumMediaAdd(_albumID, mediaId).wait();
}
} else {
APPL_ERROR("Sot send file : " << itFile << " Not manage extention...");
}
}
}
int main(int _argc, const char *_argv[]) {
etk::init(_argc, _argv);
@ -145,49 +188,68 @@ int main(int _argc, const char *_argv[]) {
if (true) {
zeus::service::ProxyPicture remoteServicePicture = client1.getService("picture");
if (remoteServicePicture.exist() == true) {
#if 1
zeus::Future<std::vector<std::string>> retCall = remoteServicePicture.getAlbums().wait();
APPL_INFO(" album list: ");
for (auto &it : retCall.get()) {
zeus::Future<uint32_t> retCount = remoteServicePicture.getAlbumCount(it).wait();
if (retCount.get() != 0) {
APPL_INFO(" - " << it << " / " << retCount.get() << " images");
zeus::Future<std::vector<std::string>> retListImage = remoteServicePicture.getAlbumListPicture(it).wait();
for (auto &it3 : retListImage.get()) {
APPL_INFO(" - " << it3);
}
} else {
APPL_INFO(" - " << it);
}
zeus::Future<std::vector<std::string>> retCall2 = remoteServicePicture.getSubAlbums(it).wait();
for (auto &it2 : retCall2.get()) {
zeus::Future<uint32_t> retCount2 = remoteServicePicture.getAlbumCount(it2).wait();
if (retCount2.get() != 0) {
APPL_INFO(" - " << it2 << " / " << retCount2.get() << " images");
zeus::Future<std::vector<std::string>> retListImage = remoteServicePicture.getAlbumListPicture(it2).wait();
for (auto &it3 : retListImage.get()) {
// Send a full path:
installPath(remoteServicePicture, "testPhoto", 0);
} else {
APPL_ERROR("Can not get service Picture ...");
}
}
if (true) {
zeus::service::ProxyPicture remoteServicePicture = client1.getService("picture");
if (remoteServicePicture.exist() == true) {
zeus::Future<std::vector<uint32_t>> retCall = remoteServicePicture.albumGetList().wait();
if (retCall.hasError() == true) {
APPL_INFO(" Get an error when getting list of albums ...");
} else {
APPL_INFO(" album list: ");
for (auto &it : retCall.get()) {
std::string name = remoteServicePicture.albumNameGet(it).wait().get();
std::string desc = remoteServicePicture.albumDescriptionGet(it).wait().get();
uint32_t retCount = remoteServicePicture.albumMediaCount(it).wait().get();
uint32_t parentId = remoteServicePicture.albumParentGet(it).wait().get();
if (retCount != 0) {
APPL_INFO(" - [" << it << "] '" << name << "' DESC=" << desc);
if (parentId != 0) {
APPL_INFO(" PARENT : " << parentId);
}
APPL_INFO(" " << retCount << " Medias");
std::vector<uint32_t> retListImage = remoteServicePicture.albumMediaIdGet(it, 0, retCount).wait().get();
for (auto &it3 : retListImage) {
APPL_INFO(" - " << it3);
// TODO : This is really bad : Do it better ...
zeus::Future<ememory::SharedPtr<zeus::ObjectRemoteBase>> retListImage = remoteServicePicture.getAlbumListPicture(it3).wait();
zeus::ProxyFile tmpFile = zeus::ObjectRemote(retListImage.get());
APPL_INFO(" mine-type: " << tmpFile.getMineType().wait().get());
APPL_INFO(" size: " << tmpFile.getSize().wait().get());
APPL_INFO(" receive in =" << int64_t(retListImage.getTransmitionTime().count()/1000)/1000.0 << " ms");
std::string tmpFileName = std::string("./out/") + it + "_" + it2 + "_" + it3 + "." + zeus::getExtention(tmpFile.getMineType().wait().get());
APPL_INFO(" store in: " << tmpFileName);
/*
etk::FSNode node(tmpFileName);
node.fileOpenWrite();
node.fileWrite(&tmpFile.getData()[0], 1, tmpFile.getData().size());
node.fileClose();
*/
}
} else {
APPL_INFO(" - " << it2);
APPL_INFO(" - " << it);
}
#if 0
std::vector<std::string> retCall2 = remoteServicePicture.getSubAlbums(it).wait().get();
for (auto &it2 : retCall2) {
uint32_t retCount2 = remoteServicePicture.getAlbumCount(it2).wait().get();
if (retCount2 != 0) {
APPL_INFO(" - " << it2 << " / " << retCount2.get() << " images");
std::vector<std::string> retListImage = remoteServicePicture.getAlbumListPicture(it2).wait().get();
for (auto &it3 : retListImage) {
APPL_INFO(" - " << it3);
zeus::ProxyFile tmpFile = zeus::ObjectRemote(remoteServicePicture.getAlbumListPicture(it3).wait().get());
APPL_INFO(" mine-type: " << tmpFile.getMineType().wait().get());
APPL_INFO(" size: " << tmpFile.getSize().wait().get());
APPL_INFO(" receive in =" << int64_t(retListImage.getTransmitionTime().count()/1000)/1000.0 << " ms");
std::string tmpFileName = std::string("./out/") + it + "_" + it2 + "_" + it3 + "." + zeus::getExtention(tmpFile.getMineType().wait().get());
APPL_INFO(" store in: " << tmpFileName);
/*
etk::FSNode node(tmpFileName);
node.fileOpenWrite();
node.fileWrite(&tmpFile.getData()[0], 1, tmpFile.getData().size());
node.fileClose();
*/
}
} else {
APPL_INFO(" - " << it2);
}
}
#endif
}
}
#endif
#if 1
echrono::Steady start = echrono::Steady::now();
//ememory::SharedPtr<zeus::File> tmp = zeus::File::create("./tmpResult.bmp");
@ -195,10 +257,14 @@ int main(int _argc, const char *_argv[]) {
//ememory::SharedPtr<zeus::File> tmp = zeus::File::create("./test_log.txt");
int32_t size = tmp->getSize();
auto retSendImage = remoteServicePicture.mediaAdd(tmp).wait();
echrono::Steady stop = echrono::Steady::now();
APPL_WARNING(" IO*=" << (stop-start) << " " << retSendImage.get());
double megaParSec = double(size)/(double((stop-start).count())/1000000000.0);
APPL_WARNING(" speed=" << int64_t(megaParSec/1024.0)/1024.0 << " Mo/s");
if (retSendImage.hasError() == true) {
APPL_ERROR(" get an error while sending the File : '" << retSendImage.getErrorType() << "' help=" << retSendImage.getErrorHelp() );
} else {
echrono::Steady stop = echrono::Steady::now();
APPL_WARNING(" IO*=" << (stop-start) << " " << retSendImage.get());
double megaParSec = double(size)/(double((stop-start).count())/1000000000.0);
APPL_WARNING(" speed=" << int64_t(megaParSec/1024.0)/1024.0 << " Mo/s");
}
#endif
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
}

View File

@ -43,7 +43,7 @@ class Album {
uint32_t m_parentId; //!< parent Album ID
std::string m_name; //!< name of the Album
std::string m_description; //!< description of the album
std::vector<uint64_t> m_listMedia; //!< List of media in this album
std::vector<uint32_t> m_listMedia; //!< List of media in this album
};
static std::vector<Album> m_listAlbum;
@ -76,138 +76,30 @@ namespace appl {
APPL_VERBOSE("delete PictureService ...");
}
public:
#if 0
std::vector<std::string> getAlbums() {
std::unique_lock<std::mutex> lock(g_mutex);
std::vector<std::string> out;
ejson::Array globalGroups = g_database["group-global"].toArray();
if (globalGroups.exist() == false) {
APPL_DEBUG("'group-global' ==> does not exist ==> No album");
return out;
}
ejson::Object groups = g_database["groups"].toObject();
if (groups.exist() == false) {
APPL_DEBUG("'group' ==> does not exist ==> No album");
return out;
}
APPL_DEBUG("for element in 'group-global'");
for (auto it: globalGroups) {
std::string tmpString = it.toString().get();
if (tmpString == "") {
continue;
}
APPL_DEBUG(" find emlement:" << tmpString);
out.push_back(tmpString);
}
return out;
/*
ejson::Object groups = g_database["groups"].toObject();
if (groups.exist() == false) {
return std::vector<std::string>();
}
groups
return getSubAlbums("");
*/
}
// Get the list of sub album
std::vector<std::string> getSubAlbums(std::string _parrentAlbum) {
std::unique_lock<std::mutex> lock(g_mutex);
std::vector<std::string> out;
ejson::Object groups = g_database["groups"].toObject();
if (groups.exist() == false) {
return out;
}
// find parrentAlbum ==> to get sub group
/*
for (size_t iii=0; iii<groups.size(); ++iii) {
//ejson::Object group = groups[iii].toObject()["sub"];
if (groups.getKey(iii) != _parrentAlbum) {
continue;
}
}
*/
ejson::Object group = groups[_parrentAlbum].toObject();
if (group.exist() == false) {
return out;
}
ejson::Array groupSubs = group["sub"].toArray();
for (auto it: groupSubs) {
std::string tmpString = it.toString().get();
if (tmpString == "") {
continue;
}
out.push_back(tmpString);
}
// TODO: Check right
return out;
}
uint32_t getAlbumCount(std::string _album) {
std::unique_lock<std::mutex> lock(g_mutex);
ejson::Object groups = g_database["groups"].toObject();
if (groups.exist() == false) {
// TODO : Throw an error ...
return 0;
}
ejson::Object group = groups[_album].toObject();
if (group.exist() == false) {
// TODO : Throw an error ...
return 0;
}
ejson::Array groupSubs = group["files"].toArray();
// TODO: Check right
return groupSubs.size();
}
// Return the list of the album files
std::vector<std::string> getAlbumListPicture(std::string _album) {
std::unique_lock<std::mutex> lock(g_mutex);
std::vector<std::string> out;
ejson::Object groups = g_database["groups"].toObject();
if (groups.exist() == false) {
// TODO : Throw an error ...
return out;
}
ejson::Object group = groups[_album].toObject();
if (group.exist() == false) {
// TODO : Throw an error ...
return out;
}
ejson::Array groupSubs = group["files"].toArray();
for (auto it: groupSubs) {
uint64_t id = it.toNumber().getU64();
/*
auto itImage = m_listFile.find(id);
if (itImage == m_listFile.end()) {
}*/
if (id == 0) {
continue;
}
out.push_back(etk::to_string(id));
}
return out;
}
#endif
uint32_t mediaIdCount() {
uint32_t mediaIdCount() override {
std::unique_lock<std::mutex> lock(g_mutex);
// TODO : Check right ...
return m_listFile.size();
}
std::vector<std::string> mediaIdGetName(uint32_t _start, uint32_t _stop) {
std::vector<uint32_t> mediaIdGetName(uint32_t _start, uint32_t _stop) override {
std::unique_lock<std::mutex> lock(g_mutex);
// TODO : Check right ...
std::vector<uint32_t> out;
for (size_t iii=_start; iii<m_listFile.size() && iii<_stop; ++iii) {
out.push_back(m_listFile[iii].m_id);
}
return out;
}
// Return a File Data (might be a picture .tiff/.png/.jpg)
ememory::SharedPtr<zeus::File> mediaGet(std::string _mediaName) {
ememory::SharedPtr<zeus::File> mediaGet(uint32_t _mediaId) override {
std::unique_lock<std::mutex> lock(g_mutex);
// TODO : Check right ...
//Check if the file exist:
bool find = false;
FileProperty property;
for (auto &it : m_listFile) {
if (it.m_fileName == _mediaName) {
if (it.m_id == _mediaId) {
find = true;
property = it;
break;
@ -218,10 +110,10 @@ namespace appl {
}
return zeus::File::create(g_basePath + property.m_fileName + "." + zeus::getExtention(property.m_mineType), "", property.m_mineType);
}
std::string mediaAdd(zeus::ProxyFile _dataFile) {
uint32_t mediaAdd(zeus::ProxyFile _dataFile) override {
std::unique_lock<std::mutex> lock(g_mutex);
// TODO : Check right ...
uint64_t id = createFileID();
uint64_t id = createUniqueID();
auto futType = _dataFile.getMineType();
auto futName = _dataFile.getName();
@ -236,7 +128,7 @@ namespace appl {
// TODO : Check if data is identical ...
// remove temporary file
etk::FSNodeRemove(tmpFileName);
return sha512String;
return it.m_id;
}
}
// move the file at the good position:
@ -247,7 +139,7 @@ namespace appl {
}
etk::FSNodeMove(tmpFileName, g_basePath + sha512String + "." + zeus::getExtention(futType.get()));
FileProperty property;
property.m_id = createUniqueID();
property.m_id = id;
property.m_fileName = sha512String;
property.m_name = futName.get();
property.m_mineType = futType.get();
@ -255,16 +147,16 @@ namespace appl {
m_listFile.push_back(property);
g_needToStore = true;
APPL_DEBUG(" filename : " << sha512String);
return sha512String;
return id;
}
void mediaRemove(std::string _mediaName) {
void mediaRemove(uint32_t _mediaId) override {
std::unique_lock<std::mutex> lock(g_mutex);
// TODO : Check right ...
//Check if the file exist:
bool find = false;
FileProperty property;
for (auto &it : m_listFile) {
if (it.m_fileName == _mediaName) {
if (it.m_id == _mediaId) {
find = true;
property = it;
break;
@ -273,22 +165,36 @@ namespace appl {
if (find == false) {
throw std::invalid_argument("Wrong file name ...");
}
if (etk::FSNodeRemove(g_basePath + _mediaName + "." + zeus::getExtention(property.m_mineType)) == false) {
// Remove media in all Album ...
for (auto &it : m_listAlbum) {
for (auto elem = it.m_listMedia.begin();
elem != it.m_listMedia.end();
/* No increment */) {
if (*elem == _mediaId) {
elem = it.m_listMedia.erase(elem);
} else {
++elem;
}
}
}
// 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 ...");
}
}
std::vector<std::string> mediaMetadataGetKeys(std::string _mediaName) {
std::vector<std::string> mediaMetadataGetKeys(uint32_t _mediaId) override {
std::vector<std::string> out;
return out;
}
std::string mediaMetadataGetKey(std::string _mediaName, std::string _key) {
std::string mediaMetadataGetKey(uint32_t _mediaId, std::string _key) override {
return "";
}
void mediaMetadataSetKey(std::string _name, std::string _key, std::string _value) {
void mediaMetadataSetKey(uint32_t _mediaId, std::string _key, std::string _value) override {
}
uint32_t albumCreate(std::string _albumName) {
uint32_t albumCreate(std::string _albumName) override {
std::unique_lock<std::mutex> lock(g_mutex);
// TODO : Check right ...
for (auto &it : m_listAlbum) {
@ -304,18 +210,7 @@ namespace appl {
}
class Album {
public:
uint64_t m_id; //!< use local reference ID to have faster access on the file ...
uint64_t m_parentId; //!< parent Album ID
std::string m_name; //!< name of the Album
std::string m_description; //!< description of the album
std::vector<uint64_t> m_listMedia; //!< List of media in this album
};
static std::vector<Album> m_listAlbum;
void albumRemove(uint32_t _albumId) {
void albumRemove(uint32_t _albumId) override {
std::unique_lock<std::mutex> lock(g_mutex);
// TODO : Check right ...
for (auto it = m_listAlbum.begin();
@ -329,7 +224,7 @@ static std::vector<Album> m_listAlbum;
}
throw std::invalid_argument("Wrong Album ID ...");
}
std::vector<uint32_t> albumGetList() {
std::vector<uint32_t> albumGetList() override {
std::unique_lock<std::mutex> lock(g_mutex);
std::vector<uint32_t> out;
for (auto &it : m_listAlbum) {
@ -337,7 +232,7 @@ static std::vector<Album> m_listAlbum;
}
return out;
}
std::string albumNameGet(uint32_t _albumId) {
std::string albumNameGet(uint32_t _albumId) override {
std::unique_lock<std::mutex> lock(g_mutex);
for (auto &it : m_listAlbum) {
if (it.m_id == _albumId) {
@ -347,7 +242,7 @@ static std::vector<Album> m_listAlbum;
throw std::invalid_argument("Wrong Album ID ...");
return "";
}
void albumNameSet(uint32_t _albumId, std::string _albumName) {
void albumNameSet(uint32_t _albumId, std::string _albumName) override {
std::unique_lock<std::mutex> lock(g_mutex);
for (auto &it : m_listAlbum) {
if (it.m_id == _albumId) {
@ -357,7 +252,7 @@ static std::vector<Album> m_listAlbum;
}
throw std::invalid_argument("Wrong Album ID ...");
}
std::string albumDescriptionGet(uint32_t _albumId) {
std::string albumDescriptionGet(uint32_t _albumId) override {
std::unique_lock<std::mutex> lock(g_mutex);
for (auto &it : m_listAlbum) {
if (it.m_id == _albumId) {
@ -367,7 +262,7 @@ static std::vector<Album> m_listAlbum;
throw std::invalid_argument("Wrong Album ID ...");
return "";
}
void albumDescriptionSet(uint32_t _albumId, std::string _desc) {
void albumDescriptionSet(uint32_t _albumId, std::string _desc) override {
std::unique_lock<std::mutex> lock(g_mutex);
for (auto &it : m_listAlbum) {
if (it.m_id == _albumId) {
@ -377,36 +272,95 @@ static std::vector<Album> m_listAlbum;
}
throw std::invalid_argument("Wrong Album ID ...");
}
void albumMediaAdd(uint32_t _albumId, std::string _mediaName) {
}
void albumMediaRemove(uint32_t _albumId, std::string _mediaName) {
}
uint32_t albumMediaCount(uint32_t _albumId) {
void albumMediaAdd(uint32_t _albumId, uint32_t _mediaId) override {
std::unique_lock<std::mutex> lock(g_mutex);
for (auto &it : m_listAlbum) {
if (it.m_id == _albumId) {
it.m_description = _desc;
return it.m_listMedia.count();
for (auto &elem : it.m_listMedia) {
if (elem == _mediaId) {
// already intalles
return;
}
}
it.m_listMedia.push_back(_mediaId);
return;
}
}
throw std::invalid_argument("Wrong Album ID ...");
}
void albumMediaRemove(uint32_t _albumId, uint32_t _mediaId) override {
std::unique_lock<std::mutex> lock(g_mutex);
for (auto &it : m_listAlbum) {
if (it.m_id == _albumId) {
for (auto elem = it.m_listMedia.begin();
elem != it.m_listMedia.end();
/* No increment */) {
if (*elem == _mediaId) {
elem = it.m_listMedia.erase(elem);
return;
}
++elem;
}
// Media not find ... ==> not a problem ...
return;
}
}
throw std::invalid_argument("Wrong Album ID ...");
}
uint32_t albumMediaCount(uint32_t _albumId) override {
std::unique_lock<std::mutex> lock(g_mutex);
for (auto &it : m_listAlbum) {
if (it.m_id == _albumId) {
return it.m_listMedia.size();
}
}
throw std::invalid_argument("Wrong Album ID ...");
return 0;
}
std::vector<std::string> albumMediaGetName(uint32_t _albumId, uint32_t _start, uint32_t _stop) {
std::vector<std::string> out;
return out;
std::vector<uint32_t> albumMediaIdGet(uint32_t _albumId, uint32_t _start, uint32_t _stop) override {
std::unique_lock<std::mutex> lock(g_mutex);
for (auto &it : m_listAlbum) {
if (it.m_id == _albumId) {
std::vector<uint32_t> out;
for (size_t iii=_start;
iii<it.m_listMedia.size()
&& iii<_stop;
++iii) {
out.push_back(it.m_listMedia[iii]);
}
return out;
}
}
throw std::invalid_argument("Wrong Album ID ...");
}
void albumParentSet(uint32_t _albumId, uint32_t _albumParentId) {
void albumParentSet(uint32_t _albumId, uint32_t _albumParentId) override {
std::unique_lock<std::mutex> lock(g_mutex);
for (auto &it : m_listAlbum) {
if (it.m_id == _albumId) {
it.m_parentId = _albumParentId;
return;
}
}
throw std::invalid_argument("Wrong Album ID ...");
}
void albumParentRemove(uint32_t _albumId) {
void albumParentRemove(uint32_t _albumId) override {
std::unique_lock<std::mutex> lock(g_mutex);
for (auto &it : m_listAlbum) {
if (it.m_id == _albumId) {
it.m_parentId = 0;
return;
}
}
throw std::invalid_argument("Wrong Album ID ...");
}
uint32_t albumParentGet(uint32_t _albumId) {
return 0;
uint32_t albumParentGet(uint32_t _albumId) override {
std::unique_lock<std::mutex> lock(g_mutex);
for (auto &it : m_listAlbum) {
if (it.m_id == _albumId) {
return it.m_parentId;
}
}
throw std::invalid_argument("Wrong Album ID ...");
}
};
}
@ -429,7 +383,7 @@ static void store_db() {
database.add("list-album", listAlbumArray);
for (auto &it : m_listAlbum) {
ejson::Object albumElement;
listAlbumArray.add(AlbumElement);
listAlbumArray.add(albumElement);
albumElement.add("id", ejson::Number(it.m_id));
albumElement.add("parent", ejson::Number(it.m_parentId));
albumElement.add("name", ejson::String(it.m_name));
@ -474,7 +428,7 @@ static void load_db() {
ejson::Object albumElement = itArray.toObject();
Album album;
album.m_id = albumElement["id"].toNumber().getU64();
album.m_parentId = albumElement["parent"].toNumber().getU64()
album.m_parentId = albumElement["parent"].toNumber().getU64();
album.m_name = albumElement["name"].toString().get();
album.m_description = albumElement["desc"].toString().get();
ejson::Array listMadiaArray = database["list-album"].toArray();

View File

@ -13,8 +13,8 @@ uint32 mediaIdCount()
#brief:Get list of name of the media in a specific range (<1024)
#param:start:First Id of the media stream requested (range [0..+inf[)
#param:stop:Last Id of the media stream requested (excluded) (range [0..+inf[)
#return:List of the media names
vector:string mediaIdGetName(uint32,uint32)
#return:List of the media Ids
vector:uint32 mediaIdGetName(uint32,uint32)
/*
// ----------------- Get media with their ID in a range of time -----------------------
@ -34,23 +34,23 @@ vector:string mediaTimeGetName(time, time, uint32,uint32)
*/
// ----------------- media Access -----------------------
#brief:Get a media
#param:mediaName:Name of the media
#param:mediaId:Id of the media
#return:A file reference on the media (transmission is async)
obj:zeus-File mediaGet(string)
obj:zeus-File mediaGet(uint32)
/*
#brief:Get a media in STREAM mode (usefull for video)
#param:mediaName:Name of the media
#param:mediaId:Id of the media
#return:A stream reference on the media (transmission is async)
obj::zeus-Stream mediaStream(string)
obj::zeus-Stream mediaStream(uint32)
*/
#brief:Add a new media in the service
#param:data:A file reference on the media (transmission is async)
#return:Full name of the media (created by the engine ==> not prefictible)
string mediaAdd(obj:zeus-File)
#return:Local personal ID of the media
uint32 mediaAdd(obj:zeus-File)
#brief:Remove a media in the service (no trash)
#param:mediaName:Name of the media
void mediaRemove(string)
#param:mediaId:Id of the media
void mediaRemove(uint32)
// ----------------- meta-data Access -----------------------
/*
@ -61,21 +61,21 @@ json mediaMetadataGet(string)
*/
#brief:Get all meta-data keys of a media
#param:mediaName:Name of the media
#param:mediaId:Id of the media
#return:List of all availlable keys
vector:string mediaMetadataGetKeys(string)
vector:string mediaMetadataGetKeys(uint32)
#brief:Get a meta-data value of a key
#param:mediaName:Name of the media
#param:mediaId:Id of the media
#param:key:Key of the meta-data
#return:data in the key
string mediaMetadataGetKey(string, string)
string mediaMetadataGetKey(uint32, string)
#brief:Set a meta-data value of a key
#param:name:Name of the media
#param:mediaId:Id of the media
#param:key:Key of the meta-data
#param:value:data in the key
void mediaMetadataSetKey(string, string, string)
void mediaMetadataSetKey(uint32, string, string)
/*
#brief:Set all meta-data of a media
@ -120,13 +120,13 @@ void albumDescriptionSet(uint32, string)
#brief:Add a media in an album
#param:albumId:Id of the Album
#param:mediaName:Name of the media to add
void albumMediaAdd(uint32, string)
#param:mediaId:Id of the media to add
void albumMediaAdd(uint32, uint32)
#brief:Remove a media in an album
#param:albumId:Id of the Album
#param:mediaName:Name of the media to remove
void albumMediaRemove(uint32, string)
#param:mediaId:Id of the media to remove
void albumMediaRemove(uint32, uint32)
#brief:Get number of media in an album
#param:albumId:Id of the Album
@ -137,8 +137,8 @@ uint32 albumMediaCount(uint32)
#param:albumId:Id of the Album
#param:start:First Id of the media stream requested (range [0..+inf[)
#param:stop:Last Id of the media stream requested (excluded) (range [0..+inf[)
#return:List of the media names
vector:string albumMediaGetName(uint32, uint32,uint32)
#return:List of the media Ids
vector:uint32 albumMediaIdGet(uint32, uint32,uint32)
#brief:Set the parrent album at a specific album
#param:albumId:Id of the Album

View File

@ -36,6 +36,13 @@ zeus::FutureBase::FutureBase(uint32_t _transactionId, ememory::SharedPtr<zeus::M
m_promise = ememory::makeShared<zeus::Promise>(_transactionId, _returnData, _source);
}
void zeus::FutureBase::remoteObjectDestroyed() {
if (m_promise == nullptr) {
return;
}
m_promise->remoteObjectDestroyed();
}
void zeus::FutureBase::andAll(zeus::Promise::Observer _callback) {
if (m_promise == nullptr) {
return;

View File

@ -87,6 +87,10 @@ namespace zeus {
* @return Client id requested or 0
*/
uint32_t getSource() const;
/**
* @brief The remote object is removed ==> no need to wait more ...
*/
void remoteObjectDestroyed();
/**
* @brief check if the answer have an error
* @return return true if an error is registered

View File

@ -27,16 +27,12 @@ void zeus::Object::receive(ememory::SharedPtr<zeus::Message> _value) {
if (_value == nullptr) {
return;
}
ZEUS_WARNING("BUFFER" << _value);
uint32_t tmpID = _value->getTransactionId();
uint32_t source = _value->getSource();
ZEUS_WARNING("direct call");
zeus::FutureBase futData(tmpID, _value, source);
if (futData.isFinished() == true) {
ZEUS_INFO("Call Binary ..");
callBinary(futData.getRaw());
} else {
ZEUS_INFO("ADD ...");
m_callMultiData.push_back(futData);
}
}

View File

@ -86,7 +86,7 @@ namespace zeus {
return nullptr;
}
tmp->setType(zeus::AbstractFunction::type::service);
ZEUS_INFO("Add function '" << _name << "' in local mode");
ZEUS_VERBOSE("Add function '" << _name << "' in local mode");
m_listFunction.push_back(tmp);
return tmp;
}
@ -138,7 +138,7 @@ namespace zeus {
return nullptr;
}
tmp->setType(zeus::AbstractFunction::type::object);
ZEUS_INFO("Add function '" << _name << "' in object mode");
ZEUS_VERBOSE("Add function '" << _name << "' in object mode");
m_listFunction.push_back(tmp);
return tmp;
}

View File

@ -15,23 +15,23 @@ zeus::ObjectRemoteBase::ObjectRemoteBase(const ememory::SharedPtr<zeus::WebServe
m_remoteAddress(_address),
m_isLinked(false) {
m_isLinked = true;
ZEUS_INFO("[" << m_id << "/" << m_objectId << "] create => to remote [" << (m_remoteAddress>>16) << "/" << (m_remoteAddress&0xFFFF) << "]");
ZEUS_VERBOSE("[" << m_id << "/" << m_objectId << "] create => to remote [" << (m_remoteAddress>>16) << "/" << (m_remoteAddress&0xFFFF) << "]");
}
void zeus::ObjectRemoteBase::display() {
ZEUS_INFO(" - [" << m_id << "/" << m_objectId << "] => [" << (m_remoteAddress>>16) << "/" << (m_remoteAddress&0xFFFF) << "]");
ZEUS_VERBOSE(" - [" << m_id << "/" << m_objectId << "] => [" << (m_remoteAddress>>16) << "/" << (m_remoteAddress&0xFFFF) << "]");
for (auto &it : m_listRemoteConnected) {
ZEUS_INFO(" * [" << (it>>16) << "/" << (it&0xFFFF) << "]");
}
}
zeus::ObjectRemoteBase::~ObjectRemoteBase() {
ZEUS_INFO("[" << m_id << "/" << m_objectId << "] DESTROY => to remote [" << (m_remoteAddress>>16) << "/" << (m_remoteAddress&0xFFFF) << "]");
ZEUS_VERBOSE("[" << m_id << "/" << m_objectId << "] DESTROY => to remote [" << (m_remoteAddress>>16) << "/" << (m_remoteAddress&0xFFFF) << "]");
if (m_isLinked == true) {
zeus::Future<bool> ret = m_interfaceWeb->call(getFullId(), m_remoteAddress&0xFFFF0000, "unlink", m_remoteAddress);
ret.wait();
if (ret.hasError() == true) {
ZEUS_WARNING("Can not unlink with the service id: '" << m_remoteAddress << "' ==> link error");
ZEUS_WARNING("Can not unlink with the object id: " << (m_remoteAddress>>16) << "/" << (m_remoteAddress&0xFFFF) << " ==> link error");
return;
}
m_isLinked = false;

View File

@ -7,6 +7,7 @@
#include <zeus/FutureBase.hpp>
#include <zeus/message/Answer.hpp>
#include <zeus/debug.hpp>
#include <zeus/WebServer.hpp>
zeus::Promise::Promise(uint32_t _transactionId, uint32_t _source) {
@ -29,6 +30,18 @@ zeus::Promise::Promise(uint32_t _transactionId, ememory::SharedPtr<zeus::Message
}
}
void zeus::Promise::remoteObjectDestroyed() {
auto answer = zeus::message::Answer::create(nullptr);
if (answer == nullptr) {
return;
}
answer->setTransactionId(m_transactionId);
answer->setSource(m_source);
answer->setDestination(0);
answer->addError("REMOTE-OBJECT-REMOVE", "The remote interface ot the Object has been destroyed");
setMessage(answer);
}
void zeus::Promise::andAll(zeus::Promise::Observer _callback) {
// TODO : Lock ...
m_callbackThen = _callback;

View File

@ -67,6 +67,10 @@ namespace zeus {
* /
void andAbort(zeus::Promise::Observer _callback); // an abort is requested in the actiron ...
*/
/**
* @brief The remote object is removed ==> no need to wait more ...
*/
void remoteObjectDestroyed();
/**
* @brief Add data on the call/answer
* @param[in] _returnValue Returned buffer

View File

@ -146,7 +146,7 @@ namespace zeus {
return nullptr;
}
tmp->setType(zeus::AbstractFunction::type::global);
ZEUS_INFO("Add function '" << _name << "' in global mode");
ZEUS_VERBOSE("Add function '" << _name << "' in global mode");
m_listFunction.push_back(tmp);
return tmp;
}
@ -177,7 +177,7 @@ namespace zeus {
return nullptr;
}
tmp->setType(zeus::AbstractFunction::type::local);
ZEUS_INFO("Add function '" << _name << "' in local mode");
ZEUS_VERBOSE("Add function '" << _name << "' in local mode");
m_listFunction.push_back(tmp);
return tmp;
}

View File

@ -11,11 +11,11 @@ zeus::WebObj::WebObj(const ememory::SharedPtr<zeus::WebServer>& _iface, uint16_t
m_interfaceWeb(_iface),
m_id(_id),
m_objectId(_objectId) {
ZEUS_INFO("[" << m_id << "/" << m_objectId << "] Create");
ZEUS_VERBOSE("[" << m_id << "/" << m_objectId << "] Create");
}
zeus::WebObj::~WebObj() {
ZEUS_INFO("[" << m_id << "/" << m_objectId << "] Delete");
ZEUS_VERBOSE("[" << m_id << "/" << m_objectId << "] Delete");
}
uint16_t zeus::WebObj::getInterfaceId() {

View File

@ -143,6 +143,22 @@ void zeus::WebServer::interfaceRemoved(std::vector<uint16_t> _list) {
++it;
}
}
for (int32_t iii=0; iii < _list.size(); ++iii) {
std::unique_lock<std::mutex> lock(m_pendingCallMutex);
auto it = m_pendingCall.begin();
while (it != m_pendingCall.end()) {
if (it->second.isValid() == false) {
it = m_pendingCall.erase(it);
continue;
}
if (it->second.getSource()>>16 != _list[iii]) {
++it;
continue;
}
it->second.remoteObjectDestroyed();
it = m_pendingCall.erase(it);
}
}
}
@ -387,7 +403,7 @@ void zeus::WebServer::newMessage(ememory::SharedPtr<zeus::Message> _buffer) {
m_processingPool.async(
[=](){
ememory::SharedPtr<zeus::WebObj> tmpObj = it;
ZEUS_INFO("PROCESS : " << _buffer);
ZEUS_LOG_INPUT_OUTPUT("PROCESS : " << _buffer);
tmpObj->receive(_buffer);
},
dest
@ -406,7 +422,7 @@ void zeus::WebServer::newMessage(ememory::SharedPtr<zeus::Message> _buffer) {
m_processingPool.async(
[=](){
ememory::SharedPtr<zeus::WebObj> tmpObj = tmp;
ZEUS_INFO("PROCESS : " << _buffer);
ZEUS_LOG_INPUT_OUTPUT("PROCESS : " << _buffer);
tmpObj->receive(_buffer);
},
dest

View File

@ -314,7 +314,7 @@ namespace zeus {
SendData(const zeus::Raw& _data, uint16_t _parameterId) :
m_data(_data),
m_parameterId(_parameterId),
m_size(_data.size()-1),
m_size(_data.size()),
m_offset(0) {
}
@ -340,7 +340,7 @@ namespace zeus {
answer->addData(m_parameterId, (void *)(&m_data.data()[m_offset]), tmpSize);
m_size -= tmpSize;
m_offset += tmpSize;
_interface->writeBinary(answer);;
_interface->writeBinary(answer);
if (m_size <= 0) {
return true;
}

View File

@ -151,7 +151,8 @@ static std::vector<std::pair<std::string, std::string>> mineList = {
{ "js", "code/javascript"},
};
std::string zeus::getMineType(const std::string& _extention) {
std::string zeus::getMineType(std::string _extention) {
_extention = etk::tolower(_extention);
for (auto &it : mineList) {
if (it.first == _extention) {
return it.second;
@ -161,7 +162,8 @@ std::string zeus::getMineType(const std::string& _extention) {
return "";
}
std::string zeus::getExtention(const std::string& _mineType) {
std::string zeus::getExtention(std::string _mineType) {
_mineType = etk::tolower(_mineType);
for (auto &it : mineList) {
if (it.second == _mineType) {
return it.first;

View File

@ -12,12 +12,12 @@ namespace zeus {
* @param[in] _extention file extention (without the '.')
* @return The generic mine tipe in http format
*/
std::string getMineType(const std::string& _extention);
std::string getMineType(std::string _extention);
/**
* @brief Retrive the extention of a file with his mine type
* @param[in] _mineType Mine tipe in http format
* @return file extention (without the '.')
*/
std::string getExtention(const std::string& _mineType);
std::string getExtention(std::string _mineType);
};

View File

@ -8,6 +8,7 @@
#include <zeus/ProxyFile.hpp>
#include <zeus/mineType.hpp>
#include <algue/sha512.hpp>
#include <etk/os/FSNode.hpp>
#include "debug.hpp"
@ -26,6 +27,7 @@ zeus::FileImpl::FileImpl(std::string _fileNameReal) :
m_node.fileOpenRead();
std::string extention = std::string(_fileNameReal.begin()+_fileNameReal.size() -3, _fileNameReal.end());
m_mineType = zeus::getMineType(extention);
m_sha512 = algue::stringConvert(algue::sha512::encodeFromFile(_fileNameReal));
}
zeus::FileImpl::FileImpl(std::string _fileNameReal, std::string _fileNameShow, std::string _mineType) :
@ -34,6 +36,7 @@ zeus::FileImpl::FileImpl(std::string _fileNameReal, std::string _fileNameShow, s
m_mineType(_mineType) {
m_size = m_node.fileSize();
m_node.fileOpenRead();
m_sha512 = algue::stringConvert(algue::sha512::encodeFromFile(_fileNameReal));
}
zeus::FileImpl::~FileImpl() {
@ -48,6 +51,10 @@ std::string zeus::FileImpl::getName() {
return m_filename;
}
std::string zeus::FileImpl::getSha512() {
return m_sha512;
}
std::string zeus::FileImpl::getMineType() {
return m_mineType;
}
@ -55,13 +62,16 @@ std::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 ...");
// TODO : throw an error ...
throw std::invalid_argument("REQUEST more that 25 Mo in a part file ..." + etk::to_string(_stop - _start) + " Bytes");
return zeus::Raw();
}
if (_start >= m_size) {
throw std::invalid_argument("REQUEST start position out of file size" + etk::to_string(_start) + " > " + etk::to_string(m_size));
}
zeus::Raw tmp(_stop - _start);
if (m_node.fileSeek(_start, etk::seekNode_start) == false) {
ZEUS_ERROR("REQUEST seek error ...");
// TODO : throw an error ...
throw std::runtime_error("Seek in the file error");
return zeus::Raw();
}
int64_t sizeCopy = m_node.fileRead(tmp.writeData(), 1, _stop-_start);
@ -71,6 +81,7 @@ zeus::Raw zeus::FileImpl::getPart(uint64_t _start, uint64_t _stop) {
std::string zeus::storeInFile(zeus::ProxyFile _file, std::string _filename) {
auto futSize = _file.getSize();
auto futSha = _file.getSha512();
futSize.wait();
int64_t retSize = futSize.get();
int64_t offset = 0;
@ -94,10 +105,17 @@ std::string zeus::storeInFile(zeus::ProxyFile _file, std::string _filename) {
nodeFile.fileWrite(buffer.data(), 1, buffer.size());
offset += nbElement;
retSize -= nbElement;
ZEUS_VERBOSE("read: " << offset << "/" << futSize.get() << " " << buffer.size());
}
nodeFile.fileClose();
// get the final sha512 of the file:
std::string sha512String = algue::stringConvert(shaCtx.finalize());
futSha.wait();
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");
}
return sha512String;
}

View File

@ -15,12 +15,14 @@ namespace zeus {
etk::FSNode m_node;
size_t m_size;
std::string m_mineType;
std::string m_sha512;
public:
FileImpl(std::string _fileNameReal, std::string _fileNameShow, std::string _mineType);
FileImpl(std::string _fileNameReal);
~FileImpl();
uint64_t getSize() override;
std::string getName() override;
std::string getSha512() override;
std::string getMineType() override;
zeus::Raw getPart(uint64_t _start, uint64_t _stop) override;

View File

@ -24,9 +24,13 @@
#return:current size of the file.
uint64 getSize()
#brief:Get the name of the file (can be the name of the local file or a theoric generated filename to be easy to user to store it, not really usefull).
#return:help name of the file.
string getName()
#brief:Get the name of the file.
#return:Full name of the file (sha512).
string getName()
string getSha512()
#brief:Get the file "mine-type".
#return:string of the mine-type.