[DEV] converge to use only object instead of single service API

This commit is contained in:
Edouard DUPIN 2017-04-14 21:19:19 +02:00
parent 723c092756
commit 4ad6f382dd
17 changed files with 392 additions and 221 deletions

View File

@ -125,6 +125,15 @@ def configure(target, my_module):
'zeus/zeus-File.impl.hpp',
])
my_module.add_depend('ejson')
zeus_macro.parse_object_idl(my_module, 'zeus/zeus-Media.obj.zeus.idl')
my_module.add_src_file([
'zeus/zeus-Media.impl.cpp',
])
my_module.add_header_file([
'zeus/zeus-Media.impl.hpp',
])
if target.config["compilator"] == "clang":
my_module.add_flag('c++', "-Wno-unsequenced", export=True)
# build in C++ mode

View File

@ -17,6 +17,7 @@
#include <etk/stdTools.hpp>
#include <zeus/service/ProxyVideo.hpp>
#include <zeus/ProxyFile.hpp>
#include <zeus/ProxyMedia.hpp>
#include <zeus/ObjectRemote.hpp>
#include <echrono/Steady.hpp>
#include <zeus/FutureGroup.hpp>
@ -45,7 +46,7 @@ static std::string extractAndRemove(const std::string& _inputValue, const char _
}
bool pushVideoFile(zeus::service::ProxyVideo& _srv, std::string _path, std::map<std::string,std::string> _basicKey = std::map<std::string,std::string>()) {
APPL_INFO("Add media : '" << _path << "'");
APPL_PRINT("Add media : '" << _path << "'");
std::string extention;
if ( _path.rfind('.') != std::string::npos
&& _path.rfind('.') != 0) {
@ -60,11 +61,19 @@ bool pushVideoFile(zeus::service::ProxyVideo& _srv, std::string _path, std::map<
return false;
}
uint32_t mediaId = _srv.mediaAdd(zeus::File::create(_path)).waitFor(echrono::seconds(20000)).get();
uint32_t mediaId = _srv.add(zeus::File::create(_path)).waitFor(echrono::seconds(20000)).get();
if (mediaId == 0) {
APPL_ERROR("Get media ID = 0 With no error");
return false;
}
// Get the media
zeus::ProxyMedia media = _srv.get(mediaId).waitFor(echrono::seconds(2000)).get();
if (media.exist() == false) {
APPL_ERROR("get media error");
return false;
}
// TODO: if the media have meta data ==> this mean that the media already added before ...
// Parse file name:
std::string fileName = etk::split(_path, '/').back();
@ -177,13 +186,13 @@ bool pushVideoFile(zeus::service::ProxyVideo& _srv, std::string _path, std::map<
episodePrint = etk::to_string(episode);
_basicKey.insert(std::pair<std::string,std::string>("episode", etk::to_string(episode)));
}
APPL_INFO(" recontituated: '" << seriesName << "-s" << saisonPrint << "-e" << episodePrint << "-" << fullEpisodeName << "'");
APPL_PRINT(" ==> '" << seriesName << "-s" << saisonPrint << "-e" << episodePrint << "-" << fullEpisodeName << "'");
}
}
// send all meta data:
zeus::FutureGroup group;
for (auto &itKey : _basicKey) {
group.add(_srv.mediaMetadataSetKey(mediaId, itKey.first, itKey.second));
group.add(media.setMetadata(itKey.first, itKey.second));
}
group.wait();
return true;
@ -380,16 +389,16 @@ int main(int _argc, const char *_argv[]) {
// TODO : Do it :
APPL_ERROR("NEED to add check in cmd line to execute it ...");
return -1;
uint32_t count = remoteServiceVideo.mediaIdCount().wait().get();
uint32_t count = remoteServiceVideo.count().wait().get();
APPL_DEBUG("have " << count << " medias");
for (uint32_t iii=0; iii<count ; iii += 1024) {
uint32_t tmpMax = std::min(iii + 1024, count);
APPL_DEBUG("read section " << iii << " -> " << tmpMax);
std::vector<uint32_t> list = remoteServiceVideo.mediaIdGet(iii,tmpMax).wait().get();
std::vector<uint32_t> list = remoteServiceVideo.getIds(iii,tmpMax).wait().get();
zeus::FutureGroup groupWait;
for (auto& it : list) {
APPL_PRINT("remove ELEMENT : " << it);
groupWait.add(remoteServiceVideo.mediaRemove(it));
groupWait.add(remoteServiceVideo.remove(it));
}
groupWait.waitFor(echrono::seconds(2000));
}
@ -400,17 +409,23 @@ int main(int _argc, const char *_argv[]) {
APPL_PRINT("============================================");
APPL_PRINT("== list files: ");
APPL_PRINT("============================================");
uint32_t count = remoteServiceVideo.mediaIdCount().wait().get();
uint32_t count = remoteServiceVideo.count().wait().get();
APPL_DEBUG("have " << count << " medias");
for (uint32_t iii=0; iii<count ; iii += 1024) {
uint32_t tmpMax = std::min(iii + 1024, count);
APPL_DEBUG("read section " << iii << " -> " << tmpMax);
std::vector<uint32_t> list = remoteServiceVideo.mediaIdGet(iii, tmpMax).wait().get();
std::vector<uint32_t> list = remoteServiceVideo.getIds(iii, tmpMax).wait().get();
for (auto& it : list) {
std::string name = remoteServiceVideo.mediaMetadataGetKey(it, "title").wait().get();
std::string serie = remoteServiceVideo.mediaMetadataGetKey(it, "series-name").wait().get();
std::string episode = remoteServiceVideo.mediaMetadataGetKey(it, "episode").wait().get();
std::string saison = remoteServiceVideo.mediaMetadataGetKey(it, "saison").wait().get();
// Get the media
zeus::ProxyMedia media = remoteServiceVideo.get(it).waitFor(echrono::seconds(2000)).get();
if (media.exist() == false) {
APPL_ERROR("get media error");
return false;
}
std::string name = media.getMetadata("title").wait().get();
std::string serie = media.getMetadata("series-name").wait().get();
std::string episode = media.getMetadata("episode").wait().get();
std::string saison = media.getMetadata("saison").wait().get();
std::string outputDesc = "";
if (serie != "") {
outputDesc += serie + "-";

View File

@ -157,7 +157,8 @@ void appl::MessageElementAudio::configure(audio::format _format, uint32_t _sampl
}
}
appl::MediaDecoder::MediaDecoder() {
appl::MediaDecoder::MediaDecoder() :
m_seekApply(-1) {
init_ffmpeg();
m_IOContext = nullptr;
m_formatContext = nullptr;
@ -236,6 +237,10 @@ int appl::MediaDecoder::decode_packet(int *_gotFrame, int _cached) {
m_videoPool[slotId].m_duration = echrono::Duration(0, 1000000000.0/float(getFps(m_videoDecoderContext)));
m_currentVideoTime += m_videoPool[slotId].m_duration;
m_videoPool[slotId].m_isUsed = true;
if (m_fistFrameSended == false) {
m_seekApply = m_currentVideoTime;
m_fistFrameSended = true;
}
}
}
} else if (m_packet.stream_index == m_audioStream_idx) {
@ -291,13 +296,17 @@ int appl::MediaDecoder::decode_packet(int *_gotFrame, int _cached) {
// inject data in the buffer:
memcpy(&m_audioPool[slotId].m_buffer[0], m_frame->extended_data[0], m_audioPool[slotId].m_buffer.size());
}
// We use the Time of the packet ==> better synchronisation when seeking
m_currentAudioTime = packetTime;
// TODO : We use the Time of the packet ==> better synchronisation when seeking
//m_currentAudioTime = packetTime;
m_audioPool[slotId].m_id = m_audioFrameCount;
m_audioPool[slotId].m_time = m_currentAudioTime;
m_audioPool[slotId].m_duration = echrono::Duration(0,(1000000000.0*m_frame->nb_samples)/float(m_frame->sample_rate));
m_currentAudioTime += m_audioPool[slotId].m_duration;
m_audioPool[slotId].m_isUsed = true;
if (m_fistFrameSended == false) {
m_seekApply = m_currentVideoTime;
m_fistFrameSended = true;
}
}
}
}

View File

@ -86,6 +86,7 @@ namespace appl {
class MediaDecoder : public gale::Thread {
bool m_stopRequested;
public:
bool m_fistFrameSended;
echrono::Duration m_seekApply;
private:
echrono::Duration m_seek;

View File

@ -272,9 +272,11 @@ void appl::widget::VideoDisplay::periodicEvent(const ewol::event::Time& _event)
if (m_decoder == nullptr) {
return;
}
if (m_decoder->m_seekApply >= echrono::Duration(0)) {
if (m_decoder->m_seekApply > echrono::Duration(-1)) {
m_currentTime = m_decoder->m_seekApply;
APPL_ERROR("Apply new position : " << m_currentTime);
APPL_ERROR("==========================================================");
APPL_ERROR("Apply seek position : " << m_currentTime);
APPL_ERROR("==========================================================");
m_decoder->m_seekApply = echrono::Duration(-1);
if (m_audioInterface != nullptr) {
m_audioInterface->clearInternalBuffer();
@ -285,6 +287,7 @@ void appl::widget::VideoDisplay::periodicEvent(const ewol::event::Time& _event)
int32_t idSlot = m_decoder->audioGetOlderSlot();
if ( idSlot != -1
&& m_currentTime > m_decoder->m_audioPool[idSlot].m_time) {
APPL_WARNING("Get Slot AUDIO " << m_currentTime << " > " << m_decoder->m_audioPool[idSlot].m_time);
if (m_audioInterface == nullptr) {
// start audio interface the first time we need it
APPL_ERROR("==========================================================");
@ -316,6 +319,7 @@ void appl::widget::VideoDisplay::periodicEvent(const ewol::event::Time& _event)
// check the slot is valid and check display time of the element:
if ( idSlot != -1
&& m_currentTime > m_decoder->m_videoPool[idSlot].m_time) {
APPL_WARNING("Get Slot VIDEO " << m_currentTime << " > " << m_decoder->m_audioPool[idSlot].m_time);
m_resource->get().swap(m_decoder->m_videoPool[idSlot].m_image);
m_imageSize = m_resource->get().getSize();
ivec2 tmpSize = m_decoder->m_videoPool[idSlot].m_imagerealSize;

View File

@ -8,7 +8,7 @@
#include <ewol/widget/Manager.hpp>
const int32_t dotRadius = 6;
const float dotRadius = 6.0f;
appl::widget::VolumeBar::VolumeBar() :
signalChange(this, "change", ""),
@ -61,18 +61,18 @@ void appl::widget::VolumeBar::onRegenerateDisplay() {
m_draw.clear();
m_draw.setColor(m_textColorFg);
// draw a line:
m_draw.setPos(vec3(dotRadius, 0, 0));
m_draw.rectangleWidth(vec3(m_size.x(), m_size.y()-dotRadius*2.0, 0));
m_draw.setPos(vec3(dotRadius, 0.0f, 0.0f));
m_draw.rectangleWidth(vec3(m_size.x(), m_size.y()-dotRadius*2.0f, 0.0f));
// chaneg color whe soud became louder ...
if (*propertyValue > 0.5f) {
m_draw.setColor(m_textColorLoaded);
} else {
m_draw.setColor(m_textColorDone);
}
m_draw.setPos(vec3(m_size.x()*0.1, dotRadius, 0));
m_draw.setPos(vec3(m_size.x()*0.1f, dotRadius, 0.0f));
float offset = (*propertyValue-*propertyMinimum)/(*propertyMaximum-*propertyMinimum);
m_draw.rectangleWidth(vec3(m_size.x()*0.8, offset*(m_size.y()-2*dotRadius), 0) );
m_draw.rectangleWidth(vec3(m_size.x()*0.8f, offset*(m_size.y()-2.0f*dotRadius), 0.0f) );
}

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg width="64" height="64">
<g transform="matrix(1.2000035,0,0,1.2000035,-76.201658,-63.592236)">
<path d="M 111.858,93.287 93.524,62.64 C 91.67,59.542 88.639,59.543 86.789,62.641 L 68.476,93.286 c -1.851,3.098 -0.413,5.633 3.197,5.633 h 36.993 c 3.608,-10e-4 5.045,-2.535 3.192,-5.632 z M 88.2,73.367 c 0,-1.084 0.887,-1.969 1.969,-1.969 1.083,0 1.969,0.885 1.969,1.969 v 9.192 c 0,1.085 -0.886,1.969 -1.969,1.969 -1.082,0 -1.969,-0.884 -1.969,-1.969 v -9.192 z m 1.969,19.596 c -1.449,0 -2.625,-1.177 -2.625,-2.625 0,-1.451 1.176,-2.624 2.625,-2.624 1.45,0 2.625,1.173 2.625,2.624 0,1.449 -1.175,2.625 -2.625,2.625 z"
style="fill:#333333" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 724 B

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg width="64" height="64">
<g transform="matrix(1.300523,0,0,1.300523,-4.3338536,-458.79144)">
<polygon points="16.142,372.236 26.103,362.274 26.103,394.151 16.142,384.189 7.177,384.189 7.177,372.236 "
style="fill:#333333" />
<path d="m 34.567,369.749 -2.816,2.816 c 1.447,1.446 2.344,3.444 2.344,5.647 0,2.203 -0.896,4.201 -2.344,5.646 l 2.816,2.816 c 2.168,-2.168 3.512,-5.161 3.512,-8.463 0,-3.302 -1.344,-6.293 -3.512,-8.462 z"
style="fill:#333333" />
<path d="m 39.704,365.025 -2.816,2.816 c 2.645,2.645 4.283,6.297 4.283,10.324 0,4.027 -1.639,7.68 -4.283,10.324 l 2.816,2.816 c 3.365,-3.367 5.451,-8.015 5.451,-13.141 0,-5.123 -2.086,-9.771 -5.451,-13.139 z"
style="fill:#333333" />
<path d="m 44.56,359.854 -2.816,2.816 c 3.982,3.982 6.449,9.48 6.449,15.543 0,6.063 -2.467,11.561 -6.447,15.543 l 2.814,2.816 c 4.705,-4.704 7.617,-11.197 7.617,-18.359 0,-7.162 -2.914,-13.655 -7.617,-18.359 z"
style="fill:#333333" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

@ -30,11 +30,17 @@
<label name="[{ID}]appl-player-label-duration"/>
</sizer>
<sizer mode="hori" fill="true" expand="true,false">
<sizer mode="vert" fill="true" expand="false,true">
<image src="DATA:Light.svg" size="8,8mm" />
<appl_VolumeBar name="[{ID}]appl-player-light" expand="false,true" fill="true" step="1" value="100" min="0" max="100" mode="vert"/>
<label name="[{ID}]appl-player-label-light">100%</label>
</sizer>
<sizer mode="vert" fill="true" expand="true">
<spacer expand="true" fill="true"/>
<label name="[{ID}]appl-player-label-fps"/>
</sizer>
<sizer mode="vert" fill="true" expand="false,true">
<image src="DATA:Volume.svg" size="8,8mm" />
<appl_VolumeBar name="[{ID}]appl-player-volume" expand="false,true" fill="true" step="0.1" value="0" min="-60" max="6" mode="vert"/>
<label name="[{ID}]appl-player-label-volume">0dB</label>
</sizer>

View File

@ -23,20 +23,13 @@
#include <zeus/ProxyClientProperty.hpp>
#include <zeus/File.hpp>
#include <zeus/ProxyFile.hpp>
#include <zeus/zeus-Media.impl.hpp>
static std::mutex g_mutex;
static std::string g_basePath;
static std::string g_baseDBName = std::string(SERVICE_NAME) + "-database.json";
class FileProperty {
public:
uint64_t m_id; //!< use local reference ID to have faster access on the file ...
std::string m_fileName; // Sha 512
std::string m_name;
std::string m_mineType;
echrono::Time m_creationData;
std::map<std::string, std::string> m_metadata;
};
static std::vector<FileProperty> m_listFile;
static std::vector<ememory::SharedPtr<zeus::MediaImpl>> m_listFile;
static uint64_t m_lastMaxId = 0;
static bool g_needToStore = false;
@ -114,80 +107,66 @@ namespace appl {
APPL_VERBOSE("delete VideoService ...");
}
public:
uint32_t mediaIdCount() override {
uint32_t count() override {
std::unique_lock<std::mutex> lock(g_mutex);
// TODO : Check right ...
return m_listFile.size();
}
std::vector<uint32_t> mediaIdGet(uint32_t _start, uint32_t _stop) override {
std::vector<uint32_t> getIds(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);
if (m_listFile[iii] == nullptr) {
continue;
}
out.push_back(m_listFile[iii]->getUniqueId());
}
return out;
}
std::string mediaMineTypeGet(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_id == _mediaId) {
find = true;
property = it;
break;
}
}
if (find == false) {
throw std::invalid_argument("Wrong file ID ...");
}
return property.m_mineType;
}
// Return a File Data (might be a video .tiff/.png/.jpg)
ememory::SharedPtr<zeus::File> mediaGet(uint32_t _mediaId) override {
ememory::SharedPtr<zeus::Media> get(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;
ememory::SharedPtr<zeus::MediaImpl> property;
for (auto &it : m_listFile) {
if (it.m_id == _mediaId) {
find = true;
property = it;
break;
if (it == nullptr) {
continue;
}
if (it->getUniqueId() == _mediaId) {
return it;
}
}
if (find == false) {
throw std::invalid_argument("Wrong file ID ...");
}
return zeus::File::create(g_basePath + property.m_fileName + "." + zeus::getExtention(property.m_mineType), "", property.m_mineType);
throw std::invalid_argument("Wrong file ID ...");
//
}
uint32_t mediaAdd(zeus::ProxyFile _dataFile) override {
uint32_t add(zeus::ProxyFile _dataFile) override {
std::unique_lock<std::mutex> lock(g_mutex);
// TODO : Check right ...
uint64_t id = createUniqueID();
auto futRemoteSha512 = _dataFile.getSha512();
auto futType = _dataFile.getMineType();
auto futName = _dataFile.getName();
// wait the sha1 to check his existance:
futRemoteSha512.wait();
std::string sha512StringRemote = futRemoteSha512.get();
for (auto &it : m_listFile) {
if (it == nullptr) {
continue;
}
if (it->getFileName() == sha512StringRemote) {
APPL_INFO("File already registered at ");// << it.m_creationData);
// simply send the Id of the file
// TODO : Check right of this file ...
return it->getUniqueId();
}
}
std::string tmpFileName = g_basePath + "tmpImport_" + etk::to_string(id);
std::string sha512String = zeus::storeInFile(_dataFile, tmpFileName);
futType.wait();
futName.wait();
// TODO : Get internal data of the file and remove all the meta-data ==> proper files ...
for (auto &it : m_listFile) {
if (it.m_fileName == sha512String) {
APPL_INFO("File already registered at " << it.m_creationData);
// TODO : Check if data is identical ...
// remove temporary file
etk::FSNodeRemove(tmpFileName);
return it.m_id;
}
}
// move the file at the good position:
APPL_DEBUG("move temporay file in : " << g_basePath << sha512String);
if (etk::FSNodeGetSize(tmpFileName) == 0) {
@ -195,30 +174,30 @@ namespace appl {
throw std::runtime_error("file size == 0");
}
etk::FSNodeMove(tmpFileName, g_basePath + sha512String + "." + zeus::getExtention(futType.get()));
FileProperty property;
property.m_id = id;
property.m_fileName = sha512String;
property.m_name = futName.get();
property.m_mineType = futType.get();
property.m_creationData = echrono::Time::now();
ememory::SharedPtr<zeus::MediaImpl> property = ememory::makeShared<zeus::MediaImpl>(id, sha512String + "." + zeus::getExtention(futType.get()));
//property->setName(futName.get());
m_listFile.push_back(property);
g_needToStore = true;
APPL_DEBUG(" filename : " << sha512String);
return id;
}
void mediaRemove(uint32_t _mediaId) override {
void remove(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;
ememory::SharedPtr<zeus::MediaImpl> property;
for (auto it = m_listFile.begin();
it != m_listFile.end();
/* No increment */) {
if (it->m_id == _mediaId) {
if (*it == nullptr) {
it = m_listFile.erase(it);
continue;
}
if ((*it)->getUniqueId() == _mediaId) {
property = *it;
it = m_listFile.erase(it);
find = true;
property = *it;
} else {
++it;
}
@ -228,56 +207,14 @@ 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) {
if (property->erase() == false) {
throw std::runtime_error("Can not remove file ...");
}
}
std::vector<std::string> mediaMetadataGetKeys(uint32_t _mediaId) override {
std::unique_lock<std::mutex> lock(g_mutex);
std::vector<std::string> out;
for (auto &it : m_listFile) {
if (it.m_id == _mediaId) {
for (auto &itM : it.m_metadata) {
out.push_back(itM.first);
}
return out;
}
}
throw std::invalid_argument("Wrong KEY ID ...");
}
std::string mediaMetadataGetKey(uint32_t _mediaId, std::string _key) override {
std::unique_lock<std::mutex> lock(g_mutex);
std::vector<std::string> out;
for (auto &it : m_listFile) {
if (it.m_id == _mediaId) {
auto itM = it.m_metadata.find(_key);
if (itM != it.m_metadata.end()) {
return itM->second;
}
return "";
}
}
throw std::invalid_argument("Wrong KEY ID ...");
}
void mediaMetadataSetKey(uint32_t _mediaId, std::string _key, std::string _value) override {
APPL_INFO("[" << _mediaId << "] set key: '" << _key << "' value: '" << _value << "'");
std::unique_lock<std::mutex> lock(g_mutex);
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(std::make_pair(_key, _value));
}
return;
}
}
throw std::invalid_argument("Wrong KEY ID ...");
}
std::vector<uint32_t> getMediaWhere(std::string _sqlLikeRequest) override {
std::vector<uint32_t> getSQL(std::string _sqlLikeRequest) override {
std::vector<uint32_t> out;
/*
if (_sqlLikeRequest == "") {
throw std::invalid_argument("empty request");
}
@ -351,6 +288,7 @@ namespace appl {
out.push_back(it.m_id);
}
}
*/
return out;
}
@ -370,19 +308,8 @@ static void store_db() {
ejson::Array listFilesArray;
database.add("list-files", listFilesArray);
for (auto &it : m_listFile) {
ejson::Object fileElement;
listFilesArray.add(fileElement);
fileElement.add("id", ejson::Number(it.m_id));
fileElement.add("file-name", ejson::String(it.m_fileName));
fileElement.add("name", ejson::String(it.m_name));
fileElement.add("mine-type", ejson::String(it.m_mineType));
fileElement.add("add-date", ejson::Number(it.m_creationData.count()));
if (it.m_metadata.size() != 0) {
ejson::Object listMetadata;
fileElement.add("meta", listMetadata);
for (auto &itM : it.m_metadata) {
listMetadata.add(itM.first, ejson::String(itM.second));
}
if (it != nullptr) {
listFilesArray.add(it->getJson());
}
}
bool retGenerate = database.storeSafe(g_basePath + g_baseDBName);
@ -398,26 +325,15 @@ static void load_db() {
}
ejson::Array listFilesArray = database["list-files"].toArray();
for (const auto itArray: listFilesArray) {
ejson::Object fileElement = itArray.toObject();
FileProperty property;
property.m_id = fileElement["id"].toNumber().getU64();
APPL_INFO("get ID : " << property.m_id);
property.m_fileName = fileElement["file-name"].toString().get();
property.m_name = fileElement["name"].toString().get();
property.m_mineType = fileElement["mine-type"].toString().get();
property.m_creationData = echrono::Time(fileElement["add-date"].toNumber().getU64()*1000);
if (m_lastMaxId < property.m_id) {
m_lastMaxId = property.m_id+1;
auto property = ememory::makeShared<zeus::MediaImpl>(g_basePath, itArray.toObject());
if (property == nullptr) {
APPL_ERROR("can not allocate element ...");
continue;
}
ejson::Object tmpObj = fileElement["meta"].toObject();
if (tmpObj.exist() == true) {
for (auto itValue = tmpObj.begin();
itValue != tmpObj.end();
++itValue) {
property.m_metadata.insert(std::make_pair(itValue.getKey(), (*itValue).toString().get()));
}
if (m_lastMaxId < property->getUniqueId()) {
m_lastMaxId = property->getUniqueId()+1;
}
if (property.m_fileName == "") {
if (property->getFileName() == "") {
APPL_ERROR("Can not access on the file : ... No name ");
} else {
m_listFile.push_back(property);

View File

@ -4,74 +4,34 @@
#elem-author:Heero Yui<yui.heero@gmail.com
import zeus-File
import zeus-Media
// ----------------- Get media with their ID -----------------------
#brief:Get the number of media availlable (a media is a picture or a video)
#return: Number of media
uint32 mediaIdCount()
uint32 count()
#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 Ids
vector:uint32 mediaIdGet(uint32,uint32)
vector:uint32 getIds(uint32,uint32)
// ----------------- media Access -----------------------
#brief:Get the media mine-type
#param:mediaId:Id of the media
#return:A string describing the type of the media
string mediaMineTypeGet(uint32)
#brief:Get a media
#param:mediaId:Id of the media
#return:A file reference on the media (transmission is async)
obj:zeus-File mediaGet(uint32)
/*
#brief:Get a media in STREAM mode (usefull for video)
#param:mediaId:Id of the media
#return:A stream reference on the media (transmission is async)
obj::zeus-Stream mediaStream(uint32)
*/
obj:zeus-Media get(uint32)
#brief:Add a new media in the service
#param:data:A file reference on the media (transmission is async)
#return:Local personal ID of the media
uint32 mediaAdd(obj:zeus-File)
uint32 add(obj:zeus-File)
#brief:Remove a media in the service (no trash)
#param:mediaId:Id of the media
void mediaRemove(uint32)
void remove(uint32)
// ----------------- meta-data Access -----------------------
/*
#brief:Get all meta-data of a media
#param:mediaName:Name of the media
#return:a json description of the metadata
json mediaMetadataGet(string)
*/
#brief:Get all meta-data keys of a media
#param:mediaId:Id of the media
#return:List of all availlable keys
vector:string mediaMetadataGetKeys(uint32)
#brief:Get a meta-data value of a key
#param:mediaId:Id of the media
#param:key:Key of the meta-data
#return:data in the key
string mediaMetadataGetKey(uint32, string)
#brief:Set a meta-data value of a key
#param:mediaId:Id of the media
#param:key:Key of the meta-data
#param:value:data in the key
void mediaMetadataSetKey(uint32, string, string)
/*
#brief:Set all meta-data of a media
#param:name:Name of the media
#param:description: a json description of the metadata
void mediaMetadataSet(string, json)
*/
/*
The SQL-like is now: ['AND','='] only...
@ -81,7 +41,7 @@ void mediaMetadataSet(string, json)
#brief:Get a meta-data research elements with a SQL-like request
#param:sqlLikeRequest:A string containing the request on the data
#return:All The requested Data filter by the value
vector:uint32 getMediaWhere(string)
vector:uint32 getSQL(string)
#brief:Get a list of possibilities of a meta-data
#param:keyName:the key metadata whe we want to have list of possibilities

View File

@ -158,7 +158,7 @@ std::string zeus::getMineType(std::string _extention) {
return it.second;
}
}
ZEUS_ERROR(" try to convert extention in mine type: '" << _extention << "'");
ZEUS_ERROR(" estention to mine type error : '" << _extention << "' ==> unknow");
return "";
}
@ -169,6 +169,6 @@ std::string zeus::getExtention(std::string _mineType) {
return it.first;
}
}
ZEUS_ERROR(" try to convert mine-type in extention: '" << _mineType << "'");
ZEUS_ERROR(" mine type to estention error : '" << _mineType << "' ==> unknow");
return "";
}

View File

@ -22,13 +22,14 @@ ememory::SharedPtr<zeus::File> zeus::File::create(std::string _fileNameReal, std
zeus::FileImpl::FileImpl(std::string _fileNameReal) :
m_filename(_fileNameReal),
m_node(_fileNameReal) {
m_node(_fileNameReal),
m_gettedData(0) {
m_size = m_node.fileSize();
m_node.fileOpenRead();
std::string extention;
if ( _fileNameReal.rfind('.') != std::string::npos
&& _fileNameReal.rfind('.') != 0) {
extention = std::string(_fileNameReal.begin()+_fileNameReal.rfind('.'), _fileNameReal.end());
extention = std::string(_fileNameReal.begin()+_fileNameReal.rfind('.')+1, _fileNameReal.end());
}
m_mineType = zeus::getMineType(extention);
m_sha512 = algue::stringConvert(algue::sha512::encodeFromFile(_fileNameReal));
@ -37,6 +38,7 @@ zeus::FileImpl::FileImpl(std::string _fileNameReal) :
zeus::FileImpl::FileImpl(std::string _fileNameReal, std::string _fileNameShow, std::string _mineType) :
m_filename(_fileNameShow),
m_node(_fileNameReal),
m_gettedData(0),
m_mineType(_mineType) {
m_size = m_node.fileSize();
m_node.fileOpenRead();
@ -72,6 +74,8 @@ zeus::Raw zeus::FileImpl::getPart(uint64_t _start, uint64_t _stop) {
if (_start >= m_size) {
throw std::invalid_argument("REQUEST start position out of file size" + etk::to_string(_start) + " > " + etk::to_string(m_size));
}
m_gettedData += (_stop - _start);
ZEUS_PRINT("Reading file : " << m_gettedData << "/" << 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 ...");

View File

@ -11,11 +11,12 @@
namespace zeus {
class FileImpl : public zeus::File {
private:
std::string m_filename;
etk::FSNode m_node;
size_t m_size;
std::string m_mineType;
std::string m_sha512;
std::string m_filename; //!< Name of the file
etk::FSNode m_node; //!< File node access
size_t m_size; //!< Size of the file
size_t m_gettedData; //!< Number of byte loaded by the remote client
std::string m_mineType; //!< Mine Type of the file
std::string m_sha512; //!< Global file sha-512
public:
FileImpl(std::string _fileNameReal, std::string _fileNameShow, std::string _mineType);
FileImpl(std::string _fileNameReal);

114
zeus/zeus-Media.impl.cpp Normal file
View File

@ -0,0 +1,114 @@
/** @file
* @author Edouard DUPIN
* @copyright 2014, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#include <zeus/zeus-Media.impl.hpp>
#include <zeus/ProxyFile.hpp>
#include <zeus/mineType.hpp>
#include <algue/sha512.hpp>
#include <etk/os/FSNode.hpp>
#include "debug.hpp"
ememory::SharedPtr<zeus::Media> zeus::Media::create(std::string _fileNameReal) {
return ememory::makeShared<zeus::MediaImpl>(0, _fileNameReal);
}
ejson::Object zeus::MediaImpl::getJson() {
ejson::Object out;
out.add("id", ejson::Number(m_id));
out.add("file-name", ejson::String(m_fileName));
out.add("name", ejson::String(m_name));
out.add("mine-type", ejson::String(m_mineType));
out.add("add-date", ejson::Number(m_creationData.count()));
if (m_metadata.size() != 0) {
ejson::Object listMetadata;
out.add("meta", listMetadata);
for (auto &it : m_metadata) {
listMetadata.add(it.first, ejson::String(it.second));
}
}
return out;
}
zeus::MediaImpl::MediaImpl(const std::string& _basePath, ejson::Object _property) :
m_basePath(_basePath) {
m_id = _property["id"].toNumber().getU64();
ZEUS_INFO("get ID : " << m_id);
m_fileName = _property["file-name"].toString().get();
m_name = _property["name"].toString().get();
m_mineType = _property["mine-type"].toString().get();
m_creationData = echrono::Time(_property["add-date"].toNumber().getU64()*1000);
ejson::Object tmpObj = _property["meta"].toObject();
if (tmpObj.exist() == true) {
for (auto itValue = tmpObj.begin();
itValue != tmpObj.end();
++itValue) {
m_metadata.insert(std::make_pair(itValue.getKey(), (*itValue).toString().get()));
}
}
}
uint64_t zeus::MediaImpl::getUniqueId() {
return m_id;
}
zeus::MediaImpl::MediaImpl(uint64_t _id, const std::string& _fileNameReal):
m_id(_id),
m_fileName(_fileNameReal) {
std::string extention;
if ( m_fileName.rfind('.') != std::string::npos
&& m_fileName.rfind('.') != 0) {
extention = etk::tolower(std::string(m_fileName.begin()+m_fileName.rfind('.')+1, m_fileName.end()));
m_fileName = std::string(m_fileName.begin(), m_fileName.begin()+m_fileName.rfind('.'));
}
m_mineType = zeus::getMineType(extention);
m_creationData = echrono::Time::now();
}
zeus::MediaImpl::~MediaImpl() {
}
std::string zeus::MediaImpl::getMineType() {
return m_mineType;
}
ememory::SharedPtr<zeus::File> zeus::MediaImpl::GetFile() {
return zeus::File::create(m_basePath + m_fileName + "." + zeus::getExtention(m_mineType), "", m_mineType);
}
std::vector<std::string> zeus::MediaImpl::getMetadataKeys() {
std::vector<std::string> out;
for (auto &it : m_metadata) {
out.push_back(it.first);
}
return out;
}
std::string zeus::MediaImpl::getMetadata(std::string _key) {
auto it = m_metadata.find(_key);
if (it != m_metadata.end()) {
return it->second;
}
throw std::invalid_argument("KEY '" + _key + "' Does not exist");
}
void zeus::MediaImpl::setMetadata(std::string _key, std::string _value) {
ZEUS_INFO("metadataSetKey: '" << _key << "' value='" << _value << "'");
auto it = m_metadata.find(_key);
if (it != m_metadata.end()) {
it->second = _value;
} else {
m_metadata.insert(std::make_pair(_key, _value));
}
}
bool zeus::MediaImpl::erase() {
return etk::FSNodeRemove(m_basePath + m_fileName + "." + zeus::getExtention(m_mineType));
}

53
zeus/zeus-Media.impl.hpp Normal file
View File

@ -0,0 +1,53 @@
/** @file
* @author Edouard DUPIN
* @copyright 2014, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#pragma once
#include <zeus/Media.hpp>
#include <etk/os/FSNode.hpp>
#include <echrono/Time.hpp>
#include <ejson/ejson.hpp>
namespace zeus {
class MediaImpl : public zeus::Media {
private:
uint64_t m_id; //!< use local reference ID to have faster access on the file ...
std::string m_basePath; //!< basic global path
std::string m_fileName; // Sha 512
std::string m_name;
std::string m_mineType;
echrono::Time m_creationData;
std::map<std::string, std::string> m_metadata; //!< all extra property
public:
/**
* @brief Generic json constructor
*/
MediaImpl(const std::string& _basePath, ejson::Object _property);
/**
* @brief Generic file constructor
*/
MediaImpl(uint64_t _id, const std::string& _fileNameReal);
/**
* @brief Generic destructor
*/
~MediaImpl();
uint64_t getUniqueId() override;
std::string getMineType() override;
ememory::SharedPtr<zeus::File> GetFile() override;
std::vector<std::string> getMetadataKeys() override;
std::string getMetadata(std::string _key) override;
void setMetadata(std::string _key, std::string _value) override;
/**
* @brief Export json property
* @return A json Object with data
*/
ejson::Object getJson();
const std::string& getFileName() {
return m_fileName;
}
bool erase();
};
}

View File

@ -0,0 +1,59 @@
#elem-brief: File Object interface
#elem-version: 1.0
#elem-type:FILE
#elem-author:Heero Yui<yui.heero@gmail.com>
import zeus-File
// --------------------------
// -- Factory --
// --------------------------
#brief:Factory to create a local object.
#param:fileName:Name of the local file to instanciate.
[factory] create(string)
#brief:Get the book unique Id of the server+user
#return:The UID requested
uint64 getUniqueId()
// ----------------- media Access -----------------------
#brief:Get the media mine-type
#return:A string describing the type of the media
string getMineType()
#brief:Get a media
#return:A file reference on the media (transmission is async)
obj:zeus-File GetFile()
/*
#brief:Get a media in STREAM mode (usefull for video)
#return:A stream reference on the media (transmission is async)
obj::zeus-Stream getStream()
*/
// ----------------- meta-data Access -----------------------
#brief:Get all meta-data keys of a media
#return:List of all availlable keys
vector:string getMetadataKeys()
#brief:Get a meta-data value of a key
#param:key:Key of the meta-data
#return:data in the key
string getMetadata(string)
#brief:Set a meta-data value of a key
#param:key:Key of the meta-data
#param:value:data in the key
void setMetadata(string, string)
/*
#brief:Get all meta-data of a media
#return:a json description of the metadata
json getMetadataJson()
*/
/*
#brief:Set all meta-data of a media
#param:description: a json description of the metadata
void setMetadataJson(json)
*/