view lib/types.h @ 19:de4bf839b565

misc: revamp SQL
author David Demelier <markand@malikania.fr>
date Fri, 15 Jul 2022 11:11:48 +0200
parents 600204c31bf0
children f98ea578b1ef
line wrap: on
line source

/*
 * types.h -- type definitions and conversions
 *
 * Copyright (c) 2021 David Demelier <markand@malikania.fr>
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#ifndef SCI_TYPES_H
#define SCI_TYPES_H

#include <sys/types.h>
#include <stddef.h>
#include <stdint.h>

#include <jansson.h>

struct job {
	intmax_t id;
	int project_id;
	const char *tag;
};

struct jobresult {
	intmax_t id;
	int job_id;
	int worker_id;
	int exitcode;
	const char *log;
};

struct worker {
	intmax_t id;
	const char *name;
	const char *desc;
};

struct project {
	intmax_t id;
	const char *name;
	const char *desc;
	const char *url;
	const char *script;
};

json_t *
job_to(const struct job *, size_t);

ssize_t
job_from(struct job *, size_t, json_t *);

json_t *
jobresult_to(const struct jobresult *, size_t);

ssize_t
jobresult_from(struct jobresult *, size_t, json_t *);

json_t *
worker_to(const struct worker *, size_t);

ssize_t
worker_from(struct worker *, size_t, json_t *);

json_t *
project_to(const struct project *, size_t);

ssize_t
project_from(struct project *, size_t, json_t *);

#endif /* !SCI_TYPES_H */