Commit c782bbafd9f347b715868705079cafbf9188c467
- Diff rendering mode:
- inline
- side by side
core/eventinterpreterplugins.cpp
(35 / 4)
|   | |||
| 106 | 106 | ||
| 107 | 107 | class ScriptContextWrapper { | |
| 108 | 108 | public: | |
| 109 | ScriptContextWrapper(boost::shared_ptr<ScriptContext> _pContext) | ||
| 109 | ScriptContextWrapper(boost::shared_ptr<ScriptContext> _pContext, PropertyNodePtr _pRootNode, const std::string& _identifier) | ||
| 110 | 110 | : 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 | } | ||
| 112 | 122 | ||
| 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 | |||
| 114 | 131 | void addFile(const std::string& _name) { | |
| 115 | 132 | m_LoadedFiles.push_back(_name); | |
| 133 | if(m_pPropertyNode != NULL) { | ||
| 134 | m_pPropertyNode->createProperty("files/file+")->setStringValue(_name); | ||
| 135 | } | ||
| 116 | 136 | } | |
| 117 | 137 | 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: | ||
| 118 | 143 | boost::shared_ptr<ScriptContext> m_pContext; | |
| 119 | 144 | DateTime m_StartTime; | |
| 120 | 145 | std::vector<std::string> m_LoadedFiles; | |
| 146 | PropertyNodePtr m_pPropertyNode; | ||
| 121 | 147 | }; | |
| 122 | 148 | ||
| 123 | 149 | //================================================== EventInterpreterPluginJavascript | |
| … | … | ||
| 162 | 162 | ||
| 163 | 163 | try { | |
| 164 | 164 | 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)); | ||
| 166 | 170 | ScriptObject raisedEvent(*ctx, NULL); | |
| 167 | 171 | raisedEvent.setProperty<const std::string&>("name", _event.getName()); | |
| 168 | 172 | ctx->getRootObject().setProperty("raisedEvent", &raisedEvent); | |
| … | … | ||
| 224 | 224 | ext = new ScriptLoggerExtension(DSS::getInstance()->getJSLogDirectory(), DSS::getInstance()->getEventInterpreter()); | |
| 225 | 225 | m_Environment.addExtension(ext); | |
| 226 | 226 | setupCleanupEvent(); | |
| 227 | m_pScriptRootNode = DSS::getInstance()->getPropertySystem().createProperty("/scripts"); | ||
| 227 | 228 | } | |
| 228 | 229 | } // initializeEnvironment | |
| 229 | 230 |
core/eventinterpreterplugins.h
(3 / 0)
|   | |||
| 45 | 45 | }; // EventInterpreterPluginRaiseEvent | |
| 46 | 46 | ||
| 47 | 47 | class ScriptContextWrapper; | |
| 48 | class PropertyNode; | ||
| 49 | typedef boost::shared_ptr<PropertyNode> PropertyNodePtr; | ||
| 48 | 50 | ||
| 49 | 51 | class EventInterpreterPluginJavascript : public EventInterpreterPlugin { | |
| 50 | 52 | private: | |
| … | … | ||
| 54 | 54 | std::vector<boost::shared_ptr<ScriptContextWrapper> > m_WrappedContexts; | |
| 55 | 55 | boost::shared_ptr<InternalEventRelayTarget> m_pRelayTarget; | |
| 56 | 56 | static const std::string kCleanupScriptsEventName; | |
| 57 | PropertyNodePtr m_pScriptRootNode; | ||
| 57 | 58 | private: | |
| 58 | 59 | void initializeEnvironment(); | |
| 59 | 60 | void setupCleanupEvent(); |
core/jshandler.h
(1 / 0)
|   | |||
| 120 | 120 | void attachObject(ScriptContextAttachedObject* _pObject); | |
| 121 | 121 | void removeAttachedObject(ScriptContextAttachedObject* _pObject); | |
| 122 | 122 | bool hasAttachedObjects() const { return !m_AttachedObjects.empty(); } | |
| 123 | int getAttachedObjectsCount() const { return m_AttachedObjects.size(); } | ||
| 123 | 124 | ScriptContextAttachedObject* getAttachedObjectByName(const std::string& _name); | |
| 124 | 125 | public: | |
| 125 | 126 |

