[DEBUG] correct future time-out and remove remote object

This commit is contained in:
Edouard DUPIN 2016-12-15 16:48:09 +01:00
parent 4b961dbc84
commit 7f1883dbea
10 changed files with 26 additions and 10 deletions

View File

@ -57,6 +57,7 @@ void installPath(zeus::service::ProxyPicture& _srv, std::string _path, uint32_t
APPL_ERROR("Get media ID = 0 With no error");
}
if (_albumID != 0) {
APPL_INFO("Add media '" << mediaId << "'in ALbum: " << _albumID);
_srv.albumMediaAdd(_albumID, mediaId).wait();
}
} else {

View File

@ -447,6 +447,7 @@ static void load_db() {
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();
@ -476,8 +477,8 @@ static void load_db() {
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();
for (const auto itArrayMedia: listAlbumArray) {
ejson::Array listMadiaArray = albumElement["media"].toArray();
for (const auto itArrayMedia: listMadiaArray) {
uint64_t tmp = itArrayMedia.toNumber().getU64();
album.m_listMedia.push_back(tmp);
}

View File

@ -92,16 +92,17 @@ void zeus::Client::onClientData(ememory::SharedPtr<zeus::Message> _value) {
return;
} else if (callFunction == "unlink") {
uint32_t objectAddress = callObj->getParameter<uint32_t>(0);
ZEUS_VERBOSE("unlink requested of " << (objectAddress>>16) << "/" << (objectAddress&0xFFFF) << " local interface adress : " << m_interfaceWeb->getAddress());
if ((objectAddress>> 16) != m_interfaceWeb->getAddress()) {
m_interfaceWeb->answerError(transactionId, _value->getDestination(), _value->getSource(), "REMOVE-OWNERSHIP-WRONG-INTERFACE");
return;
}
bool ret = m_interfaceWeb->remoteObjectOwnership(objectAddress&0xFFFF, _value->getSource());
bool ret = m_interfaceWeb->removeObjectOwnership(objectAddress&0xFFFF, _value->getSource());
if (ret == true) {
m_interfaceWeb->answerVoid(transactionId, _value->getDestination(), _value->getSource());
return;
}
m_interfaceWeb->answerError(transactionId, _value->getDestination(), _value->getSource(), "REMOVE-OWNERSHIP-ERROR");
m_interfaceWeb->answerError(transactionId, _value->getDestination(), _value->getSource(), "REMOVE-OWNERSHIP-ERROR", "the object does not exist ...");
return;
} else if (callFunction == "movelink") {
uint32_t objectAddress = callObj->getParameter<uint32_t>(0);
@ -110,7 +111,7 @@ void zeus::Client::onClientData(ememory::SharedPtr<zeus::Message> _value) {
m_interfaceWeb->answerError(transactionId, _value->getDestination(), _value->getSource(), "TRANSFER-OWNERSHIP-WRONG-INTERFACE");
return;
}
bool ret = m_interfaceWeb->transferRemoteObjectOwnership(objectAddress&0xFFFF, _value->getSource(), destinataireAddress);
bool ret = m_interfaceWeb->transferRemoteObjectOwnership(objectAddress, _value->getSource(), destinataireAddress);
if (ret == true) {
m_interfaceWeb->answerVoid(transactionId, _value->getDestination(), _value->getSource());
return;

View File

@ -31,6 +31,7 @@ zeus::ObjectRemoteBase::~ObjectRemoteBase() {
zeus::Future<bool> ret = m_interfaceWeb->call(getFullId(), m_remoteAddress&0xFFFF0000, "unlink", m_remoteAddress);
ret.wait();
if (ret.hasError() == true) {
ZEUS_WARNING("return call error: " << ret.getErrorType() << " help:" << ret.getErrorHelp());
ZEUS_WARNING("Can not unlink with the object id: " << (m_remoteAddress>>16) << "/" << (m_remoteAddress&0xFFFF) << " ==> link error");
return;
}

View File

@ -38,6 +38,7 @@ void zeus::Promise::remoteObjectDestroyed() {
answer->setTransactionId(m_transactionId);
answer->setSource(m_source);
answer->setDestination(0);
answer->setPartFinish(true);
answer->addError("REMOTE-OBJECT-REMOVE", "The remote interface ot the Object has been destroyed");
setMessage(answer);
}
@ -180,7 +181,9 @@ void zeus::Promise::waitFor(echrono::Duration _delta) const {
&& isFinished() == false) {
// TODO : Do it better ... like messaging/mutex_locked ...
std::this_thread::sleep_for(echrono::milliseconds(10));
start = echrono::Steady::now();
}
if (isFinished() == false) {
ZEUS_WARNING("Wait timeout ...");
}
}
@ -190,5 +193,8 @@ void zeus::Promise::waitUntil(echrono::Steady _endTime) const {
// TODO : Do it better ... like messaging/mutex_locked ...
std::this_thread::sleep_for(echrono::milliseconds(10));
}
if (isFinished() == false) {
ZEUS_WARNING("Wait timeout ...");
}
}

View File

@ -50,8 +50,10 @@ bool zeus::WebObj::removeOwnership(uint32_t _id) {
for (auto it = m_listRemoteConnected.begin();
it != m_listRemoteConnected.end();
) {
ZEUS_VERBOSE(" check ID : " << (*it>>16) << "/" << (*it&0xFFFF) << " == " << (_id>>16) << "/" << (_id&0xFFFF));
if (*it == _id) {
it = m_listRemoteConnected.erase(it);
ZEUS_VERBOSE(" REMOVE ...");
return true;
}
++it;
@ -71,7 +73,9 @@ void zeus::WebObj::rmRemoteInterface(uint16_t _id) {
}
bool zeus::WebObj::transferOwnership(uint32_t _sourceAddress, uint32_t _destinataireAddress) {
ZEUS_VERBOSE(" transfer onership : " << (_sourceAddress>>16) << "/" << (_sourceAddress&0xFFFF) << " ==> " << (_destinataireAddress>>16) << "/" << (_destinataireAddress&0xFFFF));
for (auto &it : m_listRemoteConnected) {
//ZEUS_INFO(" " << (it>>16) << "/" << (it&0xFFFF));
if (it == _sourceAddress) {
it = _destinataireAddress;
return true;

View File

@ -543,7 +543,7 @@ bool zeus::WebServer::transferRemoteObjectOwnership(uint16_t _objectAddress, uin
return false;
}
bool zeus::WebServer::remoteObjectOwnership(uint16_t _objectAddress, uint32_t _sourceAddress) {
bool zeus::WebServer::removeObjectOwnership(uint16_t _objectAddress, uint32_t _sourceAddress) {
if ( m_listObject.size() == 0
&& m_listRemoteObject.size() == 0) {
return false;
@ -552,6 +552,7 @@ bool zeus::WebServer::remoteObjectOwnership(uint16_t _objectAddress, uint32_t _s
if (it == nullptr) {
continue;
}
//ZEUS_INFO("1 Remove ownership of " << it->getObjectId() << " == " << _objectAddress);
if (it->getObjectId() == _objectAddress) {
return it->removeOwnership(_sourceAddress);
}
@ -561,6 +562,7 @@ bool zeus::WebServer::remoteObjectOwnership(uint16_t _objectAddress, uint32_t _s
if (tmp == nullptr) {
continue;
}
//ZEUS_INFO("2 Remove ownership of " << tmp->getObjectId() << " == " << _objectAddress);
if (tmp->getObjectId() == _objectAddress) {
ZEUS_ERROR("return a remote Object is not permited ... ==> link directly to the original elements");
return false;

View File

@ -359,7 +359,7 @@ namespace zeus {
// for debug only:
void listObjects();
bool transferRemoteObjectOwnership(uint16_t _objectAddress, uint32_t _sourceAddress, uint32_t _destinataireAddress);
bool remoteObjectOwnership(uint16_t _objectAddress, uint32_t _sourceAddress);
bool removeObjectOwnership(uint16_t _objectAddress, uint32_t _sourceAddress);
};
}

View File

@ -194,7 +194,7 @@ ememory::SharedPtr<zeus::Message> zeus::Message::create(ememory::SharedPtr<zeus:
ememory::SharedPtr<zeus::Message> zeus::Message::create(ememory::SharedPtr<zeus::WebServer> _iface, const std::vector<uint8_t>& _buffer) {
zeus::message::headerBin header;
if (_buffer.size() < sizeof(zeus::message::headerBin)) {
ZEUS_ERROR("wrong size of the buffer");
ZEUS_ERROR("wrong size of the buffer: " << _buffer.size() << " must be " << sizeof(zeus::message::headerBin));
return nullptr;
}
memcpy(reinterpret_cast<char*>(&header), &_buffer[0], sizeof(zeus::message::headerBin));

View File

@ -1469,7 +1469,7 @@ namespace zeus {
uint16_t id = iface->getAddress();
uint16_t idObj = iface->getNewObjectId();
// Sent to the interface the change of links from the curent interface to the real object remote ... (the client interface can control that the user calle r is athorised to do it ...
iface->call((uint32_t(id)<<16), objectAdress&0xFFFF0000, "movelink", objectAdress, (uint32_t(id)<<16)+idObj);
iface->call(getDestination(), objectAdress&0xFFFF0000, "movelink", objectAdress, (uint32_t(id)<<16)+idObj);
out = ememory::makeShared<zeus::ObjectRemoteBase>(iface, id, idObj, objectAdress, type.getName());
iface->addWebObjRemote(out);
} else {