# HG changeset patch # User Sebastien Jodogne # Date 1528741584 -7200 # Node ID 3fc310ceb6d4fbb6a93d2f83dd987a3c643bd4fe # Parent 373b44af938f4f5502303d93e7c24a9e7bebe29b lua callbacks for jobs diff -r 373b44af938f -r 3fc310ceb6d4 OrthancServer/LuaScripting.cpp --- a/OrthancServer/LuaScripting.cpp Mon Jun 11 16:30:13 2018 +0200 +++ b/OrthancServer/LuaScripting.cpp Mon Jun 11 20:26:24 2018 +0200 @@ -187,6 +187,64 @@ }; + class LuaScripting::JobEvent : public LuaScripting::IEvent + { + public: + enum Type + { + Type_Failure, + Type_Submitted, + Type_Success + }; + + private: + Type type_; + std::string jobId_; + + public: + JobEvent(Type type, + const std::string& jobId) : + type_(type), + jobId_(jobId) + { + } + + virtual void Apply(LuaScripting& that) + { + std::string functionName; + + switch (type_) + { + case Type_Failure: + functionName = "OnJobFailure"; + break; + + case Type_Submitted: + functionName = "OnJobSubmitted"; + break; + + case Type_Success: + functionName = "OnJobSuccess"; + break; + + default: + throw OrthancException(ErrorCode_InternalError); + } + + { + LuaScripting::Lock lock(that); + + if (lock.GetLua().IsExistingFunction(functionName.c_str())) + { + LuaFunctionCall call(lock.GetLua(), functionName.c_str()); + call.PushString(jobId_); + call.Execute(); + } + } + } + }; + + ServerContext* LuaScripting::GetServerContext(lua_State *state) { const void* value = LuaContext::GetGlobalVariable(state, "_ServerContext"); @@ -693,4 +751,22 @@ lock.GetLua().Execute(script); } } + + + void LuaScripting::SignalJobSubmitted(const std::string& jobId) + { + pendingEvents_.Enqueue(new JobEvent(JobEvent::Type_Submitted, jobId)); + } + + + void LuaScripting::SignalJobSuccess(const std::string& jobId) + { + pendingEvents_.Enqueue(new JobEvent(JobEvent::Type_Success, jobId)); + } + + + void LuaScripting::SignalJobFailure(const std::string& jobId) + { + pendingEvents_.Enqueue(new JobEvent(JobEvent::Type_Failure, jobId)); + } } diff -r 373b44af938f -r 3fc310ceb6d4 OrthancServer/LuaScripting.h --- a/OrthancServer/LuaScripting.h Mon Jun 11 16:30:13 2018 +0200 +++ b/OrthancServer/LuaScripting.h Mon Jun 11 20:26:24 2018 +0200 @@ -58,6 +58,7 @@ class IEvent; class OnStoredInstanceEvent; class StableResourceEvent; + class JobEvent; static ServerContext* GetServerContext(lua_State *state); @@ -127,5 +128,11 @@ void Execute(const std::string& command); void LoadGlobalConfiguration(); + + void SignalJobSubmitted(const std::string& jobId); + + void SignalJobSuccess(const std::string& jobId); + + void SignalJobFailure(const std::string& jobId); }; } diff -r 373b44af938f -r 3fc310ceb6d4 OrthancServer/OrthancRestApi/OrthancRestModalities.cpp --- a/OrthancServer/OrthancRestApi/OrthancRestModalities.cpp Mon Jun 11 16:30:13 2018 +0200 +++ b/OrthancServer/OrthancRestApi/OrthancRestModalities.cpp Mon Jun 11 20:26:24 2018 +0200 @@ -702,7 +702,7 @@ ServerContext& context = OrthancRestApi::GetContext(call); - bool permissive = Toolbox::GetJsonBooleanField(request, "Permissive", true); + bool permissive = Toolbox::GetJsonBooleanField(request, "Permissive", false); bool asynchronous = Toolbox::GetJsonBooleanField(request, "Asynchronous", false); int priority = Toolbox::GetJsonIntegerField(request, "Priority", 0); diff -r 373b44af938f -r 3fc310ceb6d4 OrthancServer/ServerContext.cpp --- a/OrthancServer/ServerContext.cpp Mon Jun 11 16:30:13 2018 +0200 +++ b/OrthancServer/ServerContext.cpp Mon Jun 11 20:26:24 2018 +0200 @@ -135,24 +135,21 @@ void ServerContext::SignalJobSubmitted(const std::string& jobId) { haveJobsChanged_ = true; - - // TODO: Call Lua + lua_.SignalJobSubmitted(jobId); } void ServerContext::SignalJobSuccess(const std::string& jobId) { haveJobsChanged_ = true; - - // TODO: Call Lua + lua_.SignalJobSuccess(jobId); } void ServerContext::SignalJobFailure(const std::string& jobId) { haveJobsChanged_ = true; - - // TODO: Call Lua + lua_.SignalJobFailure(jobId); }