aboutsummaryrefslogtreecommitdiff
path: root/json-rpc-shell.c
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-04-08 02:24:07 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2015-04-08 02:35:32 +0200
commitf0d60bb689324dd36e2266bbde6ff537f6d2233f (patch)
tree5dc0565c81f2a1e2c4819ac925e268990bf95044 /json-rpc-shell.c
parentec54630feff37528240a0433cb4a17d959fa4c7a (diff)
downloadjson-rpc-shell-f0d60bb689324dd36e2266bbde6ff537f6d2233f.tar.gz
json-rpc-shell-f0d60bb689324dd36e2266bbde6ff537f6d2233f.tar.xz
json-rpc-shell-f0d60bb689324dd36e2266bbde6ff537f6d2233f.zip
Handle quitting a bit better
And add some documentation.
Diffstat (limited to 'json-rpc-shell.c')
-rw-r--r--json-rpc-shell.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/json-rpc-shell.c b/json-rpc-shell.c
index 1e7038a..bdbf27b 100644
--- a/json-rpc-shell.c
+++ b/json-rpc-shell.c
@@ -85,12 +85,22 @@ struct app_context;
struct backend_iface
{
+ /// Prepare the backend for RPC calls
void (*init) (struct app_context *ctx,
const char *endpoint, struct http_parser_url *url);
+
+ /// Add an HTTP header to send with requests
void (*add_header) (struct app_context *ctx, const char *header);
+
+ /// Make an RPC call
bool (*make_call) (struct app_context *ctx,
const char *request, bool expect_content,
struct str *buf, struct error **e);
+
+ /// Do everything necessary to deal with ev_break(EVBREAK_ALL)
+ void (*on_quit) (struct app_context *ctx);
+
+ /// Free any resources
void (*destroy) (struct app_context *ctx);
};
@@ -1403,6 +1413,16 @@ backend_ws_make_call (struct app_context *ctx,
}
static void
+backend_ws_on_quit (struct app_context *ctx)
+{
+ struct ws_context *self = &ctx->ws;
+ if (self->waiting_for_event && !self->e)
+ error_set (&self->e, "aborted by user");
+
+ // We also have to be careful not to change the ev_break status
+}
+
+static void
backend_ws_destroy (struct app_context *ctx)
{
struct ws_context *self = &ctx->ws;
@@ -1432,6 +1452,7 @@ static struct backend_iface g_backend_ws =
.init = backend_ws_init,
.add_header = backend_ws_add_header,
.make_call = backend_ws_make_call,
+ .on_quit = backend_ws_on_quit,
.destroy = backend_ws_destroy,
};
@@ -1861,6 +1882,9 @@ on_readline_input (char *line)
if (!line)
{
+ if (g_ctx.backend->on_quit)
+ g_ctx.backend->on_quit (&g_ctx);
+
ev_break (EV_DEFAULT_ EVBREAK_ALL);
// We must do this here, or the prompt gets printed twice. *shrug*