|
|
@ -40,9 +40,16 @@ namespace DFHack
|
|
|
|
|
|
|
|
|
|
|
|
class DFHACK_EXPORT RPCService;
|
|
|
|
class DFHACK_EXPORT RPCService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum ServerFunctionFlags {
|
|
|
|
|
|
|
|
// The function is expected to be called only once per client,
|
|
|
|
|
|
|
|
// so always delete all cached buffers after processing.
|
|
|
|
|
|
|
|
SF_CALLED_ONCE = 1
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class DFHACK_EXPORT ServerFunctionBase : public RPCFunctionBase {
|
|
|
|
class DFHACK_EXPORT ServerFunctionBase : public RPCFunctionBase {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
const char *const name;
|
|
|
|
const char *const name;
|
|
|
|
|
|
|
|
const int flags;
|
|
|
|
|
|
|
|
|
|
|
|
virtual command_result execute(color_ostream &stream) = 0;
|
|
|
|
virtual command_result execute(color_ostream &stream) = 0;
|
|
|
|
|
|
|
|
|
|
|
@ -51,8 +58,9 @@ namespace DFHack
|
|
|
|
protected:
|
|
|
|
protected:
|
|
|
|
friend class RPCService;
|
|
|
|
friend class RPCService;
|
|
|
|
|
|
|
|
|
|
|
|
ServerFunctionBase(const message_type *in, const message_type *out, RPCService *owner, const char *name)
|
|
|
|
ServerFunctionBase(const message_type *in, const message_type *out,
|
|
|
|
: RPCFunctionBase(in, out), name(name), owner(owner), id(-1)
|
|
|
|
RPCService *owner, const char *name, int flags)
|
|
|
|
|
|
|
|
: RPCFunctionBase(in, out), name(name), flags(flags), owner(owner), id(-1)
|
|
|
|
{}
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
RPCService *owner;
|
|
|
|
RPCService *owner;
|
|
|
@ -67,8 +75,8 @@ namespace DFHack
|
|
|
|
In *in() { return static_cast<In*>(RPCFunctionBase::in()); }
|
|
|
|
In *in() { return static_cast<In*>(RPCFunctionBase::in()); }
|
|
|
|
Out *out() { return static_cast<Out*>(RPCFunctionBase::out()); }
|
|
|
|
Out *out() { return static_cast<Out*>(RPCFunctionBase::out()); }
|
|
|
|
|
|
|
|
|
|
|
|
ServerFunction(RPCService *owner, const char *name, function_type fptr)
|
|
|
|
ServerFunction(RPCService *owner, const char *name, int flags, function_type fptr)
|
|
|
|
: ServerFunctionBase(&In::default_instance(), &Out::default_instance(), owner, name),
|
|
|
|
: ServerFunctionBase(&In::default_instance(), &Out::default_instance(), owner, name, flags),
|
|
|
|
fptr(fptr) {}
|
|
|
|
fptr(fptr) {}
|
|
|
|
|
|
|
|
|
|
|
|
virtual command_result execute(color_ostream &stream) { return fptr(stream, in(), out()); }
|
|
|
|
virtual command_result execute(color_ostream &stream) { return fptr(stream, in(), out()); }
|
|
|
@ -84,8 +92,8 @@ namespace DFHack
|
|
|
|
|
|
|
|
|
|
|
|
In *in() { return static_cast<In*>(RPCFunctionBase::in()); }
|
|
|
|
In *in() { return static_cast<In*>(RPCFunctionBase::in()); }
|
|
|
|
|
|
|
|
|
|
|
|
VoidServerFunction(RPCService *owner, const char *name, function_type fptr)
|
|
|
|
VoidServerFunction(RPCService *owner, const char *name, int flags, function_type fptr)
|
|
|
|
: ServerFunctionBase(&In::default_instance(), &EmptyMessage::default_instance(), owner, name),
|
|
|
|
: ServerFunctionBase(&In::default_instance(), &EmptyMessage::default_instance(), owner, name, flags),
|
|
|
|
fptr(fptr) {}
|
|
|
|
fptr(fptr) {}
|
|
|
|
|
|
|
|
|
|
|
|
virtual command_result execute(color_ostream &stream) { return fptr(stream, in()); }
|
|
|
|
virtual command_result execute(color_ostream &stream) { return fptr(stream, in()); }
|
|
|
@ -102,8 +110,8 @@ namespace DFHack
|
|
|
|
In *in() { return static_cast<In*>(RPCFunctionBase::in()); }
|
|
|
|
In *in() { return static_cast<In*>(RPCFunctionBase::in()); }
|
|
|
|
Out *out() { return static_cast<Out*>(RPCFunctionBase::out()); }
|
|
|
|
Out *out() { return static_cast<Out*>(RPCFunctionBase::out()); }
|
|
|
|
|
|
|
|
|
|
|
|
ServerMethod(RPCService *owner, const char *name, function_type fptr)
|
|
|
|
ServerMethod(RPCService *owner, const char *name, int flags, function_type fptr)
|
|
|
|
: ServerFunctionBase(&In::default_instance(), &Out::default_instance(), owner, name),
|
|
|
|
: ServerFunctionBase(&In::default_instance(), &Out::default_instance(), owner, name, flags),
|
|
|
|
fptr(fptr) {}
|
|
|
|
fptr(fptr) {}
|
|
|
|
|
|
|
|
|
|
|
|
virtual command_result execute(color_ostream &stream) {
|
|
|
|
virtual command_result execute(color_ostream &stream) {
|
|
|
@ -121,8 +129,8 @@ namespace DFHack
|
|
|
|
|
|
|
|
|
|
|
|
In *in() { return static_cast<In*>(RPCFunctionBase::in()); }
|
|
|
|
In *in() { return static_cast<In*>(RPCFunctionBase::in()); }
|
|
|
|
|
|
|
|
|
|
|
|
VoidServerMethod(RPCService *owner, const char *name, function_type fptr)
|
|
|
|
VoidServerMethod(RPCService *owner, const char *name, int flags, function_type fptr)
|
|
|
|
: ServerFunctionBase(&In::default_instance(), &EmptyMessage::default_instance(), owner, name),
|
|
|
|
: ServerFunctionBase(&In::default_instance(), &EmptyMessage::default_instance(), owner, name, flags),
|
|
|
|
fptr(fptr) {}
|
|
|
|
fptr(fptr) {}
|
|
|
|
|
|
|
|
|
|
|
|
virtual command_result execute(color_ostream &stream) {
|
|
|
|
virtual command_result execute(color_ostream &stream) {
|
|
|
@ -154,19 +162,21 @@ namespace DFHack
|
|
|
|
template<typename In, typename Out>
|
|
|
|
template<typename In, typename Out>
|
|
|
|
void addFunction(
|
|
|
|
void addFunction(
|
|
|
|
const char *name,
|
|
|
|
const char *name,
|
|
|
|
command_result (*fptr)(color_ostream &out, const In *input, Out *output)
|
|
|
|
command_result (*fptr)(color_ostream &out, const In *input, Out *output),
|
|
|
|
|
|
|
|
int flags = 0
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
assert(!owner);
|
|
|
|
assert(!owner);
|
|
|
|
functions.push_back(new ServerFunction<In,Out>(this, name, fptr));
|
|
|
|
functions.push_back(new ServerFunction<In,Out>(this, name, flags, fptr));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename In>
|
|
|
|
template<typename In>
|
|
|
|
void addFunction(
|
|
|
|
void addFunction(
|
|
|
|
const char *name,
|
|
|
|
const char *name,
|
|
|
|
command_result (*fptr)(color_ostream &out, const In *input)
|
|
|
|
command_result (*fptr)(color_ostream &out, const In *input),
|
|
|
|
|
|
|
|
int flags = 0
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
assert(!owner);
|
|
|
|
assert(!owner);
|
|
|
|
functions.push_back(new VoidServerFunction<In>(this, name, fptr));
|
|
|
|
functions.push_back(new VoidServerFunction<In>(this, name, flags, fptr));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
protected:
|
|
|
@ -175,19 +185,21 @@ namespace DFHack
|
|
|
|
template<typename Svc, typename In, typename Out>
|
|
|
|
template<typename Svc, typename In, typename Out>
|
|
|
|
void addMethod(
|
|
|
|
void addMethod(
|
|
|
|
const char *name,
|
|
|
|
const char *name,
|
|
|
|
command_result (Svc::*fptr)(color_ostream &out, const In *input, Out *output)
|
|
|
|
command_result (Svc::*fptr)(color_ostream &out, const In *input, Out *output),
|
|
|
|
|
|
|
|
int flags = 0
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
assert(!owner);
|
|
|
|
assert(!owner);
|
|
|
|
functions.push_back(new ServerMethod<Svc,In,Out>(this, name, fptr));
|
|
|
|
functions.push_back(new ServerMethod<Svc,In,Out>(this, name, flags, fptr));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename Svc, typename In>
|
|
|
|
template<typename Svc, typename In>
|
|
|
|
void addMethod(
|
|
|
|
void addMethod(
|
|
|
|
const char *name,
|
|
|
|
const char *name,
|
|
|
|
command_result (Svc::*fptr)(color_ostream &out, const In *input)
|
|
|
|
command_result (Svc::*fptr)(color_ostream &out, const In *input),
|
|
|
|
|
|
|
|
int flags = 0
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
assert(!owner);
|
|
|
|
assert(!owner);
|
|
|
|
functions.push_back(new VoidServerMethod<Svc,In>(this, name, fptr));
|
|
|
|
functions.push_back(new VoidServerMethod<Svc,In>(this, name, flags, fptr));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|