Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
+152
@@ -0,0 +1,152 @@
|
||||
/**
|
||||
* Handler for all marker objects
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by hjl, SLSE, 2016-04-12
|
||||
*/
|
||||
|
||||
#include "handler_snapshot.h"
|
||||
#include "object_snapshot.h"
|
||||
#include "dds_handler.h"
|
||||
|
||||
namespace MarkerManagement
|
||||
{
|
||||
|
||||
HandlerSnapshot::HandlerSnapshot(const std::shared_ptr<DdsHandler> &ddsHandler,
|
||||
const std::shared_ptr<DatabaseInterface> &db)
|
||||
: Interface::Fts::SnapshotModifyRequestHandler(ddsHandler->fts())
|
||||
, Interface::Fts::SnapshotRemoveRequestHandler(ddsHandler->fts())
|
||||
, m_ddsHandler(ddsHandler)
|
||||
, m_db(db)
|
||||
, m_logger(getLogger("HandlerSnapshot"))
|
||||
{
|
||||
} // end of ctor()
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
HandlerSnapshot::~HandlerSnapshot()
|
||||
{
|
||||
qDeleteAll(m_objectSnapshotMap);
|
||||
} // end of dtor()
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
bool HandlerSnapshot::init()
|
||||
{
|
||||
INFO_LOG(m_logger) << "--- Start MarkerManagement HandlerSnapshot.";
|
||||
|
||||
bool bRet = true;
|
||||
// create markerObjects
|
||||
auto cb = [this, &bRet] (const Database::MrkSnapshot &data)
|
||||
{
|
||||
Snapshot ddsData = ObjectSnapshot::toDdsData(data);
|
||||
ObjectSnapshot *ifs(new ObjectSnapshot(m_ddsHandler, m_db));
|
||||
Core::FunctionReplyObject ret = ifs->createObject(ddsData);
|
||||
|
||||
if (ret.error())
|
||||
{
|
||||
delete ifs;
|
||||
ERROR_LOG(m_logger) << ret();
|
||||
bRet = false;
|
||||
return;
|
||||
}
|
||||
m_objectSnapshotMap.insert(ifs->getId(), ifs);
|
||||
};
|
||||
if (!m_db->select(cb) || !bRet)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error reading data from database!";
|
||||
return false;
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "m_objectSnapshotMap.size() = " << m_objectSnapshotMap.size();
|
||||
|
||||
return true;
|
||||
} // end of init()
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void HandlerSnapshot::onSnapshotModifyRequest(const rti::core::SampleIdentity &cookie,
|
||||
const Snapshot &request)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "SnapshotModifyRequest: " << request;
|
||||
auto ret = request.id() > 0 ? snapshotModifyRequest(request) : snapshotCreateRequest(request);
|
||||
if (ret.error())
|
||||
WARNING_LOG(m_logger) << ret();
|
||||
m_ddsHandler->fts()->snapshotModifyReply(cookie, ret);
|
||||
|
||||
} // end of onSnapshotModifyRequest()
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
Core::FunctionReplyObject HandlerSnapshot::snapshotCreateRequest(const Snapshot &request)
|
||||
{
|
||||
ObjectSnapshot *ifs(new ObjectSnapshot(m_ddsHandler, m_db));
|
||||
Core::FunctionReplyObject ret = ifs->createObject(request);
|
||||
|
||||
if (ret.error())
|
||||
delete ifs;
|
||||
else
|
||||
m_objectSnapshotMap.insert(ifs->getId(), ifs);
|
||||
|
||||
return ret;
|
||||
} // end of onSnapshotCreateRequest()
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
Core::FunctionReplyObject HandlerSnapshot::snapshotModifyRequest(const Snapshot &request)
|
||||
{
|
||||
ObjectSnapshot *ifs = m_objectSnapshotMap.value(request.id());
|
||||
if (ifs == nullptr)
|
||||
return Core::FunctionReplyObject(request.id(), tr_lts("dds", "Snapshot with id %1 not found")).arg(request.id());
|
||||
|
||||
Snapshot ddsData = ifs->getData();
|
||||
ddsData.name(request.name());
|
||||
ddsData.description(request.description());
|
||||
ddsData.fileContentId(request.fileContentId());
|
||||
|
||||
if (request.mapSettings().size() > 0)
|
||||
ddsData.mapSettings(request.mapSettings());
|
||||
|
||||
if (request.movementTracks().size() > 0)
|
||||
ddsData.movementTracks(request.movementTracks());
|
||||
|
||||
if (request.planOverlay().size() > 0)
|
||||
ddsData.planOverlay(request.planOverlay());
|
||||
|
||||
if (request.filter().size() > 0)
|
||||
ddsData.filter(request.filter());
|
||||
|
||||
return ifs->updateObject(ddsData);
|
||||
} // end of onSnapshotModifyRequest()
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void HandlerSnapshot::onSnapshotRemoveRequest(const rti::core::SampleIdentity &cookie,
|
||||
const Core::RemoveElementRequest &request)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "onSnapshotRemoveRequest() id:" << request.id();
|
||||
|
||||
Core::FunctionReplyObject ret;
|
||||
ObjectSnapshot *ifs = m_objectSnapshotMap.value(request.id());
|
||||
if (ifs == nullptr)
|
||||
ret = Core::FunctionReplyObject(request.id(), tr_lts("dds", "Snapshot with id %1 not found")).arg(request.id());
|
||||
else
|
||||
{
|
||||
if (m_ddsHandler->topicLockMaster()->isLocked(ifs->getData(), m_ddsHandler->ddsConnector()->getPartitionId()))
|
||||
{
|
||||
ret = Core::FunctionReplyObject(request.id(), tr_lts("dds", "Snapshot '%1' is used by another user!")).arg(ifs->getName());
|
||||
m_ddsHandler->fts()->snapshotRemoveReply(cookie, ret);
|
||||
return;
|
||||
}
|
||||
ret = ifs->removeObject();
|
||||
}
|
||||
|
||||
if (ret.error())
|
||||
ERROR_LOG(m_logger) << ret();
|
||||
else
|
||||
{
|
||||
// delete ObjectSnapshot
|
||||
delete ifs;
|
||||
m_objectSnapshotMap.remove(request.id());
|
||||
}
|
||||
|
||||
m_ddsHandler->fts()->snapshotRemoveReply(cookie, ret);
|
||||
} // end of onSnapshotRemoveRequest()
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
} // namespace MarkerManagement
|
||||
Reference in new issue
Block a user