diff options
| author | Alexander Gavrilov | 2012-03-15 11:07:43 +0400 |
|---|---|---|
| committer | Alexander Gavrilov | 2012-03-15 11:07:43 +0400 |
| commit | e7851f5abdd1a84d29020f2789efc0f932284bf0 (patch) | |
| tree | d5912bf9ba41cb9fcc018540f4cad1972fb3a975 /library/RemoteClient.cpp | |
| parent | 560e977f0589ac1c0feb6ea825d20d351e325826 (diff) | |
| download | dfhack-e7851f5abdd1a84d29020f2789efc0f932284bf0.tar.gz dfhack-e7851f5abdd1a84d29020f2789efc0f932284bf0.tar.bz2 dfhack-e7851f5abdd1a84d29020f2789efc0f932284bf0.tar.xz | |
Improve support for void RPC functions, dfhack-run, etc.
Diffstat (limited to 'library/RemoteClient.cpp')
| -rw-r--r-- | library/RemoteClient.cpp | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/library/RemoteClient.cpp b/library/RemoteClient.cpp index a8c80466..6f284dd1 100644 --- a/library/RemoteClient.cpp +++ b/library/RemoteClient.cpp @@ -176,6 +176,10 @@ bool RemoteClient::connect(int port) bind_call.p_client = this; bind_call.id = 0; + runcmd_call.name = "RunCommand"; + runcmd_call.p_client = this; + runcmd_call.id = 1; + return true; } @@ -220,6 +224,24 @@ bool RemoteClient::bind(color_ostream &out, RemoteFunctionBase *function, return true; } +command_result RemoteClient::run_command(color_ostream &out, const std::string &cmd, + const std::vector<std::string> &args) +{ + if (!active || !socket.IsSocketValid()) + { + out.printerr("In RunCommand: client connection not valid.\n"); + return CR_FAILURE; + } + + runcmd_call.reset(); + + runcmd_call.in()->set_command(cmd); + for (size_t i = 0; i < args.size(); i++) + runcmd_call.in()->add_arguments(args[i]); + + return runcmd_call.execute(out); +} + void RPCFunctionBase::reset(bool free) { if (free) @@ -256,11 +278,14 @@ bool RemoteFunctionBase::bind(color_ostream &out, RemoteClient *client, return client->bind(out, this, name, proto); } -bool DFHack::sendRemoteMessage(CSimpleSocket &socket, int16_t id, const MessageLite *msg) +bool DFHack::sendRemoteMessage(CSimpleSocket &socket, int16_t id, const MessageLite *msg, int *psz) { int size = msg->ByteSize(); int fullsz = size + sizeof(RPCMessageHeader); + if (psz) + *psz = size; + std::auto_ptr<uint8_t> data(new uint8_t[fullsz]); RPCMessageHeader *hdr = (RPCMessageHeader*)data.get(); |
