Commit d46267984bedf2322e1552280216f3214cd55cbc
- Diff rendering mode:
- inline
- side by side
core/eventinterpreterplugins.cpp
(27 / 7)
|   | |||
| 102 | 102 | } // applyOptionsWithSuffix | |
| 103 | 103 | ||
| 104 | 104 | ||
| 105 | //================================================== ScriptContextWrapper | ||
| 106 | |||
| 107 | class ScriptContextWrapper { | ||
| 108 | public: | ||
| 109 | ScriptContextWrapper(boost::shared_ptr<ScriptContext> _pContext) | ||
| 110 | : m_pContext(_pContext) | ||
| 111 | { } | ||
| 112 | |||
| 113 | boost::shared_ptr<ScriptContext> get() { return m_pContext; } | ||
| 114 | void addFile(const std::string& _name) { | ||
| 115 | m_LoadedFiles.push_back(_name); | ||
| 116 | } | ||
| 117 | private: | ||
| 118 | boost::shared_ptr<ScriptContext> m_pContext; | ||
| 119 | DateTime m_StartTime; | ||
| 120 | std::vector<std::string> m_LoadedFiles; | ||
| 121 | }; | ||
| 122 | |||
| 105 | 123 | //================================================== EventInterpreterPluginJavascript | |
| 106 | 124 | ||
| 107 | 125 | EventInterpreterPluginJavascript::EventInterpreterPluginJavascript(EventInterpreter* _pInterpreter) | |
| … | … | ||
| 136 | 136 | ||
| 137 | 137 | try { | |
| 138 | 138 | boost::shared_ptr<ScriptContext> ctx(m_Environment.getContext()); | |
| 139 | boost::shared_ptr<ScriptContextWrapper> wrapper(new ScriptContextWrapper(ctx)); | ||
| 139 | 140 | ScriptObject raisedEvent(*ctx, NULL); | |
| 140 | 141 | raisedEvent.setProperty<const std::string&>("name", _event.getName()); | |
| 141 | 142 | ctx->getRootObject().setProperty("raisedEvent", &raisedEvent); | |
| … | … | ||
| 158 | 158 | raisedEvent.setProperty("subscription", &subscriptionObj); | |
| 159 | 159 | subscriptionObj.setProperty<const std::string&>("name", _subscription.getEventName()); | |
| 160 | 160 | ||
| 161 | wrapper->addFile(scriptName); | ||
| 161 | 162 | ctx->evaluateScript<void>(scriptName); | |
| 162 | 163 | ||
| 163 | 164 | if(ctx->hasAttachedObjects()) { | |
| 164 | m_KeptContexts.push_back(ctx); | ||
| 165 | m_WrappedContexts.push_back(wrapper); | ||
| 165 | 166 | Logger::getInstance()->log("EventInterpreterPluginJavascript::handleEvent: still has objects, keeping " + scriptName + " in memory", lsInfo); | |
| 166 | 167 | } | |
| 167 | 168 | } catch(ScriptException& e) { | |
| … | … | ||
| 215 | 215 | } // setupCleanupEvent | |
| 216 | 216 | ||
| 217 | 217 | void EventInterpreterPluginJavascript::cleanupTerminatedScripts(Event& _event, const EventSubscription& _subscription) { | |
| 218 | typedef std::vector<boost::shared_ptr<ScriptContext> >::iterator tScriptContextIterator; | ||
| 219 | tScriptContextIterator ipScriptContext = m_KeptContexts.begin(); | ||
| 220 | while(ipScriptContext != m_KeptContexts.end()) { | ||
| 221 | if(!(*ipScriptContext)->hasAttachedObjects()) { | ||
| 218 | typedef std::vector<boost::shared_ptr<ScriptContextWrapper> >::iterator tScriptContextWrapperIterator; | ||
| 219 | tScriptContextWrapperIterator ipScriptContextWrapper = m_WrappedContexts.begin(); | ||
| 220 | while(ipScriptContextWrapper != m_WrappedContexts.end()) { | ||
| 221 | if(!(*ipScriptContextWrapper)->get()->hasAttachedObjects()) { | ||
| 222 | 222 | Logger::getInstance()->log("cleanupTerminatedScripts: erasing script"); | |
| 223 | ipScriptContext = m_KeptContexts.erase(ipScriptContext); | ||
| 223 | ipScriptContextWrapper = m_WrappedContexts.erase(ipScriptContextWrapper); | ||
| 224 | 224 | } else { | |
| 225 | ++ipScriptContext; | ||
| 225 | ++ipScriptContextWrapper; | ||
| 226 | 226 | } | |
| 227 | 227 | } | |
| 228 | 228 | sendCleanupEvent(); |
core/eventinterpreterplugins.h
(2 / 1)
|   | |||
| 44 | 44 | virtual void handleEvent(Event& _event, const EventSubscription& _subscription); | |
| 45 | 45 | }; // EventInterpreterPluginRaiseEvent | |
| 46 | 46 | ||
| 47 | class ScriptContextWrapper; | ||
| 47 | 48 | ||
| 48 | 49 | class EventInterpreterPluginJavascript : public EventInterpreterPlugin { | |
| 49 | 50 | private: | |
| 50 | 51 | ScriptEnvironment m_Environment; | |
| 51 | std::vector<boost::shared_ptr<ScriptContext> > m_KeptContexts; | ||
| 52 | std::vector<boost::shared_ptr<ScriptContextWrapper> > m_WrappedContexts; | ||
| 52 | 53 | boost::shared_ptr<InternalEventRelayTarget> m_pRelayTarget; | |
| 53 | 54 | static const std::string kCleanupScriptsEventName; | |
| 54 | 55 | private: |

