Commit c782bbafd9f347b715868705079cafbf9188c467

  • avatar
  • Patrick Stählin <pstaehlin @futu…lab.ch>
  • Tue Aug 24 23:21:04 CEST 2010
Expose info about running scripts with properties
core/eventinterpreterplugins.cpp
(35 / 4)
  
106106
107107 class ScriptContextWrapper {
108108 public:
109 ScriptContextWrapper(boost::shared_ptr<ScriptContext> _pContext)
109 ScriptContextWrapper(boost::shared_ptr<ScriptContext> _pContext, PropertyNodePtr _pRootNode, const std::string& _identifier)
110110 : m_pContext(_pContext)
111 { }
111 {
112 if((_pRootNode != NULL) && !_identifier.empty()) {
113 m_pPropertyNode = _pRootNode->createProperty(_identifier + "+");
114 m_pPropertyNode->createProperty("stopScript")->linkToProxy(
115 PropertyProxyMemberFunction<ScriptContextWrapper,bool>(*this, NULL, &ScriptContextWrapper::stopScript));
116 m_pPropertyNode->createProperty("startedAt")->linkToProxy(
117 PropertyProxyMemberFunction<DateTime, std::string, false>(m_StartTime, &DateTime::toString));
118 m_pPropertyNode->createProperty("attachedObjects")->linkToProxy(
119 PropertyProxyMemberFunction<ScriptContext,int>(*m_pContext, &ScriptContext::getAttachedObjectsCount));
120 }
121 }
112122
113 boost::shared_ptr<ScriptContext> get() { return m_pContext; }
123 ~ScriptContextWrapper() {
124 m_pPropertyNode->getParentNode()->removeChild(m_pPropertyNode);
125 }
126
127 boost::shared_ptr<ScriptContext> get() {
128 return m_pContext;
129 }
130
114131 void addFile(const std::string& _name) {
115132 m_LoadedFiles.push_back(_name);
133 if(m_pPropertyNode != NULL) {
134 m_pPropertyNode->createProperty("files/file+")->setStringValue(_name);
135 }
116136 }
117137 private:
138 void stopScript(bool _value) {
139 // TODO: implement
140 Logger::getInstance()->log("Script would be stopped if this would have been implemented");
141 }
142 private:
118143 boost::shared_ptr<ScriptContext> m_pContext;
119144 DateTime m_StartTime;
120145 std::vector<std::string> m_LoadedFiles;
146 PropertyNodePtr m_pPropertyNode;
121147 };
122148
123149 //================================================== EventInterpreterPluginJavascript
162162
163163 try {
164164 boost::shared_ptr<ScriptContext> ctx(m_Environment.getContext());
165 boost::shared_ptr<ScriptContextWrapper> wrapper(new ScriptContextWrapper(ctx));
165 std::string scriptID = _event.getPropertyByName("script_id");
166 if(scriptID.empty()) {
167 scriptID = _event.getName() + _subscription.getID();
168 }
169 boost::shared_ptr<ScriptContextWrapper> wrapper(new ScriptContextWrapper(ctx, m_pScriptRootNode, scriptID));
166170 ScriptObject raisedEvent(*ctx, NULL);
167171 raisedEvent.setProperty<const std::string&>("name", _event.getName());
168172 ctx->getRootObject().setProperty("raisedEvent", &raisedEvent);
224224 ext = new ScriptLoggerExtension(DSS::getInstance()->getJSLogDirectory(), DSS::getInstance()->getEventInterpreter());
225225 m_Environment.addExtension(ext);
226226 setupCleanupEvent();
227 m_pScriptRootNode = DSS::getInstance()->getPropertySystem().createProperty("/scripts");
227228 }
228229 } // initializeEnvironment
229230
core/eventinterpreterplugins.h
(3 / 0)
  
4545 }; // EventInterpreterPluginRaiseEvent
4646
4747 class ScriptContextWrapper;
48 class PropertyNode;
49 typedef boost::shared_ptr<PropertyNode> PropertyNodePtr;
4850
4951 class EventInterpreterPluginJavascript : public EventInterpreterPlugin {
5052 private:
5454 std::vector<boost::shared_ptr<ScriptContextWrapper> > m_WrappedContexts;
5555 boost::shared_ptr<InternalEventRelayTarget> m_pRelayTarget;
5656 static const std::string kCleanupScriptsEventName;
57 PropertyNodePtr m_pScriptRootNode;
5758 private:
5859 void initializeEnvironment();
5960 void setupCleanupEvent();
core/jshandler.h
(1 / 0)
  
120120 void attachObject(ScriptContextAttachedObject* _pObject);
121121 void removeAttachedObject(ScriptContextAttachedObject* _pObject);
122122 bool hasAttachedObjects() const { return !m_AttachedObjects.empty(); }
123 int getAttachedObjectsCount() const { return m_AttachedObjects.size(); }
123124 ScriptContextAttachedObject* getAttachedObjectByName(const std::string& _name);
124125 public:
125126