Commit 563a6dbb5fe1e2c8b13983cd0c9634c7b54ba021

  • avatar
  • Patrick Stählin <pstaehlin @futu…lab.ch>
  • Tue Aug 24 23:21:04 CEST 2010
Deprecate keepContext

Check if the context has session attached objects instead.
core/eventinterpreterplugins.cpp
(42 / 2)
  
141141
142142 ctx->evaluateScript<void>(scriptName);
143143
144 if(ctx->getKeepContext()) {
144 if(ctx->hasAttachedObjects()) {
145145 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);
147147 }
148148 } catch(ScriptException& e) {
149149 Logger::getInstance()->log(std::string("EventInterpreterPluginJavascript::handleEvent: Caught event while running/parsing script '")
154154 }
155155 } // handleEvent
156156
157 const std::string EventInterpreterPluginJavascript::kCleanupScriptsEventName = "EventInterpreteRPluginJavascript_cleanupScripts";
158
157159 void EventInterpreterPluginJavascript::initializeEnvironment() {
158160 m_Environment.initialize();
159161 if(DSS::hasInstance()) {
173173 m_Environment.addExtension(ext);
174174 ext = new ScriptLoggerExtension(DSS::getInstance()->getJSLogDirectory(), DSS::getInstance()->getEventInterpreter());
175175 m_Environment.addExtension(ext);
176 setupCleanupEvent();
176177 }
177178 } // 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
178216
179217
180218 //================================================== EventInterpreterPluginDS485
core/eventinterpreterplugins.h
(6 / 0)
  
3232namespace dss {
3333
3434 class Apartment;
35 class InternalEventRelayTarget;
3536
3637 class EventInterpreterPluginRaiseEvent : public EventInterpreterPlugin {
3738 private:
4949 private:
5050 ScriptEnvironment m_Environment;
5151 std::vector<boost::shared_ptr<ScriptContext> > m_KeptContexts;
52 boost::shared_ptr<InternalEventRelayTarget> m_pRelayTarget;
53 static const std::string kCleanupScriptsEventName;
5254 private:
5355 void initializeEnvironment();
56 void setupCleanupEvent();
57 void cleanupTerminatedScripts(Event& _event, const EventSubscription& _subscription);
58 void sendCleanupEvent();
5459 public:
5560 EventInterpreterPluginJavascript(EventInterpreter* _pInterpreter);
5661
core/jshandler.cpp
(2 / 4)
  
206206 } // global_print
207207
208208 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);
211210 return JS_TRUE;
212211 } // global_keepContext
213212
270270
271271 ScriptContext::ScriptContext(ScriptEnvironment& _env, JSContext* _pContext)
272272 : m_Environment(_env),
273 m_pContext(_pContext),
274 m_KeepContext(false)
273 m_pContext(_pContext)
275274 {
276275 JSRequest req(m_pContext);
277276 JS_SetOptions(m_pContext, JSOPTION_VAROBJFIX | JSOPTION_DONT_REPORT_UNCAUGHT);
core/jshandler.h
(0 / 3)
  
9191 boost::scoped_ptr<ScriptObject> m_RootObject;
9292 ScriptEnvironment& m_Environment;
9393 JSContext* m_pContext;
94 bool m_KeepContext;
9594 std::vector<ScriptContextAttachedObject*> m_AttachedObjects;
9695 static void jsErrorHandler(JSContext *ctx, const char *msg, JSErrorReport *er);
9796 public:
116116 ScriptEnvironment& getEnvironment() { return m_Environment; }
117117 ScriptObject& getRootObject() { return *m_RootObject; }
118118 bool raisePendingExceptions();
119 bool getKeepContext() { return m_KeepContext; };
120 void setKeepContext(bool _value) { m_KeepContext = _value; }
121119
122120 void attachObject(ScriptContextAttachedObject* _pObject);
123121 void removeAttachedObject(ScriptContextAttachedObject* _pObject);