Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add event counter.
Matthew Seaman committed 11 years ago
commit 764846e1131feb3ed3229256277ba9a5389e8220
parent 26757cf
3 files changed +61 -21
modified libpkg/pkg.h.in
@@ -6,7 +6,7 @@
 * Copyright (c) 2011-2012 Marin Atanasov Nikolov <dnaeon@gmail.com>
 * Copyright (c) 2013-2014 Matthew Seaman <matthew@FreeBSD.org>
 * All rights reserved.
-
 * 
+
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
@@ -16,7 +16,7 @@
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
-
 * 
+
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
@@ -227,8 +227,8 @@ typedef enum {
	 */
	PKG_FILE = (1U << 0),
	/**
-
         * The pkg refers to data read from a non-regular file
-
         * (device, pipeline, unix dmain socket etc.)
+
	 * The pkg refers to data read from a non-regular file
+
	 * (device, pipeline, unix dmain socket etc.)
	 */
	PKG_STREAM = (1U << 1),
	/**
@@ -283,7 +283,7 @@ typedef enum {
	PKG_CATEGORIES,
	PKG_UNIQUEID,
	PKG_OLD_DIGEST,
-
	PKG_NUM_FIELDS, 	/* end of fields */
+
	PKG_NUM_FIELDS,		/* end of fields */
} pkg_attr;

typedef enum {
@@ -450,7 +450,7 @@ typedef enum {
	 */
	EPKG_DEPENDENCY,
	/**
-
         * Can not operate on package because it is locked
+
	 * Can not operate on package because it is locked
	 */
	EPKG_LOCKED,
	/**
@@ -470,8 +470,8 @@ typedef enum {
	 */
	EPKG_REPOSCHEMA,
	/**
-
         * Insufficient privilege for action
-
         */
+
	 * Insufficient privilege for action
+
	 */
	EPKG_ENOACCESS,
	/**
	 * Insecure permissions on any component of
@@ -524,7 +524,7 @@ typedef enum {

/**
 * test if pkg is installed and activated.
-
 * @param count  If all the tests pass, and count is non-NULL,
+
 * @param count	If all the tests pass, and count is non-NULL,
 * write the number of installed packages into *count
 */
pkg_status_t pkg_status(int *count);
@@ -882,7 +882,7 @@ int pkgdb_load(struct pkgdb *db, const char *src);
int pkgdb_register_ports(struct pkgdb *db, struct pkg *pkg);

/**
-
 * Set the case sensitivity flag on or off.  Defaults to 
+
 * Set the case sensitivity flag on or off.  Defaults to
 * true (case_sensitive)
 */
void pkgdb_set_case_sensitivity(bool);
@@ -912,7 +912,7 @@ struct pkgdb_it * pkgdb_query_which(struct pkgdb *db, const char *path, bool glo
struct pkgdb_it * pkgdb_query_shlib_require(struct pkgdb *db, const char *shlib);
struct pkgdb_it * pkgdb_query_shlib_provide(struct pkgdb *db, const char *shlib);

-
struct pkgdb_it * pkgdb_rquery_provide(struct pkgdb *db, 
+
struct pkgdb_it * pkgdb_rquery_provide(struct pkgdb *db,
    const char *provide, const char *repo);

/**
@@ -926,7 +926,7 @@ int pkgdb_add_annotation(struct pkgdb *db, struct pkg *pkg,
int pkgdb_modify_annotation(struct pkgdb *db, struct pkg *pkg,
	const char *tag, const char *value);
int pkgdb_delete_annotation(struct pkgdb *db, struct pkg *pkg,
-
        const char *tag);
+
	const char *tag);

#define PKG_LOAD_BASIC			0
#define PKG_LOAD_DEPS			(1U << 0)
@@ -1037,7 +1037,7 @@ int pkg_jobs_total(struct pkg_jobs *jobs);
 * @param iter Must be set to NULL for the first call.
 * @return A next pkg or NULL.
 */
-
bool pkg_jobs_iter(struct pkg_jobs *jobs, void **iter, struct pkg **n, 
+
bool pkg_jobs_iter(struct pkg_jobs *jobs, void **iter, struct pkg **n,
	struct pkg **o, int *type);

/**
@@ -1251,6 +1251,7 @@ typedef enum {
	PKG_EVENT_SANDBOX_GET_STRING,
	PKG_EVENT_PROGRESS_START,
	PKG_EVENT_PROGRESS_TICK,
+
	PKG_EVENT_COUNTER,
	PKG_EVENT_BACKUP,
	PKG_EVENT_RESTORE,
	/* errors */
@@ -1273,6 +1274,13 @@ typedef enum {
	PKG_EVENT_NOT_FOUND,
} pkg_event_t;

+
typedef enum {
+
  PKG_EVENT_COUNTER_START,
+
  PKG_EVENT_COUNTER_MINOR_TICK,
+
  PKG_EVENT_COUNTER_MAJOR_TICK,
+
  PKG_EVENT_COUNTER_END,
+
} pkg_event_counter_t;
+

struct pkg_event {
	pkg_event_t type;
	union {
@@ -1419,6 +1427,10 @@ struct pkg_event {
			int64_t current;
			int64_t total;
		} e_progress_tick;
+
		struct {
+
			int64_t count;
+
			pkg_event_counter_t state;
+
		} e_counter;
	};
};

@@ -1552,7 +1564,7 @@ int pkg_vsnprintf(char * restrict str, size_t size,
 * Allocate a string buffer ret sufficiently big to contain formatted
 * data data from pkg as indicated by the format code format
 * @param ret location of pointer to be set to point to buffer containing
-
 * result 
+
 * result
 * @param ... Varargs list of struct pkg etc. supplying the data
 * @param format String with embedded %-escapes indicating what to output
 * @return count of the number of characters printed
@@ -1563,7 +1575,7 @@ int pkg_asprintf(char **ret, const char * restrict format, ...);
 * Allocate a string buffer ret sufficiently big to contain formatted
 * data data from pkg as indicated by the format code format
 * @param ret location of pointer to be set to point to buffer containing
-
 * result 
+
 * result
 * @param ap Varargs list of struct pkg etc. supplying the data
 * @param format String with embedded %-escapes indicating what to output
 * @return count of the number of characters printed
@@ -1603,13 +1615,13 @@ bool pkg_is_locked(const struct pkg * restrict p);
 *  def bp(m, n):
 *      power = -(n * n) / (2. * m)
 *      return 1. - exp(power)
-
 * 
+
 *
 * For our choice of 2^40 (or 10 hex characters) it is:
 *  >>> bp(float(2 ** 40), 24500.)
 *  0.00027292484660568217
-
 * 
+
 *
 * And it is negligible probability
-
 */ 
+
 */
#define PKG_FILE_CKSUM_CHARS 10

struct pkg_audit;
@@ -1649,7 +1661,7 @@ int pkg_audit_process(struct pkg_audit *audit);
 */
bool pkg_audit_is_vulnerable(struct pkg_audit *audit, struct pkg *pkg,
		bool quiet, struct sbuf **result);
-
		
+

void pkg_audit_free (struct pkg_audit *audit);
char *pkg_utils_tokenize(char **);
int pkg_utils_count_spaces(const char *);
modified libpkg/pkg_event.c
@@ -1,8 +1,9 @@
/*-
 * Copyright (c) 2011-2013 Baptiste Daroussin <bapt@FreeBSD.org>
 * Copyright (c) 2011-2012 Julien Laffaye <jlaffaye@FreeBSD.org>
+
 * Copyright (c) 2015 Matthew Seaman <matthew@FreeBSD.org>
 * All rights reserved.
-
 * 
+
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
@@ -12,7 +13,7 @@
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
-
 * 
+
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
@@ -37,6 +38,13 @@
static pkg_event_cb _cb = NULL;
static void *_data = NULL;

+
static const char *counter_states[] = {
+
	[PKG_EVENT_COUNTER_START]      = "start",
+
	[PKG_EVENT_COUNTER_MINOR_TICK] = "minor_tick",
+
	[PKG_EVENT_COUNTER_MAJOR_TICK] = "major_tick",
+
	[PKG_EVENT_COUNTER_END]        = "end",
+
};
+

static char *
sbuf_json_escape(struct sbuf *buf, const char *str)
{
@@ -375,6 +383,11 @@ pipeevent(struct pkg_event *ev)
		  "\"data\": { \"current\": %ld, \"total\" : %ld}}",
		  ev->e_progress_tick.current, ev->e_progress_tick.total);
		break;
+
	case PKG_EVENT_COUNTER:
+
		sbuf_printf(msg, "{ \"type\": \"COUNTER\", "
+
		    "\"data\": %ld, \"state\": %s}",
+
		    ev->e_counter.count, counter_states[ev->e_counter.state]);
+
		break;
	case PKG_EVENT_BACKUP:
	case PKG_EVENT_RESTORE:
		break;
@@ -1000,3 +1013,15 @@ pkg_emit_progress_tick(int64_t current, int64_t total)
	pkg_emit_event(&ev);

}
+

+
void
+
pkg_emit_counter(int64_t count, pkg_event_counter_t state)
+
{
+
	struct pkg_event ev;
+

+
	ev.type = PKG_EVENT_COUNTER;
+
	ev.e_counter.count = count;
+
	ev.e_counter.state = state;
+

+
	pkg_emit_event(&ev);
+
}
modified libpkg/private/event.h
@@ -2,6 +2,7 @@
 * Copyright (c) 2011-2012 Baptiste Daroussin <bapt@FreeBSD.org>
 * Copyright (c) 2011-2012 Julien Laffaye <jlaffaye@FreeBSD.org>
 * Copyright (c) 2014 Vsevolod Stakhov <vsevolod@FreeBSD.org>
+
 * Copyright (c) 2015 Matthew Seaman <matthew@FreeBSD.org>
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
@@ -69,6 +70,8 @@ int pkg_emit_query_select(const char *msg, const char **items, int ncnt, int def
void pkg_emit_progress_start(const char *fmt, ...);
void pkg_emit_progress_tick(int64_t current, int64_t total);

+
void pkg_emit_counter(int64_t count, pkg_event_counter_t state);
+

void pkg_emit_add_deps_begin(struct pkg *p);
void pkg_emit_add_deps_finished(struct pkg *p);
void pkg_emit_extract_begin(struct pkg *p);