Commit d46267984bedf2322e1552280216f3214cd55cbc

  • avatar
  • Patrick Stählin <pstaehlin @futu…lab.ch>
  • Tue Aug 24 23:21:04 CEST 2010
Replaced ScriptContext by a Wrapper
core/eventinterpreterplugins.cpp
(27 / 7)
  
102102 } // applyOptionsWithSuffix
103103
104104
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
105123 //================================================== EventInterpreterPluginJavascript
106124
107125 EventInterpreterPluginJavascript::EventInterpreterPluginJavascript(EventInterpreter* _pInterpreter)
136136
137137 try {
138138 boost::shared_ptr<ScriptContext> ctx(m_Environment.getContext());
139 boost::shared_ptr<ScriptContextWrapper> wrapper(new ScriptContextWrapper(ctx));
139140 ScriptObject raisedEvent(*ctx, NULL);
140141 raisedEvent.setProperty<const std::string&>("name", _event.getName());
141142 ctx->getRootObject().setProperty("raisedEvent", &raisedEvent);
158158 raisedEvent.setProperty("subscription", &subscriptionObj);
159159 subscriptionObj.setProperty<const std::string&>("name", _subscription.getEventName());
160160
161 wrapper->addFile(scriptName);
161162 ctx->evaluateScript<void>(scriptName);
162163
163164 if(ctx->hasAttachedObjects()) {
164 m_KeptContexts.push_back(ctx);
165 m_WrappedContexts.push_back(wrapper);
165166 Logger::getInstance()->log("EventInterpreterPluginJavascript::handleEvent: still has objects, keeping " + scriptName + " in memory", lsInfo);
166167 }
167168 } catch(ScriptException& e) {
215215 } // setupCleanupEvent
216216
217217 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()) {
222222 Logger::getInstance()->log("cleanupTerminatedScripts: erasing script");
223 ipScriptContext = m_KeptContexts.erase(ipScriptContext);
223 ipScriptContextWrapper = m_WrappedContexts.erase(ipScriptContextWrapper);
224224 } else {
225 ++ipScriptContext;
225 ++ipScriptContextWrapper;
226226 }
227227 }
228228 sendCleanupEvent();
core/eventinterpreterplugins.h
(2 / 1)
  
4444 virtual void handleEvent(Event& _event, const EventSubscription& _subscription);
4545 }; // EventInterpreterPluginRaiseEvent
4646
47 class ScriptContextWrapper;
4748
4849 class EventInterpreterPluginJavascript : public EventInterpreterPlugin {
4950 private:
5051 ScriptEnvironment m_Environment;
51 std::vector<boost::shared_ptr<ScriptContext> > m_KeptContexts;
52 std::vector<boost::shared_ptr<ScriptContextWrapper> > m_WrappedContexts;
5253 boost::shared_ptr<InternalEventRelayTarget> m_pRelayTarget;
5354 static const std::string kCleanupScriptsEventName;
5455 private: