Blob Blame History Raw
#ifndef TOKSVC_H
#define TOKSVC_H

#include <stdint.h>
#include <stddef.h>

#include "toksvc_api.h"

#ifdef __cplusplus
extern "C" {
#endif

/* pre-alpha */
#ifndef TOKS_APP
#ifndef TOKS_PRE_ALPHA
#error  libtoks: pre-alpha: ABI is not final!
#error  to use the library, compile with -DTOKS_PRE_ALPHA.
#endif
#endif

/* daemon */
#define TOKS_PORT_GUID_DAEMON		{0x7d36f145,  \
					  0xd8f0,     \
					  0x440f,     \
					 {0x92,0xbe,0xc3,0x53,0x61,0x7b,0xbc,0x96}}

#define TOKS_PORT_NAME_PREFIX		{'t','o','k','s','v','c'}

/* status codes */
#define TOKS_OK				0x00
#define TOKS_USAGE			0x01
#define TOKS_ERROR			0x02

/* driver flags */
#define TOKS_DRIVER_VERBOSITY_NONE	0x0000
#define TOKS_DRIVER_VERBOSITY_ERRORS	0x0001
#define TOKS_DRIVER_VERBOSITY_STATUS	0x0002
#define TOKS_DRIVER_VERBOSITY_USAGE	0x0004
#define TOKS_DRIVER_CLONE_VECTOR	0x0008

#define TOKS_DRIVER_VERSION		0x0010
#define TOKS_DRIVER_DRY_RUN		0x0020

#define TOKS_DRIVER_DAEMON_ALWAYS	0x0040
#define TOKS_DRIVER_DAEMON_NEVER	0x0080

#define TOKS_DRIVER_ANNOTATE_ALWAYS	0x1000
#define TOKS_DRIVER_ANNOTATE_NEVER	0x2000
#define TOKS_DRIVER_ANNOTATE_FULL	0x4000

#define TOKS_DRIVER_MODE_SERVER		0X10000
#define TOKS_DRIVER_MODE_CLIENT		0X20000

#define TOKS_DRIVER_ACTION_ACQUIRE	0X100000
#define TOKS_DRIVER_ACTION_RELEASE	0X200000
#define TOKS_DRIVER_ACTION_ABORT	0X400000

/* error flags */
#define TOKS_ERROR_TOP_LEVEL		0x0001
#define TOKS_ERROR_NESTED		0x0002
#define TOKS_ERROR_CHILD		0x0004
#define TOKS_ERROR_CUSTOM		0x0008

enum toks_custom_error {
	TOKS_ERR_FLOW_ERROR,
	TOKS_ERR_FLEE_ERROR,
	TOKS_ERR_NULL_CONTEXT,
	TOKS_ERR_BAD_DATA,
	TOKS_ERR_CAP,
};

enum toks_warning_level {
	TOKS_WARNING_LEVEL_UNKNOWN,
	TOKS_WARNING_LEVEL_ALL,
	TOKS_WARNING_LEVEL_ERROR,
	TOKS_WARNING_LEVEL_NONE,
};

struct toks_source_version {
	int		major;
	int		minor;
	int		revision;
	const char *	commit;
};

struct toks_token_string{
	char            token[128];
};

struct toks_error_info {
	const struct toks_driver_ctx *	edctx;
	const struct toks_unit_ctx *	euctx;
	const char *			eunit;
	int				esyscode;
	int				elibcode;
	const char *			efunction;
	int				eline;
	unsigned			eflags;
	void *				eany;
};

struct toks_common_ctx {
	uint64_t			drvflags;
	uint64_t			actflags;
	uint64_t			fmtflags;
	int32_t				loglevel;
	const nt_guid *			uuid;
	void *				hroot;
	const char *			sysroot;
	char **				eargv;
};

struct toks_driver_ctx {
	const char **                   units;
	const char *			program;
	const char *			module;
	const struct toks_common_ctx *	cctx;
	struct toks_error_info **	errv;
	void *				any;
};

/* driver api */
toks_api int  toks_get_driver_ctx       (char ** argv, char ** envp, uint32_t flags,
                                         struct toks_driver_ctx **);

toks_api void toks_free_driver_ctx      (struct toks_driver_ctx *);

toks_api void toks_driver_set_timeout   (struct toks_driver_ctx *, int64_t millisecs);
toks_api void toks_driver_unset_timeout (struct toks_driver_ctx *);

/* core api */
toks_api int  toks_service_abort        (struct toks_driver_ctx *);

/* client api */
toks_api int  toks_client_connect       (struct toks_driver_ctx *);
toks_api int  toks_client_acquire       (struct toks_driver_ctx *);
toks_api int  toks_client_release       (struct toks_driver_ctx *);
toks_api int  toks_client_token_to_str  (struct toks_driver_ctx *, struct toks_token_string *);
toks_api int  toks_client_str_to_token  (struct toks_driver_ctx *, const struct toks_token_string *);

/* utility api */
toks_api int  toks_main                 (char **, char **);

/* error trace api */
toks_api int  toks_output_error_record  (const struct toks_driver_ctx *, const struct toks_error_info *);
toks_api int  toks_output_error_vector  (const struct toks_driver_ctx *);

/* package info */
toks_api const struct toks_source_version * toks_source_version(void);

#ifdef __cplusplus
}
#endif

#endif