summaryrefslogtreecommitdiff
path: root/cesar/host/system
diff options
context:
space:
mode:
authorburet2008-04-25 09:08:24 +0000
committerburet2008-04-25 09:08:24 +0000
commite7d8a95df450338da2e8bea4ea2a416dec3562b8 (patch)
treef45a6fba5384ba106126ae153533321383e5fae0 /cesar/host/system
parent7925d5613b15c59c4d65322dfe684eb41bb0a220 (diff)
Proto fcall: re-organize host module and sub-modules.
git-svn-id: svn+ssh://pessac/svn/cesar/trunk@1911 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'cesar/host/system')
-rw-r--r--cesar/host/system/Module1
-rw-r--r--cesar/host/system/src/system.c117
-rw-r--r--cesar/host/system/system.h63
3 files changed, 181 insertions, 0 deletions
diff --git a/cesar/host/system/Module b/cesar/host/system/Module
new file mode 100644
index 0000000000..fd9e1697e9
--- /dev/null
+++ b/cesar/host/system/Module
@@ -0,0 +1 @@
+SOURCES := system.c \ No newline at end of file
diff --git a/cesar/host/system/src/system.c b/cesar/host/system/src/system.c
new file mode 100644
index 0000000000..b5d0a69179
--- /dev/null
+++ b/cesar/host/system/src/system.c
@@ -0,0 +1,117 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+
+ /**
+ * \file system.c
+ * \brief The system layer for fulminata.
+ * \ingroup host
+ */
+#include "common/std.h"
+#include <string.h>
+#include <stdio.h>
+#include <errno.h>
+#include "host/system/system.h"
+#ifndef UNIT_TEST
+#include "lib/swap.h"
+#include "host/syscall.h"
+#else /* UNIT_TEST */
+#include <unistd.h>
+#include <arpa/inet.h>
+#endif /* UNIT_TEST */
+
+/**
+ * initialize a static system context, called during station context creation.
+ * \param system system context to initialize
+ * \param sci sci which uses the system context
+ * \return 0 if ok, -1 if failed with errno=
+ * - EINVAL if system or station is NULL
+ */
+int system_init(system_ctx_t *system, sci_ctx_t *sci)
+{
+ DBG_ASSERT(system);
+ DBG_ASSERT(sci);
+ if((system == NULL)
+ || (sci == NULL))
+ {
+ errno = EINVAL;
+ return -1;
+ }
+
+ memset(system, '\0', sizeof(system_ctx_t));
+ system->sci = sci;
+ sci_register_callback(sci, SCI_MSG_TYPE_SYSTEM, system_recv, system);
+ return 0;
+}
+
+
+/**
+ * system message processing function; called by sci_recv()
+ * must be registred to sci layer with SCI_MSG_TYPE_SYSTEM type
+ * \param msg pointer to received message with sci pre-processing
+ * \param system pointer to current system context
+ * \return 0 if ok, -1 if failed with errno=
+ * - EINVAL if system or msg is NULL
+ * - EPROTOTYPE if system type != SYSTEM_TYPE_STATION_NAME
+ */
+int system_recv(sci_msg_t *msg, void *system_data)
+{
+ system_ctx_t *system;
+ int len = 0;
+
+ system = (system_ctx_t *)system_data;
+
+ DBG_ASSERT(system);
+ DBG_ASSERT(msg);
+ if((system == NULL)
+ || (msg == NULL))
+ {
+ errno = EINVAL;
+ return -1;
+ }
+
+ /* set header pointer in case of not already done */
+ msg->hdr.station = (struct station_msg_hdr *)(msg->data_begin);
+ /* check header content */
+ if(msg->hdr.station->type != SYSTEM_TYPE_STATION_NAME)
+ {
+ station_log(system->sci->station, STATION_LOG_WARNING, STATION_LOGTYPE_STATION,
+ "%s bad type %x", __FUNCTION__, msg->hdr.station->type);
+ errno = EPROTOTYPE;
+ return -1;
+ }
+
+ if(sci_msg_pop(msg, sizeof(struct station_msg_hdr)) < (int)sizeof(struct station_msg_hdr))
+ return -1;
+
+ /* init station name */
+ if(strlen((char *)(msg->data_begin)) + 1 > SYSTEM_STATION_NAME_MAX_SIZE)
+ {
+ station_log(system->sci->station, STATION_LOG_WARNING, STATION_LOGTYPE_STATION,
+ "%s station name too long %x", __FUNCTION__, strlen((char *)(msg->data_begin)) + 1);
+ errno = EPROTOTYPE;
+ return -1;
+ }
+ strcpy(system->station_name, (char *)(msg->data_begin));
+ len = (int)strlen((char *)(msg->data_begin)) + 1;
+ if(sci_msg_pop(msg, len) < len)
+ return -1;
+
+ if(msg->length > 0)
+ {
+ station_log(system->sci->station, STATION_LOG_WARNING, STATION_LOGTYPE_STATION,
+ "%s msg length > 0 (%d) after station name extraction",
+ __FUNCTION__,
+ msg->length);
+ return -1;
+ }
+ station_log(system->sci->station, STATION_LOG_INFO, STATION_LOGTYPE_STATION,
+ "%s station name set to '%s'",
+ __FUNCTION__,
+ system->station_name);
+ return 0;
+}
diff --git a/cesar/host/system/system.h b/cesar/host/system/system.h
new file mode 100644
index 0000000000..bdcc0798b9
--- /dev/null
+++ b/cesar/host/system/system.h
@@ -0,0 +1,63 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+
+ /**
+ * \file system.h
+ * \brief The system layer for fulminata.
+ * \ingroup host
+ */
+#ifndef host_system_h
+#define host_system_h
+
+#include <string.h>
+#include "maximus/common/types/system_types.h"
+#ifndef UNIT_TEST
+#include "lib/swap.h"
+#else /* UNIT_TEST */
+#include <arpa/inet.h>
+#endif /* UNIT_TEST */
+#include "host/fwd.h"
+#include "host/sci/sci.h"
+#include "host/station/station.h"
+
+struct station_ctx;
+struct sci_msg;
+
+/** type of system message; used by system msg header */
+typedef enum System_Type system_type_t;
+
+/** system context definition */
+struct system_ctx
+{
+ /** current sci context */
+ struct sci_ctx *sci;
+ /** station name */
+ char station_name[SYSTEM_STATION_NAME_MAX_SIZE];
+};
+
+/**
+ * initialize a static system context, called during station context creation.
+ * \param system system context to initialize
+ * \param sci sci which uses the system context
+ * \return 0 if ok, -1 if failed with errno=
+ * - EINVAL if system or station is NULL
+ */
+int system_init(system_ctx_t *system, sci_ctx_t *sci);
+
+/**
+ * system message processing function; called by sci_recv()
+ * must be registred to sci layer with SCI_MSG_TYPE_SYSTEM type
+ * \param msg pointer to received message with sci pre-processing
+ * \param system pointer to current system context
+ * \return 0 if ok, -1 if failed with errno=
+ * - EINVAL if system or msg is NULL
+ * - EPROTOTYPE if system type != SYSTEM_TYPE_STATION_NAME
+ */
+int system_recv(sci_msg_t *msg, void *system);
+
+#endif /* host_system_h */