Commit 563a6dbb5fe1e2c8b13983cd0c9634c7b54ba021
- Diff rendering mode:
- inline
- side by side
core/eventinterpreterplugins.cpp
(42 / 2)
|   | |||
| 141 | 141 | ||
| 142 | 142 | ctx->evaluateScript<void>(scriptName); | |
| 143 | 143 | ||
| 144 | if(ctx->getKeepContext()) { | ||
| 144 | if(ctx->hasAttachedObjects()) { | ||
| 145 | 145 | m_KeptContexts.push_back(ctx); | |
| 146 | Logger::getInstance()->log("EventInterpreterPluginJavascript::handleEvent: keeping script " + scriptName + " in memory", lsInfo); | ||
| 146 | Logger::getInstance()->log("EventInterpreterPluginJavascript::handleEvent: still has objects, keeping " + scriptName + " in memory", lsInfo); | ||
| 147 | 147 | } | |
| 148 | 148 | } catch(ScriptException& e) { | |
| 149 | 149 | Logger::getInstance()->log(std::string("EventInterpreterPluginJavascript::handleEvent: Caught event while running/parsing script '") | |
| … | … | ||
| 154 | 154 | } | |
| 155 | 155 | } // handleEvent | |
| 156 | 156 | ||
| 157 | const std::string EventInterpreterPluginJavascript::kCleanupScriptsEventName = "EventInterpreteRPluginJavascript_cleanupScripts"; | ||
| 158 | |||
| 157 | 159 | void EventInterpreterPluginJavascript::initializeEnvironment() { | |
| 158 | 160 | m_Environment.initialize(); | |
| 159 | 161 | if(DSS::hasInstance()) { | |
| … | … | ||
| 173 | 173 | m_Environment.addExtension(ext); | |
| 174 | 174 | ext = new ScriptLoggerExtension(DSS::getInstance()->getJSLogDirectory(), DSS::getInstance()->getEventInterpreter()); | |
| 175 | 175 | m_Environment.addExtension(ext); | |
| 176 | setupCleanupEvent(); | ||
| 176 | 177 | } | |
| 177 | 178 | } // initializeEnvironment | |
| 179 | |||
| 180 | void EventInterpreterPluginJavascript::setupCleanupEvent() { | ||
| 181 | EventInterpreterInternalRelay* pRelay = | ||
| 182 | dynamic_cast<EventInterpreterInternalRelay*>(getEventInterpreter().getPluginByName(EventInterpreterInternalRelay::getPluginName())); | ||
| 183 | m_pRelayTarget = boost::shared_ptr<InternalEventRelayTarget>(new InternalEventRelayTarget(*pRelay)); | ||
| 184 | |||
| 185 | boost::shared_ptr<EventSubscription> cleanupEventSubscription( | ||
| 186 | new dss::EventSubscription( | ||
| 187 | kCleanupScriptsEventName, | ||
| 188 | EventInterpreterInternalRelay::getPluginName(), | ||
| 189 | getEventInterpreter(), | ||
| 190 | boost::shared_ptr<SubscriptionOptions>()) | ||
| 191 | ); | ||
| 192 | m_pRelayTarget->subscribeTo(cleanupEventSubscription); | ||
| 193 | m_pRelayTarget->setCallback(boost::bind(&EventInterpreterPluginJavascript::cleanupTerminatedScripts, this, _1, _2)); | ||
| 194 | sendCleanupEvent(); | ||
| 195 | } // setupCleanupEvent | ||
| 196 | |||
| 197 | void EventInterpreterPluginJavascript::cleanupTerminatedScripts(Event& _event, const EventSubscription& _subscription) { | ||
| 198 | typedef std::vector<boost::shared_ptr<ScriptContext> >::iterator tScriptContextIterator; | ||
| 199 | tScriptContextIterator ipScriptContext = m_KeptContexts.begin(); | ||
| 200 | while(ipScriptContext != m_KeptContexts.end()) { | ||
| 201 | if(!(*ipScriptContext)->hasAttachedObjects()) { | ||
| 202 | ipScriptContext = m_KeptContexts.erase(ipScriptContext); | ||
| 203 | } else { | ||
| 204 | ++ipScriptContext; | ||
| 205 | } | ||
| 206 | } | ||
| 207 | sendCleanupEvent(); | ||
| 208 | } // cleanupTerminatedScripts | ||
| 209 | |||
| 210 | void EventInterpreterPluginJavascript::sendCleanupEvent() { | ||
| 211 | boost::shared_ptr<Event> pEvent(new Event(kCleanupScriptsEventName)); | ||
| 212 | pEvent->setProperty("time", "+" + intToString(20)); | ||
| 213 | getEventInterpreter().getQueue().pushEvent(pEvent); | ||
| 214 | } // sendCleanupEvent | ||
| 215 | |||
| 178 | 216 | ||
| 179 | 217 | ||
| 180 | 218 | //================================================== EventInterpreterPluginDS485 |
core/eventinterpreterplugins.h
(6 / 0)
|   | |||
| 32 | 32 | namespace dss { | |
| 33 | 33 | ||
| 34 | 34 | class Apartment; | |
| 35 | class InternalEventRelayTarget; | ||
| 35 | 36 | ||
| 36 | 37 | class EventInterpreterPluginRaiseEvent : public EventInterpreterPlugin { | |
| 37 | 38 | private: | |
| … | … | ||
| 49 | 49 | private: | |
| 50 | 50 | ScriptEnvironment m_Environment; | |
| 51 | 51 | std::vector<boost::shared_ptr<ScriptContext> > m_KeptContexts; | |
| 52 | boost::shared_ptr<InternalEventRelayTarget> m_pRelayTarget; | ||
| 53 | static const std::string kCleanupScriptsEventName; | ||
| 52 | 54 | private: | |
| 53 | 55 | void initializeEnvironment(); | |
| 56 | void setupCleanupEvent(); | ||
| 57 | void cleanupTerminatedScripts(Event& _event, const EventSubscription& _subscription); | ||
| 58 | void sendCleanupEvent(); | ||
| 54 | 59 | public: | |
| 55 | 60 | EventInterpreterPluginJavascript(EventInterpreter* _pInterpreter); | |
| 56 | 61 |
core/jshandler.cpp
(2 / 4)
|   | |||
| 206 | 206 | } // global_print | |
| 207 | 207 | ||
| 208 | 208 | JSBool global_keepContext(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { | |
| 209 | ScriptContext* ctx = static_cast<ScriptContext*>(JS_GetContextPrivate(cx)); | ||
| 210 | ctx->setKeepContext(true); | ||
| 209 | Logger::getInstance()->log("keepContext() is deprecated", lsWarning); | ||
| 211 | 210 | return JS_TRUE; | |
| 212 | 211 | } // global_keepContext | |
| 213 | 212 | ||
| … | … | ||
| 270 | 270 | ||
| 271 | 271 | ScriptContext::ScriptContext(ScriptEnvironment& _env, JSContext* _pContext) | |
| 272 | 272 | : m_Environment(_env), | |
| 273 | m_pContext(_pContext), | ||
| 274 | m_KeepContext(false) | ||
| 273 | m_pContext(_pContext) | ||
| 275 | 274 | { | |
| 276 | 275 | JSRequest req(m_pContext); | |
| 277 | 276 | JS_SetOptions(m_pContext, JSOPTION_VAROBJFIX | JSOPTION_DONT_REPORT_UNCAUGHT); |
core/jshandler.h
(0 / 3)
|   | |||
| 91 | 91 | boost::scoped_ptr<ScriptObject> m_RootObject; | |
| 92 | 92 | ScriptEnvironment& m_Environment; | |
| 93 | 93 | JSContext* m_pContext; | |
| 94 | bool m_KeepContext; | ||
| 95 | 94 | std::vector<ScriptContextAttachedObject*> m_AttachedObjects; | |
| 96 | 95 | static void jsErrorHandler(JSContext *ctx, const char *msg, JSErrorReport *er); | |
| 97 | 96 | public: | |
| … | … | ||
| 116 | 116 | ScriptEnvironment& getEnvironment() { return m_Environment; } | |
| 117 | 117 | ScriptObject& getRootObject() { return *m_RootObject; } | |
| 118 | 118 | bool raisePendingExceptions(); | |
| 119 | bool getKeepContext() { return m_KeepContext; }; | ||
| 120 | void setKeepContext(bool _value) { m_KeepContext = _value; } | ||
| 121 | 119 | ||
| 122 | 120 | void attachObject(ScriptContextAttachedObject* _pObject); | |
| 123 | 121 | void removeAttachedObject(ScriptContextAttachedObject* _pObject); |

