Howto:Exposing Subsystems to Nasal: Difference between revisions

Line 36: Line 36:
== Patching ==
== Patching ==


For starters, we will just add some debugging statements to the event manager
<syntaxhighlight lang="diff">
<syntaxhighlight lang="diff">
diff --git a/simgear/structure/event_mgr.cxx b/simgear/structure/event_mgr.cxx
index 2e4f7b7..eb892ad 100644
--- a/simgear/structure/event_mgr.cxx
+++ b/simgear/structure/event_mgr.cxx
@@ -24,9 +24,26 @@ void SGEventMgr::add(const std::string& name, SGCallback* cb,
   
    SGTimerQueue* q = simtime ? &_simQueue : &_rtQueue;
+    SG_LOG(SG_GENERAL, SG_ALERT, "== Inserting timer into queue" <<
+ "\t type:" << name <<
+ "\t interval:" << interval <<
+ "\t delay:" << delay <<
+ "\t repeated:" << repeat <<
+ "\t simtime/realtime:" << simtime <<"/"<<!simtime
+ << std::endl);
+
+    info();
    q->insert(t, delay);
}
+void info() {
+    SG_LOG(SG_GENERAL, SG_ALERT, "Total Entries in queues" <<
+ "\t simtime queue:" << _simQueue->getQueueSize() << std::endl
+ "\t realtime queue:" << _rtQueue->getQueueSize() << std::endl
+ );
+}
+
+
SGTimer::~SGTimer()
{
    delete callback;
diff --git a/simgear/structure/event_mgr.hxx b/simgear/structure/event_mgr.hxx
index 699522b..0cab8b7 100644
--- a/simgear/structure/event_mgr.hxx
+++ b/simgear/structure/event_mgr.hxx
@@ -38,6 +38,9 @@ public:
    double  nextTime()  { return -_table[0].pri; }
    SGTimer* findByName(const std::string& name) const;
+    unsigned int getQueueSize() const {
+ return _numEntries;
+ }
private:
    // The "priority" is stored as a negative time.  This allows the
    // implementation to treat the "top" of the heap as the largest
@@ -76,6 +79,7 @@ public:
    virtual void update(double delta_time_sec);
    virtual void unbind();
    virtual void shutdown();
+    virtual void info(); // dumps queue info to the console
   
    void setRealtimeProperty(SGPropertyNode* node) { _rtProp = node; }
@@ -120,6 +124,11 @@ public:
    void removeTask(const std::string& name);
private:
+
+    typedef std::pair<std::string, int> CallbackInfo; //callback name & number of instances
+    typedef std::map<SGCallback*, CallbackInfo> CallbackMap;
+    CallbackMap _registeredCallbacks;
+
    friend class SGTimer;
    void add(const std::string& name, SGCallback* cb,
</syntaxhighlight>
</syntaxhighlight>