[DEBUG] many correction of low level interface

This commit is contained in:
Edouard DUPIN 2017-04-27 22:17:19 +02:00
parent a4f861886d
commit ebdf836ab1
13 changed files with 357 additions and 131 deletions

View File

@ -66,6 +66,7 @@ void appl::ClientProperty::connect() {
} else {
m_connection.propertyPort.set(m_port);
}
APPL_INFO("Connection on : " << m_connection.propertyIp.get() << ":" << m_connection.propertyPort.get() << " '" << m_fromUser << "' ==> '" << m_toUser << "'");
// Connection depending on the mode requested
if (m_fromUser == m_toUser) {
bool ret = m_connection.connect(m_fromUser, m_pass);
@ -92,6 +93,7 @@ void appl::ClientProperty::connect() {
APPL_INFO(" ==> Connected with 'anonymous' to '" << m_toUser << "'");
}
}
APPL_INFO("Done");
}
void appl::ClientProperty::setLogin(std::string _login) {

View File

@ -67,6 +67,274 @@ void appl::widget::ListViewer::searchElements(std::string _filter) {
}
}
void appl::ElementProperty::loadData() {
// Check progression status:
{
std::unique_lock<std::mutex> lock(m_mutex);
if (m_metadataUpdated != appl::statusLoadingData::noData) {
return;
}
m_metadataUpdated = appl::statusLoadingData::inProgress;
}
auto tmpProperty = sharedFromThis();
// Get the media
zeus::Future<zeus::ProxyMedia> futMedia = m_remoteServiceVideo.get(m_id);
futMedia.andElse([=](zeus::Future<zeus::ProxyMedia> _fut) mutable {
APPL_INFO(" [" << tmpProperty->m_id << "] get media error: " << tmpProperty->m_id);
{
std::unique_lock<std::mutex> lock(tmpProperty->m_mutex);
tmpProperty->m_title = "[ERROR] can not get media informations <br/>" + _fut.getErrorType() + ": " + _fut.getErrorHelp();
tmpProperty->m_metadataUpdated = appl::statusLoadingData::done;
}
m_widget->markToRedraw();
return true;
});
futMedia.andThen([=](zeus::Future<zeus::ProxyMedia> _fut) mutable {
APPL_INFO(" [" << tmpProperty->m_id << "] get media: " << tmpProperty->m_id);
zeus::ProxyMedia media = _fut.get();
if (media.exist() == false) {
APPL_ERROR("get media error");
{
std::unique_lock<std::mutex> lock(tmpProperty->m_mutex);
tmpProperty->m_title = "[ERROR] can not get media informations (2)<br/>" + _fut.getErrorType() + ": " + _fut.getErrorHelp();
tmpProperty->m_metadataUpdated = appl::statusLoadingData::done;
}
m_widget->markToRedraw();
return true;
}
media.getMetadata("title")
.andElse([=](zeus::Future<std::string> _fut) mutable {
{
std::unique_lock<std::mutex> lock(tmpProperty->m_mutex);
tmpProperty->m_nbElementLoaded++;
if (tmpProperty->m_nbElementLoaded >= 8) {
tmpProperty->m_metadataUpdated = appl::statusLoadingData::done;
}
}
return true;
})
.andThen([=](zeus::Future<std::string> _fut) mutable {
APPL_INFO(" [" << tmpProperty->m_id << "] get title: " << _fut.get());
{
std::unique_lock<std::mutex> lock(tmpProperty->m_mutex);
tmpProperty->m_title = _fut.get();
}
m_widget->markToRedraw();
{
std::unique_lock<std::mutex> lock(tmpProperty->m_mutex);
tmpProperty->m_nbElementLoaded++;
if (tmpProperty->m_nbElementLoaded >= 8) {
tmpProperty->m_metadataUpdated = appl::statusLoadingData::done;
}
}
return true;
});
media.getMetadata("series-name")
.andElse([=](zeus::Future<std::string> _fut) mutable {
{
std::unique_lock<std::mutex> lock(tmpProperty->m_mutex);
tmpProperty->m_nbElementLoaded++;
if (tmpProperty->m_nbElementLoaded >= 8) {
tmpProperty->m_metadataUpdated = appl::statusLoadingData::done;
}
}
return true;
})
.andThen([=](zeus::Future<std::string> _fut) mutable {
APPL_ERROR(" [" << tmpProperty->m_id << "] get serie: " << _fut.get());
{
std::unique_lock<std::mutex> lock(tmpProperty->m_mutex);
tmpProperty->m_serie = _fut.get();
}
m_widget->markToRedraw();
{
std::unique_lock<std::mutex> lock(tmpProperty->m_mutex);
tmpProperty->m_nbElementLoaded++;
if (tmpProperty->m_nbElementLoaded >= 8) {
tmpProperty->m_metadataUpdated = appl::statusLoadingData::done;
}
}
return true;
});
media.getMetadata("saison")
.andElse([=](zeus::Future<std::string> _fut) mutable {
{
std::unique_lock<std::mutex> lock(tmpProperty->m_mutex);
tmpProperty->m_nbElementLoaded++;
if (tmpProperty->m_nbElementLoaded >= 8) {
tmpProperty->m_metadataUpdated = appl::statusLoadingData::done;
}
}
return true;
})
.andThen([=](zeus::Future<std::string> _fut) mutable {
APPL_INFO(" [" << tmpProperty->m_id << "] get saison: " << _fut.get());
{
std::unique_lock<std::mutex> lock(tmpProperty->m_mutex);
tmpProperty->m_saison = _fut.get();
}
m_widget->markToRedraw();
{
std::unique_lock<std::mutex> lock(tmpProperty->m_mutex);
tmpProperty->m_nbElementLoaded++;
if (tmpProperty->m_nbElementLoaded >= 8) {
tmpProperty->m_metadataUpdated = appl::statusLoadingData::done;
}
}
return true;
});
media.getMetadata("episode")
.andElse([=](zeus::Future<std::string> _fut) mutable {
{
std::unique_lock<std::mutex> lock(tmpProperty->m_mutex);
tmpProperty->m_nbElementLoaded++;
if (tmpProperty->m_nbElementLoaded >= 8) {
tmpProperty->m_metadataUpdated = appl::statusLoadingData::done;
}
}
return true;
})
.andThen([=](zeus::Future<std::string> _fut) mutable {
APPL_INFO(" [" << tmpProperty->m_id << "] get episode: " << _fut.get());
{
std::unique_lock<std::mutex> lock(tmpProperty->m_mutex);
tmpProperty->m_episode = _fut.get();
}
m_widget->markToRedraw();
{
std::unique_lock<std::mutex> lock(tmpProperty->m_mutex);
tmpProperty->m_nbElementLoaded++;
if (tmpProperty->m_nbElementLoaded >= 8) {
tmpProperty->m_metadataUpdated = appl::statusLoadingData::done;
}
}
return true;
});
media.getMetadata("description")
.andElse([=](zeus::Future<std::string> _fut) mutable {
{
std::unique_lock<std::mutex> lock(tmpProperty->m_mutex);
tmpProperty->m_nbElementLoaded++;
if (tmpProperty->m_nbElementLoaded >= 8) {
tmpProperty->m_metadataUpdated = appl::statusLoadingData::done;
}
}
return true;
})
.andThen([=](zeus::Future<std::string> _fut) mutable {
APPL_INFO(" [" << tmpProperty->m_id << "] get description: " << _fut.get());
{
std::unique_lock<std::mutex> lock(tmpProperty->m_mutex);
tmpProperty->m_description = _fut.get();
}
m_widget->markToRedraw();
{
std::unique_lock<std::mutex> lock(tmpProperty->m_mutex);
tmpProperty->m_nbElementLoaded++;
if (tmpProperty->m_nbElementLoaded >= 8) {
tmpProperty->m_metadataUpdated = appl::statusLoadingData::done;
}
}
return true;
});
media.getMetadata("production-methode")
.andElse([=](zeus::Future<std::string> _fut) mutable {
{
std::unique_lock<std::mutex> lock(tmpProperty->m_mutex);
tmpProperty->m_nbElementLoaded++;
if (tmpProperty->m_nbElementLoaded >= 8) {
tmpProperty->m_metadataUpdated = appl::statusLoadingData::done;
}
}
return true;
})
.andThen([=](zeus::Future<std::string> _fut) mutable {
APPL_INFO(" [" << tmpProperty->m_id << "] get production-methode: " << _fut.get());
{
std::unique_lock<std::mutex> lock(tmpProperty->m_mutex);
tmpProperty->m_productMethode = _fut.get();
}
m_widget->markToRedraw();
{
std::unique_lock<std::mutex> lock(tmpProperty->m_mutex);
tmpProperty->m_nbElementLoaded++;
if (tmpProperty->m_nbElementLoaded >= 8) {
tmpProperty->m_metadataUpdated = appl::statusLoadingData::done;
}
}
return true;
});
media.getMetadata("type")
.andElse([=](zeus::Future<std::string> _fut) mutable {
{
std::unique_lock<std::mutex> lock(tmpProperty->m_mutex);
tmpProperty->m_nbElementLoaded++;
if (tmpProperty->m_nbElementLoaded >= 8) {
tmpProperty->m_metadataUpdated = appl::statusLoadingData::done;
}
}
return true;
})
.andThen([=](zeus::Future<std::string> _fut) mutable {
APPL_INFO(" [" << tmpProperty->m_id << "] get type: " << _fut.get());
{
std::unique_lock<std::mutex> lock(tmpProperty->m_mutex);
tmpProperty->m_type = _fut.get();
}
m_widget->markToRedraw();
{
std::unique_lock<std::mutex> lock(tmpProperty->m_mutex);
tmpProperty->m_nbElementLoaded++;
if (tmpProperty->m_nbElementLoaded >= 8) {
tmpProperty->m_metadataUpdated = appl::statusLoadingData::done;
}
}
return true;
});
media.getMineType()
.andElse([=](zeus::Future<std::string> _fut) mutable {
{
std::unique_lock<std::mutex> lock(tmpProperty->m_mutex);
tmpProperty->m_nbElementLoaded++;
if (tmpProperty->m_nbElementLoaded >= 8) {
tmpProperty->m_metadataUpdated = appl::statusLoadingData::done;
}
}
return true;
})
.andThen([=](zeus::Future<std::string> _fut) mutable {
APPL_INFO(" [" << tmpProperty->m_id << "] get mine-type: " << _fut.get());
{
std::unique_lock<std::mutex> lock(tmpProperty->m_mutex);
tmpProperty->m_mineType = _fut.get();
if (etk::start_with(tmpProperty->m_mineType, "video") == true) {
// TODO : Optimise this ...
tmpProperty->m_thumb = egami::load("DATA:Video.svg", ivec2(128,128));
} else if (etk::start_with(tmpProperty->m_mineType, "audio") == true) {
// TODO : Optimise this ...
tmpProperty->m_thumb = egami::load("DATA:MusicNote.svg", ivec2(128,128));
}
}
m_widget->markToRedraw();
{
std::unique_lock<std::mutex> lock(tmpProperty->m_mutex);
tmpProperty->m_nbElementLoaded++;
if (tmpProperty->m_nbElementLoaded >= 8) {
tmpProperty->m_metadataUpdated = appl::statusLoadingData::done;
}
}
return true;
});
return true;
});
}
bool appl::ElementProperty::LoadDataEnded() {
std::unique_lock<std::mutex> lock(m_mutex);
return m_metadataUpdated == appl::statusLoadingData::done;
}
void appl::widget::ListViewer::searchElementsInternal(const std::string& _filter, const std::string& _group) {
m_listElement.clear();
m_listElementGroup.clear();
@ -128,114 +396,16 @@ void appl::widget::ListViewer::searchElementsInternal(const std::string& _filter
std::vector<uint32_t> returnValues = listElem.get();
APPL_INFO("Get some Values: " << returnValues << "");
for (auto &it : returnValues) {
auto elem = ememory::makeShared<ElementProperty>();
auto elem = ememory::makeShared<ElementProperty>(remoteServiceVideo, ememory::staticPointerCast<ewol::Widget>(sharedFromThis()));
if (elem == nullptr) {
APPL_ERROR("Can not allocate element... " << it);
continue;
}
elem->m_id = it;
elem->m_metadataUpdated = false;
/*
// TODO : Type the "andThen" to simplify user experience
// TODO : Add the reference on the typed future in the function andTrn ... ==> then we can add later the cancel
// Get the media
zeus::ProxyMedia media = remoteServiceVideo.get(it).waitFor(echrono::seconds(2000)).get();
if (media.exist() == false) {
APPL_ERROR("get media error");
continue;
}
appl::widget::ListViewerShared tmpWidget = ememory::staticPointerCast<appl::widget::ListViewer>(sharedFromThis());
media.getMetadata("title")
.andThen([=](zeus::Future<std::string> _fut) mutable {
APPL_INFO(" [" << elem->m_id << "] get title: " << _fut.get());
{
std::unique_lock<std::mutex> lock(elem->m_mutex);
elem->m_title = _fut.get();
}
tmpWidget->markToRedraw();
return true;
});
media.getMetadata("series-name")
.andThen([=](zeus::Future<std::string> _fut) mutable {
APPL_ERROR(" [" << elem->m_id << "] get serie: " << _fut.get());
{
std::unique_lock<std::mutex> lock(elem->m_mutex);
elem->m_serie = _fut.get();
}
tmpWidget->markToRedraw();
return true;
});
media.getMetadata("saison")
.andThen([=](zeus::Future<std::string> _fut) mutable {
APPL_INFO(" [" << elem->m_id << "] get saison: " << _fut.get());
{
std::unique_lock<std::mutex> lock(elem->m_mutex);
elem->m_saison = _fut.get();
}
tmpWidget->markToRedraw();
return true;
});
media.getMetadata("episode")
.andThen([=](zeus::Future<std::string> _fut) mutable {
APPL_INFO(" [" << elem->m_id << "] get episode: " << _fut.get());
{
std::unique_lock<std::mutex> lock(elem->m_mutex);
elem->m_episode = _fut.get();
}
tmpWidget->markToRedraw();
return true;
});
media.getMetadata("description")
.andThen([=](zeus::Future<std::string> _fut) mutable {
APPL_INFO(" [" << elem->m_id << "] get description: " << _fut.get());
{
std::unique_lock<std::mutex> lock(elem->m_mutex);
elem->m_description = _fut.get();
}
tmpWidget->markToRedraw();
return true;
});
media.getMetadata("production-methode")
.andThen([=](zeus::Future<std::string> _fut) mutable {
APPL_INFO(" [" << elem->m_id << "] get production-methode: " << _fut.get());
{
std::unique_lock<std::mutex> lock(elem->m_mutex);
elem->m_productMethode = _fut.get();
}
tmpWidget->markToRedraw();
return true;
});
media.getMetadata("type")
.andThen([=](zeus::Future<std::string> _fut) mutable {
APPL_INFO(" [" << elem->m_id << "] get type: " << _fut.get());
{
std::unique_lock<std::mutex> lock(elem->m_mutex);
elem->m_type = _fut.get();
}
tmpWidget->markToRedraw();
return true;
});
media.getMineType()
.andThen([=](zeus::Future<std::string> _fut) mutable {
APPL_INFO(" [" << elem->m_id << "] get mine-type: " << _fut.get());
{
std::unique_lock<std::mutex> lock(elem->m_mutex);
elem->m_mineType = _fut.get();
if (etk::start_with(elem->m_mineType, "video") == true) {
// TODO : Optimise this ...
elem->m_thumb = egami::load("DATA:Video.svg", ivec2(128,128));
} else if (etk::start_with(elem->m_mineType, "audio") == true) {
// TODO : Optimise this ...
elem->m_thumb = egami::load("DATA:MusicNote.svg", ivec2(128,128));
}
}
tmpWidget->markToRedraw();
return true;
});
*/
elem->m_metadataUpdated = true;
//elem->m_thumb = remoteServiceVideo.mediaThumbGet(it, 128).wait().get();
m_listElement.push_back(elem);
}
@ -343,6 +513,9 @@ void appl::widget::ListViewer::onRegenerateDisplay() {
elem->m_idCurentElement = offset + iii;
if (offset + iii < m_listElement.size()) {
elem->m_property = m_listElement[offset + iii];
if (elem->m_property != nullptr) {
elem->m_property->loadData();
}
} else {
elem->m_property.reset();
}
@ -456,7 +629,7 @@ void appl::ElementDisplayed::generateDisplay(vec2 _startPos, vec2 _size) {
std::string textToDisplay;
if (m_property != nullptr) {
std::unique_lock<std::mutex> lock(m_property->m_mutex);
if (m_property->m_metadataUpdated == false) {
if (m_property->LoadDataEnded() == false) {
textToDisplay += "<br/><i>Loading in progress</i>";
} else {
//m_text.setClipping(drawClippingPos, drawClippingSize);

View File

@ -12,16 +12,37 @@
#include <ewol/compositing/Drawing.hpp>
#include <ewol/widget/Manager.hpp>
#include <esignal/Signal.hpp>
#include <zeus/service/ProxyVideo.hpp>
#include <zeus/Client.hpp>
#include <appl/ClientProperty.hpp>
namespace appl {
class ElementProperty {
enum class statusLoadingData {
noData,
inProgress,
done
};
class ElementProperty : public ememory::EnableSharedFromThis<appl::ElementProperty> {
private:
zeus::service::ProxyVideo m_remoteServiceVideo;
ewol::WidgetShared m_widget;
public:
ElementProperty(zeus::service::ProxyVideo& _remoteServiceVideo, ewol::WidgetShared _widget):
m_remoteServiceVideo(_remoteServiceVideo),
m_widget(_widget),
m_metadataUpdated(appl::statusLoadingData::noData),
m_nbElementLoaded(0) {
}
protected:
enum appl::statusLoadingData m_metadataUpdated; //!< Check value to know when metadata is getted (like thumb ...)
uint32_t m_nbElementLoaded; //!< this cont the number of lement loaded to set tle media full loaded
public:
bool LoadDataEnded();
std::mutex m_mutex;
uint64_t m_id; //!< Remote Id of the Media
bool m_metadataUpdated; //!< Check value to know when metadata is getted (like thumb ...)
egami::Image m_thumb; //!< simple image describing the element
std::string m_title; //!< Title of the Element
std::string m_description; //!< Description of the element
@ -34,6 +55,7 @@ namespace appl {
// TODO: float m_globalNote; //!< note over [0,0..1,0]
// TODO: int32_t m_countPersonalView; //!< number of view this media
// TODO: int64_t m_globalPersonalView; //!< number of time this media has been viewed
void loadData();
};
class ElementPropertyGroup {
public:
@ -71,7 +93,6 @@ namespace appl {
class ListViewer;
using ListViewerShared = ememory::SharedPtr<appl::widget::ListViewer>;
using ListViewerWeak = ememory::WeakPtr<appl::widget::ListViewer>;
class ListViewer : public ewol::widget::WidgetScrolled {
protected:
ewol::compositing::Text m_text;

View File

@ -223,10 +223,10 @@ void zeus::Client::onPropertyChangePort(){
}
bool zeus::Client::connectTo(const std::string& _address) {
bool zeus::Client::connectTo(const std::string& _address, echrono::Duration _timeOut) {
ZEUS_DEBUG("connect [START]");
disconnect();
enet::Tcp connection = std::move(enet::connectTcpClient(*propertyIp, *propertyPort));
enet::Tcp connection = std::move(enet::connectTcpClient(*propertyIp, *propertyPort, 1));
m_interfaceWeb = ememory::makeShared<zeus::WebServer>();
if (m_interfaceWeb == nullptr) {
ZEUS_ERROR("Allocate connection error");
@ -265,12 +265,12 @@ bool zeus::Client::connectTo(const std::string& _address) {
return true;
}
bool zeus::Client::connect() {
bool ret = connectTo("directIO");
bool zeus::Client::connect(echrono::Duration _timeOut) {
bool ret = connectTo("directIO", _timeOut);
if (ret==false) {
return false;
}
zeus::Future<bool> retIdentify = call(0, ZEUS_ID_GATEWAY, "service").wait();
zeus::Future<bool> retIdentify = call(0, ZEUS_ID_GATEWAY, "service").waitFor(_timeOut);
if (retIdentify.hasError() == true) {
disconnect();
return false;
@ -281,13 +281,13 @@ bool zeus::Client::connect() {
return retIdentify.get();
}
bool zeus::Client::connect(const std::string& _address) {
bool zeus::Client::connect(const std::string& _address, echrono::Duration _timeOut) {
m_clientName = _address;
bool ret = connectTo(_address);
bool ret = connectTo(_address, _timeOut);
if (ret==false) {
return false;
}
zeus::Future<bool> retIdentify = call(0, ZEUS_ID_GATEWAY, "anonymous").wait();
zeus::Future<bool> retIdentify = call(0, ZEUS_ID_GATEWAY, "anonymous").waitFor(_timeOut);
if (retIdentify.hasError() == true) {
disconnect();
return false;
@ -298,13 +298,13 @@ bool zeus::Client::connect(const std::string& _address) {
return retIdentify.get();
}
bool zeus::Client::connect(const std::string& _address, const std::string& _userPassword) {
bool zeus::Client::connect(const std::string& _address, const std::string& _userPassword, echrono::Duration _timeOut) {
m_clientName = _address;
bool ret = connectTo(_address);
bool ret = connectTo(_address, _timeOut);
if (ret==false) {
return false;
}
zeus::Future<bool> retIdentify = call(0, ZEUS_ID_GATEWAY, "auth", _userPassword).wait();
zeus::Future<bool> retIdentify = call(0, ZEUS_ID_GATEWAY, "auth", _userPassword).waitFor(_timeOut);
if (retIdentify.hasError() == true) {
disconnect();
return false;
@ -315,13 +315,13 @@ bool zeus::Client::connect(const std::string& _address, const std::string& _user
return retIdentify.get();
}
bool zeus::Client::connect(const std::string& _address, const std::string& _clientName, const std::string& _clientTocken) {
bool zeus::Client::connect(const std::string& _address, const std::string& _clientName, const std::string& _clientTocken, echrono::Duration _timeOut) {
m_clientName = _clientName;
bool ret = connectTo(_address);
bool ret = connectTo(_address, _timeOut);
if (ret==false) {
return false;
}
zeus::Future<bool> retIdentify = call(0, ZEUS_ID_GATEWAY, "identify", _clientName, _clientTocken).wait();
zeus::Future<bool> retIdentify = call(0, ZEUS_ID_GATEWAY, "identify", _clientName, _clientTocken).waitFor(_timeOut);
if (retIdentify.hasError() == true) {
disconnect();
return false;

View File

@ -49,32 +49,37 @@ namespace zeus {
/**
* @brief Connetc to a remote extern server
* @param[in] _address Address of the user: "ABCD.efgh~atria-soft.com:1993"
* @param[in] _timeOut duration that we are waiting the server answer
*/
bool connectTo(const std::string& _address);
bool connectTo(const std::string& _address, echrono::Duration _timeOut = echrono::seconds(1));
public:
/**
* @brief Direct connection on a GateWay No Identification needed, the Port on the Gateway garenty the connection)
* @note This is exclusively reserve for server service provicers
* @param[in] _timeOut duration that we are waiting the server answer
*/
bool connect();
bool connect(echrono::Duration _timeOut = echrono::seconds(1));
/**
* @brief Create a client on a specific user in an ANONIMOUS way
* @param[in] _address Address of the user: "ABCD.efgh~atria-soft.com:1993"
* @param[in] _timeOut duration that we are waiting the server answer
*/
bool connect(const std::string& _address);
bool connect(const std::string& _address, echrono::Duration _timeOut = echrono::seconds(1));
/**
* @brief Create a client on a specific user in a user mode (connect to your personnal account)
* @param[in] _address Address of the user: "ABCD.efgh~atria-soft.com:1993"
* @param[in] _userPassword Password of the user
* @param[in] _timeOut duration that we are waiting the server answer
*/
bool connect(const std::string& _address, const std::string& _userPassword);
bool connect(const std::string& _address, const std::string& _userPassword, echrono::Duration _timeOut = echrono::seconds(1));
/**
* @brief Create a client on a specific user in a client mode with the tocken associated
* @param[in] _address Address of the user: "ABCD.efgh~atria-soft.com:1993"
* @param[in]
* @param[in]
* @param[in] _timeOut duration that we are waiting the server answer
*/
bool connect(const std::string& _address, const std::string& _clientName, const std::string& _clientTocken);
bool connect(const std::string& _address, const std::string& _clientName, const std::string& _clientTocken, echrono::Duration _timeOut = echrono::seconds(1));
/**
* @brief Disconnect of the current interface
*/

View File

@ -12,6 +12,7 @@ namespace zeus {
/**
* @brief Class that permit to add all waiting feture inside this group and wait only one time
*/
// TODO : Add the posiboilities to have a andFinished()
class FutureGroup {
private:
std::vector<zeus::FutureBase> m_listFuture;

View File

@ -45,7 +45,7 @@ zeus::WebServer::WebServer() :
m_connection(),
m_processingPool(20),
m_localAddress(0),
m_licalIdObjectIncrement(1),
m_localIdObjectIncrement(1),
m_interfaceId(0),
m_transmissionId(1),
m_observerElement(nullptr),
@ -59,7 +59,7 @@ zeus::WebServer::WebServer(enet::Tcp _connection, bool _isServer) :
m_connection(),
m_processingPool(20),
m_localAddress(0),
m_licalIdObjectIncrement(1),
m_localIdObjectIncrement(1),
m_interfaceId(0),
m_transmissionId(1),
m_observerElement(nullptr),
@ -103,10 +103,12 @@ void zeus::WebServer::setInterfaceName(const std::string& _name) {
}
void zeus::WebServer::addWebObj(ememory::SharedPtr<zeus::WebObj> _obj) {
std::unique_lock<std::mutex> lock(m_mutex);
m_listObject.push_back(_obj);
}
void zeus::WebServer::addWebObjRemote(ememory::SharedPtr<zeus::ObjectRemoteBase> _obj) {
std::unique_lock<std::mutex> lock(m_mutex);
m_listRemoteObject.push_back(_obj);
}
@ -265,7 +267,6 @@ int32_t zeus::WebServer::writeBinary(ememory::SharedPtr<zeus::Message> _obj) {
_obj->setInterfaceId(m_interfaceId);
ZEUS_LOG_INPUT_OUTPUT("Send :" << _obj);
if (_obj->writeOn(m_connection) == true) {
m_connection.send();
if (_obj->haveAsync() == true) {
addAsync(SendAsyncBinary(_obj->getTransactionId(), _obj->getSource(), _obj->getDestination(), std::move(_obj->moveAsync())));
}
@ -343,11 +344,13 @@ void zeus::WebServer::newMessage(ememory::SharedPtr<zeus::Message> _buffer) {
}
if ( _buffer->getPartFinish() == false
&& _buffer->getType() != zeus::message::type::data) {
std::unique_lock<std::mutex> lock(m_mutex);
m_listPartialMessage.push_back(_buffer);
return;
}
if (_buffer->getType() == zeus::message::type::data) {
// Add data in a previous buffer...
std::unique_lock<std::mutex> lock(m_mutex);
auto it = m_listPartialMessage.begin();
while (it != m_listPartialMessage.end()) {
if (*it == nullptr) {
@ -417,6 +420,7 @@ void zeus::WebServer::newMessage(ememory::SharedPtr<zeus::Message> _buffer) {
return;
}
}
std::unique_lock<std::mutex> lock(m_mutex);
// call local map object on remote object
for (auto &it : m_listRemoteObject) {
ememory::SharedPtr<zeus::ObjectRemoteBase> tmp = it.lock();
@ -474,6 +478,7 @@ void zeus::WebServer::newMessage(ememory::SharedPtr<zeus::Message> _buffer) {
}
void zeus::WebServer::listObjects() {
std::unique_lock<std::mutex> lock(m_mutex);
if ( m_listObject.size() == 0
&& m_listRemoteObject.size() == 0) {
return;
@ -495,6 +500,7 @@ void zeus::WebServer::listObjects() {
}
void zeus::WebServer::cleanDeadObject() {
std::unique_lock<std::mutex> lock(m_mutex);
if ( m_listObject.size() == 0
&& m_listRemoteObject.size() == 0) {
return;
@ -524,6 +530,7 @@ void zeus::WebServer::cleanDeadObject() {
}
bool zeus::WebServer::transferRemoteObjectOwnership(uint16_t _objectAddress, uint32_t _sourceAddress, uint32_t _destinataireAddress) {
std::unique_lock<std::mutex> lock(m_mutex);
if ( m_listObject.size() == 0
&& m_listRemoteObject.size() == 0) {
return false;
@ -550,6 +557,7 @@ bool zeus::WebServer::transferRemoteObjectOwnership(uint16_t _objectAddress, uin
}
bool zeus::WebServer::removeObjectOwnership(uint16_t _objectAddress, uint32_t _sourceAddress) {
std::unique_lock<std::mutex> lock(m_mutex);
if ( m_listObject.size() == 0
&& m_listRemoteObject.size() == 0) {
return false;

View File

@ -98,6 +98,8 @@ namespace zeus {
* @brief
*/
class WebServer : public ememory::EnableSharedFromThis<zeus::WebServer> {
protected:
std::mutex m_mutex;
public:
std::vector<ememory::SharedPtr<zeus::WebObj>> m_actifObject; //!< List of all active object created and that remove is in progress ...
private:
@ -105,7 +107,7 @@ namespace zeus {
ethread::Pool m_processingPool;
std::vector<ememory::SharedPtr<zeus::Message>> m_listPartialMessage;
uint16_t m_localAddress;
uint16_t m_licalIdObjectIncrement; //!< attribute a unique ID for an object
uint16_t m_localIdObjectIncrement; //!< attribute an unique ID for an object
public:
uint16_t getAddress() const {
return m_localAddress;
@ -114,7 +116,7 @@ namespace zeus {
m_localAddress = _address;
}
uint16_t getNewObjectId() {
return m_licalIdObjectIncrement++;
return m_localIdObjectIncrement++;
}
private:
std::vector<ememory::SharedPtr<zeus::WebObj>> m_listObject;

View File

@ -46,7 +46,11 @@ bool zeus::message::Answer::writeOn(enet::WebSocket& _interface) {
if (m_errorType.size() != 0) {
_interface.writeData((uint8_t*)m_errorHelp.c_str(), m_errorHelp.size() + 1);
}
return message::Parameter::writeOn(_interface);
if (message::Parameter::writeOn(_interface) == false) {
return false;
}
int32_t count = _interface.send();
return count > 0;
}
void zeus::message::Answer::composeWith(const uint8_t* _buffer, uint32_t _lenght) {

View File

@ -38,7 +38,11 @@ bool zeus::message::Call::writeOn(enet::WebSocket& _interface) {
std::unique_lock<std::mutex> lock = _interface.getScopeLock();
zeus::Message::writeOn(_interface);
_interface.writeData((uint8_t*)m_callName.c_str(), m_callName.size() + 1);
return message::Parameter::writeOn(_interface);
if (message::Parameter::writeOn(_interface) == false) {
return false;
}
int32_t count = _interface.send();
return count > 0;
}
void zeus::message::Call::composeWith(const uint8_t* _buffer, uint32_t _lenght) {

View File

@ -37,11 +37,15 @@ void zeus::message::Data::setPartId(uint32_t _value) {
}
bool zeus::message::Data::writeOn(enet::WebSocket& _interface) {
zeus::Message::writeOn(_interface);
std::unique_lock<std::mutex> lock = _interface.getScopeLock();
if (zeus::Message::writeOn(_interface) == false) {
return false;
}
_interface.writeData((uint8_t*)&m_partId, sizeof(uint32_t));
_interface.writeData((uint8_t*)&m_parameterId, sizeof(uint16_t));
_interface.writeData((uint8_t*)&m_data[0], m_data.size());
return true;
int32_t count = _interface.send();
return count > 0;
}
void zeus::message::Data::composeWith(const uint8_t* _buffer, uint32_t _lenght) {

View File

@ -268,6 +268,7 @@ namespace zeus {
* @param[in] _interface socket to write data
* @return true of no error appear
*/
// This fucntion does not lock the interface
virtual bool writeOn(enet::WebSocket& _interface);
virtual void generateDisplay(std::ostream& _os) const ;
};

View File

@ -64,6 +64,7 @@ namespace zeus {
*/
std::string simpleStringParam(uint32_t _id) const;
void composeWith(const uint8_t* _buffer, uint32_t _lenght) override;
// !! This function does not lock the socket interface
bool writeOn(enet::WebSocket& _interface) override;
protected:
/**