FlightGear next
NasalSys_private.hxx
Go to the documentation of this file.
1// NasalSys.hxx -
2// SPDX-License-Identifier: GPL-2.0-or-later
3// SPDX-FileCopyrightText: Copyright (C) 2013 James Turner
4
5#pragma once
6
7#include <simgear/debug/BufferedLogCallback.hxx>
8#include <simgear/nasal/nasal.h>
9#include <simgear/props/props.hxx>
10#include <simgear/threads/SGQueue.hxx>
11#include <simgear/xml/easyxml.hxx>
12
13#include "NasalModelData.hxx"
14
15// forward decls
16class FGNasalSys;
17class TimerObj;
19class NasalCommand;
20
25int nasalStructEqual(naContext ctx, naRef a, naRef b);
26
27class FGNasalListener : public SGPropertyChangeListener {
28public:
29 FGNasalListener(SGPropertyNode* node, naRef code, FGNasalSys* nasal,
30 int key, int id, int init, int type);
31
32 virtual ~FGNasalListener();
33 virtual void valueChanged(SGPropertyNode* node);
34 virtual void childAdded(SGPropertyNode* parent, SGPropertyNode* child);
35 virtual void childRemoved(SGPropertyNode* parent, SGPropertyNode* child);
36
37private:
38 bool changed(SGPropertyNode* node);
39 void call(SGPropertyNode* which, naRef mode);
40
41 friend class FGNasalSys;
42 SGPropertyNode_ptr _node;
43 naRef _code;
44 int _gcKey;
45 int _id;
46 FGNasalSys* _nas;
47 int _init;
48 int _type;
49 unsigned int _active;
50 bool _dead;
51 long _last_int;
52 double _last_float;
53 std::string _last_string;
54};
55
56
57class NasalXMLVisitor : public XMLVisitor {
58public:
59 NasalXMLVisitor(naContext c, int argc, naRef* args);
60 virtual ~NasalXMLVisitor() { naFreeContext(_c); }
61
62 virtual void startElement(const char* tag, const XMLAttributes& a);
63 virtual void endElement(const char* tag);
64 virtual void data(const char* str, int len);
65 virtual void pi(const char* target, const char* data);
66
67private:
68 void call(naRef func, int num, naRef a = naNil(), naRef b = naNil());
69 naRef make_string(const char* s, int n = -1);
70
71 naContext _c;
72 naRef _start_element, _end_element, _data, _pi;
73};
74
75//
76// See the implementation of the settimer() extension function for
77// more notes.
78//
80{
81 NasalTimer(naRef handler, FGNasalSys* sys);
82
83 void timerExpired();
85
86 naRef handler;
87 int gcKey = 0;
88 FGNasalSys* nasal = nullptr;
89};
90
91// declare the interface to the unit-testing module
92naRef initNasalUnitTestCppUnit(naRef globals, naContext c);
93naRef initNasalUnitTestInSim(naRef globals, naContext c);
94
95
97{
98public:
100
101 //friend class FGNasalScript;
102 // friend class FGNasalListener;
103 // friend class FGNasalModuleListener;
104
105 SGLockedQueue<SGSharedPtr<FGNasalModelData>> _loadList;
106 SGLockedQueue<SGSharedPtr<FGNasalModelData>> _unloadList;
107 // Delay removing items of the _loadList to ensure the are already attached
108 // to the scene graph (eg. enables to retrieve world position in load
109 // callback).
111
112 // Listener
113 std::map<int, FGNasalListener*> _listener;
114 std::vector<FGNasalListener*> _dead_listener;
115
116 std::vector<FGNasalModuleListener*> _moduleListeners;
117
118 static int _listenerId;
119
120 bool _inited = false;
121 naContext _context = nullptr;
122 naRef _globals,
124
125 SGPropertyNode_ptr _cmdArg;
126
127 std::unique_ptr<simgear::BufferedLogCallback> _log;
128
129 typedef std::map<std::string, NasalCommand*> NasalCommandDict;
131
133
134 // track NasalTimer instances (created via settimer() call) -
135 // this allows us to clean these up on shutdown
136 std::vector<NasalTimer*> _nasalTimers;
137
138
139 // track persistent timers. These are owned from the Nasal side, so we
140 // only track a non-owning reference here.
141 std::vector<TimerObj*> _persistentTimers;
142};
naRef initNasalUnitTestCppUnit(naRef globals, naContext c)
int nasalStructEqual(naContext ctx, naRef a, naRef b)
@breif wrapper for naEqual which recursively checks vec/hash equality Probably not very performant.
naRef initNasalUnitTestInSim(naRef globals, naContext c)
virtual ~FGNasalListener()
FGNasalListener(SGPropertyNode *node, naRef code, FGNasalSys *nasal, int key, int id, int init, int type)
virtual void childRemoved(SGPropertyNode *parent, SGPropertyNode *child)
virtual void valueChanged(SGPropertyNode *node)
friend class FGNasalSys
virtual void childAdded(SGPropertyNode *parent, SGPropertyNode *child)
std::unique_ptr< simgear::BufferedLogCallback > _log
std::vector< TimerObj * > _persistentTimers
NasalCommandDict _commands
std::vector< FGNasalModuleListener * > _moduleListeners
std::vector< FGNasalListener * > _dead_listener
SGLockedQueue< SGSharedPtr< FGNasalModelData > > _loadList
std::map< std::string, NasalCommand * > NasalCommandDict
std::map< int, FGNasalListener * > _listener
SGLockedQueue< SGSharedPtr< FGNasalModelData > > _unloadList
std::vector< NasalTimer * > _nasalTimers
SGPropertyNode_ptr _cmdArg
virtual void endElement(const char *tag)
virtual void startElement(const char *tag, const XMLAttributes &a)
virtual void data(const char *str, int len)
NasalXMLVisitor(naContext c, int argc, naRef *args)
FGGlobals * globals
Definition globals.cxx:142
naCFunction func
void timerExpired()
NasalTimer(naRef handler, FGNasalSys *sys)
static const double pi
Definition sview.cxx:59