ADD: added function that gives a shared_pointer to the ID of the Track
This commit is contained in:
@@ -9,12 +9,15 @@ namespace SimCore {
|
||||
|
||||
class Identifier{
|
||||
public:
|
||||
Identifier(int number,SimCore::ObjectSource ObjectSource);
|
||||
Identifier() = default;
|
||||
Identifier(int number,SimCore::ObjectSource ObjectSource) ;
|
||||
Identifier(std::pair<int, SimCore::ObjectSource> id);
|
||||
|
||||
|
||||
int getNumber();
|
||||
SimCore::ObjectSource getObjectSource();
|
||||
bool isExternal();
|
||||
bool isValid();
|
||||
|
||||
std::pair<int, SimCore::ObjectSource> getPair();
|
||||
|
||||
@@ -22,6 +25,6 @@ namespace SimCore {
|
||||
|
||||
private:
|
||||
SimCore::ObjectSource objectSource_;
|
||||
int number_;
|
||||
int number_ = 0;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "SimCore/SimCore.hpp"
|
||||
#include <SimCore/SimCore.hpp>
|
||||
#include <condition_variable>
|
||||
#include <cstddef>
|
||||
#include <list>
|
||||
#include <SimCore/Identifier.hpp>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
namespace SimCore {
|
||||
|
||||
@@ -23,6 +25,9 @@ namespace SimCore {
|
||||
std::list<std::shared_ptr<SimCore::Identifier>> IDList_;
|
||||
bool ObjectSource_;
|
||||
|
||||
mutable std::mutex mx_;
|
||||
std::condition_variable c;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace track {
|
||||
PROTOBUF_CONSTEXPR Track_Identifier::Track_Identifier(
|
||||
::_pbi::ConstantInitialized): _impl_{
|
||||
/*decltype(_impl_.number_)*/int64_t{0}
|
||||
, /*decltype(_impl_.external_)*/false
|
||||
, /*decltype(_impl_.external_)*/0u
|
||||
, /*decltype(_impl_._cached_size_)*/{}} {}
|
||||
struct Track_IdentifierDefaultTypeInternal {
|
||||
PROTOBUF_CONSTEXPR Track_IdentifierDefaultTypeInternal()
|
||||
@@ -125,7 +125,7 @@ const char descriptor_table_protodef_Track_2eproto[] PROTOBUF_SECTION_VARIABLE(p
|
||||
"Position\022\r\n\005Speed\030\003 \001(\001\022\016\n\006Course\030\004 \001(\001\022"
|
||||
"-\n\ttimestamp\030\006 \001(\0132\032.google.protobuf.Tim"
|
||||
"estamp\032.\n\nIdentifier\022\016\n\006number\030\001 \001(\003\022\020\n\010"
|
||||
"external\030\002 \001(\010\032;\n\030EntityGeocentricPositi"
|
||||
"external\030\002 \001(\r\032;\n\030EntityGeocentricPositi"
|
||||
"on\022\t\n\001X\030\001 \001(\001\022\t\n\001Y\030\002 \001(\001\022\t\n\001Z\030\003 \001(\001b\006pro"
|
||||
"to3"
|
||||
;
|
||||
@@ -183,7 +183,7 @@ inline void Track_Identifier::SharedCtor(
|
||||
(void)is_message_owned;
|
||||
new (&_impl_) Impl_{
|
||||
decltype(_impl_.number_){int64_t{0}}
|
||||
, decltype(_impl_.external_){false}
|
||||
, decltype(_impl_.external_){0u}
|
||||
, /*decltype(_impl_._cached_size_)*/{}
|
||||
};
|
||||
}
|
||||
@@ -231,10 +231,10 @@ const char* Track_Identifier::_InternalParse(const char* ptr, ::_pbi::ParseConte
|
||||
} else
|
||||
goto handle_unusual;
|
||||
continue;
|
||||
// bool external = 2;
|
||||
// uint32 external = 2;
|
||||
case 2:
|
||||
if (PROTOBUF_PREDICT_TRUE(static_cast<uint8_t>(tag) == 16)) {
|
||||
_impl_.external_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr);
|
||||
_impl_.external_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr);
|
||||
CHK_(ptr);
|
||||
} else
|
||||
goto handle_unusual;
|
||||
@@ -274,10 +274,10 @@ uint8_t* Track_Identifier::_InternalSerialize(
|
||||
target = ::_pbi::WireFormatLite::WriteInt64ToArray(1, this->_internal_number(), target);
|
||||
}
|
||||
|
||||
// bool external = 2;
|
||||
// uint32 external = 2;
|
||||
if (this->_internal_external() != 0) {
|
||||
target = stream->EnsureSpace(target);
|
||||
target = ::_pbi::WireFormatLite::WriteBoolToArray(2, this->_internal_external(), target);
|
||||
target = ::_pbi::WireFormatLite::WriteUInt32ToArray(2, this->_internal_external(), target);
|
||||
}
|
||||
|
||||
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
|
||||
@@ -301,9 +301,9 @@ size_t Track_Identifier::ByteSizeLong() const {
|
||||
total_size += ::_pbi::WireFormatLite::Int64SizePlusOne(this->_internal_number());
|
||||
}
|
||||
|
||||
// bool external = 2;
|
||||
// uint32 external = 2;
|
||||
if (this->_internal_external() != 0) {
|
||||
total_size += 1 + 1;
|
||||
total_size += ::_pbi::WireFormatLite::UInt32SizePlusOne(this->_internal_external());
|
||||
}
|
||||
|
||||
return MaybeComputeUnknownFieldsSize(total_size, &_impl_._cached_size_);
|
||||
|
||||
@@ -201,13 +201,13 @@ class Track_Identifier final :
|
||||
void _internal_set_number(int64_t value);
|
||||
public:
|
||||
|
||||
// bool external = 2;
|
||||
// uint32 external = 2;
|
||||
void clear_external();
|
||||
bool external() const;
|
||||
void set_external(bool value);
|
||||
uint32_t external() const;
|
||||
void set_external(uint32_t value);
|
||||
private:
|
||||
bool _internal_external() const;
|
||||
void _internal_set_external(bool value);
|
||||
uint32_t _internal_external() const;
|
||||
void _internal_set_external(uint32_t value);
|
||||
public:
|
||||
|
||||
// @@protoc_insertion_point(class_scope:messages.track.Track.Identifier)
|
||||
@@ -219,7 +219,7 @@ class Track_Identifier final :
|
||||
typedef void DestructorSkippable_;
|
||||
struct Impl_ {
|
||||
int64_t number_;
|
||||
bool external_;
|
||||
uint32_t external_;
|
||||
mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_;
|
||||
};
|
||||
union { Impl_ _impl_; };
|
||||
@@ -648,22 +648,22 @@ inline void Track_Identifier::set_number(int64_t value) {
|
||||
// @@protoc_insertion_point(field_set:messages.track.Track.Identifier.number)
|
||||
}
|
||||
|
||||
// bool external = 2;
|
||||
// uint32 external = 2;
|
||||
inline void Track_Identifier::clear_external() {
|
||||
_impl_.external_ = false;
|
||||
_impl_.external_ = 0u;
|
||||
}
|
||||
inline bool Track_Identifier::_internal_external() const {
|
||||
inline uint32_t Track_Identifier::_internal_external() const {
|
||||
return _impl_.external_;
|
||||
}
|
||||
inline bool Track_Identifier::external() const {
|
||||
inline uint32_t Track_Identifier::external() const {
|
||||
// @@protoc_insertion_point(field_get:messages.track.Track.Identifier.external)
|
||||
return _internal_external();
|
||||
}
|
||||
inline void Track_Identifier::_internal_set_external(bool value) {
|
||||
inline void Track_Identifier::_internal_set_external(uint32_t value) {
|
||||
|
||||
_impl_.external_ = value;
|
||||
}
|
||||
inline void Track_Identifier::set_external(bool value) {
|
||||
inline void Track_Identifier::set_external(uint32_t value) {
|
||||
_internal_set_external(value);
|
||||
// @@protoc_insertion_point(field_set:messages.track.Track.Identifier.external)
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ message Track {
|
||||
|
||||
message Identifier{
|
||||
int64 number = 1;
|
||||
bool external = 2;
|
||||
uint32 external = 2;
|
||||
}
|
||||
Identifier EntityIdentifier = 1;
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "SimCore/Identifier.hpp"
|
||||
#include "google/protobuf/any.pb.h"
|
||||
#include <SimCore/Position.hpp>
|
||||
#include <WHISPER/Messages/Message.hpp>
|
||||
@@ -37,8 +38,9 @@ namespace SimCore {
|
||||
/// function that packs all information to a protobuf message
|
||||
void packToMessage();
|
||||
|
||||
/// the unique tracknumber for now
|
||||
std::uint32_t trackNo_;
|
||||
/// ID of the object
|
||||
SimCore::Identifier ID_;
|
||||
|
||||
|
||||
|
||||
public:
|
||||
@@ -52,12 +54,13 @@ namespace SimCore {
|
||||
* @brief constructor for building a track which is also the trackmessage to send
|
||||
* @param uint32_t deviceID the id of the sending device
|
||||
* @param WHISPER::SourceType sourcetype of the sending device
|
||||
* @param uint32_t internal tracknumber
|
||||
* @param bool external indicates if track is from an external source e.g. dis
|
||||
* @param SimCore::Identifier object identifier
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
Track(std::uint32_t deviceID, WHISPER::SourceType src,std::uint32_t trackNo, bool external);
|
||||
Track(std::uint32_t deviceID, WHISPER::SourceType src,SimCore::Identifier id);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief set the position of the track
|
||||
@@ -103,6 +106,8 @@ namespace SimCore {
|
||||
/// return true if is external
|
||||
bool isExternal();
|
||||
|
||||
std::shared_ptr<SimCore::Identifier> getIdentifier();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -20,9 +20,9 @@ Z
|
||||
};
|
||||
|
||||
|
||||
enum ObjectSource : std::uint8_t {
|
||||
EXTERNAL = 0,
|
||||
INTERNAL = 1
|
||||
enum ObjectSource : std::uint32_t {
|
||||
EXTERNAL = 1,
|
||||
INTERNAL = 2
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -21,6 +21,17 @@ int Identifier::getNumber()
|
||||
return number_;
|
||||
}
|
||||
|
||||
bool Identifier::isValid()
|
||||
{
|
||||
if (number_>0 && objectSource_ != 0) {
|
||||
return true;
|
||||
}else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool Identifier::isExternal()
|
||||
{
|
||||
if (objectSource_ == SimCore::EXTERNAL) {
|
||||
|
||||
@@ -9,6 +9,8 @@ namespace SimCore {
|
||||
IdentifierMaker::IdentifierMaker(){}
|
||||
|
||||
std::shared_ptr<SimCore::Identifier> IdentifierMaker::getNewIdentifier(SimCore::ObjectSource ObjectSource){
|
||||
|
||||
std::lock_guard<std::mutex> lock(mx_);
|
||||
|
||||
long size = IDList_.size();
|
||||
|
||||
@@ -35,6 +37,8 @@ std::shared_ptr<SimCore::Identifier> IdentifierMaker::getNewIdentifier(SimCore::
|
||||
}
|
||||
|
||||
bool IdentifierMaker::isInList(std::shared_ptr<SimCore::Identifier> ID){
|
||||
std::lock_guard<std::mutex> lock(mx_);
|
||||
|
||||
for (std::list<std::shared_ptr<SimCore::Identifier>>::iterator it=IDList_.begin(); it != IDList_.end(); ++it){
|
||||
if (ID.get() == it->get()) {
|
||||
return true;
|
||||
@@ -44,6 +48,8 @@ bool IdentifierMaker::isInList(std::shared_ptr<SimCore::Identifier> ID){
|
||||
}
|
||||
|
||||
size_t IdentifierMaker::size(){
|
||||
std::lock_guard<std::mutex> lock(mx_);
|
||||
|
||||
return IDList_.size();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include "SimCore/Identifier.hpp"
|
||||
#include "SimCore/Position.hpp"
|
||||
#include "SimCore/SimCore.hpp"
|
||||
#include "WHISPER/Messages/Message.hpp"
|
||||
@@ -7,6 +8,7 @@
|
||||
#include <SimCore/Messages/Track.hpp>
|
||||
#include <memory>
|
||||
#include <sys/time.h>
|
||||
#include <utility>
|
||||
|
||||
|
||||
|
||||
@@ -30,7 +32,7 @@ namespace SimCore {
|
||||
|
||||
messages::track::Track_Identifier ID = trackMessage.entityidentifier();
|
||||
|
||||
trackNo_ = trackMessage.mutable_entityidentifier()->number();
|
||||
ID_ = SimCore::Identifier(trackMessage.mutable_entityidentifier()->number(),(SimCore::ObjectSource)trackMessage.mutable_entityidentifier()->external());
|
||||
external_ = trackMessage.mutable_entityidentifier()->external();
|
||||
// trackNo_ = trackMessage.trackno();
|
||||
// external_ = trackMessage.external();
|
||||
@@ -48,11 +50,11 @@ namespace SimCore {
|
||||
}
|
||||
|
||||
|
||||
Track::Track(std::uint32_t deviceID, WHISPER::SourceType src,std::uint32_t trackNo, bool external):
|
||||
Message(deviceID,WHISPER::MsgTopics::TRACK,WHISPER::RAW_TRACK,src),trackNo_(trackNo), external_(external)
|
||||
|
||||
Track::Track(std::uint32_t deviceID, WHISPER::SourceType src,SimCore::Identifier id):
|
||||
Message(deviceID,WHISPER::MsgTopics::TRACK,WHISPER::RAW_TRACK,src),external_(id.isExternal()),ID_(id)
|
||||
{
|
||||
|
||||
|
||||
|
||||
packToMessage();
|
||||
|
||||
}
|
||||
@@ -68,7 +70,7 @@ namespace SimCore {
|
||||
|
||||
|
||||
trackMessage_.mutable_entityidentifier()->set_external(external_);
|
||||
trackMessage_.mutable_entityidentifier()->set_number(trackNo_);
|
||||
trackMessage_.mutable_entityidentifier()->set_number(ID_.getNumber());
|
||||
|
||||
// trackMessage_.set_trackno(trackNo_);
|
||||
// trackMessage_.set_external(external_);
|
||||
@@ -149,6 +151,11 @@ namespace SimCore {
|
||||
return external_;
|
||||
}
|
||||
|
||||
std::shared_ptr<SimCore::Identifier> Track::getIdentifier()
|
||||
{
|
||||
return std::make_shared<SimCore::Identifier>(std::move(ID_));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include "SimCore/IdentifierMaker.hpp"
|
||||
#include <SimCore/Messages/Track.hpp>
|
||||
#include <WHISPER/Messages/Message.hpp>
|
||||
#include <SimCore/SimCore.hpp>
|
||||
@@ -29,6 +30,8 @@ SCENARIO("Testing the SimCore Track")
|
||||
std::shared_ptr<WHISPER::Message> msg = NULL;
|
||||
|
||||
std::shared_ptr<SimCore::Track> trackPtr = NULL;
|
||||
SimCore::IdentifierMaker IDMaker;
|
||||
auto ID = IDMaker.getNewIdentifier(SimCore::ObjectSource::EXTERNAL);
|
||||
|
||||
|
||||
std::string serializedMSG;
|
||||
@@ -36,8 +39,7 @@ SCENARIO("Testing the SimCore Track")
|
||||
WHEN("constructing Track Object with data")
|
||||
{
|
||||
SimCore::Position pos( GeocentPos1(SimCore::GeocentricPosition::X), GeocentPos1(SimCore::GeocentricPosition::Y), GeocentPos1(SimCore::GeocentricPosition::Z));
|
||||
|
||||
SimCore::Track track(1,WHISPER::SourceType::SHIP,10,false);
|
||||
SimCore::Track track(1,WHISPER::SourceType::SHIP,*ID.get());
|
||||
track.setCourse(course);
|
||||
track.setSpeed(speed);
|
||||
track.setPosition(GeocentPos1(SimCore::X),GeocentPos1(SimCore::Y),GeocentPos1(SimCore::Z));
|
||||
@@ -64,6 +66,8 @@ SCENARIO("Testing the SimCore Track")
|
||||
REQUIRE(msg.get()->msgType_ == WHISPER::RAW_TRACK);
|
||||
REQUIRE(trackPtr->getSpeed() == speed);
|
||||
REQUIRE(trackPtr->getPostion().getGeocentricPos() == GeocentPos1);
|
||||
REQUIRE(trackPtr->getIdentifier()->getNumber() > 0);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user