Commit 5fd802f7 authored by jdelange's avatar jdelange

* src/po_hi_monitor.c

   include/po_hi_monitor.h
   - Implement the whole monitoring service



git-svn-id: https://tecsw.estec.esa.int/svn/taste/trunk/po-hi-c@3478 129961e7-ef38-4bb5-a8f7-c9a525a55882
parent 14d2366f
......@@ -33,6 +33,10 @@
#define __PO_HI_NB_BUSES 0
#endif
#ifndef __PO_HI_MONITOR_NB_FAILURES
#define __PO_HI_MONITOR_NB_FAILURES 10
#endif
#ifndef __PO_HI_NB_DEVICES
#define __PO_HI_NB_DEVICES 0
#endif
......@@ -44,7 +48,7 @@
#endif
/*
* \enum __po_hi_monitor_status_t
* \enum __po_hi_monitor_status_code_t
*
* \brief Status code for a bus/device. Indicated wether the
* entity is ok or not.
......@@ -54,7 +58,7 @@ typedef enum
po_hi_monitor_status_ok = 0, /* Working */
po_hi_monitor_status_ko = 1, /* Not working for unknown reason */
po_hi_monitor_status_unavailable = 2 /* No longer available, it used to work previously */
} __po_hi_monitor_status_t;
} __po_hi_monitor_status_code_t;
/*
......@@ -70,6 +74,20 @@ typedef enum
po_hi_monitor_failure_value = 1 /* Bad value was sent or received */
} __po_hi_monitor_failure_t;
/*
* \struct __po_hi_monitor_status_t
*
* \brief Structure that contains the status of an entity
*/
typedef struct
{
__po_hi_monitor_status_code_t status;
int n_failures;
__po_hi_monitor_failure_t* failures;
} __po_hi_monitor_status_t;
/*
* \fn __po_hi_monitor_init
*
......@@ -95,7 +113,7 @@ void __po_hi_monitor_init (void);
* second argument is invalid (e.g. NULL
* pointer).
*/
int __po_hi_monitor_get_status_port (const __po_hi_port_t port, __po_hi_monitor_status_t* );
int __po_hi_monitor_get_status_port (const __po_hi_port_t port, __po_hi_monitor_status_t*);
/*
* \fn __po_hi_monitor_get_status_device
......@@ -155,6 +173,8 @@ int __po_hi_monitor_get_status_bus (const __po_hi_bus_id, __po_hi_monitor_status
* not exist.
* - __PO_HI_ERROR_INVALID - the value of the second argument is
* invalid.
* - __PO_HI_TOOMANY - The max number of failures that can be
* registered was already reached.
*/
int __po_hi_monitor_report_failure_port (const __po_hi_port_t, const __po_hi_monitor_failure_t);
......@@ -180,6 +200,8 @@ int __po_hi_monitor_report_failure_port (const __po_hi_port_t, const __po_hi_mon
* not exist.
* - __PO_HI_ERROR_INVALID - the value of the second argument is
* invalid.
* - __PO_HI_TOOMANY - The max number of failures that can be
* registered was already reached.
*/
int __po_hi_monitor_report_failure_device (const __po_hi_device_id, const __po_hi_monitor_failure_t);
......@@ -206,6 +228,8 @@ int __po_hi_monitor_report_failure_device (const __po_hi_device_id, const __po_h
* not exist (invalid first argument).
* - __PO_HI_ERROR_INVALID - the value of the second argument is
* invalid.
* - __PO_HI_TOOMANY - The max number of failures that can be
* registered was already reached.
*/
int __po_hi_monitor_report_failure_bus (const __po_hi_bus_id, const __po_hi_monitor_failure_t);
......
......@@ -21,17 +21,17 @@
#include <deployment.h>
#include <po_hi_debug.h>
#include <po_hi_transport.h>
#include <po_hi_monitor.h>
#include <po_hi_returns.h>
#if __PO_HI_MONITOR_ENABLED == 1
#ifndef __PO_HI_MONITOR_NB_FAILURES
#define __PO_HI_MONITOR_NB_FAILURES 10
#endif
__po_hi_monitor_failure_t __po_hi_monitor_failures_devices[__PO_HI_NB_DEVICES][__PO_HI_MONITOR_NB_FAILURES];
__po_hi_monitor_failure_t __po_hi_monitor_failures_buses[__PO_HI_NB_BUSES][__PO_HI_MONITOR_NB_FAILURES];
__po_hi_monitor_status_t __po_hi_monitor_status_devices[__PO_HI_NB_DEVICES];
__po_hi_monitor_status_t __po_hi_monitor_status_buses[__PO_HI_NB_BUSES];
int __po_hi_monitor_n_failures_devices[__PO_HI_NB_DEVICES];
int __po_hi_monitor_n_failures_buses[__PO_HI_NB_BUSES];
void __po_hi_monitor_init (void)
......@@ -45,25 +45,38 @@ void __po_hi_monitor_init (void)
*/
for (i = 0 ; i < __PO_HI_NB_DEVICES ; i++)
{
__po_hi_monitor_status_devices[i] = po_hi_monitor_status_ok;
__po_hi_monitor_n_failures_devices[i] = 0;
}
for (i = 0 ; i < __PO_HI_NB_BUSES ; i++)
{
__po_hi_monitor_status_buses[i] = po_hi_monitor_status_ok;
__po_hi_monitor_n_failures_buses[i] = 0;
}
}
int __po_hi_monitor_get_status_port (const __po_hi_port_t port, __po_hi_monitor_status_t* status)
{
__po_hi_device_id associated_device;
__PO_HI_DEBUG_DEBUG ("[MONITOR] call __po_hi_monitor_get_status_port with argument %d (port) and 0x%x (status pointer)\n", port, status);
return __PO_HI_SUCCESS;
associated_device = __po_hi_get_device_from_port (port);
if (associated_device == invalid_device_id)
{
__PO_HI_DEBUG_DEBUG ("[MONITOR] This port is not associated to a valid device (device-id=%d)\n", associated_device);
return __PO_HI_UNAVAILABLE;
}
return __po_hi_monitor_get_status_device (associated_device, status);
}
int __po_hi_monitor_get_status_device (const __po_hi_device_id device,
__po_hi_monitor_status_t* status)
{
int n_failure;
uint32_t n_buses;
__po_hi_bus_id* buses;
uint32_t i;
__PO_HI_DEBUG_DEBUG ("[MONITOR] call __po_hi_monitor_get_status_device with argument %d (device) and 0x%x (status pointer)\n", device, status);
if ((device < 0) || (device >= __PO_HI_NB_DEVICES))
......@@ -71,29 +84,103 @@ int __po_hi_monitor_get_status_device (const __po_hi_device_id device,
__PO_HI_DEBUG_DEBUG ("[MONITOR] invalid device-id %d\n", device);
return __PO_HI_UNAVAILABLE;
}
*status = __po_hi_monitor_status_devices[device];
n_failure = __po_hi_monitor_n_failures_devices[device];
n_buses = __po_hi_transport_get_n_accessed_buses (device);
buses = __po_hi_transport_get_accessed_buses (device);
for (i = 0 ; i < n_buses ; i++)
{
if (__po_hi_monitor_get_status_bus (buses[i], status) == __PO_HI_SUCCESS)
{
if (status->status != po_hi_monitor_status_ok)
{
__PO_HI_DEBUG_DEBUG ("[MONITOR] return status of failed bus %d\n", i);
return __PO_HI_SUCCESS;
}
}
}
if (n_failure == 0)
{
status->status = po_hi_monitor_status_ok;
status->n_failures = 0;
status->failures = NULL;
}
else
{
status->status = po_hi_monitor_status_ko;
status->n_failures = n_failure;
status->failures = __po_hi_monitor_failures_devices[device];
}
return __PO_HI_SUCCESS;
}
int __po_hi_monitor_get_status_bus (const __po_hi_bus_id bus,
__po_hi_monitor_status_t* status)
int __po_hi_monitor_get_status_bus (const __po_hi_bus_id bus,
__po_hi_monitor_status_t* status)
{
int n_failure;
__PO_HI_DEBUG_DEBUG ("[MONITOR] call __po_hi_monitor_get_status_bus with argument %d (bus) and 0x%x (status pointer)\n", bus, status);
if ((bus < 0) || (bus >= __PO_HI_NB_BUSES))
{
__PO_HI_DEBUG_DEBUG ("[MONITOR] invalid bus-id %d\n", bus);
return __PO_HI_UNAVAILABLE;
}
n_failure = __po_hi_monitor_n_failures_buses[bus];
if (n_failure == 0)
{
status->status = po_hi_monitor_status_ok;
status->n_failures = 0;
status->failures = NULL;
}
else
{
status->status = po_hi_monitor_status_ko;
status->n_failures = n_failure;
status->failures = __po_hi_monitor_failures_buses[bus];
}
return __PO_HI_SUCCESS;
}
int __po_hi_monitor_report_failure_bus (const __po_hi_bus_id bus,
const __po_hi_monitor_failure_t failure)
{
int n_failure;
__PO_HI_DEBUG_DEBUG ("[MONITOR] call __po_hi_monitor_report_failure_bus with argument %d (bus) and %d (failure)\n", bus, failure);
if ((bus < 0) || (bus >= __PO_HI_NB_BUSES))
{
__PO_HI_DEBUG_DEBUG ("[MONITOR] invalid bus-id %d\n", bus);
return __PO_HI_UNAVAILABLE;
}
n_failure = __po_hi_monitor_n_failures_buses[bus];
if (n_failure >= __PO_HI_MONITOR_NB_FAILURES)
{
return __PO_HI_TOOMANY;
}
__po_hi_monitor_n_failures_buses[bus] = n_failure + 1;
__po_hi_monitor_failures_buses[bus][n_failure] = failure;
return __PO_HI_SUCCESS;
}
int __po_hi_monitor_report_failure_device (const __po_hi_device_id device,
const __po_hi_monitor_failure_t failure)
{
int n_failure;
__PO_HI_DEBUG_DEBUG ("[MONITOR] call __po_hi_monitor_report_failure_device with argument %d (device) and %d (failure)\n", device, failure);
if ((device < 0) || (device >= __PO_HI_NB_DEVICES))
......@@ -101,8 +188,17 @@ int __po_hi_monitor_report_failure_device (const __po_hi_device_id device,
__PO_HI_DEBUG_DEBUG ("[MONITOR] invalid device-id %d\n", device);
return __PO_HI_UNAVAILABLE;
}
__po_hi_monitor_status_devices[device] = po_hi_monitor_status_ko;
n_failure = __po_hi_monitor_n_failures_devices[device];
if (n_failure >= __PO_HI_MONITOR_NB_FAILURES)
{
return __PO_HI_TOOMANY;
}
__po_hi_monitor_n_failures_devices[device] = n_failure + 1;
__po_hi_monitor_failures_devices[device][n_failure] = failure;
return __PO_HI_SUCCESS;
}
......@@ -110,13 +206,29 @@ int __po_hi_monitor_report_failure_device (const __po_hi_device_id device,
int __po_hi_monitor_report_failure_port (const __po_hi_port_t port,
const __po_hi_monitor_failure_t failure)
{
__po_hi_device_id associated_device;
__PO_HI_DEBUG_DEBUG ("[MONITOR] call __po_hi_monitor_report_failure_port with argument %d (port) and %d (failure)\n", port, failure);
return __PO_HI_SUCCESS;
associated_device = __po_hi_get_device_from_port (port);
if (associated_device == invalid_device_id)
{
__PO_HI_DEBUG_DEBUG ("[MONITOR] This port is not associated to a valid device (device-id=%d)\n", associated_device);
return __PO_HI_UNAVAILABLE;
}
return __po_hi_monitor_report_failure_device (associated_device, failure);
}
int __po_hi_monitor_recover_bus (const __po_hi_bus_id bus)
{
__PO_HI_DEBUG_DEBUG ("[MONITOR] call __po_hi_monitor_recover_bus with argument %d\n", bus);
if ((bus < 0) || (bus >= __PO_HI_NB_BUSES))
{
__PO_HI_DEBUG_DEBUG ("[MONITOR] invalid bus-id %d\n", bus);
return __PO_HI_UNAVAILABLE;
}
__po_hi_monitor_n_failures_buses[bus] = 0;
return __PO_HI_SUCCESS;
}
......@@ -129,15 +241,23 @@ int __po_hi_monitor_recover_device (const __po_hi_device_id device)
return __PO_HI_UNAVAILABLE;
}
__po_hi_monitor_status_devices[device] = po_hi_monitor_status_ok;
__po_hi_monitor_n_failures_devices[device] = 0;
return __PO_HI_SUCCESS;
}
int __po_hi_monitor_recover_port (const __po_hi_port_t port)
{
__po_hi_device_id associated_device;
__PO_HI_DEBUG_DEBUG ("[MONITOR] call __po_hi_monitor_recover_port with argument %d\n", port);
return __PO_HI_SUCCESS;
associated_device = __po_hi_get_device_from_port (port);
if (associated_device == invalid_device_id)
{
__PO_HI_DEBUG_DEBUG ("[MONITOR] This port is not associated to a valid device (device-id=%d)\n", associated_device);
return __PO_HI_UNAVAILABLE;
}
return __po_hi_monitor_recover_device (associated_device);
}
#endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment