/*
  This file is part of Anastasis
  Copyright (C) 2020-2022 Anastasis SARL

  Anastasis is free software; you can redistribute it and/or modify it under the
  terms of the GNU Affero General Public License as published by the Free Software
  Foundation; either version 3, or (at your option) any later version.

  Anastasis is distributed in the hope that it will be useful, but WITHOUT ANY
  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details.

  You should have received a copy of the GNU Affero General Public License along with
  Anastasis; see the file COPYING.GPL.  If not, see <http://www.gnu.org/licenses/>
*/
/**
 * @file include/anastasis/anastasis-database/event.h
 * @brief database event (notification) support for Anastasis
 * @author Christian Grothoff
 */
#ifndef ANASTASIS_DATABASE_EVENT_H
#define ANASTASIS_DATABASE_EVENT_H

#include <gnunet/gnunet_util_lib.h>
#include <gnunet/gnunet_db_lib.h>

/**
 * Register callback to be invoked on events of type @a es.
 *
 * @param es specification of the event to listen for
 * @param timeout how long to wait for the event
 * @param cb function to call when the event happens, possibly
 *         multiple times (until cancel is invoked)
 * @param cb_cls closure for @a cb
 * @return handle useful to cancel the listener
 */
struct GNUNET_DB_EventHandler *
ANASTASIS_DB_event_listen (const struct GNUNET_DB_EventHeaderP *es,
                           struct GNUNET_TIME_Relative timeout,
                           GNUNET_DB_EventCallback cb,
                           void *cb_cls);


/**
 * Stop notifications.
 *
 * @param eh handle to unregister.
 */
void
ANASTASIS_DB_event_listen_cancel (struct GNUNET_DB_EventHandler *eh);


/**
 * Notify all that listen on @a es of an event.
 *
 * @param es specification of the event to generate
 * @param extra additional event data provided
 * @param extra_size number of bytes in @a extra
 */
void
ANASTASIS_DB_event_notify (const struct GNUNET_DB_EventHeaderP *es,
                           const void *extra,
                           size_t extra_size);

#endif
