default_CONFIG = CONFIG_FRSH_FORB=y
ifeq ($(CONFIG_FRSH_FORB),y)
+
+SUBDIRS=tests
+
shared_LIBRARIES = frsh
-frsh_SOURCES = contract.c frsh_contract.c
-frsh_CLIENT_IDL = contract-idl.idl
+frsh_SOURCES = forb_contract.c frsh_contract.c
+frsh_CLIENT_IDL = forb_contract_idl.idl
-include_HEADERS = contract.h frsh_opaque_types.h
+include_HEADERS = forb_contract.h frsh_opaque_types.h idl_native.h
-include_GEN_HEADERS = contract-idl.h
+include_GEN_HEADERS = forb_contract_idl.h
endif
+++ /dev/null
-#include <contract.h>
-#include "contract_internal.h"
-#include <stdbool.h>
-#include <ul_list.h>
-#include <string.h>
-#include <frsh_error.h>
-
-
-struct contract *
-contract_new(void)
-{
- struct contract *c;
-
- c = malloc(sizeof(*c));
- if (c) {
- memset(c, 0, sizeof(*c));
- }
- return c;
-}
-
-void
-contract_destroy(struct contract *contract)
-{
- /* TODO handle all other deallocations */
- free(contract);
-}
-
-int
-contract_add_params(struct contract *contract,
- enum contract_part_type type,
- void *part_data)
-{
- if (!TYPE_VALID(type) ||
- contract->parts[type].state != CONTRACT_PART_EMPTY)
- return FRSH_ERR_BAD_ARGUMENT;
-
- contract->parts[type].u.data = part_data;
- return 0;
-}
-
-int
-contract_del_params(struct contract *contract,
- enum contract_part_type type)
-{
- if (TYPE_VALID(type)) {
- switch (contract->parts[type].state) {
- case CONTRACT_PART_EMPTY:
- /* nothing to do */
- break;
- case CONTRACT_PART_DATA:
- free(contract->parts[type].u.data);
- contract->parts[type].state = CONTRACT_PART_EMPTY;
- break;
- case CONTRACT_PART_STREAM:
- /* TODO: stream_free(contract->parts[type].u.seq); */
- contract->parts[type].state = CONTRACT_PART_EMPTY;
- break;
- }
- }
- return 0;
-}
-
-void *
-contract_get_params(struct contract *contract,
- enum contract_part_type type)
-{
- if (contract &&
- TYPE_VALID(type) &&
- contract->parts[type].state == CONTRACT_PART_DATA) {
- return contract->parts[type].u.data;
- } else {
- return NULL;
- }
-}
-
-CORBA_boolean
-contract_serialize(CDR_Codec *codec, const struct contract *contract)
-{
- CORBA_long l;
- CORBA_long count;
- CORBA_short s;
- int i;
- if (!contract)
- return false;
-
- l = contract->resource_id;
- CORBA_long_serialize(codec, &l);
- l = contract->resource_type;
- CORBA_long_serialize(codec, &l);
- /* TODO: Label */
-
- count=0;
- for (i=0; i<_FRSH_CONTRACT_NUM_PARAMS; i++) {
- if (contract->parts[i].state != CONTRACT_PART_EMPTY)
- count++;
- }
-
- if (!CORBA_long_serialize(codec, &count))
- goto err;
-
- for (i=0; i<_FRSH_CONTRACT_NUM_PARAMS; i++) {
- if (contract->parts[i].state != CONTRACT_PART_EMPTY) {
- s = i;
- CORBA_short_serialize(codec, &s);
-
- }
- }
- return CORBA_TRUE;
-err:
- return CORBA_FALSE;
-}
-
+++ /dev/null
-#ifndef CONTRACT_H
-#define CONTRACT_H
-
-
-#include <forb/basic_types.h>
-#include <frsh_cpp_macros.h>
-#include <fosa_types.h>
-#include <frsh_core_types.h>
-#include <contract-idl.h>
-
-/*============================================================================*/
-
-/**
- * Incomplete declaration of contract type
- */
-struct contract;
-
-enum contract_part_type {
- FRSH_CONTRACT_BASIC_PARAMS,
- FRSH_CONTRACT_SPARE_CAPACITY,
- _FRSH_CONTRACT_NUM_PARAMS
-};
-
-struct contract *
-contract_new(void);
-
-void
-contract_destroy(struct contract *contract);
-
-int
-contract_add_params(struct contract *contract,
- enum contract_part_type type,
- void *part_data);
-
-int
-contract_del_params(struct contract *contract,
- enum contract_part_type type);
-
-void *
-contract_get_params(struct contract *contract,
- enum contract_part_type type);
-
-CORBA_boolean
-contract_serialize(CDR_Codec *codec, const struct contract *contract);
-
-CORBA_boolean
-contract_deserialize(CDR_Codec *codec, struct contract **contract);
-
-
-#endif
+++ /dev/null
-#ifndef CONTRACT_INTERNAL_H
-#define CONTRACT_INTERNAL_H
-
-enum contract_part_state {
- CONTRACT_PART_EMPTY,
- CONTRACT_PART_DATA,
- CONTRACT_PART_STREAM
-};
-
-struct contract_part {
- enum contract_part_state state;
- union {
- void *data; /**< Pointer to data according to part_type */
- stream seq;
- } u;
-};
-
-struct contract {
- /** Processor Id or Network Id **/
- frsh_resource_id_t resource_id;
-
- /** Whether processor or network **/
- frsh_resource_type_t resource_type;
-
- struct contract_part parts[_FRSH_CONTRACT_NUM_PARAMS];
-};
-
-#define TYPE_VALID(type) \
- ((type) < _FRSH_CONTRACT_NUM_PARAMS && \
- (type) >= 0)
-
-
-#endif
--- /dev/null
+/**
+ * @file forb_contract.c
+ * @author Michal Sojka <sojkam1@fel.cvut.cz>
+ *
+ * @brief Functions for manipulating with forb-based contracts.
+ *
+ *
+ */
+#include <forb_contract.h>
+#include "forb_contract_internal.h"
+#include <stdbool.h>
+#include <ul_list.h>
+#include <string.h>
+#include <frsh_error.h>
+
+struct forb_contract *
+forb_contract_new(void)
+{
+ struct forb_contract *c;
+
+ c = malloc(sizeof(*c));
+ if (c) {
+ memset(c, 0, sizeof(*c));
+ }
+ return c;
+}
+
+void
+forb_contract_destroy(struct forb_contract *contract)
+{
+ enum forb_contract_params_type i;
+ for (i=0; i<_FORB_CONTRACT_NUM_PARAMS; i++) {
+ forb_contract_del_params(contract, i);
+ }
+
+ free(contract);
+}
+
+int
+forb_contract_add_params(struct forb_contract *contract,
+ enum forb_contract_params_type type,
+ void *params)
+{
+ if (!TYPE_VALID(type) ||
+ contract->params[type].state != FORB_CONTRACT_PARAM_EMPTY)
+ return FRSH_ERR_BAD_ARGUMENT;
+
+ contract->params[type].u.data = params;
+ return 0;
+}
+
+int
+forb_contract_del_params(struct forb_contract *contract,
+ enum forb_contract_params_type type)
+{
+ if (TYPE_VALID(type)) {
+ switch (contract->params[type].state) {
+ case FORB_CONTRACT_PARAM_EMPTY:
+ /* nothing to do */
+ break;
+ case FORB_CONTRACT_PARAM_DATA:
+ free(contract->params[type].u.data);
+ contract->params[type].state = FORB_CONTRACT_PARAM_EMPTY;
+ break;
+ case FORB_CONTRACT_PARAM_STREAM:
+ /* FIXME: IDL compiler should generate stream_free() */
+ forb_free(contract->params[type].u.stream._buffer);
+ contract->params[type].state = FORB_CONTRACT_PARAM_EMPTY;
+ break;
+ }
+ }
+ return 0;
+}
+
+void *
+forb_contract_get_params(struct forb_contract *contract,
+ enum forb_contract_params_type type)
+{
+ if (contract &&
+ TYPE_VALID(type) &&
+ contract->params[type].state == FORB_CONTRACT_PARAM_DATA) {
+ return contract->params[type].u.data;
+ } else {
+ return NULL;
+ }
+}
+
+CORBA_boolean
+forb_contract_serialize(CDR_Codec *codec, const struct forb_contract *contract)
+{
+ CORBA_long l;
+ CORBA_long count;
+ CORBA_short s;
+ enum forb_contract_params_type i;
+ if (!contract)
+ return false;
+
+ l = contract->resource_id;
+ CORBA_long_serialize(codec, &l);
+ l = contract->resource_type;
+ CORBA_long_serialize(codec, &l);
+ /* TODO: Label */
+
+ count=0;
+ for (i=0; i<_FORB_CONTRACT_NUM_PARAMS; i++) {
+ if (contract->params[i].state != FORB_CONTRACT_PARAM_EMPTY)
+ count++;
+ }
+
+ if (!CORBA_long_serialize(codec, &count))
+ goto err;
+
+ for (i=0; i<_FORB_CONTRACT_NUM_PARAMS; i++) {
+ if (contract->params[i].state != FORB_CONTRACT_PARAM_EMPTY) {
+ s = i;
+ CORBA_short_serialize(codec, &s);
+
+ }
+ }
+ return CORBA_TRUE;
+err:
+ return CORBA_FALSE;
+}
+
--- /dev/null
+/**
+ * @file forb_contract.h
+ * @author Michal Sojka <sojkam1@fel.cvut.cz>
+ *
+ * @brief Public interface to forb-based contracts.
+ *
+ *
+ */
+#ifndef FORB_CONTRACT_H
+#define FORB_CONTRACT_H
+
+
+#include <forb/basic_types.h>
+#include <frsh_cpp_macros.h>
+#include <fosa_types.h>
+#include <frsh_core_types.h>
+#include <forb_contract_idl.h>
+
+/*============================================================================*/
+
+/**
+ * Data type for represenataion of contracts (imcomplete declaration).
+ */
+struct forb_contract;
+
+
+/**
+ * Identification of different types of contract parameters.
+ *
+ * All contract parameters should define their ID here. This is the
+ * only place, where the different parameters (e.g. for different
+ * kinds of resources) share a common source file. The declaration of
+ * params struture can occur at any place (.h or better .idl).
+ *
+ */
+enum forb_contract_params_type {
+ FORB_CONTRACT_PARAMS_BASIC,
+ FORB_CONTRACT_PARAMS_TIMING_REQS,
+ FORB_CONTRACT_PARAMS_SPARE_CAPACITY,
+ _FORB_CONTRACT_NUM_PARAMS
+};
+
+struct forb_contract_params_desc {
+ size_t size;
+ CORBA_boolean (*serialize)(CDR_Codec *codec, const void *params);
+ CORBA_boolean (*deserialize)(CDR_Codec *codec, void **params);
+};
+
+/**
+ * Allocates memory for a new contract.
+ *
+ * @return
+ */
+struct forb_contract *
+forb_contract_new(void);
+
+/**
+ * Deallocates all memory occupied by a contract.
+ *
+ * @param contract
+ */
+void
+forb_contract_destroy(struct forb_contract *contract);
+
+/**
+ * Adds parameters of a specific type to a contract.
+ *
+ * @param contract Contract to which add the parameters.
+ * @param type Which type of parameters is being added.
+ * @param params Values of parameters to add (in most cases pointer to
+ * a structure defined in IDL).
+ *
+ * @return Zero on success, FRSH_ERR_BAD_ARGUMENT if the contract
+ * already contains this @a type of parameters.
+ */
+int
+forb_contract_add_params(struct forb_contract *contract,
+ enum forb_contract_params_type type,
+ void *params);
+/**
+ * Removes specific parameters from a contract and frees all memory
+ * occupied by these parameters.
+ *
+ * @param contract
+ * @param type Which type of parameters to remove.
+ *
+ * @return
+ */
+int
+forb_contract_del_params(struct forb_contract *contract,
+ enum forb_contract_params_type type);
+
+/**
+ * Return a specific type of contract parameters.
+ *
+ * @param contract
+ * @param type Which parameters to return.
+ *
+ * @return Pointer to the requested parameters of NULL if the
+ * parameters was not added to the contract.
+ */
+void *
+forb_contract_get_params(struct forb_contract *contract,
+ enum forb_contract_params_type type);
+
+CORBA_boolean
+forb_contract_serialize(CDR_Codec *codec, const struct forb_contract *contract);
+
+CORBA_boolean
+forb_contract_deserialize(CDR_Codec *codec, struct forb_contract **contract);
+
+#define FORB_CONTRACT_ACCESSOR(TYPE, type) \
+ static inline int \
+ forb_contract_add_params_##type(struct forb_contract *contract, \
+ forb_contract_params_##type *params) \
+ { \
+ return forb_contract_add_params(contract, \
+ FORB_CONTRACT_PARAMS_##TYPE, \
+ params); \
+ } \
+ static inline forb_contract_params_##type * \
+ forb_contract_get_params_##type(struct forb_contract *contract) \
+ { \
+ return forb_contract_get_params(contract, \
+ FORB_CONTRACT_PARAMS_##TYPE); \
+ } \
+ static inline int \
+ forb_contract_del_params_##type(struct forb_contract *contract) \
+ { \
+ return forb_contract_del_params(contract, \
+ FORB_CONTRACT_PARAMS_##TYPE); \
+ }
+
+FORB_CONTRACT_ACCESSOR(BASIC, basic);
+FORB_CONTRACT_ACCESSOR(TIMING_REQS, timing_reqs);
+FORB_CONTRACT_ACCESSOR(SPARE_CAPACITY, spare_capacity);
+
+#endif
*/
typedef sequence<octet> stream;
-
-module frsh {
- struct timespec {
- long tv_sec;
- long tv_nsec;
- };
- // TODO: Try to use native types
- typedef timespec fosa_rel_time_t;
- typedef timespec fosa_abs_time_t;
+native fosa_rel_time_t;
+native fosa_abs_time_t;
+
+module forb {
+ enum frsh_workload_t {
+ FRSH_WT_BOUNDED,
+ FRSH_WT_INDETERMINATE,
+ FRSH_WT_SYNCHRONIZED
+ };
enum frsh_contract_type_t {
FRSH_CT_REGULAR,
FRSH_CT_DUMMY
};
-
native contract_t;
native contract_handle_t;
/// modules. Any other module can add their own
/// parameters.
module params {
-
- /// IDs of all (even externally defined) parameters
- enum id {
- BASIC_PARAMS,
- SPARE_CAPACITY_PARAMS
- };
struct basic {
+ // forb_contract_params_type == FORB_CONTRACT_PARAMS_BASIC
fosa_rel_time_t budget;
fosa_rel_time_t period;
+ frsh_workload_t workload;
frsh_contract_type_t contract_type;
};
fosa_rel_time_t stability_time;
granularity_t granularity;
};
+ struct timing_reqs {
+ boolean d_equals_t;
+ fosa_rel_time_t deadline;
+ // TODO: Signals
+ };
+
};
+
};
};
--- /dev/null
+/**
+ * @file forb_contract_internal.h
+ * @author Michal Sojka <sojkam1@fel.cvut.cz>
+ *
+ * @brief Internal interface to forb-based contracts.
+ *
+ * This header should only be included by files in frsh library.
+ *
+ */
+#ifndef FORB_CONTRACT_INTERNAL_H
+#define FORB_CONTRACT_INTERNAL_H
+
+#include "forb_contract.h"
+
+enum forb_contract_param_state {
+ /** There are no such parameters inside contract. */
+ FORB_CONTRACT_PARAM_EMPTY,
+ /** The contract contains the parameters in the deserialized
+ * form. */
+ FORB_CONTRACT_PARAM_DATA,
+ /** The contract contains the parameters in the serialized
+ * form (sequence of octets).*/
+ FORB_CONTRACT_PARAM_STREAM
+};
+
+struct forb_contract_params {
+ enum forb_contract_param_state state;
+ union {
+ void *data; /**< Pointer to data according to param_type */
+ stream stream;
+ } u;
+};
+
+struct forb_contract {
+ /** Processor Id or Network Id **/
+ frsh_resource_id_t resource_id;
+
+ /** Whether processor or network **/
+ frsh_resource_type_t resource_type;
+
+ struct forb_contract_params params[_FORB_CONTRACT_NUM_PARAMS];
+};
+
+#define TYPE_VALID(type) \
+ ((type) < _FORB_CONTRACT_NUM_PARAMS && \
+ (type) >= 0)
+
+
+#endif
-#include <contract.h>
-#include "contract_internal.h"
+/**
+ * @file frsh_contract.c
+ * @author Michal Sojka <sojkam1@fel.cvut.cz>
+ *
+ * @brief Implementation of FRSH contract API on top of forb-based contracts.
+ *
+ *
+ */
+#include <forb_contract.h>
+#include "forb_contract_internal.h"
+#include <forb_contract_idl.h>
#include <frsh_core.h>
#include <frsh_error.h>
int
frsh_contract_init(frsh_contract_t *contract)
{
- struct contract *c;
+ struct forb_contract *c;
if (!contract) {
return FRSH_ERR_BAD_ARGUMENT;
}
- c = contract_new();
+ c = forb_contract_new();
*contract = c;
if (!c) {
return FOSA_ENOMEM;
return 0;
}
+int frsh_contract_set_basic_params
+ (frsh_contract_t *contract,
+ const frsh_rel_time_t *budget_min,
+ const frsh_rel_time_t *period_max,
+ const frsh_workload_t workload,
+ const frsh_contract_type_t contract_type)
+{
+ forb_contract_params_basic *b;
+ if (!contract ||
+ !*contract ||
+ !budget_min ||
+ !period_max) {
+ return FRSH_ERR_BAD_ARGUMENT;
+ }
+
+ b = malloc(sizeof(*b));
+ if (!b) {
+ /* We should return something else, but the FRSH API
+ * allows only this error. errno is set correctly. */
+ return FRSH_ERR_BAD_ARGUMENT;
+ }
+
+ b->budget = *budget_min;
+ b->period = *period_max;
+ b->workload = workload; /* FIXME: Handle type range */
+ b->contract_type = contract_type; /* FIXME: Handle type range */
+ return forb_contract_add_params_basic(*contract, b);
+}
+
int frsh_contract_set_resource_and_label
(frsh_contract_t *contract,
const frsh_resource_type_t resource_type,
const frsh_resource_id_t resource_id,
const char *contract_label)
{
- struct contract *c = *contract;
- if (!c)
+ struct forb_contract *c;
+ if (!contract || !*contract)
return FRSH_ERR_BAD_ARGUMENT;
-
+ c = *contract;
+
c->resource_type = resource_type;
c->resource_id = resource_id;
/* contract_label is currently ignored */
const frsh_signal_t deadline_miss_signal,
const frsh_signal_info_t deadline_miss_siginfo)
{
+ forb_contract_params_timing_reqs *p;
+
+ if (!contract || !*contract)
+ return FRSH_ERR_BAD_ARGUMENT;
+
+ p = malloc(sizeof(*p));
+ if (!p) {
+ /* We should return something else, but the FRSH API
+ * allows only this error. errno is set correctly. */
+ return FRSH_ERR_BAD_ARGUMENT;
+ }
+ p->d_equals_t = d_equals_t;
+ if (!d_equals_t) {
+ if (deadline) {
+ p->deadline = *deadline;
+ } else {
+ return FRSH_ERR_BAD_ARGUMENT;
+ }
+ }
+ return forb_contract_add_params_timing_reqs(*contract, p);
}
#ifndef _FRSH_OPAQUE_TYPES_H_
#define _FRSH_OPAQUE_TYPES_H_
-#include <contract.h>
+#include <forb_contract.h>
FRSH_CPP_BEGIN_DECLS
**/
/** frsh_contract_parameters_t **/
-#define FRSH_CONTRACT_T_OPAQUE struct contract *
+#define FRSH_CONTRACT_T_OPAQUE struct forb_contract *
typedef int FRSH_SYNCHOBJ_HANDLE_T_OPAQUE;
--- /dev/null
+#ifndef _IDL_NATIVE_H
+#define _IDL_NATIVE_H
+
+/* /\* FIXME: time.h should be included in fosa_opaque_types.h *\/ */
+/* #include <time.h> /\* We need struct timespec *\/ */
+#include <fosa.h>
+
+#define fosa_rel_time_t_serialize(a,b) CORBA_FALSE
+#define fosa_rel_time_t_deserialize(a,b) CORBA_FALSE
+#define fosa_abs_time_t_serialize(a,b) CORBA_FALSE
+#define fosa_abs_time_t_deserialize(a,b) CORBA_FALSE
+
+#endif
--- /dev/null
+# Generic directory or leaf node makefile for OCERA make framework
+
+ifndef MAKERULES_DIR
+MAKERULES_DIR := $(shell ( old_pwd="" ; while [ ! -e Makefile.rules ] ; do if [ "$$old_pwd" = `pwd` ] ; then exit 1 ; else old_pwd=`pwd` ; cd -L .. 2>/dev/null ; fi ; done ; pwd ) )
+endif
+
+ifeq ($(MAKERULES_DIR),)
+all : default
+.DEFAULT::
+ @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n"
+else
+include $(MAKERULES_DIR)/Makefile.rules
+endif
+
--- /dev/null
+test_PROGRAMS:=$(basename $(notdir $(wildcard $(SOURCES_DIR)/*.c)))
+
+$(foreach t,$(test_PROGRAMS),\
+$(eval $(t)_SOURCES = $(t).c)\
+$(eval $(t)_LIBS = fosa m frsh utils rt forb)\
+)
--- /dev/null
+#include <forb_contract.h>
+
+int main()
+{
+ struct forb_contract *c;
+
+ c = forb_contract_new();
+
+ return 0;
+}