From e4ddecc0eb923cfe5725c7ddcc5667eafc1f409f Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Fri, 26 May 2017 23:27:31 +0000 Subject: [PATCH] [DEV] build back --- .../cli-video/appl/main-tool-client-video.cpp | 32 +++++++++++++++++-- .../service-video/appl/main-service-video.cpp | 14 ++++++++ .../appl/zeus-service-video.srv.zeus.idl | 6 ++++ zeus/AbstractFunction.cpp | 2 +- zeus/AbstractFunction.hpp | 6 ++-- zeus/Future.hpp | 4 +-- zeus/Promise.cpp | 3 +- zeus/Promise.hpp | 2 +- zeus/zeus-Media.obj.zeus.idl | 1 + 9 files changed, 60 insertions(+), 10 deletions(-) diff --git a/tools/cli-video/appl/main-tool-client-video.cpp b/tools/cli-video/appl/main-tool-client-video.cpp index 08037f4..539e948 100644 --- a/tools/cli-video/appl/main-tool-client-video.cpp +++ b/tools/cli-video/appl/main-tool-client-video.cpp @@ -71,12 +71,40 @@ bool pushVideoFile(zeus::service::ProxyVideo& _srv, std::string _path, std::map< } std::string storedSha512; if (etk::FSNodeExist(_path + ".sha512") == true) { - //TODO ... - storedSha512 = etk::FSNodeReadAllData(_path + ".sha512"); + uint64_t time_sha512 = etk::FSNodeGetTimeModified(_path + ".sha512"); + uint64_t time_elem = etk::FSNodeGetTimeModified(_path); + std::string storedSha512_file = etk::FSNodeReadAllData(_path + ".sha512"); + if (time_elem > time_sha512) { + // check the current sha512 + storedSha512 = algue::stringConvert(algue::sha512::encodeFromFile(_path)); + if (storedSha512_file != storedSha512) { + //need to remove the old sha file + auto idFileToRemove_fut = _srv.getId(storedSha512_file).waitFor(echrono::seconds(2)); + if (idFileToRemove_fut.hasError() == true) { + APPL_ERROR("can not remove the remote file with sha " + storedSha512_file); + } else { + APPL_INFO("Remove old deprecated file: " + storedSha512_file); + _srv.remove(idFileToRemove_fut.get()); + // note, no need to wait the call is async ... and the user does not interested with the result ... + } + } + // store new sha512 ==> this update tile too ... + etk::FSNodeWriteAllData(_path + ".sha512", storedSha512); + } else { + // store new sha512 + storedSha512 = etk::FSNodeReadAllData(_path + ".sha512"); + } } else { storedSha512 = algue::stringConvert(algue::sha512::encodeFromFile(_path)); etk::FSNodeWriteAllData(_path + ".sha512", storedSha512); } + // push only if the file exist + // TODO : Check the metadata updating ... + auto idFile_fut = _srv.getId(storedSha512).waitFor(echrono::seconds(2)); + if (idFile_fut.hasError() == false) { + // media already exit ==> stop here ... + return true; + } // TODO: Do it better ==> add the calback to know the push progression ... uint32_t mediaId = _srv.add(zeus::File::create(_path, storedSha512)).waitFor(echrono::seconds(20000)).get(); if (mediaId == 0) { diff --git a/tools/service-video/appl/main-service-video.cpp b/tools/service-video/appl/main-service-video.cpp index 9a2572d..543d768 100644 --- a/tools/service-video/appl/main-service-video.cpp +++ b/tools/service-video/appl/main-service-video.cpp @@ -140,6 +140,20 @@ namespace appl { } return out; } + uint32_t getId(std::string _sha512) override { + std::unique_lock lock(g_mutex); + // TODO : Check right ... + uint32_t out; + for (size_t iii=0; iiigetSha512() == _sha512) { + return m_listFile[iii]->getUniqueId(); + } + } + throw std::invalid_argument("sha512 not find..."); + } // Return a File Data (might be a video .tiff/.png/.jpg) ememory::SharedPtr get(uint32_t _mediaId) override { diff --git a/tools/service-video/appl/zeus-service-video.srv.zeus.idl b/tools/service-video/appl/zeus-service-video.srv.zeus.idl index 9984f17..95b7b57 100644 --- a/tools/service-video/appl/zeus-service-video.srv.zeus.idl +++ b/tools/service-video/appl/zeus-service-video.srv.zeus.idl @@ -17,6 +17,12 @@ uint32 count() #return:List of the media Ids vector:uint32 getIds(uint32,uint32) +#brief: Get the Id of the element with the current sha 512 +#param:sha512:Sha512 of the file searched +#return:Id of the media +uint32 getId(string) + + // ----------------- media Access ----------------------- #brief:Get a media #param:mediaId:Id of the media diff --git a/zeus/AbstractFunction.cpp b/zeus/AbstractFunction.cpp index e473fe7..c1b6b65 100644 --- a/zeus/AbstractFunction.cpp +++ b/zeus/AbstractFunction.cpp @@ -37,7 +37,7 @@ bool zeus::checkOrderFunctionParameter() { const std::string zeus::g_threadKeyTransactionId("zeus-transaction-id"); const std::string zeus::g_threadKeyTransactionSource("zeus-transaction-source"); -const std::string zeus::g_threadKeyTransactiondestination("zeus-transaction-destination"); +const std::string zeus::g_threadKeyTransactionDestination("zeus-transaction-destination"); enum zeus::AbstractFunction::type zeus::AbstractFunction::getType() const { diff --git a/zeus/AbstractFunction.hpp b/zeus/AbstractFunction.hpp index 0b23e42..7a2b957 100644 --- a/zeus/AbstractFunction.hpp +++ b/zeus/AbstractFunction.hpp @@ -13,9 +13,9 @@ namespace zeus { - static const std::string g_threadKeyTransactionId; - static const std::string g_threadKeyTransactionSource; - static const std::string g_threadKeyTransactiondestination; + extern const std::string g_threadKeyTransactionId; + extern const std::string g_threadKeyTransactionSource; + extern const std::string g_threadKeyTransactionDestination; /** * @bried check if the compilater order the function element call in order or backOrder */ diff --git a/zeus/Future.hpp b/zeus/Future.hpp index 8dbfa34..be89cb0 100644 --- a/zeus/Future.hpp +++ b/zeus/Future.hpp @@ -100,7 +100,7 @@ namespace zeus { * @brief Attach callback on activity of the action if user set some return information * @param[in] _callback Handle on the function to call in progress information */ - Future& onProgress(ObserverProgress _callback) { + Future& onProgress(Promise::ObserverProgress _callback) { zeus::FutureBase::onProgress(_callback); return *this; } @@ -190,7 +190,7 @@ namespace zeus { * @brief Attach callback on activity of the action if user set some return information * @param[in] _callback Handle on the function to call in progress information */ - Future& onProgress(ObserverProgress _callback) { + Future& onProgress(Promise::ObserverProgress _callback) { zeus::FutureBase::onProgress(_callback); return *this; } diff --git a/zeus/Promise.cpp b/zeus/Promise.cpp index 4c22ec1..836b957 100644 --- a/zeus/Promise.cpp +++ b/zeus/Promise.cpp @@ -123,7 +123,8 @@ bool zeus::Promise::setMessage(ememory::SharedPtr _value) { std::unique_lock lock(m_mutex); // notification of a progresion ... if (m_callbackProgress != nullptr) { - return m_callbackProgress(_value.); + // TODO: return m_callbackProgress(_value.); + #warning progress callback to do .. } return false; } diff --git a/zeus/Promise.hpp b/zeus/Promise.hpp index dac18c8..2dceb0c 100644 --- a/zeus/Promise.hpp +++ b/zeus/Promise.hpp @@ -23,7 +23,7 @@ namespace zeus { using Observer = std::function; //!< Define an Observer: function pointer using ObserverProgress = std::function; //!< Define the observer on activity of the action (note that is a string, but it can contain json or other ...) private: - std::mutex m_mutex; //!< local prevention of multiple acess + mutable std::mutex m_mutex; //!< local prevention of multiple acess uint32_t m_transactionId; //!< waiting answer data uint32_t m_source; //!< Source of the message. ememory::SharedPtr m_message; //!< all buffer concatenate or last buffer if synchronous diff --git a/zeus/zeus-Media.obj.zeus.idl b/zeus/zeus-Media.obj.zeus.idl index ec860f1..800ba11 100644 --- a/zeus/zeus-Media.obj.zeus.idl +++ b/zeus/zeus-Media.obj.zeus.idl @@ -65,3 +65,4 @@ string getSha512() #brief:Get decorated name of the file #return:decorated name: Name of the file decorated like StarWars-e04-A new Hope(1978).mkv string getDecoratedName() +