diff --git a/.cproject b/.cproject index 0649f5e..b616eb7 100644 --- a/.cproject +++ b/.cproject @@ -44,8 +44,8 @@ - - + + diff --git a/cmake/Pytest.cmake b/cmake/Pytest.cmake index 43a1983..37b8c43 100644 --- a/cmake/Pytest.cmake +++ b/cmake/Pytest.cmake @@ -9,7 +9,7 @@ find_package(Python COMPONENTS Interpreter Development) function(pytest_discover_tests) cmake_parse_arguments( PARSE_ARGV 0 "" "" - "NAME;WORKING_DIRECTORY;TRIM_FROM_NAME;BUNDLE_TESTS" + "NAME;WORKING_DIRECTORY;BUNDLE_TESTS" "LIBRARY_PATH_PREPEND;PYTHON_PATH_PREPEND;ENVIRONMENT" ) @@ -66,9 +66,7 @@ function(pytest_discover_tests) if (NOT _WORKING_DIRECTORY) set(_WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/python) endif() - if (NOT _TRIM_FROM_NAME) - set(_TRIM_FROM_NAME "^test_") - endif() + # Override option by environment variable if available. if (DEFINED ENV{BUNDLE_PYTHON_TESTS}) set(_BUNDLE_TESTS $ENV{BUNDLE_PYTHON_TESTS}) @@ -97,7 +95,6 @@ function(pytest_discover_tests) " LIB_ENV_PATH" " [==[" "${LIB_ENV_PATH}" "]==]" "\n" " LIBRARY_PATH" " [==[" "${libpath}" "]==]" "\n" " PYTHON_PATH" " [==[" "${pythonpath}" "]==]" "\n" - " TRIM_FROM_NAME" " [==[" "${_TRIM_FROM_NAME}" "]==]" "\n" " WORKING_DIRECTORY" " [==[" "${_WORKING_DIRECTORY}" "]==]" "\n" " ENVIRONMENT" " [==[" "${_ENVIRONMENT}" "]==]" "\n" " CTEST_FILE" " [==[" "${ctest_tests_file}" "]==]" "\n" diff --git a/cmake/PytestAddTests.cmake b/cmake/PytestAddTests.cmake index 48a6ecd..07a73ef 100644 --- a/cmake/PytestAddTests.cmake +++ b/cmake/PytestAddTests.cmake @@ -6,7 +6,7 @@ function(pytest_discover_tests_impl) cmake_parse_arguments( "" "" - "PYTHON_EXECUTABLE;TEST_GROUP_NAME;BUNDLE_TESTS;LIB_ENV_PATH;LIBRARY_PATH;PYTHON_PATH;TRIM_FROM_NAME;WORKING_DIRECTORY;ENVIRONMENT;CTEST_FILE" + "PYTHON_EXECUTABLE;TEST_GROUP_NAME;BUNDLE_TESTS;LIB_ENV_PATH;LIBRARY_PATH;PYTHON_PATH;WORKING_DIRECTORY;ENVIRONMENT;CTEST_FILE" "" ${ARGN} ) @@ -73,16 +73,17 @@ function(pytest_discover_tests_impl) set(_class ${CMAKE_MATCH_3}) set(_func ${CMAKE_MATCH_4}) + + string(REGEX REPLACE "^test_?" "" _func "${_func}") + if (_class) + #string(REGEX REPLACE "^Test|Test$" "" _class "${_class}") set(test_name "${_class}.${_func}") else() set(test_name "${_func}") endif() - if (_TRIM_FROM_NAME) - string(REGEX REPLACE - "${_TRIM_FROM_NAME}" "" test_name "${test_name}") - endif() + set(test_name "${_TEST_GROUP_NAME}/${test_name}") set(test_case "${_WORKING_DIRECTORY}/${test_case}") @@ -128,7 +129,6 @@ if(CMAKE_SCRIPT_MODE_FILE) LIB_ENV_PATH ${LIB_ENV_PATH} LIBRARY_PATH ${LIBRARY_PATH} PYTHON_PATH ${PYTHON_PATH} - TRIM_FROM_NAME ${TRIM_FROM_NAME} WORKING_DIRECTORY ${WORKING_DIRECTORY} ENVIRONMENT ${ENVIRONMENT} CTEST_FILE ${CTEST_FILE} diff --git a/examples/project1/python/xsmp_example_project1/Example/__init__.py b/examples/project1/python/xsmp_example_project1/Example/__init__.py index 7a02a6c..f9a9580 100644 --- a/examples/project1/python/xsmp_example_project1/Example/__init__.py +++ b/examples/project1/python/xsmp_example_project1/Example/__init__.py @@ -10,7 +10,7 @@ import ecss_smp -class M1: +class Counter: uuid: ecss_smp.Smp.Uuid = ecss_smp.Smp.Uuid("2386045d-5cff-46b5-b6da-3ff6e2cfd792") del ecss_smp diff --git a/examples/project1/python/xsmp_example_project1/_test_xsmp_example_project1.py b/examples/project1/python/xsmp_example_project1/_test_Counter.py similarity index 80% rename from examples/project1/python/xsmp_example_project1/_test_xsmp_example_project1.py rename to examples/project1/python/xsmp_example_project1/_test_Counter.py index 717c7c1..8daa4ee 100644 --- a/examples/project1/python/xsmp_example_project1/_test_xsmp_example_project1.py +++ b/examples/project1/python/xsmp_example_project1/_test_Counter.py @@ -39,21 +39,18 @@ class __XsmpScheduler(ecss_smp.Smp.Services.IScheduler, ecss_smp.Smp.IDynamicInv _Models: ecss_smp.Smp.IContainer - class __name(ecss_smp.Smp.IModel, ecss_smp.Smp.IDynamicInvocation, ecss_smp.Smp.ILinkingComponent, ecss_smp.Smp.IComposite, ): - class __integer1(ecss_smp.Smp.ISimpleField, ): - pass - - integer1: __integer1 + class __counter(ecss_smp.Smp.IModel, ecss_smp.Smp.IDynamicInvocation, ecss_smp.Smp.IEventConsumer, ecss_smp.Smp.ILinkingComponent, ecss_smp.Smp.IEntryPointPublisher, ): + def ResetCount(self, ): ... + Add: ecss_smp.Smp.IEventSink - class __integer2(ecss_smp.Smp.ISimpleField, ): + class __count(ecss_smp.Smp.ISimpleField, ): pass - integer2: __integer2 - - _subModels: ecss_smp.Smp.IContainer + count: __count + IncrementCount: ecss_smp.Smp.IEntryPoint - name: __name + counter: __counter diff --git a/examples/project1/python/xsmp_example_project1/test_Counter.py b/examples/project1/python/xsmp_example_project1/test_Counter.py new file mode 100644 index 0000000..7664bd6 --- /dev/null +++ b/examples/project1/python/xsmp_example_project1/test_Counter.py @@ -0,0 +1,36 @@ +import ecss_smp +import xsmp +import xsmp_example_project1 + + +class TestCounter(xsmp.unittest.TestCase): + try: + sim: xsmp_example_project1._test_xsmp_example_project1.Simulator + except AttributeError: + pass + + def loadAssembly(self, sim: ecss_smp.Smp.ISimulator): + sim.LoadLibrary("xsmp_example_project1") + sim.AddModel(sim.CreateInstance(xsmp_example_project1.Example.Counter.uuid, "counter", "", sim)) + + def test_Init(self): + self.assertEqual(self.sim.counter.count, 0, "Initial value of count is 0") + + def test_IncrementCount(self): + self.sim.counter.IncrementCount() + self.assertEqual(self.sim.counter.count, 1, "Count incremented") + + def test_ScheduleIncrementCount(self): + self.sim.GetScheduler().AddSimulationTimeEvent(self.sim.counter.IncrementCount, 0, 1_000_000_000, 5) + self.sim.Run(seconds=10) + self.assertEqual(self.sim.counter.count, 6, "Count incremented 6 times") + + def test_ResetCount(self): + self.sim.counter.count = 10 + self.sim.counter.ResetCount() + self.assertEqual(self.sim.counter.count, 0, "Count is reseted") + + def test_Add(self): + self.sim.counter.Add(arg=10) + self.assertEqual(self.sim.counter.count, 10, "Add 10 to count") + diff --git a/examples/project1/python/xsmp_example_project1/test_xsmp_example_project1.py b/examples/project1/python/xsmp_example_project1/test_xsmp_example_project1.py deleted file mode 100644 index 927f8aa..0000000 --- a/examples/project1/python/xsmp_example_project1/test_xsmp_example_project1.py +++ /dev/null @@ -1,21 +0,0 @@ -import ecss_smp -import xsmp -import xsmp_example_project1 - - -class TestXsmpExampleProject1(xsmp.unittest.TestCase): - try: - sim: xsmp_example_project1._test_xsmp_example_project1.Simulator - except AttributeError: - pass - - def loadAssembly(self, sim: ecss_smp.Smp.ISimulator): - sim.LoadLibrary("xsmp_example_project1") - sim.AddModel(sim.CreateInstance(xsmp_example_project1.Example.M1.uuid, "name", "", sim)) - - def test_Init(self): - pass - - - def test_Init2(self): - pass \ No newline at end of file diff --git a/examples/project1/smdl-gen/xsmp_example_project1.smpcat b/examples/project1/smdl-gen/xsmp_example_project1.smpcat index cd0c972..1622e21 100644 --- a/examples/project1/smdl-gen/xsmp_example_project1.smpcat +++ b/examples/project1/smdl-gen/xsmp_example_project1.smpcat @@ -1,22 +1,29 @@ - + Catalogue xsmp_example_project1 - + - + + + + + - - - + + - - - + + + + + + - - + + + diff --git a/examples/project1/smdl-gen/xsmp_example_project1.smppkg b/examples/project1/smdl-gen/xsmp_example_project1.smppkg index de7d253..98d0030 100644 --- a/examples/project1/smdl-gen/xsmp_example_project1.smppkg +++ b/examples/project1/smdl-gen/xsmp_example_project1.smppkg @@ -1,5 +1,6 @@ - + Catalogue xsmp_example_project1 - + + diff --git a/examples/project1/smdl/xsmp_example_project1.xsmpcat b/examples/project1/smdl/xsmp_example_project1.xsmpcat index 25bb20d..e711bef 100644 --- a/examples/project1/smdl/xsmp_example_project1.xsmpcat +++ b/examples/project1/smdl/xsmp_example_project1.xsmpcat @@ -7,20 +7,24 @@ * Catalogue xsmp_example_project1 * * @creator Y.Daveluy - * @date 2023-06-02T17:08:16.000+0200 + * @date 2024-01-04T10:37:00.000+0100 */ catalogue xsmp_example_project1 namespace Example { + /** @uuid f80c5d8e-deb4-492a-a5c0-4d37eadebe24 */ + event CountEvent extends Int32 + /** @uuid 2386045d-5cff-46b5-b6da-3ff6e2cfd792 */ - model M1 + model Counter { - field Int8 integer1 - field Int16 integer2 + field Int32 count = 0 - container M1[*] subModels + entrypoint IncrementCount + def void ResetCount () + eventsink CountEvent Add } } diff --git a/examples/project1/src-gen/Example/CounterGen.cpp b/examples/project1/src-gen/Example/CounterGen.cpp new file mode 100644 index 0000000..485e402 --- /dev/null +++ b/examples/project1/src-gen/Example/CounterGen.cpp @@ -0,0 +1,121 @@ +// Copyright 2023 YOUR ORGANIZATION. All rights reserved. +// +// YOUR NOTICE + +// ----------------------------------------------------------------------------- +// File Name : CounterGen.cpp +// Generated by : XsmpSdkGenerator-${qualifiedVersion} +// ----------------------------------------------------------------------------- +/// @file Example/CounterGen.cpp +// This file is auto-generated, Do not edit otherwise your changes will be lost + +// ---------------------------------------------------------------------------- +// ---------------------------- Include Header Files -------------------- +// ---------------------------------------------------------------------------- + +#include +#include +#include +#include +#include +#include + +namespace Example { +//--------------------------- Constructor ------------------------- +CounterGen::CounterGen(::Smp::String8 name, ::Smp::String8 description, + ::Smp::IObject *parent, ::Smp::ISimulator *simulator) : + // Base class initialization + ::Xsmp::Model(name, description, parent, simulator), + // EntryPoint: IncrementCount + IncrementCount { new ::Xsmp::EntryPoint("IncrementCount", "", this, + std::bind(&CounterGen::_IncrementCount, this)) }, + // Event Sink: Add + Add { new ::Xsmp::EventSink<::Smp::Int32>("Add", "", this, + std::bind(&CounterGen::_Add, this, std::placeholders::_1, + std::placeholders::_2), + ::Smp::PrimitiveTypeKind::PTK_Int32) }, + // count initialization + count { 0 } { +} + +/// Virtual destructor that is called by inherited classes as well. +CounterGen::~CounterGen() { + delete IncrementCount; + IncrementCount = nullptr; + delete Add; + Add = nullptr; +} + +void CounterGen::Publish(::Smp::IPublication *receiver) { + // Call parent class implementation first + ::Xsmp::Model::Publish(receiver); + + // Publish field count + receiver->PublishField("count", "", &count, ::Smp::ViewKind::VK_None, true, + false, false); + { + // Publish operation ResetCount + receiver->PublishOperation("ResetCount", "", ::Smp::ViewKind::VK_None); + } + // Call user DoPublish if any + ::Xsmp::Component::Helper::Publish < ::Example::Counter > (this, receiver); +} + +void CounterGen::Configure(::Smp::Services::ILogger *logger, + ::Smp::Services::ILinkRegistry *linkRegistry) { + // Call parent implementation first + ::Xsmp::Model::Configure(logger, linkRegistry); + + // Call user DoConfigure if any + ::Xsmp::Component::Helper::Configure < ::Example::Counter + > (this, logger, linkRegistry); +} + +void CounterGen::Connect(::Smp::ISimulator *simulator) { + // Call parent implementation first + ::Xsmp::Model::Connect(simulator); + + // Call user DoConnect if any + ::Xsmp::Component::Helper::Connect < ::Example::Counter > (this, simulator); +} + +void CounterGen::Disconnect() { + // Call user DoDisconnect if any + ::Xsmp::Component::Helper::Disconnect < ::Example::Counter > (this); + + // Call parent implementation last, to remove references to the Simulator and its services + ::Xsmp::Model::Disconnect(); +} + +CounterGen::RequestHandlers CounterGen::requestHandlers = InitRequestHandlers(); + +CounterGen::RequestHandlers CounterGen::InitRequestHandlers() { + RequestHandlers handlers; + if (handlers.find("ResetCount") == handlers.end()) { + handlers["ResetCount"] = [](CounterGen *cmp, ::Smp::IRequest*) { + + /// Invoke ResetCount + cmp->ResetCount(); + + }; + } + return handlers; +} + +void CounterGen::Invoke(::Smp::IRequest *request) { + if (request == nullptr) { + return; + } + auto handler = requestHandlers.find(request->GetOperationName()); + if (handler != requestHandlers.end()) { + handler->second(this, request); + } else { + // pass the request down to the base model + ::Xsmp::Model::Invoke(request); + } +} + +const Smp::Uuid& CounterGen::GetUuid() const { + return Uuid_Counter; +} +} // namespace Example diff --git a/examples/project1/src-gen/Example/M1Gen.h b/examples/project1/src-gen/Example/CounterGen.h similarity index 60% rename from examples/project1/src-gen/Example/M1Gen.h rename to examples/project1/src-gen/Example/CounterGen.h index 8f1cc81..c3d9d9b 100644 --- a/examples/project1/src-gen/Example/M1Gen.h +++ b/examples/project1/src-gen/Example/CounterGen.h @@ -3,25 +3,31 @@ // YOUR NOTICE // ----------------------------------------------------------------------------- -// File Name : M1Gen.h +// File Name : CounterGen.h // Generated by : XsmpSdkGenerator-${qualifiedVersion} // ----------------------------------------------------------------------------- -/// @file Example/M1Gen.h +/// @file Example/CounterGen.h // This file is auto-generated, Do not edit otherwise your changes will be lost -#ifndef EXAMPLE_M1GEN_H_ -#define EXAMPLE_M1GEN_H_ +#ifndef EXAMPLE_COUNTERGEN_H_ +#define EXAMPLE_COUNTERGEN_H_ // ---------------------------------------------------------------------------- // ---------------------------- Include Header Files -------------------- // ---------------------------------------------------------------------------- -#include "Smp/ISimulator.h" -#include "Smp/PrimitiveTypes.h" -#include "Smp/Publication/ITypeRegistry.h" -#include "Xsmp/Composite.h" -#include "Xsmp/Container.h" -#include "Xsmp/Model.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include // ---------------------------------------------------------------------------- @@ -30,14 +36,16 @@ namespace Example { // forward declaration of user class -class M1; -/// Universally unique identifier of type M1. -static constexpr ::Smp::Uuid Uuid_M1 { 0x2386045dU, 0x5cffU, 0x46b5U, 0xb6daU, - 0x3ff6e2cfd792U }; +class Counter; +/// Universally unique identifier of type Counter. +static constexpr ::Smp::Uuid Uuid_Counter { 0x2386045dU, 0x5cffU, 0x46b5U, + 0xb6daU, 0x3ff6e2cfd792U }; -class M1Gen: public ::Xsmp::Model, public virtual ::Xsmp::Composite { +class CounterGen: public ::Xsmp::Model, + public virtual ::Xsmp::EventConsumer, + public virtual ::Xsmp::EntryPointPublisher { - friend class ::Example::M1; + friend class ::Example::Counter; public: // ------------------------------------------------------------------------------------ @@ -49,19 +57,19 @@ class M1Gen: public ::Xsmp::Model, public virtual ::Xsmp::Composite { /// @param description Description of new model instance. /// @param parent Parent of new model instance. /// @param simulator The simulator instance. - M1Gen(::Smp::String8 name, ::Smp::String8 description, + CounterGen(::Smp::String8 name, ::Smp::String8 description, ::Smp::IObject *parent, ::Smp::ISimulator *simulator); /// deleted copy constructor - M1Gen(const M1Gen&) = delete; + CounterGen(const CounterGen&) = delete; /// deleted move constructor - M1Gen(M1Gen&&) = delete; + CounterGen(CounterGen&&) = delete; /// deleted copy assignment - M1Gen& operator=(const M1Gen&) = delete; + CounterGen& operator=(const CounterGen&) = delete; /// deleted move assignment - M1Gen& operator=(M1Gen&&) = delete; + CounterGen& operator=(CounterGen&&) = delete; /// Virtual destructor to release memory. - ~M1Gen() override; + ~CounterGen() override; // ---------------------------------------------------------------------------------- // -------------------------------- IComponent --------------------------------- @@ -91,12 +99,27 @@ class M1Gen: public ::Xsmp::Model, public virtual ::Xsmp::Composite { /// @return Universally Unique Identifier of the Model. const Smp::Uuid& GetUuid() const override; + // ---------------------------------------------------------------------------------- + // --------------------------- IDynamicInvocation --------------------------- + // ---------------------------------------------------------------------------------- + using RequestHandlers = std::map>; + static RequestHandlers requestHandlers; + static RequestHandlers InitRequestHandlers(); + + /// Invoke the operation for the given request. + /// @param request Request object to invoke. + void Invoke(::Smp::IRequest *request) override; + private: - ::Smp::Int8 integer1; - ::Smp::Int16 integer2; + virtual void ResetCount()=0; public: - ::Xsmp::Container<::Example::M1> *subModels; + ::Smp::IEntryPoint *IncrementCount; + virtual void _IncrementCount() = 0; + ::Smp::IEventSink *Add; + virtual void _Add(::Smp::IObject *sender, ::Smp::Int32 value) = 0; +private: + ::Smp::Int32 count; }; } // namespace Example -#endif // EXAMPLE_M1GEN_H_ +#endif // EXAMPLE_COUNTERGEN_H_ diff --git a/examples/project1/src-gen/Example/M1Gen.cpp b/examples/project1/src-gen/Example/M1Gen.cpp deleted file mode 100644 index 16a7ff2..0000000 --- a/examples/project1/src-gen/Example/M1Gen.cpp +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright 2023 YOUR ORGANIZATION. All rights reserved. -// -// YOUR NOTICE - -// ----------------------------------------------------------------------------- -// File Name : M1Gen.cpp -// Generated by : XsmpSdkGenerator-${qualifiedVersion} -// ----------------------------------------------------------------------------- -/// @file Example/M1Gen.cpp -// This file is auto-generated, Do not edit otherwise your changes will be lost - -// ---------------------------------------------------------------------------- -// ---------------------------- Include Header Files -------------------- -// ---------------------------------------------------------------------------- - -#include "Example/M1.h" -#include "Smp/IPublication.h" -#include "Xsmp/ComponentHelper.h" - -namespace Example { -//--------------------------- Constructor ------------------------- -M1Gen::M1Gen(::Smp::String8 name, ::Smp::String8 description, - ::Smp::IObject *parent, ::Smp::ISimulator *simulator) : - // Base class initialization - ::Xsmp::Model(name, description, parent, simulator), - // integer1 initialization - integer1 { }, - // integer2 initialization - integer2 { }, - // Container: subModels - subModels { new ::Xsmp::Container<::Example::M1>("subModels", "", this, - 0, -1) } { -} - -/// Virtual destructor that is called by inherited classes as well. -M1Gen::~M1Gen() { - delete subModels; - subModels = nullptr; -} - -void M1Gen::Publish(::Smp::IPublication *receiver) { - // Call parent class implementation first - ::Xsmp::Model::Publish(receiver); - - // Publish field integer1 - receiver->PublishField("integer1", "", &integer1, ::Smp::ViewKind::VK_None, - true, false, false); - // Publish field integer2 - receiver->PublishField("integer2", "", &integer2, ::Smp::ViewKind::VK_None, - true, false, false); - // Call user DoPublish if any - ::Xsmp::Component::Helper::Publish < ::Example::M1 > (this, receiver); -} - -void M1Gen::Configure(::Smp::Services::ILogger *logger, - ::Smp::Services::ILinkRegistry *linkRegistry) { - // Call parent implementation first - ::Xsmp::Model::Configure(logger, linkRegistry); - - // Call user DoConfigure if any - ::Xsmp::Component::Helper::Configure < ::Example::M1 - > (this, logger, linkRegistry); -} - -void M1Gen::Connect(::Smp::ISimulator *simulator) { - // Call parent implementation first - ::Xsmp::Model::Connect(simulator); - - // Call user DoConnect if any - ::Xsmp::Component::Helper::Connect < ::Example::M1 > (this, simulator); -} - -void M1Gen::Disconnect() { - // Call user DoDisconnect if any - ::Xsmp::Component::Helper::Disconnect < ::Example::M1 > (this); - - // Call parent implementation last, to remove references to the Simulator and its services - ::Xsmp::Model::Disconnect(); -} - -const Smp::Uuid& M1Gen::GetUuid() const { - return Uuid_M1; -} -} // namespace Example diff --git a/examples/project1/src-gen/xsmp_example_project1.cpp b/examples/project1/src-gen/xsmp_example_project1.cpp index 5280539..b3f7eb2 100644 --- a/examples/project1/src-gen/xsmp_example_project1.cpp +++ b/examples/project1/src-gen/xsmp_example_project1.cpp @@ -13,10 +13,10 @@ // ---------------------------- Include Header Files -------------------- // ---------------------------------------------------------------------------- -#include "Example/M1.h" -#include "Xsmp/Factory.h" -#include "xsmp_example_project1.h" +#include +#include #include +#include // ---------------------------------------------------------------------------------- // ----------------------------- Global variables ------------------------------ @@ -47,12 +47,13 @@ bool Initialise_xsmp_example_project1(::Smp::ISimulator *simulator, return true; } - // Register factory for Model M1 - simulator->RegisterFactory(::Xsmp::Factory::Create < ::Example::M1 > ("M1", // name - "", // description - simulator, // simulator - ::Example::Uuid_M1 // UUID - )); + // Register factory for Model Counter + simulator->RegisterFactory( + ::Xsmp::Factory::Create < ::Example::Counter > ("Counter", // name + "", // description + simulator, // simulator + ::Example::Uuid_Counter // UUID + )); return true; } diff --git a/examples/project1/src-gen/xsmp_example_project1.h b/examples/project1/src-gen/xsmp_example_project1.h index c07d971..4a300ff 100644 --- a/examples/project1/src-gen/xsmp_example_project1.h +++ b/examples/project1/src-gen/xsmp_example_project1.h @@ -16,7 +16,7 @@ // ---------------------------- Include Header Files -------------------- // ---------------------------------------------------------------------------- -#include "Smp/ISimulator.h" +#include // ---------------------------------------------------------------------------- // ------------------------ Types and Interfaces ------------------------ diff --git a/examples/project1/src-gen/xsmp_example_project1.pkg.cpp b/examples/project1/src-gen/xsmp_example_project1.pkg.cpp index f68336c..394bbf0 100644 --- a/examples/project1/src-gen/xsmp_example_project1.pkg.cpp +++ b/examples/project1/src-gen/xsmp_example_project1.pkg.cpp @@ -12,8 +12,8 @@ // ------------------------------------------------------------------------------- // --------------------------------- Includes ---------------------------------- // ------------------------------------------------------------------------------- -#include "xsmp_example_project1.h" -#include "Smp/Publication/ITypeRegistry.h" +#include +#include #ifdef WIN32 #define DLL_EXPORT __declspec(dllexport) // %RELAX Visual Studio requires a define @@ -43,6 +43,7 @@ DLL_EXPORT bool Initialise(::Smp::ISimulator *simulator, extern "C" { /// Global Finalise function of Package xsmp_example_project1. +/// @param simulator Simulator. /// @return True if finalisation was successful, false otherwise. DLL_EXPORT bool Finalise(::Smp::ISimulator *simulator) { return Finalise_xsmp_example_project1(simulator); diff --git a/examples/project1/src/Example/Counter.cpp b/examples/project1/src/Example/Counter.cpp new file mode 100644 index 0000000..a9a8dd8 --- /dev/null +++ b/examples/project1/src/Example/Counter.cpp @@ -0,0 +1,36 @@ +// Copyright 2023 YOUR ORGANIZATION. All rights reserved. +// +// YOUR NOTICE + +// ----------------------------------------------------------------------------- +// File Name : Counter.cpp +// Generated by : XsmpSdkGenerator-1.1.0.202401040913 +// ----------------------------------------------------------------------------- +/// @file Example/Counter.cpp + +#include + +namespace Example { +void Counter::DoPublish(::Smp::IPublication *receiver) { +} + +void Counter::DoConfigure(::Smp::Services::ILogger *logger, + ::Smp::Services::ILinkRegistry *linkRegistry) { +} + +void Counter::DoConnect(::Smp::ISimulator *simulator) { +} + +void Counter::DoDisconnect() { +} + +void Counter::_IncrementCount() { + ++count; +} +void Counter::ResetCount() { + count = 0; +} +void Counter::_Add(::Smp::IObject *sender, ::Smp::Int32 value) { + count += value; +} +} // namespace Example diff --git a/examples/project1/src/Example/M1.h b/examples/project1/src/Example/Counter.h similarity index 76% rename from examples/project1/src/Example/M1.h rename to examples/project1/src/Example/Counter.h index 96991e3..635d67e 100644 --- a/examples/project1/src/Example/M1.h +++ b/examples/project1/src/Example/Counter.h @@ -3,29 +3,29 @@ // YOUR NOTICE // ----------------------------------------------------------------------------- -// File Name : M1.h -// Generated by : XsmpSdkGenerator-${qualifiedVersion} +// File Name : Counter.h +// Generated by : XsmpSdkGenerator-1.1.0.202401040913 // ----------------------------------------------------------------------------- -/// @file Example/M1.h +/// @file Example/Counter.h -#ifndef EXAMPLE_M1_H_ -#define EXAMPLE_M1_H_ +#ifndef EXAMPLE_COUNTER_H_ +#define EXAMPLE_COUNTER_H_ // Include the generated header file -#include "Example/M1Gen.h" +#include // ---------------------------------------------------------------------------- // ------------------------ Types and Interfaces ------------------------ // ---------------------------------------------------------------------------- namespace Example { -class M1: public M1Gen { +class Counter: public CounterGen { public: /// Re-use parent constructors - using M1Gen::M1Gen; + using CounterGen::CounterGen; /// Virtual destructor to release memory. - ~M1() noexcept override = default; + ~Counter() noexcept override = default; private: // visibility to call DoPublish/DoConfigure/DoConnect/DoDisconnect @@ -51,7 +51,11 @@ class M1: public M1Gen { /// @throws Smp::InvalidComponentState void DoDisconnect(); + void ResetCount() override; +public: + void _IncrementCount() override; + void _Add(::Smp::IObject *sender, ::Smp::Int32 value) override; }; } // namespace Example -#endif // EXAMPLE_M1_H_ +#endif // EXAMPLE_COUNTER_H_ diff --git a/examples/project1/src/Example/M1.cpp b/examples/project1/src/Example/M1.cpp deleted file mode 100644 index e5bb195..0000000 --- a/examples/project1/src/Example/M1.cpp +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2023 YOUR ORGANIZATION. All rights reserved. -// -// YOUR NOTICE - -// ----------------------------------------------------------------------------- -// File Name : M1.cpp -// Generated by : XsmpSdkGenerator-${qualifiedVersion} -// ----------------------------------------------------------------------------- -/// @file Example/M1.cpp - -// ---------------------------------------------------------------------------- -// ---------------------------- Include Header Files -------------------- -// ---------------------------------------------------------------------------- - -#include "Example/M1.h" -#include "Smp/IPublication.h" - -namespace Example { - -void M1::DoPublish(::Smp::IPublication *) { -} - -void M1::DoConfigure(::Smp::Services::ILogger *, - ::Smp::Services::ILinkRegistry *) { -} - -void M1::DoConnect(::Smp::ISimulator *) { -} - -void M1::DoDisconnect() { -} -} // namespace Example diff --git a/src-gen/xsmp_event_manager.pkg.cpp b/src-gen/xsmp_event_manager.pkg.cpp index 95c803f..ac0f882 100644 --- a/src-gen/xsmp_event_manager.pkg.cpp +++ b/src-gen/xsmp_event_manager.pkg.cpp @@ -53,6 +53,7 @@ DLL_EXPORT bool Initialise(::Smp::ISimulator *simulator, extern "C" { /// Global Finalise function of Package xsmp_event_manager. +/// @param simulator Simulator. /// @return True if finalisation was successful, false otherwise. DLL_EXPORT bool Finalise(::Smp::ISimulator *simulator) { return Finalise_xsmp_event_manager(simulator); diff --git a/src-gen/xsmp_link_registry.pkg.cpp b/src-gen/xsmp_link_registry.pkg.cpp index 2abef35..883772d 100644 --- a/src-gen/xsmp_link_registry.pkg.cpp +++ b/src-gen/xsmp_link_registry.pkg.cpp @@ -53,6 +53,7 @@ DLL_EXPORT bool Initialise(::Smp::ISimulator *simulator, extern "C" { /// Global Finalise function of Package xsmp_link_registry. +/// @param simulator Simulator. /// @return True if finalisation was successful, false otherwise. DLL_EXPORT bool Finalise(::Smp::ISimulator *simulator) { return Finalise_xsmp_link_registry(simulator); diff --git a/src-gen/xsmp_logger.pkg.cpp b/src-gen/xsmp_logger.pkg.cpp index 48037a9..b2337a3 100644 --- a/src-gen/xsmp_logger.pkg.cpp +++ b/src-gen/xsmp_logger.pkg.cpp @@ -53,6 +53,7 @@ DLL_EXPORT bool Initialise(::Smp::ISimulator *simulator, extern "C" { /// Global Finalise function of Package xsmp_logger. +/// @param simulator Simulator. /// @return True if finalisation was successful, false otherwise. DLL_EXPORT bool Finalise(::Smp::ISimulator *simulator) { return Finalise_xsmp_logger(simulator); diff --git a/src-gen/xsmp_resolver.pkg.cpp b/src-gen/xsmp_resolver.pkg.cpp index 2bec5e0..7ecbaa8 100644 --- a/src-gen/xsmp_resolver.pkg.cpp +++ b/src-gen/xsmp_resolver.pkg.cpp @@ -53,6 +53,7 @@ DLL_EXPORT bool Initialise(::Smp::ISimulator *simulator, extern "C" { /// Global Finalise function of Package xsmp_resolver. +/// @param simulator Simulator. /// @return True if finalisation was successful, false otherwise. DLL_EXPORT bool Finalise(::Smp::ISimulator *simulator) { return Finalise_xsmp_resolver(simulator); diff --git a/src-gen/xsmp_scheduler.pkg.cpp b/src-gen/xsmp_scheduler.pkg.cpp index 1f15455..96d6bbd 100644 --- a/src-gen/xsmp_scheduler.pkg.cpp +++ b/src-gen/xsmp_scheduler.pkg.cpp @@ -53,6 +53,7 @@ DLL_EXPORT bool Initialise(::Smp::ISimulator *simulator, extern "C" { /// Global Finalise function of Package xsmp_scheduler. +/// @param simulator Simulator. /// @return True if finalisation was successful, false otherwise. DLL_EXPORT bool Finalise(::Smp::ISimulator *simulator) { return Finalise_xsmp_scheduler(simulator); diff --git a/src-gen/xsmp_tests.pkg.cpp b/src-gen/xsmp_tests.pkg.cpp index f0475e3..a28c0f4 100644 --- a/src-gen/xsmp_tests.pkg.cpp +++ b/src-gen/xsmp_tests.pkg.cpp @@ -53,6 +53,7 @@ DLL_EXPORT bool Initialise(::Smp::ISimulator *simulator, extern "C" { /// Global Finalise function of Package xsmp_tests. +/// @param simulator Simulator. /// @return True if finalisation was successful, false otherwise. DLL_EXPORT bool Finalise(::Smp::ISimulator *simulator) { return Finalise_xsmp_tests(simulator); diff --git a/src-gen/xsmp_time_keeper.pkg.cpp b/src-gen/xsmp_time_keeper.pkg.cpp index 0d9ac1d..694dea4 100644 --- a/src-gen/xsmp_time_keeper.pkg.cpp +++ b/src-gen/xsmp_time_keeper.pkg.cpp @@ -53,6 +53,7 @@ DLL_EXPORT bool Initialise(::Smp::ISimulator *simulator, extern "C" { /// Global Finalise function of Package xsmp_time_keeper. +/// @param simulator Simulator. /// @return True if finalisation was successful, false otherwise. DLL_EXPORT bool Finalise(::Smp::ISimulator *simulator) { return Finalise_xsmp_time_keeper(simulator); diff --git a/src/python/Smp/IEventSinkBinding.h b/src/python/Smp/IEventSinkBinding.h index 07ccf1d..e8a4d9a 100644 --- a/src/python/Smp/IEventSinkBinding.h +++ b/src/python/Smp/IEventSinkBinding.h @@ -29,6 +29,11 @@ ::Smp::IEventSink& UnsubscribeEventSink(::Smp::IEventSink &self, eso.Unsubscribe(&self); return self; } +void NotifyEventSink(::Smp::IEventSink &self, ::Smp::IObject *sender, + const py::handle &arg) { + self.Notify(sender, convert(arg, self.GetEventArgType())); + +} inline void RegisterIEventSink(const py::module_ &m) { py::class_<::Smp::IEventSink, ::Smp::IObject>(m, "IEventSink", @@ -51,6 +56,19 @@ An event sink can only be unsubscribed if it has been subscribed before.)") .def("__isub__", &UnsubscribeEventSink, py::arg("event_source"), py::return_value_policy::reference) + .def("GetEventArgType", &::Smp::IEventSink::GetEventArgType, + R"(Get the primitive type kind of the event argument. +Use PTK_None for an event without an argument. +This operation allows for type checking between an Event Source (implementing IEventSource) and an event sink (implementing IEventSink) during Subscribe.)") + + .def("Notify", &NotifyEventSink, py::arg("sender") = py::none(), + py::arg("arg") = py::none(), + R"(This event handler method is called when an event is emitted. +Components providing event sinks must ensure that these event sinks do not throw exceptions.)") + + .def("__call__", &NotifyEventSink, py::arg("sender") = py::none(), + py::arg("arg") = py::none(), "Notify the EventSink.") + .doc() = R"(Interface of an event sink that can be subscribed to an event source (IEventSource). This interface provides a notification method (event handler) that can be called by event sources when an event is emitted.)"; diff --git a/src/python/Smp/IObjectBinding.h b/src/python/Smp/IObjectBinding.h index ec2bbfd..170785d 100644 --- a/src/python/Smp/IObjectBinding.h +++ b/src/python/Smp/IObjectBinding.h @@ -31,8 +31,6 @@ static bool SetValue(::Smp::IObject &self, ::Smp::String8 name, try { if (child == value.cast<::Smp::IObject*>()) { - // increment the reference: - //value.inc_ref(); return true; } } @@ -56,7 +54,7 @@ static bool SetValue(::Smp::IObject &self, ::Smp::String8 name, } inline void RegisterIObject(const py::module_ &m) { - py::class_<::Smp::IObject>(m, "IObject"/*, py::dynamic_attr()*/) + py::class_<::Smp::IObject>(m, "IObject") .def("__getattr__", [](::Smp::IObject &self, ::Smp::String8 name) { if (auto *child = ::Xsmp::Helper::Resolve(&self, name)) { diff --git a/src/python/ecss_smp.cpp b/src/python/ecss_smp.cpp index 57b2da4..ec1b7d6 100644 --- a/src/python/ecss_smp.cpp +++ b/src/python/ecss_smp.cpp @@ -388,7 +388,7 @@ const void* IObjectHook(const ::Smp::IObject *src, } // return a pointer to IObject (instead of dynamic_cast ) - return static_cast(src); + return src; } type = nullptr; return nullptr;