]> rtime.felk.cvut.cz Git - frescor/fna.git/commitdiff
starting to build the negotiations infrastructure
authorsangorrin <sangorrin@35b4ef3e-fd22-0410-ab77-dab3279adceb>
Tue, 1 Apr 2008 09:55:07 +0000 (09:55 +0000)
committersangorrin <sangorrin@35b4ef3e-fd22-0410-ab77-dab3279adceb>
Tue, 1 Apr 2008 09:55:07 +0000 (09:55 +0000)
git-svn-id: http://www.frescor.org/private/svn/frescor/fna/trunk@1054 35b4ef3e-fd22-0410-ab77-dab3279adceb

13 files changed:
src_frescan/frescan.c
src_frescan/frescan.h [new file with mode: 0644]
src_frescan/frescan_config.h
src_frescan/frescan_data.h
src_frescan/frescan_hw_buffer.h
src_frescan/frescan_packets.h
src_frescan/frescan_queues.h
src_frescan/frescan_reply_objects.c [new file with mode: 0644]
src_frescan/frescan_reply_objects.h [new file with mode: 0644]
src_frescan/frescan_requests_queue.c [new file with mode: 0644]
src_frescan/frescan_requests_queue.h [new file with mode: 0644]
src_frescan/frescan_servers.h
src_frescan/frescan_servers_replenishments.h

index ae6134dfda45bcb922eaba474e3bb4c7db7206e2..30fbc02b3e724a6f8d092fbd6d0584f28c382aef 100644 (file)
@@ -27,7 +27,7 @@
 #include <string.h> // memcpy
 
 #include <drivers/can.h>       // can_chip_t, can_frame_t
-#include <drivers/frescan.h>   // frescan_init_params_t, frescan_send_params_t
+#include "frescan.h"           // frescan_init_params_t, frescan_send_params_t
 #include "frescan_queues.h"    // init, enqueue, requeue
 #include "frescan_data.h"      // init, the_networks
 #include "frescan_servers.h"   // init, frame_sent
diff --git a/src_frescan/frescan.h b/src_frescan/frescan.h
new file mode 100644 (file)
index 0000000..04bdde8
--- /dev/null
@@ -0,0 +1,156 @@
+/*!
+ * @file frescan.h
+ *
+ * @brief interface of the FRESCAN protocol
+ *
+ * @version 0.01
+ *
+ * @date 20-Feb-2008
+ *
+ * @author
+ *      Daniel Sangorrin
+ *
+ * @comments
+ *
+ * This file contains the interface to the FRESCAN protocol
+ *
+ * @license
+ *
+ * See MaRTE OS license
+ *
+ */
+
+#ifndef _MARTE_FRESCAN_H_
+#define _MARTE_FRESCAN_H_
+
+#include <stdint.h>  // uint8_t
+#include <stdbool.h> // bool
+#include <unistd.h>  // size_t
+
+typedef uint8_t frescan_network_t;
+typedef uint8_t frescan_node_t;
+typedef uint8_t frescan_channel_t;
+typedef uint8_t frescan_prio_t;
+typedef uint8_t frescan_ss_t;
+typedef uint32_t frescan_budget_t;
+
+/**
+ * frescan_flags_t - frescan flags
+ *
+ * @FRESCAN_SS: send the message using sporadic servers
+ * @FRESCAN_FP: send the message using fixed priorities
+ * @FRESCAN_POLL: no buffer copy, only pointer and use the ID to poll status
+ * @FRESCAN_SYNC: no buffer copy, only pointer and block until it is sent
+ * @FRESCAN_ASYNC: use buffer copy and return immediately
+ */
+
+typedef enum {
+        FRESCAN_SS    = 1<<4,  // sporadic server
+        FRESCAN_FP    = 1<<3,  // fixed priorities
+        FRESCAN_POLL  = 1<<2,  // polling
+        FRESCAN_SYNC  = 1<<1,  // synchronous
+        FRESCAN_ASYNC = 1      // asynchronous
+} frescan_flags_t;
+
+/**
+ * frescan_send_params_t - send parameters
+ *
+ * @net: the network to use
+ * @to: the node where the message shoud be sent to
+ * @channel: the channel in 'to' where the message shoud be sent to
+ * @flags: the flags (see frescan_flags_t)
+ * @prio: the priority for the message if (flags & FRESCAN_FP)
+ * @ss: the sporadic server for the message if (flags & FRESCAN_SS)
+ */
+
+typedef struct {
+        frescan_network_t net;
+        frescan_node_t to;
+        frescan_channel_t channel;
+        frescan_flags_t flags;
+        union {
+                frescan_prio_t prio;
+                frescan_ss_t ss;
+        };
+} frescan_send_params_t;
+
+/**
+ * frescan_recv_params_t - receive parameters
+ *
+ * @net: the network to use
+ * @channel: the channel from which we want to extract a message
+ * @flags: FRESCAN_SYNC/ASYNC
+ */
+
+typedef struct {
+        frescan_network_t net;
+        frescan_channel_t channel;
+        frescan_flags_t flags;
+} frescan_recv_params_t;
+
+/**
+ * frescan_init_params_t - initialization parameters
+ *
+ * @net: network to initialize (minor number ie: /dev/can0 -> 0)
+ * @node: set the local node identificator
+ * @tx_fp_max_prio: maximum number of priorities for the fixed priority
+ *                  transmission queues. (prio = 0 .. max_prio - 1)
+ * @rx_num_of_channels: number of rx channels (0 .. rx_num_of_channels - 1)
+ * @rx_channel_max_prio: array (range rx_num_of_channels) saying the number
+ *                       of priorities for each channel. If this parameter is
+ *                       NULL tx_fp_max_prio will be used for all queues.
+ */
+
+typedef struct {
+        frescan_network_t net;
+        frescan_node_t node;
+        uint32_t tx_fp_max_prio;
+        uint32_t rx_num_of_channels;
+        uint32_t *rx_channel_max_prio;
+} frescan_init_params_t;
+
+/**
+ * frescan_init - initializes the network and the internal structures
+ *
+ * @params: the initialization parameters
+ */
+
+int frescan_init(frescan_init_params_t *params);
+
+/**
+ * frescan_send - send a message
+ *
+ * @params: the parameters needed by the protocol to send the message
+ * @msg: the message buffer
+ * @size: the size of the message
+ *
+ * This is one of the main functions of the protocol and it provides the
+ * means to send a message through the protocol stack.
+ */
+
+int frescan_send(const frescan_send_params_t *params,
+                 const uint8_t *msg,
+                 const size_t size);
+
+/**
+ * frescan_recv - receive a message
+ *
+ * @params: the parameters needed by the protocol to receive the message
+ * @msg: the message buffer
+ * @size: the size of the message buffer
+ * @recv_bytes: the number of bytes received
+ * @from: the node that sent the message
+ * @prio: the priority of the message
+ *
+ * This is one of the main functions of the protocol and it provides the
+ * means to receive a message through the protocol stack.
+ */
+
+int frescan_recv(const frescan_recv_params_t *params,
+                 uint8_t *msg,
+                 const size_t size,
+                 size_t *recv_bytes,
+                 frescan_node_t *from,
+                 frescan_prio_t *prio);
+
+#endif // _MARTE_FRESCAN_H_
index 091f5b7d471dfbae9899e4db8be205cef8e6cc6d..088322062be3d8f47b83e2d78b7c8d8354fb24dc 100644 (file)
@@ -36,6 +36,7 @@
 #define FRESCAN_BACKGROUND_PRIO   0
 #define FRESCAN_MX_REPLY_OBJECTS  40
 #define FRESCAN_REPL_THREAD_PRIO  60
+#define FRESCAN_MX_REQUESTS       40
 
 #define FRESCAN_MLOCK_T            unsigned
 #define FRESCAN_CREATE_LOCK(l)
index 3d76a0d9c2b9a51197c7d30fed06f7c8176b1270..079a4e26e9e41f6fc9c3aec4a6f46736d1155ce5 100644 (file)
@@ -32,7 +32,7 @@
 #include <misc/linux_list.h> // struct list_head
 #include <misc/freelist.h>   // freelist_t
 
-#include <drivers/frescan.h> // frescan_node_t, _prio_t, _budget_t
+#include "frescan.h"         // frescan_node_t, _prio_t, _budget_t
 #include "frescan_config.h"  // FRESCAN_MLOCK_T, FRESCAN_MX_XXX
 #include "frescan_packets.h" // frescan_packet_t
 #include "frescan_servers_replenishments.h" // frescan_repl_op_t
@@ -100,6 +100,18 @@ extern frescan_server_data_t the_servers_pool[FRESCAN_MX_NETWORKS][FRESCAN_MX_ID
 extern freelist_t the_servers_pool_freelist[FRESCAN_MX_NETWORKS];
 extern frescan_server_data_t the_active_servers[FRESCAN_MX_NETWORKS];
 
+/**
+ * frescan_contract_t
+ */
+
+typedef struct {
+        frescan_budget_t max_budget;
+        struct timespec  min_period;
+        frescan_budget_t min_budget;
+        struct timespec  max_period;
+        frescan_prio_t prio;
+} frescan_contract_t;
+
 /**
  * frescan_prio_queue_t - priority queue
  *
index f1b1b4fabcf355024070bff3b3ab4b0b7a34cbec..c47f9d3769d46c492423d3384709a62c0faf05ad 100644 (file)
@@ -26,7 +26,7 @@
 #ifndef _MARTE_FRESCAN_HW_BUFFER_H_
 #define _MARTE_FRESCAN_HW_BUFFER_H_
 
-#include <drivers/frescan.h>
+#include "frescan.h"
 
 extern int frescan_hw_buffer_update(frescan_network_t net);
 
index 47a5de45fdfbf08d09e086c098a90502eac82732..62e57489a24d65752363fea649de1b4c81a9b213 100644 (file)
@@ -26,7 +26,7 @@
 #define _MARTE_FRESCAN_PACKETS_H_
 
 #include <stdint.h>           // uint8_t ...
-#include <drivers/frescan.h>  // frescan_flags_t
+#include "frescan.h"          // frescan_flags_t
 #include <misc/linux_list.h>  // struct list_head
 #include <drivers/can.h>      // can_frame_t
 
index 422717370ab976c0af70f19eaaa7e92b04ec702b..ce4c8afaeb8f5acbe5f36643142e5c479314c3ce 100644 (file)
@@ -27,7 +27,7 @@
 #include <stdint.h>           // uint8_t
 #include <stdbool.h>          // bool
 
-#include <drivers/frescan.h>  // frescan_prio_t
+#include "frescan.h"          // frescan_prio_t
 #include "frescan_packets.h"  // frescan_packet_t
 #include "frescan_data.h"
 
diff --git a/src_frescan/frescan_reply_objects.c b/src_frescan/frescan_reply_objects.c
new file mode 100644 (file)
index 0000000..d741397
--- /dev/null
@@ -0,0 +1,264 @@
+/*!
+ * @file frescan_reply_objects.h
+ *
+ * @brief FRESCAN reply objects
+ *
+ * This module contains the definition of the data object and operations to
+ * create a pool of objects, obtain the id of an unused object, wait upon it,
+ * signal it, and finish using it.
+ *
+ * @version 0.01
+ *
+ * @date 1-Apr-2008
+ *
+ * @author Daniel Sangorrin <daniel.sangorrin@unican.es>
+ *
+ */
+
+#include <misc/freelist.h>
+#include "frescan_reply_objects.h"
+#include "fosa_mutexes_and_condvars.h"
+#include "frescan_config.h"
+#include "frescan_debug.h"
+
+static bool is_initialized = false;
+
+/**
+ * the_reply_objects
+ *
+ * We will use a freelist to allocate and free the reply object. Reply objects
+ * are FOSA conditional variables (we can't use synchobjects because they are
+ * only for bound-workload) stored in an array together with their condition
+ * and a mutex variable to control the access and to be able to wait and
+ * signal the conditional variables. We could have used semaphores instead, but
+ * it would introduce a dependency on the OS because they are not in FOSA.
+ *
+ **/
+
+static fosa_mutex_t freelist_mutex;
+
+struct replyobj_t {
+        bool is_work_done;
+        fosa_cond_t cond;
+        fosa_mutex_t mutex;
+};
+
+static struct replyobj_t the_reply_objects[FRESCAN_MX_REPLY_OBJECTS];
+static freelist_t freelist;
+
+/**
+ * frescan_replyobjects_init()
+ *
+ * Init the freelist and its mutex. The conditional variables are not
+ * initialized here but when allocating a reply object. This can be more
+ * efficient for memory usage in some OS (not in MaRTE OS though).
+ *
+ **/
+
+int frescan_replyobjects_init(int max_ceiling)
+{
+        int err;
+
+        err = fosa_mutex_init(&freelist_mutex, max_ceiling);
+        if (err != 0) return err;
+
+        err = freelist_init(&freelist, FRESCAN_MX_REPLY_OBJECTS);
+        if (err != 0) return err;
+
+        is_initialized = true;
+        return 0;
+}
+
+/**
+ * frescan_replyobject_alloc()
+ *
+ * Allocate an reply object with the freelist_mutex locked and then initialize
+ * its cond variable, condition (predicate) and mutex. The ID of the allocated
+ * reply object represents the position in the array the_reply_objects.
+ *
+ **/
+
+int frescan_replyobject_alloc(frescan_robj_id_t *id, int ceiling)
+{
+        int err, pos;
+
+        DEBUG(FRESCAN_REPLYOBJ_ENABLE_DEBUG,
+              "allocating reply object, is_initialized=%d\n", is_initialized);
+
+        if (is_initialized == false) return -1;
+
+        err = fosa_mutex_lock(&freelist_mutex);
+        if (err != 0) return err;
+
+                pos = freelist_alloc(&freelist);
+                if (pos < 0) goto locked_error;
+
+        err = fosa_mutex_unlock(&freelist_mutex);
+        if (err != 0) return err;
+
+        err = fosa_cond_init(&the_reply_objects[pos].cond);
+        if (err != 0) return err;
+
+        the_reply_objects[pos].is_work_done = false;
+        *id = (unsigned int)pos;
+
+        err = fosa_mutex_init(&the_reply_objects[pos].mutex, ceiling);
+        if (err != 0) return err;
+
+        DEBUG(FRESCAN_REPLYOBJ_ENABLE_DEBUG,
+              "reply object allocated, id=%d\n", *id);
+
+        return 0;
+
+locked_error:
+        fosa_mutex_unlock(&freelist_mutex);
+        return pos;
+}
+
+/**
+ * frescan_replyobject_free()
+ *
+ * Destroy the cond variable and then free the replyobject
+ *
+ **/
+
+int frescan_replyobject_free(frescan_robj_id_t id)
+{
+        int err;
+
+        DEBUG(FRESCAN_REPLYOBJ_ENABLE_DEBUG,
+              "free reply id=%d, is_initialized=%d\n", id, is_initialized);
+
+        if (is_initialized == false) return -1;
+
+        err = fosa_mutex_lock(&freelist_mutex);
+        if (err != 0) return err;
+
+                err = freelist_free(&freelist, id);
+                if (err != 0) goto locked_error;
+
+                err = fosa_cond_destroy(&the_reply_objects[id].cond);
+                if (err != 0) return err;
+
+                err = fosa_mutex_destroy(&the_reply_objects[id].mutex);
+                if (err != 0) return err;
+
+                the_reply_objects[id].is_work_done = false;
+
+        err = fosa_mutex_unlock(&freelist_mutex);
+        if (err != 0) return err;
+
+        return 0;
+
+locked_error:
+        fosa_mutex_unlock(&freelist_mutex);
+        return err;
+}
+
+/**
+ * frescan_replyobject_signal()
+ *
+ * Signal the cond variable
+ *
+ **/
+
+int frescan_replyobject_signal(frescan_robj_id_t id)
+{
+        int err;
+
+        DEBUG(FRESCAN_REPLYOBJ_ENABLE_DEBUG,
+              "is_initialized=%d\n", is_initialized);
+        if (is_initialized == false) return -1;
+
+        DEBUG(FRESCAN_REPLYOBJ_ENABLE_DEBUG,
+              "taking mutex of the reply id=%d\n", id);
+        err = fosa_mutex_lock(&the_reply_objects[id].mutex);
+        if (err != 0) return err;
+
+                the_reply_objects[id].is_work_done = true;
+
+                DEBUG(FRESCAN_REPLYOBJ_ENABLE_DEBUG,
+                      "signal the cond variable\n");
+                err = fosa_cond_signal(&the_reply_objects[id].cond);
+                if (err != 0) goto locked_error;
+
+        err = fosa_mutex_unlock(&the_reply_objects[id].mutex);
+        if (err != 0) return err;
+
+        return 0;
+
+locked_error:
+        ERROR("locked error %d\n", err);
+        fosa_mutex_unlock(&the_reply_objects[id].mutex);
+        return err;
+}
+
+/**
+ * frescan_replyobject_wait()
+ *
+ * Wait on the cond variable.
+ *
+ **/
+
+int frescan_replyobject_wait(frescan_robj_id_t id)
+{
+        int err;
+
+        if (is_initialized == false) return -1;
+
+        err = fosa_mutex_lock(&the_reply_objects[id].mutex);
+        if (err != 0) return err;
+
+                while (the_reply_objects[id].is_work_done == false) {
+                        err = fosa_cond_wait(&the_reply_objects[id].cond,
+                                             &the_reply_objects[id].mutex);
+                        if (err != 0) goto locked_error;
+                }
+
+                the_reply_objects[id].is_work_done = false;
+
+        err = fosa_mutex_unlock(&the_reply_objects[id].mutex);
+        if (err != 0) return err;
+
+        return 0;
+
+locked_error:
+        fosa_mutex_unlock(&the_reply_objects[id].mutex);
+        return err;
+}
+
+/**
+ * frescan_replyobject_timedwait()
+ *
+ * Wait on the cond variable with a timeout.
+ *
+ **/
+
+int frescan_replyobject_timedwait(frescan_robj_id_t id,
+                                  const struct timespec *abstime)
+{
+        int err;
+
+        if (is_initialized == false) return -1;
+
+        err = fosa_mutex_lock(&the_reply_objects[id].mutex);
+        if (err != 0) return err;
+
+        while (the_reply_objects[id].is_work_done == false) {
+                err = fosa_cond_timedwait(&the_reply_objects[id].cond,
+                                          &the_reply_objects[id].mutex,
+                                          abstime);
+                if (err != 0) goto locked_error;
+        }
+
+        the_reply_objects[id].is_work_done = false;
+
+        err = fosa_mutex_unlock(&the_reply_objects[id].mutex);
+        if (err != 0) return err;
+
+        return 0;
+
+locked_error:
+        fosa_mutex_unlock(&the_reply_objects[id].mutex);
+        return err;
+}
diff --git a/src_frescan/frescan_reply_objects.h b/src_frescan/frescan_reply_objects.h
new file mode 100644 (file)
index 0000000..e570baa
--- /dev/null
@@ -0,0 +1,35 @@
+/*!
+ * @file frescan_reply_objects.h
+ *
+ * @brief FRESCAN reply objects
+ *
+ * This module contains the definition of the data object and operations to
+ * create a pool of objects, obtain the id of an unused object, wait upon it,
+ * signal it, and finish using it.
+ *
+ * @version 0.01
+ *
+ * @date 1-Apr-2008
+ *
+ * @author Daniel Sangorrin <daniel.sangorrin@unican.es>
+ *
+ */
+
+#ifndef _FRESCAN_REPLY_OBJECTS_H_
+#define _FRESCAN_REPLY_OBJECTS_H_
+
+#include <time.h> /* for timespec */
+#include "fosa_opaque_types.h" /* for FOSA_ETIMEDOUT */
+
+typedef unsigned int frescan_robj_id_t; /* 0 .. MX_REPLY_OBJECTS-1 */
+#define FRESCAN_ETIMEDOUT FOSA_ETIMEDOUT
+
+extern int frescan_replyobjects_init(int max_ceiling);
+extern int frescan_replyobject_alloc(frescan_robj_id_t *id, int ceiling);
+extern int frescan_replyobject_free(frescan_robj_id_t id);
+extern int frescan_replyobject_signal(frescan_robj_id_t id);
+extern int frescan_replyobject_wait(frescan_robj_id_t id);
+extern int frescan_replyobject_timedwait(frescan_robj_id_t id,
+                                         const struct timespec *abstime);
+
+#endif // _FRESCAN_REPLY_OBJECTS_H_
diff --git a/src_frescan/frescan_requests_queue.c b/src_frescan/frescan_requests_queue.c
new file mode 100644 (file)
index 0000000..2c6f81b
--- /dev/null
@@ -0,0 +1,291 @@
+/*!
+ * @file frescan_requests_queue.c
+ *
+ * @brief FRESCAN requests queue
+ *
+ * This module contains an operation to create the queue, an operation to
+ * enqueue a message (with a request), and an operation to
+ * dequeue a message.
+ *
+ * @version 0.01
+ *
+ * @date 1-Apr-2008
+ *
+ * @author Daniel Sangorrin <daniel.sangorrin@unican.es>
+ *
+ */
+
+#include <misc/freelist.h>
+#include <misc/linux_list.h>
+#include "frescan.h"
+#include "frescan_requests_queue.h"
+#include "frescan_config.h"
+#include "fosa_mutexes_and_condvars.h"
+
+static bool is_initialized = false;
+
+/**
+ * the_requests_pool
+ *
+ * We will use a freelist to allocate and free the requests.
+ *
+ **/
+
+struct request_t {
+        frescan_req_type_t  type;
+        frescan_robj_id_t   reply;
+        frescan_contract_t  *contract;
+        frescan_node_t      src;
+        struct list_head    request_list;
+        int pool_pos;
+};
+
+static fosa_mutex_t requests_mutex;
+static fosa_cond_t  requests_cond;
+
+static struct request_t the_requests_pool[FRESCAN_MX_REQUESTS];
+static freelist_t freelist;
+static struct request_t the_requests_list;
+
+/**
+ * frescan_requests_init()
+ *
+ * Init the freelist, requests list, cond var and mutex.
+ *
+ **/
+
+int frescan_requests_init(int max_ceiling)
+{
+        int err;
+
+        err = fosa_mutex_init(&requests_mutex, max_ceiling);
+        if (err != 0) return err;
+
+        err = fosa_cond_init(&requests_cond);
+        if (err != 0) return err;
+
+        err = freelist_init(&freelist, FRESCAN_MX_REQUESTS);
+        if (err != 0) return err;
+
+        INIT_LIST_HEAD(&the_requests_list.request_list);
+
+        is_initialized = true;
+        return 0;
+}
+
+/**
+ * frescan_request_alloc()
+ *
+ * Allocate a request with the mutex locked
+ *
+ **/
+
+int frescan_request_alloc(frescan_request_id_t *id)
+{
+        int err, pos;
+
+        if (is_initialized == false) return -1;
+
+        err = fosa_mutex_lock(&requests_mutex);
+        if (err != 0) return err;
+
+                pos = freelist_alloc(&freelist);
+                if (pos < 0) goto locked_error;
+
+        err = fosa_mutex_unlock(&requests_mutex);
+        if (err != 0) return err;
+
+        *id = (unsigned int)pos;
+        the_requests_pool[*id].pool_pos = pos;
+
+        return 0;
+
+locked_error:
+        fosa_mutex_unlock(&requests_mutex);
+        return pos;
+}
+
+/**
+ * frescan_request_free()
+ *
+ * free the request from the pool
+ *
+ **/
+
+int frescan_request_free(frescan_request_id_t id)
+{
+        int err;
+
+        if (is_initialized == false) return -1;
+
+        err = fosa_mutex_lock(&requests_mutex);
+        if (err != 0) return err;
+
+                err = freelist_free(&freelist, id);
+                if (err != 0) goto locked_error;
+
+        err = fosa_mutex_unlock(&requests_mutex);
+        if (err != 0) return err;
+
+        return 0;
+
+locked_error:
+        fosa_mutex_unlock(&requests_mutex);
+        return err;
+}
+
+/**
+ * frescan_request_set_type()
+ *
+ **/
+
+int frescan_request_set_type(frescan_request_id_t id, frescan_req_type_t type)
+{
+        the_requests_pool[id].type = type;
+        return 0;
+}
+
+/**
+ * frescan_request_set_reply()
+ *
+ **/
+
+int frescan_request_set_reply(frescan_request_id_t id, frescan_robj_id_t reply)
+{
+        the_requests_pool[id].reply = reply;
+        return 0;
+}
+
+/**
+ * frescan_request_set_contract()
+ *
+ **/
+
+int frescan_request_set_contract(frescan_request_id_t id,
+                                 frescan_contract_t *contract)
+{
+        the_requests_pool[id].contract = contract;
+        return 0;
+}
+
+/**
+ * frescan_request_set_src()
+ *
+ **/
+
+int frescan_request_set_src(frescan_request_id_t id, frescan_node_t src)
+{
+        the_requests_pool[id].src = src;
+        return 0;
+}
+
+/**
+ * frescan_request_get_type()
+ *
+ **/
+
+int frescan_request_get_type(frescan_request_id_t id, frescan_req_type_t *type)
+{
+        *type = the_requests_pool[id].type;
+        return 0;
+}
+
+/**
+ * frescan_request_get_reply()
+ *
+ **/
+
+int frescan_request_get_reply(frescan_request_id_t id, frescan_robj_id_t *reply)
+{
+        *reply = the_requests_pool[id].reply;
+        return 0;
+}
+
+/**
+ * frescan_request_get_contract()
+ *
+ **/
+
+int frescan_request_get_contract(frescan_request_id_t id,
+                                 frescan_contract_t **contract)
+{
+        *contract = the_requests_pool[id].contract;
+        return 0;
+}
+
+/**
+ * frescan_request_get_src()
+ *
+ **/
+
+int frescan_request_get_src(frescan_request_id_t id, frescan_node_t *src)
+{
+        *src = the_requests_pool[id].src;
+        return 0;
+}
+
+/**
+ * frescan_requestqueue_enqueue()
+ *
+ **/
+
+int frescan_requestqueue_enqueue(frescan_request_id_t id)
+{
+        int err;
+
+        err = fosa_mutex_lock(&requests_mutex);
+        if (err != 0) return err;
+
+        list_add_tail(&the_requests_list.request_list,
+                      &the_requests_pool[id].request_list);
+
+        err = fosa_cond_signal(&requests_cond);
+        if (err != 0) goto locked_error;
+
+        err = fosa_mutex_unlock(&requests_mutex);
+        if (err != 0) return err;
+
+        return 0;
+
+locked_error:
+        fosa_mutex_unlock(&requests_mutex);
+        return err;
+}
+
+/**
+ * frescan_requestqueue_dequeue()
+ *
+ **/
+
+int frescan_requestqueue_dequeue(frescan_request_id_t *id)
+{
+        int err;
+        struct list_head *pos;
+        struct request_t *request;
+
+        err = fosa_mutex_lock(&requests_mutex);
+        if (err != 0) return err;
+
+        while (list_empty(&the_requests_pool[*id].request_list)) {
+                err = fosa_cond_wait(&requests_cond, &requests_mutex);
+                if (err != 0) goto locked_error;
+        }
+
+        list_for_each(pos, &the_requests_pool[*id].request_list) {
+                request = list_entry(pos, struct request_t, request_list);
+                break;
+        }
+
+        list_del(&request->request_list);
+
+        *id = request->pool_pos;
+
+        err = fosa_mutex_unlock(&requests_mutex);
+        if (err != 0) return err;
+
+        return 0;
+
+locked_error:
+        fosa_mutex_unlock(&requests_mutex);
+        return err;
+}
diff --git a/src_frescan/frescan_requests_queue.h b/src_frescan/frescan_requests_queue.h
new file mode 100644 (file)
index 0000000..3ae1108
--- /dev/null
@@ -0,0 +1,66 @@
+/*!
+ * @file frescan_requests_queue.h
+ *
+ * @brief FRESCAN requests queue
+ *
+ * This module contains an operation to create the queue, an operation to
+ * enqueue a message (with a request), and an operation to
+ * dequeue a message.
+ *
+ * @version 0.01
+ *
+ * @date 1-Apr-2008
+ *
+ * @author Daniel Sangorrin <daniel.sangorrin@unican.es>
+ *
+ */
+
+#ifndef _FRESCAN_REQUESTS_QUEUE_H_
+#define _FRESCAN_REQUESTS_QUEUE_H_
+
+#include "frescan_data.h"          // frescan_contract_t
+#include "frescan_reply_objects.h" // frescan_robj_id_t
+
+typedef unsigned int frescan_request_id_t; /* 0 .. MX_REQUESTS */
+
+typedef enum {
+        FRESCAN_NEGOTIATE   =  0,  // Negotiate a contract
+        FRESCAN_RENEGOTIATE =  1,  // Renegotiate a contract
+        FRESCAN_CANCEL      =  2,  // Cancel a contract
+ } frescan_req_type_t;
+
+extern int frescan_requests_init(int max_ceiling);
+
+extern int frescan_request_alloc(frescan_request_id_t *id);
+
+extern int frescan_request_free(frescan_request_id_t id);
+
+extern int frescan_request_set_type(frescan_request_id_t id,
+                                    frescan_req_type_t type);
+
+extern int frescan_request_set_reply(frescan_request_id_t id,
+                                     frescan_robj_id_t reply);
+
+extern int frescan_request_set_contract(frescan_request_id_t id,
+                                        frescan_contract_t *contract);
+
+extern int frescan_request_set_src(frescan_request_id_t id,
+                                   frescan_node_t src);
+
+extern int frescan_request_get_type(frescan_request_id_t id,
+                                    frescan_req_type_t *type);
+
+extern int frescan_request_get_reply(frescan_request_id_t id,
+                                     frescan_robj_id_t *reply);
+
+extern int frescan_request_get_contract(frescan_request_id_t id,
+                                        frescan_contract_t **contract);
+
+extern int frescan_request_get_src(frescan_request_id_t id,
+                                   frescan_node_t *src);
+
+extern int frescan_requestqueue_enqueue(frescan_request_id_t id);
+
+extern int frescan_requestqueue_dequeue(frescan_request_id_t *id);
+
+#endif // _FRESCAN_REQUESTS_QUEUE_H_
index e38622cae44b2ce0a76929c04a74266ddced40b4..047225dd3762a51fa76550c5efe1bb4231f01cad 100644 (file)
@@ -25,7 +25,7 @@
 #ifndef _MARTE_FRESCAN_SERVERS_H_
 #define _MARTE_FRESCAN_SERVERS_H_
 
-#include <drivers/frescan.h> // frescan_prio_t, frescan_ss_t
+#include "frescan.h"         // frescan_prio_t, frescan_ss_t
 #include "frescan_packets.h" // frescan_packet_t
 #include <time.h>            // struct timespec
 #include "frescan_data.h"
index c723a0944a6a50ddb39ff437584bb8f09575b6b5..0a10d0662639ad8add7c341d93b8faf9df0a3064 100644 (file)
@@ -24,7 +24,7 @@
 #ifndef _MARTE_FRESCAN_SERVERS_REPLENISHMENTS_H_
 #define _MARTE_FRESCAN_SERVERS_REPLENISHMENTS_H_
 
-#include <drivers/frescan.h> // frescan_network_t
+#include "frescan.h" // frescan_network_t
 
 /**
  * frescan_replenishments_init - init the replenishment structures and thread