Track a root property on subsystem-manager
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
#include "exception.hxx"
|
||||
#include "subsystem_mgr.hxx"
|
||||
|
||||
#include <simgear/props/props.hxx>
|
||||
#include <simgear/math/SGMath.hxx>
|
||||
#include "SGSmplstat.hxx"
|
||||
|
||||
@@ -966,5 +967,16 @@ void SGSubsystemMgr::notifyDelegatesDidChange(SGSubsystem* sub, State state)
|
||||
{ d->didChange(sub, state); });
|
||||
}
|
||||
|
||||
void SGSubsystemMgr::set_root_node(SGPropertyNode_ptr node)
|
||||
{
|
||||
_rootNode = node;
|
||||
}
|
||||
|
||||
SGPropertyNode_ptr
|
||||
SGSubsystemMgr::root_node() const
|
||||
{
|
||||
return _rootNode;
|
||||
}
|
||||
|
||||
|
||||
// end of subsystem_mgr.cxx
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <simgear/timing/timestamp.hxx>
|
||||
#include <simgear/structure/SGSharedPtr.hxx>
|
||||
#include <simgear/misc/strutils.hxx>
|
||||
#include <simgear/props/propsfwd.hxx>
|
||||
|
||||
class TimingInfo
|
||||
{
|
||||
@@ -433,6 +434,8 @@ typedef SGSharedPtr<SGSubsystemGroup> SGSubsystemGroupRef;
|
||||
class SGSubsystemMgr : public SGSubsystem
|
||||
{
|
||||
public:
|
||||
SGSubsystemMgr(const SGSubsystemMgr&) = delete;
|
||||
SGSubsystemMgr& operator=(const SGSubsystemMgr&) = delete;
|
||||
|
||||
/**
|
||||
* Types of subsystem groups.
|
||||
@@ -483,6 +486,18 @@ public:
|
||||
void reportTiming();
|
||||
void setReportTimingCb(void* userData,SGSubsystemTimingCb cb) {reportTimingCb = cb;reportTimingUserData = userData;}
|
||||
|
||||
/**
|
||||
* @brief set the root property node for this subsystem manager
|
||||
* subsystems can retrieve this value during init/bind (or at any time)
|
||||
* to base their own properties trees off of.
|
||||
*/
|
||||
void set_root_node(SGPropertyNode_ptr node);
|
||||
|
||||
/**
|
||||
* @brief retrieve the root property node for this subsystem manager
|
||||
*/
|
||||
SGPropertyNode_ptr root_node() const;
|
||||
|
||||
template<class T>
|
||||
T* get_subsystem() const
|
||||
{
|
||||
@@ -631,6 +646,7 @@ private:
|
||||
std::vector<SGSubsystemGroupRef> _groups;
|
||||
unsigned int _initPosition = 0;
|
||||
bool _destructorActive = false;
|
||||
SGPropertyNode_ptr _rootNode;
|
||||
|
||||
// non-owning reference, this is to accelerate lookup
|
||||
// by name which otherwise needs a full walk of the entire tree
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <simgear/constants.h>
|
||||
#include <simgear/structure/subsystem_mgr.hxx>
|
||||
#include <simgear/misc/test_macros.hxx>
|
||||
#include <simgear/props/props.hxx>
|
||||
|
||||
using std::string;
|
||||
using std::cout;
|
||||
@@ -26,6 +27,12 @@ public:
|
||||
wasInited = true;
|
||||
}
|
||||
|
||||
void bind() override
|
||||
{
|
||||
auto node = get_manager()->root_node();
|
||||
node->setIntValue("mysub/foo", 42);
|
||||
}
|
||||
|
||||
void update(double dt) override
|
||||
{
|
||||
|
||||
@@ -44,6 +51,12 @@ public:
|
||||
|
||||
}
|
||||
|
||||
void bind() override
|
||||
{
|
||||
auto node = get_manager()->root_node();
|
||||
node->setIntValue("anothersub/bar", 172);
|
||||
}
|
||||
|
||||
void update(double dt) override
|
||||
{
|
||||
lastUpdateTime = dt;
|
||||
@@ -297,10 +310,6 @@ void testIncrementalInit()
|
||||
break;
|
||||
}
|
||||
|
||||
for (auto ev : d->events) {
|
||||
std::cerr << "ev:" << ev.nameForEvent() << std::endl;
|
||||
}
|
||||
|
||||
SG_VERIFY(mySub->wasInited);
|
||||
|
||||
SG_VERIFY(d->hasEvent("mysub-will-init"));
|
||||
@@ -392,6 +401,32 @@ void testSuspendResume()
|
||||
SG_CHECK_EQUAL_EP(5.0, radio2->lastUpdateTime);
|
||||
}
|
||||
|
||||
void testPropertyRoot()
|
||||
{
|
||||
SGSharedPtr<SGSubsystemMgr> manager = new SGSubsystemMgr;
|
||||
SGPropertyNode_ptr props(new SGPropertyNode);
|
||||
manager->set_root_node(props);
|
||||
|
||||
auto d = new RecorderDelegate;
|
||||
manager->addDelegate(d);
|
||||
|
||||
manager->add<MySub1>();
|
||||
auto anotherSub = manager->add<AnotherSub>();
|
||||
auto instruments = manager->add<InstrumentGroup>();
|
||||
|
||||
auto radio1 = manager->createInstance<FakeRadioSub>("nav1");
|
||||
auto radio2 = manager->createInstance<FakeRadioSub>("nav2");
|
||||
|
||||
instruments->set_subsystem(radio1);
|
||||
instruments->set_subsystem(radio2);
|
||||
|
||||
manager->bind();
|
||||
manager->init();
|
||||
|
||||
SG_CHECK_EQUAL(props->getIntValue("mysub/foo"), 42);
|
||||
SG_CHECK_EQUAL(props->getIntValue("anothersub/bar"), 172);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
@@ -402,6 +437,7 @@ int main(int argc, char* argv[])
|
||||
testSubGrouping();
|
||||
testIncrementalInit();
|
||||
testSuspendResume();
|
||||
testPropertyRoot();
|
||||
|
||||
cout << __FILE__ << ": All tests passed" << endl;
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
Reference in New Issue
Block a user