Skip to content

Commit

Permalink
storyboard: introduce shared library API
Browse files Browse the repository at this point in the history
  • Loading branch information
riebl committed Jul 21, 2023
1 parent fccbd6a commit b05d60d
Show file tree
Hide file tree
Showing 28 changed files with 75 additions and 47 deletions.
2 changes: 1 addition & 1 deletion src/artery/storyboard/AndCondition.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace artery
/**
* Class to create a Tree of AndConditions
*/
class AndCondition : public Condition
class STORYBOARD_API AndCondition : public Condition
{
public:
using ConditionPtr = std::shared_ptr<Condition>;
Expand Down
1 change: 1 addition & 0 deletions src/artery/storyboard/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ target_include_directories(pybind11 INTERFACE
${PYTHON_INCLUDE_DIRS})
target_link_libraries(pybind11 INTERFACE ${PYTHON_LIBRARIES})
target_link_libraries(storyboard PRIVATE pybind11)
set_property(TARGET storyboard PROPERTY CXX_VISIBILITY_PRESET hidden)
2 changes: 1 addition & 1 deletion src/artery/storyboard/CarSetCondition.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace artery
* Condition: CarSet
* allows to specify the affected cars of a Story
*/
class CarSetCondition : public Condition {
class STORYBOARD_API CarSetCondition : public Condition {
public:

/**
Expand Down
3 changes: 2 additions & 1 deletion src/artery/storyboard/Condition.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define ARTERY_CONDITION_H_

#include "artery/storyboard/ConditionResult.h"
#include "artery/storyboard/Macros.h"
#include "artery/storyboard/Vehicle.h"

namespace omnetpp { class cCanvas; }
Expand All @@ -12,7 +13,7 @@ namespace artery
/**
* Condition Interface
*/
class Condition
class STORYBOARD_API Condition
{
public:
virtual ~Condition() = default;
Expand Down
3 changes: 2 additions & 1 deletion src/artery/storyboard/ConditionResult.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef ARTERY_CONDITIONRESULT_H_2UBLV1EE
#define ARTERY_CONDITIONRESULT_H_2UBLV1EE

#include "artery/storyboard/Macros.h"
#include <boost/variant.hpp>
#include <set>

Expand All @@ -11,7 +12,7 @@ namespace artery
class Vehicle;

using ConditionResult = boost::variant<bool, std::set<const Vehicle*>>;
bool is_true(const ConditionResult&);
bool STORYBOARD_API is_true(const ConditionResult&);

} // namespace artery

Expand Down
2 changes: 1 addition & 1 deletion src/artery/storyboard/DeferringCondition.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace artery
* The delay is drawn uniformly from the given [min; max) range once per vehicle.
* The condition evaluates to true after the delay expired relative to the first evaluation's time point.
*/
class DeferringCondition : public Condition
class STORYBOARD_API DeferringCondition : public Condition
{
public:
DeferringCondition(omnetpp::cRNG*, omnetpp::SimTime min, omnetpp::SimTime max);
Expand Down
4 changes: 3 additions & 1 deletion src/artery/storyboard/Effect.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef ARTERY_EFFECT_H_
#define ARTERY_EFFECT_H_

#include "artery/storyboard/Macros.h"

namespace artery
{

Expand All @@ -10,7 +12,7 @@ class Vehicle;
/**
* Effect Interface
*/
class Effect
class STORYBOARD_API Effect
{
public:
Effect(Story& story, Vehicle& car);
Expand Down
3 changes: 2 additions & 1 deletion src/artery/storyboard/EffectFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "artery/storyboard/Condition.h"
#include "artery/storyboard/Effect.h"
#include "artery/storyboard/Macros.h"
#include <memory>

namespace artery
Expand All @@ -11,7 +12,7 @@ namespace artery
/**
* EffectFactory Interface
*/
class EffectFactory
class STORYBOARD_API EffectFactory
{
public:
virtual ~EffectFactory() = default;
Expand Down
3 changes: 2 additions & 1 deletion src/artery/storyboard/EffectStack.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef ARTERY_EFFECTSTACK_H_
#define ARTERY_EFFECTSTACK_H_

#include "artery/storyboard/Macros.h"
#include <vector>
#include <memory>

Expand All @@ -10,7 +11,7 @@ namespace artery
class Effect;
class Story;

class EffectStack
class STORYBOARD_API EffectStack
{
public:
/**
Expand Down
2 changes: 1 addition & 1 deletion src/artery/storyboard/EmergencyStopEffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace artery
* EmergencyStopEffect stops vehicle with emergency deceleration.
* Once stopped vehicle remains stopped.
*/
class EmergencyStopEffect : public Effect
class STORYBOARD_API EmergencyStopEffect : public Effect
{
public:
using Effect::Effect;
Expand Down
2 changes: 1 addition & 1 deletion src/artery/storyboard/GenericEffectFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace artery
{

class GenericEffectFactory : public EffectFactory
class STORYBOARD_API GenericEffectFactory : public EffectFactory
{
public:
using FactoryFunction = std::function<std::shared_ptr<Effect>(Vehicle&, Story&, ConditionResult&)>;
Expand Down
2 changes: 1 addition & 1 deletion src/artery/storyboard/LikelihoodCondition.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace artery
* If this condition evaluates to true for a particular vehicle is only determined once.
* The likelihood has to be given in the range [0.0; 1.0].
*/
class LikelihoodCondition : public Condition
class STORYBOARD_API LikelihoodCondition : public Condition
{
public:
LikelihoodCondition(omnetpp::cRNG*, double likelihood);
Expand Down
2 changes: 1 addition & 1 deletion src/artery/storyboard/LimitCondition.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace artery
/**
* Condition holds only true for the first N vehicles
*/
class LimitCondition : public Condition
class STORYBOARD_API LimitCondition : public Condition
{
public:
LimitCondition(unsigned);
Expand Down
22 changes: 22 additions & 0 deletions src/artery/storyboard/Macros.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef ARTERY_MACROS_H_3PHIGCXK
#define ARTERY_MACROS_H_3PHIGCXK

#if defined _WIN32 || defined __CYGWIN__
#define STORYBOARD_DLL_IMPORT __declspec(dllimport)
#define STORYBOARD_DLL_EXPORT __declspec(dllexport)
#define STORYBOARD_DLL_LOCAL
#else
#define STORYBOARD_DLL_IMPORT __attribute__ ((visibility ("default")))
#define STORYBOARD_DLL_EXPORT __attribute__ ((visibility ("default")))
#define STORYBOARD_DLL_LOCAL __attribute__ ((visibility ("hidden")))
#endif

// storyboard_EXPORTS is defined by CMake
#ifdef storyboard_EXPORTS
#define STORYBOARD_API STORYBOARD_DLL_EXPORT
#else
#define STORYBOARD_API STORYBOARD_DLL_IMPORT
#endif
#define STORYBOARD_LOCAL STORYBOARD_DLL_LOCAL

#endif /* ARTERY_MACROS_H_3PHIGCXK */
2 changes: 1 addition & 1 deletion src/artery/storyboard/OrCondition.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace artery
/**
* Class to create a Tree of OrConditions
*/
class OrCondition : public Condition
class STORYBOARD_API OrCondition : public Condition
{
public:
using ConditionPtr = std::shared_ptr<Condition>;
Expand Down
4 changes: 2 additions & 2 deletions src/artery/storyboard/PolygonCondition.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace artery
{

class PolygonCondition : public Condition
class STORYBOARD_API PolygonCondition : public Condition
{
public:
/**
Expand All @@ -31,7 +31,7 @@ class PolygonCondition : public Condition
private:
std::vector<Position> m_vertices;
bool mDraw;
int edges() const;
int STORYBOARD_LOCAL edges() const;
};

} // namespace artery
Expand Down
2 changes: 1 addition & 1 deletion src/artery/storyboard/SignalEffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace artery
* Triggers an OMNeT Signal which can be received by any submodule of car
* Signal is triggered only if the effect is applied the first time
*/
class SignalEffect : public Effect
class STORYBOARD_API SignalEffect : public Effect
{
public:
SignalEffect(Vehicle& car, std::string cause, Story& story, ConditionResult& result) :
Expand Down
2 changes: 1 addition & 1 deletion src/artery/storyboard/SignalEffectFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace artery
/**
* SignalEffectFactory creates SignalEffects
*/
class SignalEffectFactory : public EffectFactory
class STORYBOARD_API SignalEffectFactory : public EffectFactory
{
public:
SignalEffectFactory(std::string cause) :
Expand Down
6 changes: 3 additions & 3 deletions src/artery/storyboard/SpeedDifferenceCondition.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace artery
{

class SpeedDifferenceCondition : public Condition
class STORYBOARD_API SpeedDifferenceCondition : public Condition
{
public:
SpeedDifferenceCondition(double difference) :
Expand All @@ -23,7 +23,7 @@ class SpeedDifferenceCondition : public Condition
};


class SpeedDifferenceConditionFaster : public SpeedDifferenceCondition
class STORYBOARD_API SpeedDifferenceConditionFaster : public SpeedDifferenceCondition
{
public:
SpeedDifferenceConditionFaster(double difference) : SpeedDifferenceCondition(difference)
Expand All @@ -33,7 +33,7 @@ class SpeedDifferenceConditionFaster : public SpeedDifferenceCondition
virtual ConditionResult testCondition(const Vehicle& car) override;
};

class SpeedDifferenceConditionSlower : public SpeedDifferenceCondition
class STORYBOARD_API SpeedDifferenceConditionSlower : public SpeedDifferenceCondition
{
public:
SpeedDifferenceConditionSlower(double difference) : SpeedDifferenceCondition(difference)
Expand Down
2 changes: 1 addition & 1 deletion src/artery/storyboard/SpeedEffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace artery
* Changes the cars speed according to m_speed
* Resets the speed to the previous with removing the Effect
*/
class SpeedEffect : public Effect
class STORYBOARD_API SpeedEffect : public Effect
{
public:
/**
Expand Down
2 changes: 1 addition & 1 deletion src/artery/storyboard/SpeedEffectFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace artery
/**
* SpeedEffectFactory creates SpeedEffects
*/
class SpeedEffectFactory : public EffectFactory
class STORYBOARD_API SpeedEffectFactory : public EffectFactory
{
public:
SpeedEffectFactory(double speed) :
Expand Down
2 changes: 1 addition & 1 deletion src/artery/storyboard/StopEffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace artery
* This causes the car to slow down to zero (and starting the waiting timer in SUMO)
* Speed is reset to previous speed after removing the effect
*/
class StopEffect : public Effect
class STORYBOARD_API StopEffect : public Effect
{
public:
StopEffect(Vehicle& car, Story& story) :
Expand Down
2 changes: 1 addition & 1 deletion src/artery/storyboard/StopEffectFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace artery
/**
* StopEffectFactories creates StopEffects
*/
class StopEffectFactory : public EffectFactory
class STORYBOARD_API StopEffectFactory : public EffectFactory
{
public:
StopEffectFactory() {};
Expand Down
3 changes: 2 additions & 1 deletion src/artery/storyboard/Story.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "artery/storyboard/Condition.h"
#include "artery/storyboard/EffectFactory.h"
#include "artery/storyboard/Macros.h"
#include "artery/storyboard/Vehicle.h"
#include <memory>
#include <vector>
Expand All @@ -17,7 +18,7 @@ class EffectFactory;
* Class providing a basic set of member functions for creating a story
* Can be used to create stories with any trigger conditions and any effect
*/
class Story
class STORYBOARD_API Story
{
public:
using EffectFactories = std::vector<std::shared_ptr<EffectFactory>>;
Expand Down
15 changes: 8 additions & 7 deletions src/artery/storyboard/Storyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <omnetpp/csimplemodule.h>
#include "artery/storyboard/Condition.h"
#include "artery/storyboard/EffectStack.h"
#include "artery/storyboard/Macros.h"
#include "artery/storyboard/Vehicle.h"
#include "artery/utility/Geometry.h"
#include "traci/Boundary.h"
Expand All @@ -21,7 +22,7 @@ class Effect;
class Story;
class Vehicle;

class Storyboard : public omnetpp::cSimpleModule, public omnetpp::cListener
class STORYBOARD_API Storyboard : public omnetpp::cSimpleModule, public omnetpp::cListener
{
public:
Storyboard();
Expand Down Expand Up @@ -57,27 +58,27 @@ class Storyboard : public omnetpp::cSimpleModule, public omnetpp::cListener
* Updates the storyboard by checking all stories
* Is called each time TraCIScenarioManager processes one omnet step
*/
void updateStoryboard();
void STORYBOARD_LOCAL updateStoryboard();

/**
* Adds all effects generated from a story
* \param list all effects to add, all effects needs to be from the same story and the same car
*/
void addEffect(const std::vector<std::shared_ptr<Effect>>&);
void STORYBOARD_LOCAL addEffect(const std::vector<std::shared_ptr<Effect>>&);

/**
* Removes all Effects from one car related to one Story
* \param Vehicle from which the Effects should be removed
* \param Story to remove
*/
void removeStory(Vehicle*, const Story*);
void STORYBOARD_LOCAL removeStory(Vehicle*, const Story*);

/**
* Checks if a specific Story is already applied on a TraCIMobility
* \param Vehicle which should be tested
* \param Story that should be tested
*/
bool storyApplied(Vehicle*, const Story*);
bool STORYBOARD_LOCAL storyApplied(Vehicle*, const Story*);

/**
* Checks if the story has to be applied or removed
Expand All @@ -86,12 +87,12 @@ class Storyboard : public omnetpp::cSimpleModule, public omnetpp::cListener
* param: bool result of condition test
* param: Story which was tested in the update function
*/
void checkCar(Vehicle&, ConditionResult&, Story*);
void STORYBOARD_LOCAL checkCar(Vehicle&, ConditionResult&, Story*);

/**
* Iterate over all conditions associated with registered stories and draw them on canvas
*/
void drawConditions();
void STORYBOARD_LOCAL drawConditions();

std::unique_ptr<PythonContext> m_python;
std::vector<std::shared_ptr<Story>> m_stories;
Expand Down
2 changes: 1 addition & 1 deletion src/artery/storyboard/TimeCondition.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace artery
* Condition: Time
* Checks if the current SimTime is in the specified time interval
*/
class TimeCondition : public Condition
class STORYBOARD_API TimeCondition : public Condition
{
public:
/**
Expand Down
Loading

0 comments on commit b05d60d

Please sign in to comment.