Commit 56875f7d authored by Pascal Palenda's avatar Pascal Palenda
Browse files

Add update interface - WIP

parent 69517f86
......@@ -9,6 +9,10 @@ set( SubDirs
set( DirFiles
definitions.h
3d_object.h
update_message.h
update_config.h
update_scene.h
types.h
#_SourceFiles.cmake
)
......
#ifndef INCLUDE_WATCHER_ITA_SIMULATION_SCHEDULER_TYPES
#define INCLUDE_WATCHER_ITA_SIMULATION_SCHEDULER_TYPES
// API includes
#include <ITA/simulation_scheduler/definitions.h>
// simulation scheduler includes
#include <ITA/simulation_scheduler/3d_object.h>
namespace ITA
{
namespace simulation_scheduler
{
///
/// \brief struct to represent a source-reciever-pair.
///
typedef struct{
const C3DObject* source;
const C3DObject* receiver;
} SourceReceiverPair;
} // namespace simulation_scheduler
} // namespace ITA
#endif // INCLUDE_WATCHER_ITA_SIMULATION_SCHEDULER_TYPES
#ifndef INCLUDE_WATCHER_ITA_SIMULATION_SCHEDULER_UPDATE_CONFIG
#define INCLUDE_WATCHER_ITA_SIMULATION_SCHEDULER_UPDATE_CONFIG
// std includes
#include <string>
// API includes
#include <ITA/simulation_scheduler/definitions.h>
// simulation scheduler includes
#include <ITA/simulation_scheduler/update_message.h>
namespace ITA
{
namespace simulation_scheduler
{
///
/// \brief Special IUpdateMessage to signal configuration changes.
///
class ITA_SIMULATION_SCHEDULER_API CUpdateConfig : public IUpdateMessage
{
public:
///
/// \brief Types of configuration changes
///
enum class ConfigChangeType
{
resetAll, ///< Reset all simulations.
changeHRTF, ///< Signal a change in receiver HRTF.
changeDirectivity ///< Signal a change in source directivity.
};
///
/// \brief Default constructor.
///
/// This constructor is primarily used for creating an object for deserialization.
/// It inizializes the object with ConfigChangeType::resetAll and an empty payload string.
///
CUpdateConfig ( );
///
/// \brief Constructor for a CUpdateConfig.
/// \param type the type of configuration change.
/// \param payload optional payload of the update.
/// Can encode a json file.
///
CUpdateConfig ( ConfigChangeType type, const std::string& payload = "" );
///
/// \brief Get the ConfigChangeType of the update.
/// \return the ConfigChangeType of the update.
///
ConfigChangeType getType ( );
///
/// \brief Get the payload of the update.
/// \return the payload of the update.
/// Can encode a json file.
///
const std::string& getPayload ( );
///
/// \brief Serialize the object.
/// \param pSerializer the IVistaSerializer to use.
/// \return the number of bytes written or -1 on failure.
///
int Serialize ( IVistaSerializer& pSerializer) const;
///
/// \brief DeSerialize the object.
/// \param pSerializer the IVistaDeSerializer to use.
/// \return the number of bytes written or -1 on failure.
///
int DeSerialize ( IVistaDeSerializer& pDeserializer );
///
/// \brief Return a unique identifier for the object for serialization.
/// \return "CUpdateConfig".
///
virtual std::string GetSignature ( ) const;
private:
///
/// \brief ConfigChangeType of the update.
///
ConfigChangeType m_eConfigChangeType;
///
/// \brief The payload of the update.
/// Can encode a json file.
///
std::string m_sPayload;
};
} // namespace simulation_scheduler
} // namespace ITA
#endif // INCLUDE_WATCHER_ITA_SIMULATION_SCHEDULER_UPDATE_CONFIG
#ifndef INCLUDE_WATCHER_ITA_SIMULATION_SCHEDULER_UPDATE_MESSAGE
#define INCLUDE_WATCHER_ITA_SIMULATION_SCHEDULER_UPDATE_MESSAGE
// API includes
#include <ITA/simulation_scheduler/definitions.h>
// VISTA includes
#include <VistaAspects/VistaSerializable.h>
namespace ITA
{
namespace simulation_scheduler
{
///
/// \brief Abstract base interface for all update messages that can be issued to a scheduler or master controller.
/// \remark Currently this base interface does nothing, maybe one day it gets an aditional use.
///
class ITA_SIMULATION_SCHEDULER_API IUpdateMessage : public IVistaSerializable
{
public:
///
/// \brief Pure virtual destructor to make this class abstract.
///
virtual ~IUpdateMessage ( ) = 0
{ };
};
} // namespace simulation_scheduler
} // namespace ITA
#endif // INCLUDE_WATCHER_ITA_SIMULATION_SCHEDULER_UPDATE_MESSAGE
#ifndef INCLUDE_WATCHER_ITA_SIMULATION_SCHEDULER_UPDATE_SCENE
#define INCLUDE_WATCHER_ITA_SIMULATION_SCHEDULER_UPDATE_SCENE
// std includes
#include <string>
#include <memory>
// API includes
#include <ITA/simulation_scheduler/definitions.h>
// simulation scheduler includes
#include <ITA/simulation_scheduler/update_message.h>
#include <ITA/simulation_scheduler/3d_object.h>
#include <ITA/simulation_scheduler/types.h>
namespace ITA
{
namespace simulation_scheduler
{
///
/// \brief Special IUpdateMessage to signal scene changes.
///
/// A scene change is a change of a source or receiver pose.
/// A change of either source or receiver can lead to a change in the tansferpath between a coressponding source-receiver-pair.
/// Thus, a CUpdateScene combines pose information for such a source-receiver-pair.
///
class ITA_SIMULATION_SCHEDULER_API CUpdateScene : public IUpdateMessage
{
public:
///
/// \brief Default constructor.
///
/// This constructor is primarily used for creating an object for deserialization.
/// It initializes the object with nullptrs for source and receiver but no IDs.
///
CUpdateScene ( ) = default;
///
/// \brief Constructor for a CUpdateScene.
///
/// This constrictor initializes the ID to the next free ID and source and receiver to nullptrs.
/// \param referenceID the reference ID for the update.
///
explicit CUpdateScene ( unsigned int referenceID );
///
/// \brief Get the source-receiver-pair of the update.
/// \return the SourceReceiverPair of the update.
///
SourceReceiverPair getSourceReceiverPair ( ) const;
///
/// \brief Set the source-receiver-pair of the update.
///
/// With this function the CUpdateScene takes ownership of the objects.
/// \param pSource the new source for the update.
/// \param pReceiver the new reciever for the update.
/// \todo Maybe split this function?
///
void setSourceReceiverPair ( std::unique_ptr<C3DObject> pSource, std::unique_ptr<C3DObject> pReceiver );
///
/// \brief Get the ID of update.
/// \return the ID of update.
///
unsigned int getID ( ) const;
///
/// \brief Get the reference ID of update.
/// \return the reference ID of update.
///
unsigned int getReferenceID ( ) const;
///
/// \brief Compare two CUpdateScene, with a given tolerance.
///
/// Similar to operator==(), this function compares two CUpdateScene.
/// However, this comparison allows for a tolerance for the comparison of the source and receiver.
/// And does \b not compare the unique ID of the update.
/// \sa C3DObject::isEqualTolerance()
/// \param obj the object to check against.
/// \param dTolerance the allowed tolerance.
/// \return true if the given object is the same as this with the given tolerance.
///
bool isEqualTolerance ( const CUpdateScene& obj, double dTolerance ) const;
///
/// \brief Serialize the object.
/// \param pSerializer the IVistaSerializer to use.
/// \return the number of bytes written or -1 on failure.
///
int Serialize ( IVistaSerializer& pSerializer ) const;
///
/// \brief DeSerialize the object.
/// \param pSerializer the IVistaDeSerializer to use.
/// \return the number of bytes written or -1 on failure.
///
int DeSerialize ( IVistaDeSerializer& pDeserializer );
///
/// \brief Return a unique identifier for the object for serialization.
/// \return "CUpdateScene".
///
virtual std::string GetSignature ( ) const;
private:
///
/// \brief The source of the update.
///
std::unique_ptr<C3DObject> m_pSource;
///
/// \brief The source of the update.
///
std::unique_ptr<C3DObject> m_pReceiver;
///
/// \brief The unique ID of the update.
///
unsigned int m_uiID;
///
/// \brief The reference ID of the update (For the user).
///
/// It encodes the source receiver path.
///
unsigned int m_uiReferenceID;
///
/// \brief Time stamp of the update.
/// \todo Is this necessary?
/// Or for the profiler?
/// Define it.
///
double m_dTimeStamp;
///
/// \brief updateSceneMaxID counts CUpdateScene%s that are constructed.
///
/// With this we can give every CUpdateScene an unique ID.
///
static unsigned int updateSceneMaxID;
};
///
/// \brief Compare two CUpdateScene.
///
/// Check if \p lhs and \p rhs are exactly the same.
/// For this all members have to match.
/// \param lhs the first object to check.
/// \param rhs the second object to check.
/// \return true if the given objects are exactly the same.
///
inline bool operator==( const CUpdateScene& lhs, const CUpdateScene& rhs )
{
auto lhsSourceReceiverPair = lhs.getSourceReceiverPair ( );
auto rhsSourceReceiverPair = rhs.getSourceReceiverPair ( );
return lhs.getID ( ) == rhs.getID ( ) &&
lhs.getReferenceID ( ) == rhs.getReferenceID ( ) &&
*lhsSourceReceiverPair.source == *rhsSourceReceiverPair.source &&
*lhsSourceReceiverPair.receiver == *rhsSourceReceiverPair.receiver;
}
} // namespace simulation_scheduler
} // namespace ITA
#endif // INCLUDE_WATCHER_ITA_SIMULATION_SCHEDULER_UPDATE_CONFIG
......@@ -8,6 +8,8 @@ set( SubDirs
set( DirFiles
3d_object.cpp
update_config.cpp
update_scene.cpp
#_SourceFiles.cmake
)
......
// Header include
#include <ITA/simulation_scheduler/update_config.h>
// Vista include
#include <VistaAspects/VistaSerializer.h>
#include <VistaAspects/VistaDeSerializer.h>
namespace ITA
{
namespace simulation_scheduler
{
CUpdateConfig::CUpdateConfig ( ) :
m_eConfigChangeType( ), m_sPayload( )
{ }
CUpdateConfig::CUpdateConfig ( ConfigChangeType type, const std::string& payload ) :
m_eConfigChangeType ( type ), m_sPayload ( payload )
{ }
CUpdateConfig::ConfigChangeType CUpdateConfig::getType ( )
{
return m_eConfigChangeType;
}
const std::string& CUpdateConfig::getPayload ( )
{
return m_sPayload;
}
int CUpdateConfig::Serialize ( IVistaSerializer& pSerializer ) const
{
int returnVal = 0;
returnVal += pSerializer.WriteInt32 ( static_cast< std::underlying_type<ConfigChangeType>::type >( m_eConfigChangeType ) );
returnVal += pSerializer.WriteEncodedString ( m_sPayload );
return returnVal;
}
int CUpdateConfig::DeSerialize ( IVistaDeSerializer& pDeserializer )
{
int returnVal = 0;
int tmp;
returnVal += pDeserializer.ReadInt32 ( tmp );
m_eConfigChangeType = ConfigChangeType ( tmp );
returnVal += pDeserializer.ReadEncodedString ( m_sPayload );
return returnVal;
}
std::string CUpdateConfig::GetSignature ( ) const
{
return "CUpdateConfig";
}
} // namespace simulation_scheduler
} // namespace ITA
\ No newline at end of file
// Header include
#include <ITA/simulation_scheduler/update_scene.h>
// Vista include
#include <VistaAspects/VistaSerializer.h>
#include <VistaAspects/VistaDeSerializer.h>
// ITA includes
#include <ITAException.h>
namespace ITA
{
namespace simulation_scheduler
{
unsigned int CUpdateScene::updateSceneMaxID = 0;
CUpdateScene::CUpdateScene ( unsigned int referenceID ) :
m_uiReferenceID ( referenceID )
{
m_uiID = updateSceneMaxID++;
}
SourceReceiverPair CUpdateScene::getSourceReceiverPair ( ) const
{
SourceReceiverPair pair;
pair.source = m_pSource.get ( );
pair.receiver = m_pReceiver.get ( );
return pair;
}
void CUpdateScene::setSourceReceiverPair ( std::unique_ptr<C3DObject> pSource, std::unique_ptr<C3DObject> pReceiver )
{
if ( pSource->getType ( ) == C3DObject::Type::source )
m_pSource = std::move ( pSource );
else
ITA_EXCEPT_INVALID_PARAMETER ( "Wrong type given" );
if ( pReceiver->getType ( ) == C3DObject::Type::receiver )
m_pReceiver = std::move ( pReceiver );
else
ITA_EXCEPT_INVALID_PARAMETER ( "Wrong type given" );
}
unsigned int CUpdateScene::getID ( ) const
{
return m_uiID;
}
unsigned int CUpdateScene::getReferenceID ( ) const
{
return m_uiReferenceID;
}
bool CUpdateScene::isEqualTolerance ( const CUpdateScene& obj, double dTolerance ) const
{
return m_pSource->isEqualTolerance(*obj.m_pSource.get(), dTolerance) &&
m_pReceiver->isEqualTolerance ( *obj.m_pReceiver.get ( ), dTolerance ) &&
m_uiReferenceID == obj.m_uiReferenceID;
}
int CUpdateScene::Serialize ( IVistaSerializer& pSerializer ) const
{
int returnVal = 0;
returnVal += pSerializer.WriteInt32 ( m_uiID );
returnVal += pSerializer.WriteInt32 ( m_uiReferenceID );
returnVal += pSerializer.WriteSerializable ( *m_pReceiver.get ( ) );
returnVal += pSerializer.WriteSerializable ( *m_pSource.get ( ) );
return returnVal;
}
int CUpdateScene::DeSerialize ( IVistaDeSerializer& pDeserializer )
{
int returnVal = 0;
returnVal += pDeserializer.ReadInt32 ( m_uiID );
returnVal += pDeserializer.ReadInt32 ( m_uiReferenceID );
if ( m_pReceiver == nullptr && m_pSource == nullptr )
{
C3DObject tmp;
returnVal += pDeserializer.ReadSerializable ( tmp );
m_pReceiver = std::make_unique<C3DObject> ( tmp );
returnVal += pDeserializer.ReadSerializable ( tmp );
m_pSource = std::make_unique<C3DObject> ( tmp );
}
else
{
returnVal += pDeserializer.ReadSerializable ( *m_pReceiver.get ( ) );
returnVal += pDeserializer.ReadSerializable ( *m_pSource.get ( ) );
}
return returnVal;
}
std::string CUpdateScene::GetSignature ( ) const
{
return "CUpdateScene";
}
} // namespace simulation_scheduler
} // namespace ITA
\ No newline at end of file
......@@ -10,6 +10,8 @@ vista_use_package( Gtest REQUIRED FIND_DEPENDENCIES )
set( ProjectSources "all_tests.cpp"
"3d_object_test.cpp"
"update_config_test.cpp"
"update_scene_test.cpp"
"enum_to_int.cpp"
)
......
#include <iostream>
#include <string>
#include <memory>
// simulation scheduler includes
#include <ITA/simulation_scheduler/update_config.h>
// Vista includes
#include <VistaInterProcComm/Connections/VistaByteBufferSerializer.h>
#include <VistaInterProcComm/Connections/VistaByteBufferDeSerializer.h>
// GTest
#include "gtest/gtest.h"
#include "enum_to_int.cpp"
namespace simsched = ITA::simulation_scheduler;
struct UpdateConfigTest : testing::Test
{
simsched::CUpdateConfig update = simsched::CUpdateConfig ( simsched::CUpdateConfig::ConfigChangeType::resetAll, "Hello World!" );
UpdateConfigTest ( ) = default;
};
TEST_F ( UpdateConfigTest, getter )
{
EXPECT_EQ ( simsched::CUpdateConfig::ConfigChangeType::resetAll, update.getType ( ) );
EXPECT_EQ ( "Hello World!", update.getPayload ( ) );
}
TEST_F ( UpdateConfigTest, serialization )
{
auto serializer = VistaByteBufferSerializer ( );
auto deserializer = VistaByteBufferDeSerializer ( );
update.Serialize ( serializer );
deserializer.SetBuffer ( serializer.GetBuffer ( ), serializer.GetBufferSize ( ) );
auto newUpdate = simsched::CUpdateConfig ( );
newUpdate.DeSerialize ( deserializer );
EXPECT_EQ ( update.getType ( ), newUpdate.getType ( ) );
EXPECT_EQ ( update.getPayload ( ), newUpdate.getPayload ( ) );
}
\ No newline at end of file
#include <iostream>
#include <string>
#include <memory>
// simulation scheduler includes
#include <ITA/simulation_scheduler/update_scene.h>
// Vista includes
#include <VistaInterProcComm/Connections/VistaByteBufferSerializer.h>
#include <VistaInterProcComm/Connections/VistaByteBufferDeSerializer.h>
// GTest
#include "gtest/gtest.h"
#include "enum_to_int.cpp"
namespace simsched = ITA::simulation_scheduler;
struct UpdateSceneTest : testing::Test
{
std::unique_ptr<simsched::CUpdateScene> update;
std::unique_ptr<simsched::C3DObject> source;
std::unique_ptr<simsched::C3DObject> receiver;
simsched::C3DObject* raw_source;
simsched::C3DObject* raw_receiver;
UpdateSceneTest ( )
{
update = std::make_unique<simsched::CUpdateScene> ( 1 );
source = std::make_unique<simsched::C3DObject> (
VistaVector3D ( 3, 2, 6 ), VistaQuaternion ( 1, 0, 0, 0 ), simsched::C3DObject::Type::source, 1 );
receiver = std::make_unique<simsched::C3DObject> (
VistaVector3D ( 6, 1, 10 ), VistaQuaternion ( 1, 0, 0, 0 ), simsched::C3DObject::Type::receiver, 1 );
// save them for later
raw_source = source.get ( );
raw_receiver = receiver.get ( );
update->setSourceReceiverPair ( std::move ( source ),
std::move ( receiver ) );
}
};
TEST_F ( UpdateSceneTest, getter )
{
EXPECT_EQ ( 1, update->getReferenceID ( ) );
EXPECT_EQ ( 0, update->getID ( ) );
auto pair = update->getSourceReceiverPair ( );
EXPECT_EQ ( raw_source, pair.source );
EXPECT_EQ ( raw_receiver, pair.receiver );
}
TEST_F ( UpdateSceneTest, operatorEqual )
{
auto alt1 = simsched::CUpdateScene ( 1 );
alt1.setSourceReceiverPair ( std::make_unique<simsched::C3DObject> ( *raw_source ),
std::make_unique<simsched::C3DObject> ( *raw_receiver ) );
EXPECT_FALSE ( *update == alt1 );