Skip to content
pi-c Artifact [df0ddd0f21]
Login

Artifact [df0ddd0f21]

Artifact df0ddd0f21a38e13c3f50991d1d97c2bc98bbd753a18d5aac488741d6db70d54:


/* --commands (commands.c): while pic runs a request, Pi's RPC command lines
 * on a descriptor (stdin) steer it. Supported: steer, follow_up (prompt
 * templates expanded; Pi's images field attached), clear_queue, abort (Ctrl-C's cancel),
 * set_steering_mode and set_follow_up_mode ("all" or "one-at-a-time"),
 * set_auto_compaction (Pi's compaction.enabled, saved in the user's settings).
 * Each gets Pi's response line on the events' out; anything else is an
 * error response and the run goes on. The descriptor is read only when pic
 * waits (net.h's side descriptor) and at each step of the loop, never inside
 * a transaction; accepted messages are journaled before the response. */
#ifndef PIC_COMMANDS_H
#define PIC_COMMANDS_H

#include "pic.h"

/* expand returns a template's expansion of TEXT (malloc'd), or NULL to keep it.
 * FD < 0: the caller reads the lines itself and hands each to pic_commands_line. */
void pic_commands_start(pic_store *s, int fd, char *(*expand)(void *ctx, const char *text), void *ctx);
/* A command of another type goes to OTHER (rpc.c), which returns 1 when it
 * answered it; 0 makes it an unknown command. */
void pic_commands_other(int (*other)(void *ctx, const char *line, const char *type), void *ctx);
void pic_commands_line(const char *line);
/* Whether pic_commands_start has run and pic_commands_stop has not. */
int pic_commands_active(void);
/* While SINK is set, response lines go to it, not to the events' out: an
 * inbox delivery (inbox.c) keeps the response on its row. NULL restores. */
void pic_commands_sink(void (*sink)(void *ctx, const char *response), void *ctx);
/* LINE's message and images queued as TYPE ("steer" or "follow_up") for the
 * running request, answered as COMMAND's response; 0, or -1 when refused. */
int pic_commands_enqueue(const char *line, const char *command, const char *type, const char *message);
void pic_commands_stop(void);

#endif