summaryrefslogtreecommitdiff
path: root/library/RemoteServer.cpp
diff options
context:
space:
mode:
authorAlexander Gavrilov2012-03-15 15:33:19 +0400
committerAlexander Gavrilov2012-03-15 15:33:19 +0400
commit4eb481177737fe47cda80808dc4a62bd864a15e0 (patch)
treee41f625df61c782a110a68042593312c88e98b7b /library/RemoteServer.cpp
parent605ee9669a5cd4d2f69ca8adcbe96c9e62671b87 (diff)
downloaddfhack-4eb481177737fe47cda80808dc4a62bd864a15e0.tar.gz
dfhack-4eb481177737fe47cda80808dc4a62bd864a15e0.tar.bz2
dfhack-4eb481177737fe47cda80808dc4a62bd864a15e0.tar.xz
Make the DF suspend lock recursive, and add RPC calls for batch suspend.
The idea is that if you have to execute many RPC calls, it is faster to suspend once. The service class takes care to auto-resume in the destructor in case the client just disappears.
Diffstat (limited to 'library/RemoteServer.cpp')
-rw-r--r--library/RemoteServer.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/library/RemoteServer.cpp b/library/RemoteServer.cpp
index 14b64f19..9d3c1101 100644
--- a/library/RemoteServer.cpp
+++ b/library/RemoteServer.cpp
@@ -64,11 +64,21 @@ using dfproto::CoreTextFragment;
using google::protobuf::MessageLite;
CoreService::CoreService() {
+ suspend_depth = 0;
+
// These 2 methods must be first, so that they get id 0 and 1
addMethod("BindMethod", &CoreService::BindMethod);
addMethod("RunCommand", &CoreService::RunCommand);
// Add others here:
+ addMethod("CoreSuspend", &CoreService::CoreSuspend);
+ addMethod("CoreResume", &CoreService::CoreResume);
+}
+
+CoreService::~CoreService()
+{
+ while (suspend_depth-- > 0)
+ Core::getInstance().Resume();
}
command_result CoreService::BindMethod(color_ostream &stream,
@@ -107,6 +117,23 @@ command_result CoreService::RunCommand(color_ostream &stream,
return Core::getInstance().plug_mgr->InvokeCommand(stream, cmd, args);
}
+command_result CoreService::CoreSuspend(color_ostream &stream, const EmptyMessage*, IntMessage *cnt)
+{
+ Core::getInstance().Suspend();
+ cnt->set_value(++suspend_depth);
+ return CR_OK;
+}
+
+command_result CoreService::CoreResume(color_ostream &stream, const EmptyMessage*, IntMessage *cnt)
+{
+ if (suspend_depth <= 0)
+ return CR_WRONG_USAGE;
+
+ Core::getInstance().Resume();
+ cnt->set_value(--suspend_depth);
+ return CR_OK;
+}
+
RPCService::RPCService()
{
owner = NULL;