summaryrefslogtreecommitdiff
path: root/cesar/host/netclock.h
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/host/netclock.h')
-rw-r--r--cesar/host/netclock.h158
1 files changed, 158 insertions, 0 deletions
diff --git a/cesar/host/netclock.h b/cesar/host/netclock.h
new file mode 100644
index 0000000000..55a4c57ddb
--- /dev/null
+++ b/cesar/host/netclock.h
@@ -0,0 +1,158 @@
+#ifndef NETCLOCK_H_
+#define NETCLOCK_H_
+
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+
+ /**
+ * \file netclock.h
+ * \brief The netclock event processing structures for fulminata.
+ * \ingroup host
+ *
+ * This file descibe the content of netclock structures used by fulminata sci layer
+ *
+ * \todo
+ */
+
+#include "lib/set.h"
+#include "maximus/common/types/networkclock_types.h"
+#include "host/fwd.h"
+#include "host/sci.h"
+
+struct sci_msg;
+struct station_ctx;
+
+/** netclock event type */
+typedef enum Network_Clock_Type netclock_type_t;
+
+/** netclock message id */
+typedef int netclock_id_t;
+
+struct netclock_callback
+{
+ netclock_id_t id; /** netclock message identifier (allow to retrieved the good message for callback) */
+ tick_t tick; /** the scheduled tick */
+ void (*function)(void *data); /** callback function */
+ void *data; /** callback private data to be set as parameter */
+ set_node_t node; /** list reference */
+};
+
+/*
+ * The table of registred callback is managed a simple as possible with an incremental search for
+ * wanted function.
+ * The best solution would be a hash table of linked list with id as the hash key;
+ * then the list nodes whould have to be into a pool of available nodes for the hash table.
+ */
+
+struct netclock_ctx {
+ struct sci_ctx *sci; /** current sci context */
+ set_t callback_set; /** set list of waiting callback functions */
+ int callback_nb; /** number of registred callback */
+ netclock_id_t current_id; /** current netclock id to put into the msg */
+};
+
+//BEGIN_DECLS
+
+/**
+ * netclock context, called during station context creation. It will manage the callback of
+ * received events
+ * \param station station which uses the sci context
+ * \return the new sci context, NULL if station is NULL
+ */
+netclock_ctx_t *netclock_new(struct station_ctx *station);
+
+/**
+ * netclock context destruction with memory freeing.
+ * \param netclock netclock context to destroy
+ */
+void netclock_free(netclock_ctx_t *netclock);
+
+/**
+ * initialize a static netclock context, called during station context creation.
+ * \param netclock netclock context to initialize
+ * \param sci sci which uses the netclock context
+ * \return 0 if ok, -1 if failed with errno=
+ * - EINVAL if netclock or station is NULL
+ */
+int netclock_init(netclock_ctx_t *netclock, sci_ctx_t *sci);
+
+/**
+ * schedule a netclock event inside maximus netclock manager
+ * \param netclock current netclock context
+ * \param callback callback context to insert into callback queue
+ * \param event type of event (phy, system...)
+ * \param tick next tick to start the event
+ * \param function pointer to the callback function to process the received message
+ * \param data user data to be included into callback function as 'data' parameter
+ * \param id pointer filled with id used to create the netclock msg
+ * \return 0 if ok, -1 if failed with errno:
+ * - EINVAL if netclock or msg is null, or if tick < current_tick
+ * - ENOSPC if there is no more place to register a callback function
+ */
+int netclock_schedule(
+ netclock_ctx_t *netclock,
+ netclock_callback_t *callback,
+ netclock_type_t type,
+ tick_t schedule_tick,
+ void (*callback_function)(void *data),
+ void *callback_data,
+ netclock_id_t *id);
+
+/**
+ * remove a scheduled netclock event
+ * \param netclock current netclock context
+ * \param id id of scheduled event
+ * \return 0 if ok, -1 if failed with errno:
+ * - EINVAL if netclock is null
+ * - ENOENT if id is not registred
+ */
+int netclock_unschedule(
+ netclock_ctx_t *netclock,
+ netclock_id_t id);
+
+/**
+ * fill a blank netclock header with needed msg type and length
+ * \param netclock netclock current context
+ * \param msg current msg to fill
+ * \param event type of event (phy, system...)
+ * \param type type of action for message: insert or remove
+ * \return 0 if ok, -1 if failed with errno:
+ * - EINVAL if sci or hdr are NULL, or if type or length are out of range
+ */
+int netclock_fill_hdr(
+ netclock_ctx_t *netclock,
+ sci_msg_t *msg,
+ netclock_type_t type,
+ int flags,
+ tick_t tick);
+
+/**
+ * check if a waiting callback is still valid (if planned tick is < current tick)
+ * \param current_tick system/station current tick value
+ * \param callback pointer to checked callback
+ * \return 0 if not more valid, 1 if still valid
+ */
+//int netclock_is_callback_valid(tick_t current_tick, struct netclock_callback *callback);
+
+/**
+ * Process netclock message received by the sci layer.
+ * This function must be registred to SCI layer with SCI_MSG_TYPE_NETWORK_CLOCK type.
+ * It will execute the netclock registred callback function
+ * \param msg message to process
+ * \param netclock netclock current context
+ * \return 0 if ok, -1 if failed with errno=
+ * - EINVAL if netclock or msg is NULL
+ * - errno from sci_send() call
+ * */
+int netclock_recv(sci_msg_t *msg, void *netclock);
+
+void netclock_hdr_dump(netclock_msg_hdr_t *hdr, int fd, char *buffer, int size);
+
+//END_DECLS
+
+#endif /*NETCLOCK_H_*/