Permalink
Browse files

Service, refactor: modify service control function to static function.

  • Loading branch information...
xicilion committed Sep 19, 2017
1 parent a286b7b commit 2de4dbae9f02765fd1aebc6f9c2fe5af548f3277
Showing with 250 additions and 205 deletions.
  1. +1 −8 fibjs/include/Service.h
  2. +124 −118 fibjs/include/ifs/Service.h
  3. +35 −0 fibjs/src/os/Service_other.cpp
  4. +56 −56 fibjs/src/os/Service_win.cpp
  5. +34 −23 idl/zh-cn/Service.idl
View
@@ -24,16 +24,9 @@ class Service : public Service_base {
public:
// Service_base
virtual result_t run(AsyncEvent* ac);
virtual result_t get_name(exlib::string& retVal);
virtual result_t set_name(exlib::string newVal);
virtual result_t install(exlib::string cmd, exlib::string displayName, exlib::string description);
virtual result_t remove();
virtual result_t start();
virtual result_t stop();
virtual result_t restart();
virtual result_t run(AsyncEvent* ac);
virtual result_t isInstalled(bool& retVal);
virtual result_t isRunning(bool& retVal);
public:
EVENT_FUNC(stop);
View
@@ -25,45 +25,45 @@ class Service_base : public EventEmitter_base {
public:
// Service_base
static result_t _new(exlib::string name, v8::Local<v8::Function> worker, v8::Local<v8::Object> event, obj_ptr<Service_base>& retVal, v8::Local<v8::Object> This = v8::Local<v8::Object>());
virtual result_t run(AsyncEvent* ac) = 0;
virtual result_t get_name(exlib::string& retVal) = 0;
virtual result_t set_name(exlib::string newVal) = 0;
virtual result_t install(exlib::string cmd, exlib::string displayName, exlib::string description) = 0;
virtual result_t remove() = 0;
virtual result_t start() = 0;
virtual result_t stop() = 0;
virtual result_t restart() = 0;
virtual result_t run(AsyncEvent* ac) = 0;
virtual result_t isInstalled(bool& retVal) = 0;
virtual result_t isRunning(bool& retVal) = 0;
virtual result_t get_onstop(v8::Local<v8::Function>& retVal) = 0;
virtual result_t set_onstop(v8::Local<v8::Function> newVal) = 0;
virtual result_t get_onpause(v8::Local<v8::Function>& retVal) = 0;
virtual result_t set_onpause(v8::Local<v8::Function> newVal) = 0;
virtual result_t get_oncontinue(v8::Local<v8::Function>& retVal) = 0;
virtual result_t set_oncontinue(v8::Local<v8::Function> newVal) = 0;
static result_t install(exlib::string name, exlib::string cmd, exlib::string displayName, exlib::string description);
static result_t remove(exlib::string name);
static result_t start(exlib::string name);
static result_t stop(exlib::string name);
static result_t restart(exlib::string name);
static result_t isInstalled(exlib::string name, bool& retVal);
static result_t isRunning(exlib::string name, bool& retVal);
public:
template <typename T>
static void __new(const T& args);
public:
static void s__new(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_run(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_get_name(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args);
static void s_set_name(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& args);
static void s_get_onstop(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args);
static void s_set_onstop(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& args);
static void s_get_onpause(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args);
static void s_set_onpause(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& args);
static void s_get_oncontinue(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args);
static void s_set_oncontinue(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& args);
static void s_install(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_remove(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_start(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_stop(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_restart(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_run(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_isInstalled(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_isRunning(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_get_onstop(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args);
static void s_set_onstop(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& args);
static void s_get_onpause(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args);
static void s_set_onpause(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& args);
static void s_get_oncontinue(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args);
static void s_set_oncontinue(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& args);
public:
ASYNC_MEMBER0(Service_base, run);
@@ -74,15 +74,15 @@ namespace fibjs {
inline ClassInfo& Service_base::class_info()
{
static ClassData::ClassMethod s_method[] = {
{ "install", s_install, false },
{ "remove", s_remove, false },
{ "start", s_start, false },
{ "stop", s_stop, false },
{ "restart", s_restart, false },
{ "run", s_run, false },
{ "runSync", s_run, false },
{ "isInstalled", s_isInstalled, false },
{ "isRunning", s_isRunning, false }
{ "install", s_install, true },
{ "remove", s_remove, true },
{ "start", s_start, true },
{ "stop", s_stop, true },
{ "restart", s_restart, true },
{ "isInstalled", s_isInstalled, true },
{ "isRunning", s_isRunning, true }
};
static ClassData::ClassProperty s_property[] = {
@@ -126,6 +126,22 @@ void Service_base::__new(const T& args)
CONSTRUCT_RETURN();
}
inline void Service_base::s_run(const v8::FunctionCallbackInfo<v8::Value>& args)
{
METHOD_INSTANCE(Service_base);
METHOD_ENTER();
ASYNC_METHOD_OVER(0, 0);
if (!cb.IsEmpty()) {
pInst->acb_run(cb);
hr = CALL_RETURN_NULL;
} else
hr = pInst->ac_run();
METHOD_VOID();
}
inline void Service_base::s_get_name(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args)
{
exlib::string vr;
@@ -149,181 +165,171 @@ inline void Service_base::s_set_name(v8::Local<v8::String> property, v8::Local<v
PROPERTY_SET_LEAVE();
}
inline void Service_base::s_install(const v8::FunctionCallbackInfo<v8::Value>& args)
inline void Service_base::s_get_onstop(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args)
{
METHOD_INSTANCE(Service_base);
METHOD_ENTER();
METHOD_OVER(3, 1);
v8::Local<v8::Function> vr;
ARG(exlib::string, 0);
OPT_ARG(exlib::string, 1, "");
OPT_ARG(exlib::string, 2, "");
METHOD_INSTANCE(Service_base);
PROPERTY_ENTER();
hr = pInst->install(v0, v1, v2);
hr = pInst->get_onstop(vr);
METHOD_VOID();
METHOD_RETURN();
}
inline void Service_base::s_remove(const v8::FunctionCallbackInfo<v8::Value>& args)
inline void Service_base::s_set_onstop(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& args)
{
METHOD_INSTANCE(Service_base);
METHOD_ENTER();
METHOD_OVER(0, 0);
PROPERTY_ENTER();
PROPERTY_VAL(v8::Local<v8::Function>);
hr = pInst->remove();
hr = pInst->set_onstop(v0);
METHOD_VOID();
PROPERTY_SET_LEAVE();
}
inline void Service_base::s_start(const v8::FunctionCallbackInfo<v8::Value>& args)
inline void Service_base::s_get_onpause(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args)
{
METHOD_INSTANCE(Service_base);
METHOD_ENTER();
v8::Local<v8::Function> vr;
METHOD_OVER(0, 0);
METHOD_INSTANCE(Service_base);
PROPERTY_ENTER();
hr = pInst->start();
hr = pInst->get_onpause(vr);
METHOD_VOID();
METHOD_RETURN();
}
inline void Service_base::s_stop(const v8::FunctionCallbackInfo<v8::Value>& args)
inline void Service_base::s_set_onpause(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& args)
{
METHOD_INSTANCE(Service_base);
METHOD_ENTER();
METHOD_OVER(0, 0);
PROPERTY_ENTER();
PROPERTY_VAL(v8::Local<v8::Function>);
hr = pInst->stop();
hr = pInst->set_onpause(v0);
METHOD_VOID();
PROPERTY_SET_LEAVE();
}
inline void Service_base::s_restart(const v8::FunctionCallbackInfo<v8::Value>& args)
inline void Service_base::s_get_oncontinue(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args)
{
METHOD_INSTANCE(Service_base);
METHOD_ENTER();
v8::Local<v8::Function> vr;
METHOD_OVER(0, 0);
METHOD_INSTANCE(Service_base);
PROPERTY_ENTER();
hr = pInst->restart();
hr = pInst->get_oncontinue(vr);
METHOD_VOID();
METHOD_RETURN();
}
inline void Service_base::s_run(const v8::FunctionCallbackInfo<v8::Value>& args)
inline void Service_base::s_set_oncontinue(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& args)
{
METHOD_INSTANCE(Service_base);
METHOD_ENTER();
ASYNC_METHOD_OVER(0, 0);
PROPERTY_ENTER();
PROPERTY_VAL(v8::Local<v8::Function>);
if (!cb.IsEmpty()) {
pInst->acb_run(cb);
hr = CALL_RETURN_NULL;
} else
hr = pInst->ac_run();
hr = pInst->set_oncontinue(v0);
METHOD_VOID();
PROPERTY_SET_LEAVE();
}
inline void Service_base::s_isInstalled(const v8::FunctionCallbackInfo<v8::Value>& args)
inline void Service_base::s_install(const v8::FunctionCallbackInfo<v8::Value>& args)
{
bool vr;
METHOD_INSTANCE(Service_base);
METHOD_ENTER();
METHOD_OVER(0, 0);
METHOD_OVER(4, 2);
hr = pInst->isInstalled(vr);
ARG(exlib::string, 0);
ARG(exlib::string, 1);
OPT_ARG(exlib::string, 2, "");
OPT_ARG(exlib::string, 3, "");
METHOD_RETURN();
hr = install(v0, v1, v2, v3);
METHOD_VOID();
}
inline void Service_base::s_isRunning(const v8::FunctionCallbackInfo<v8::Value>& args)
inline void Service_base::s_remove(const v8::FunctionCallbackInfo<v8::Value>& args)
{
bool vr;
METHOD_INSTANCE(Service_base);
METHOD_ENTER();
METHOD_OVER(0, 0);
METHOD_OVER(1, 1);
hr = pInst->isRunning(vr);
ARG(exlib::string, 0);
METHOD_RETURN();
hr = remove(v0);
METHOD_VOID();
}
inline void Service_base::s_get_onstop(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args)
inline void Service_base::s_start(const v8::FunctionCallbackInfo<v8::Value>& args)
{
v8::Local<v8::Function> vr;
METHOD_ENTER();
METHOD_INSTANCE(Service_base);
PROPERTY_ENTER();
METHOD_OVER(1, 1);
hr = pInst->get_onstop(vr);
ARG(exlib::string, 0);
METHOD_RETURN();
hr = start(v0);
METHOD_VOID();
}
inline void Service_base::s_set_onstop(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& args)
inline void Service_base::s_stop(const v8::FunctionCallbackInfo<v8::Value>& args)
{
METHOD_INSTANCE(Service_base);
PROPERTY_ENTER();
PROPERTY_VAL(v8::Local<v8::Function>);
METHOD_ENTER();
hr = pInst->set_onstop(v0);
METHOD_OVER(1, 1);
PROPERTY_SET_LEAVE();
ARG(exlib::string, 0);
hr = stop(v0);
METHOD_VOID();
}
inline void Service_base::s_get_onpause(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args)
inline void Service_base::s_restart(const v8::FunctionCallbackInfo<v8::Value>& args)
{
v8::Local<v8::Function> vr;
METHOD_ENTER();
METHOD_INSTANCE(Service_base);
PROPERTY_ENTER();
METHOD_OVER(1, 1);
hr = pInst->get_onpause(vr);
ARG(exlib::string, 0);
METHOD_RETURN();
hr = restart(v0);
METHOD_VOID();
}
inline void Service_base::s_set_onpause(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& args)
inline void Service_base::s_isInstalled(const v8::FunctionCallbackInfo<v8::Value>& args)
{
METHOD_INSTANCE(Service_base);
PROPERTY_ENTER();
PROPERTY_VAL(v8::Local<v8::Function>);
hr = pInst->set_onpause(v0);
bool vr;
PROPERTY_SET_LEAVE();
}
METHOD_ENTER();
inline void Service_base::s_get_oncontinue(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args)
{
v8::Local<v8::Function> vr;
METHOD_OVER(1, 1);
METHOD_INSTANCE(Service_base);
PROPERTY_ENTER();
ARG(exlib::string, 0);
hr = pInst->get_oncontinue(vr);
hr = isInstalled(v0, vr);
METHOD_RETURN();
}
inline void Service_base::s_set_oncontinue(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& args)
inline void Service_base::s_isRunning(const v8::FunctionCallbackInfo<v8::Value>& args)
{
METHOD_INSTANCE(Service_base);
PROPERTY_ENTER();
PROPERTY_VAL(v8::Local<v8::Function>);
bool vr;
hr = pInst->set_oncontinue(v0);
METHOD_ENTER();
PROPERTY_SET_LEAVE();
METHOD_OVER(1, 1);
ARG(exlib::string, 0);
hr = isRunning(v0, vr);
METHOD_RETURN();
}
}
Oops, something went wrong.

0 comments on commit 2de4dba

Please sign in to comment.