12#include <ChimeraTK/BackendFactory.h>
13#include <ChimeraTK/Device.h>
14#include <ChimeraTK/DummyRegisterAccessor.h>
15#include <ChimeraTK/ExceptionDummyBackend.h>
16#include <ChimeraTK/NDRegisterAccessor.h>
38 } reg1{
this,
"PushModule",
""};
52 } reg1{
this,
"PushModuleForFanOut",
""};
66 } reg1{
this,
"PushModuleForTrigger",
""};
105 } group1{
this,
"Group1",
""};
114 } group2{
this,
"Group2",
""};
120 } group3{
this,
"Group3",
""};
126template<
bool enableTestFacility,
bool addInitHandlers = false,
bool breakSecondDeviceAtStart = false>
133 auto read(ChimeraTK::DummyRegisterRawAccessor& accessor);
136 auto read(ChimeraTK::DummyRegisterRawAccessor&& accessor);
139 void write(ChimeraTK::DummyRegisterRawAccessor& accessor, T value);
142 void write(ChimeraTK::DummyRegisterRawAccessor&& accessor, T value);
154 ChimeraTK::ScalarRegisterAccessor<std::string>
message;
183template<
bool enableTestFacility,
bool addInitHandlers,
bool breakSecondDeviceAtStart>
186: deviceBackend(boost::dynamic_pointer_cast<
ChimeraTK::ExceptionDummy>(
188 deviceBackend2(boost::dynamic_pointer_cast<
ChimeraTK::ExceptionDummy>(
190 deviceBackend3(boost::dynamic_pointer_cast<
ChimeraTK::ExceptionDummy>(
192 exceptionDummyRegister(deviceBackend->getRawAccessor(
"",
"REG1.DUMMY_WRITEABLE")),
193 exceptionDummyRegister2(deviceBackend->getRawAccessor(
"",
"REG2")),
194 exceptionDummyRegister3(deviceBackend->getRawAccessor(
"",
"REG3")),
195 exceptionDummy2Register(deviceBackend2->getRawAccessor(
"",
"REG1.DUMMY_WRITEABLE")) {
199 if constexpr(addInitHandlers) {
204 throw ChimeraTK::runtime_error(
"Init handler 1 throws by request");
212 throw ChimeraTK::runtime_error(
"Init handler 2 throws by request");
216 application.group1.device.addInitialisationHandler(initHandler1);
217 application.group1.device.addInitialisationHandler(initHandler2);
233 testFacitiy.
getVoid(ChimeraTK::RegisterPath(
"/Devices") / dm1 /
"deviceBecameFunctional"));
238 interrupt.replace(dev.getVoidRegisterAccessor(
"DUMMY_INTERRUPT_1"));
241 application.group1.pollModule.p.get_future().wait();
242 application.group1.pushModule.p.get_future().wait();
243 application.group1.outputModule.p.get_future().wait();
244 if(!breakSecondDeviceAtStart) {
245 application.group2.outputModule2.p.get_future().wait();
247 application.group2.pushModule2.p.get_future().wait();
248 application.group2.pushModule3.p.get_future().wait();
250 application.group3.pollModule3.p.get_future().wait();
253 catch(std::exception& e) {
254 std::cout <<
"Exception caught in constructor: " << e.what() << std::endl;
261template<
bool enableTestFacility,
bool addInitHandlers,
bool breakSecondDeviceAtStart>
263 breakSecondDeviceAtStart>::~FixtureWithPollAndPushInput() {
265 deviceBackend->throwExceptionOpen =
false;
266 deviceBackend->throwExceptionRead =
false;
267 deviceBackend->throwExceptionWrite =
false;
268 deviceBackend2->throwExceptionOpen =
false;
269 deviceBackend2->throwExceptionRead =
false;
270 deviceBackend2->throwExceptionWrite =
false;
271 deviceBackend3->throwExceptionOpen =
false;
272 deviceBackend3->throwExceptionRead =
false;
273 deviceBackend3->throwExceptionWrite =
false;
278template<
bool enableTestFacility,
bool addInitHandlers,
bool breakSecondDeviceAtStart>
282 return static_cast<int>(status);
287template<
bool enableTestFacility,
bool addInitHandlers,
bool breakSecondDeviceAtStart>
290 ChimeraTK::DummyRegisterRawAccessor& accessor) {
291 auto lock = accessor.getBufferLock();
292 return static_cast<T
>(accessor);
297template<
bool enableTestFacility,
bool addInitHandlers,
bool breakSecondDeviceAtStart>
300 ChimeraTK::DummyRegisterRawAccessor&& accessor) {
306template<
bool enableTestFacility,
bool addInitHandlers,
bool breakSecondDeviceAtStart>
309 ChimeraTK::DummyRegisterRawAccessor& accessor, T value) {
310 auto lock = accessor.getBufferLock();
311 accessor =
static_cast<int32_t
>(value);
316template<
bool enableTestFacility,
bool addInitHandlers,
bool breakSecondDeviceAtStart>
319 ChimeraTK::DummyRegisterRawAccessor&& accessor, T value) {
320 write(accessor, value);
boost::shared_ptr< DeviceManager > getDeviceManager(const std::string &aliasOrCDD)
Return the DeviceManager for the given alias name or CDD.
void optimiseUnmappedVariables(const std::set< std::string > &names) override
void shutdown() override
This will remove the global pointer to the instance and allows creating another instance afterwards.
ApplicationModule()=default
Default constructor: Allows late initialisation of modules (e.g.
ModuleGroup()=default
Default constructor to allow late initialisation of module groups.
void writeAll(bool includeReturnChannels=false)
Just call write() on all writable variables in the group.
Helper class to facilitate tests of applications based on ApplicationCore.
ChimeraTK::VoidRegisterAccessor getVoid(const ChimeraTK::RegisterPath &name) const
Obtain a void process variable from the application, which is published to the control system.
ChimeraTK::ScalarRegisterAccessor< T > getScalar(const ChimeraTK::RegisterPath &name) const
Obtain a scalar process variable from the application, which is published to the control system.
void runApplication() const
Start the application in testable mode.
VariableGroup()=default
Default constructor: Allows late initialisation of VariableGroups (e.g.
std::string escapeName(const std::string &name, bool allowDotsAndSlashes)
Convert all characters which are not allowed in variable or module names into underscores followed by...
InvalidityTracer application module.
Convenience class for output scalar accessors (always UpdateMode::push)
Convenience class for output void (always UpdateMode::push)
ChimeraTK::DeviceModule device
OutputModule outputModule
PushModuleForFanOut pushModule3
ChimeraTK::DeviceModule device2
PushModuleForTrigger pushModule2
OutputModule outputModule2
ChimeraTK::DeviceModule device3
static constexpr const char * ExceptionDummyCDD2
~DummyApplication() override
static constexpr const char * ExceptionDummyCDD1
static constexpr const char * ExceptionDummyCDD3
void prepare() override
Prepare the execution of the module.
ChimeraTK::ScalarOutput< int > deviceRegister3
ChimeraTK::ScalarOutput< int > deviceRegister2
void mainLoop() override
To be implemented by the user: function called in a separate thread executing the main loop of the mo...
ChimeraTK::VoidOutput deviceRegisterV
ChimeraTK::ScalarOutput< int > trigger
ChimeraTK::ScalarPollInput< int > pollInput2
void mainLoop() override
To be implemented by the user: function called in a separate thread executing the main loop of the mo...
ChimeraTK::ScalarPollInput< int > pollInput
void mainLoop() override
To be implemented by the user: function called in a separate thread executing the main loop of the mo...
ChimeraTK::ScalarPushInput< int > pushInputCopy
ChimeraTK::ScalarPushInput< int > pushInput
ChimeraTK::ScalarPushInput< int > pushInput
void mainLoop() override
To be implemented by the user: function called in a separate thread executing the main loop of the mo...
ChimeraTK::ScalarPushInput< int > pushInputCopy
void mainLoop() override
To be implemented by the user: function called in a separate thread executing the main loop of the mo...
ChimeraTK::ScalarPushInput< int > pushInput