+++ /dev/null
-shared_LIBRARIES = contract
-
-contract_SOURCES = cm_contract.c cm_container.c
-contract_CLIENT_IDL = cm_contract_idl.idl cm_blocks.idl
-
-cm_contract_idl_IDLFLAGS = --include=cm_contract_type.h
-cm_blocks_IDLFLAGS = --include=idl_native.h
-
-include_HEADERS = cm_container.h cm_container_type.h \
- cm_contract_type.h cm_container_internal.h \
- idl_native.h cm_contract.h
-
-include_GEN_HEADERS = cm_contract_idl.h cm_blocks.h
-
-SUBDIRS=tests
+++ /dev/null
-/**
- * @file cm_container.h
- * @author Michal Sojka <sojkam1@fel.cvut.cz>
- *
- * @brief Container for managing contract blocks.
- *
- *
- */
-#ifndef CM_CONTAINER_H
-#define CM_CONTAINER_H
-
-
-#include <cm_container_type.h>
-#include <cm_blocks.h>
-#include <forb/basic_types.h>
-#include <forb/cdr_codec.h>
-#include <fosa_types.h>
-
-/*============================================================================*/
-
-/**
- * Identification of different contract blocks.
- *
- * All contract blocks 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
- * block struture can occur at any place (.h or better .idl).
- *
- */
-enum cm_block_type {
- CM_BLOCK_LABEL,
- CM_BLOCK_RESOURCE,
- CM_BLOCK_BASIC,
- CM_BLOCK_TIMING_REQS,
- CM_BLOCK_SPARE_CAPACITY,
- CM_NUM_BLOCKS
-};
-
-typedef CORBA_boolean (cm_block_serialize_fnc_t)(CDR_Codec *codec, const void *block_data);
-typedef CORBA_boolean (cm_block_deserialize_fnc_t)(CDR_Codec *codec, void **block_data);
-
-struct cm_block_desc {
- size_t size; /**< Size of the block (used by cm_block_duplicate_default() and cm_container_ptr_deserialize()) */
- cm_block_serialize_fnc_t *serialize;
- cm_block_deserialize_fnc_t *deserialize;
- void *(*duplicate)(enum cm_block_type type, const void *block_data);
-};
-
-struct cm_container *
-cm_container_new(void);
-
-void
-cm_container_destroy(struct cm_container *container);
-
-struct cm_container *
-cm_container_duplicate(const struct cm_container *source);
-
-int
-cm_container_add_block(struct cm_container *container,
- enum cm_block_type type,
- void *block);
-
-void
-cm_container_del_block(struct cm_container *container,
- enum cm_block_type type);
-
-void *
-cm_container_get_block(struct cm_container *container,
- enum cm_block_type type);
-
-#define CM_CONTAINER_ACCESSOR(TYPE, type) \
- static inline int \
- cm_container_add_##type(struct cm_container *container, \
- cm_block_##type *block) \
- { \
- return cm_container_add_block( \
- container, CM_BLOCK_##TYPE, block); \
- } \
- static inline cm_block_##type * \
- cm_container_get_##type(struct cm_container *container) \
- { \
- return cm_container_get_block( \
- container, CM_BLOCK_##TYPE); \
- } \
- static inline void \
- cm_container_del_##type(struct cm_container *container) \
- { \
- cm_container_del_block(container, CM_BLOCK_##TYPE); \
- }
-
-CM_CONTAINER_ACCESSOR(LABEL, label)
-CM_CONTAINER_ACCESSOR(RESOURCE, resource)
-CM_CONTAINER_ACCESSOR(BASIC, basic)
-CM_CONTAINER_ACCESSOR(TIMING_REQS, timing_reqs)
-CM_CONTAINER_ACCESSOR(SPARE_CAPACITY, spare_capacity)
-
-int
-cm_block_register(enum cm_block_type, const struct cm_block_desc *desc);
-
-#endif
+++ /dev/null
-/**
- * @file cm_container_internal.h
- * @author Michal Sojka <sojkam1@fel.cvut.cz>
- *
- * @brief Internal interface to cm_container.
- *
- * This header should only be included by files in frsh/cm library.
- *
- */
-#ifndef CM_CONTAINER_INTERNAL_H
-#define CM_CONTAINER_INTERNAL_H
-
-#include <cm_contract_idl.h>
-
-enum cm_block_state {
- /** There is no such block in the container. */
- CM_BLOCK_EMPTY,
- /** The container contains the block in the deserialized
- * form. */
- CM_BLOCK_DATA,
- /** The container contains the block in the serialized form
- * (sequence of octets).*/
- CM_BLOCK_STREAM
-};
-
-struct cm_block {
- enum cm_block_state state;
- union {
- void *data; /**< Pointer to data according to param_type */
- cm_block_stream stream; /**< Unserialized (unknown) data */
- } u;
-};
-
-struct cm_container {
- struct cm_block blocks[CM_NUM_BLOCKS];
-};
-
-#define CM_BLOCK_TYPE_VALID(type) \
- ((type) < CM_NUM_BLOCKS && \
- (type) >= 0)
-
-
-#endif
+++ /dev/null
-#ifndef CM_CONTAINER_TYPE_H
-#define CM_CONTAINER_TYPE_H
-
-#include <forb/basic_types.h>
-#include <forb/cdr_codec.h>
-
-/**
- * Data type for represenataion of contract container (imcomplete declaration).
- */
-typedef struct cm_container *cm_container_ptr;
-
-CORBA_boolean
-cm_container_ptr_serialize(CDR_Codec *codec,
- const cm_container_ptr *container);
-
-CORBA_boolean
-cm_container_ptr_deserialize(CDR_Codec *codec,
- cm_container_ptr *container);
-
-#endif
+++ /dev/null
-#include <cm_contract.h>
-#include <cm_container_internal.h>
-#include <string.h>
-
-/**
- * Allocates new cm_contract structure. Use cm_contract_destroy to
- * deallocate the contract.
- *
- * @param contract
- *
- * @return Zero on succes, -1 on error and errno is set appropriately.
- */
-struct cm_contract *
-cm_contract_new()
-{
- struct cm_contract *c;
-
- c = malloc(sizeof(*c));
- if (!c) goto err;
- memset(c, 0, sizeof(*c));
- c->container = cm_container_new();
- if (!c->container) goto free_err;
- return c;
-free_err:
- free(c);
-err:
- return NULL;
-}
-
-void cm_contract_destroy(struct cm_contract *contract)
-{
- cm_container_destroy(contract->container);
- free(contract);
-}
-
-struct cm_contract *
-cm_contract_duplicate(struct cm_contract *src)
-{
- struct cm_contract *dst;
-
- dst = malloc(sizeof(*dst));
- if (!dst) goto err;
- memcpy(dst, src, sizeof(*dst));
- dst->container = cm_container_duplicate(src->container);
- if (!dst->container) goto free_err;
-
- return dst;
-free_err:
- free(dst);
-err:
- return NULL;
-}
-
-CORBA_boolean
-cm_contract_ptr_serialize(CDR_Codec *codec,
- const cm_contract_ptr *contract)
-{
- CORBA_boolean cb;
- cb = cm_contract_id_t_serialize(codec, &(*contract)->id);
- if (!cb) goto err;
- cb = cm_container_ptr_serialize(codec, &(*contract)->container);
- if (!cb) goto err;
- return CORBA_TRUE;
-err:
- return CORBA_FALSE;
-}
-
-CORBA_boolean
-cm_contract_ptr_deserialize(CDR_Codec *codec,
- cm_contract_ptr *contract)
-{
- CORBA_boolean cb;
- struct cm_contract *c;
-
- c = malloc(sizeof(*c));
- if (!c) goto err;
-
- cb = cm_contract_id_t_deserialize(codec, &c->id);
- if (!cb) goto free_err;
- cb = cm_container_ptr_deserialize(codec, &c->container);
- if (!cb) goto free_err;
-
- *contract = c;
- return CORBA_TRUE;
-free_err:
- cm_contract_destroy(c);
-err:
- return CORBA_FALSE;
-}
-
-void cm_contract_ptr_free(cm_contract_ptr contract)
-{
- cm_contract_destroy(contract);
-}
+++ /dev/null
-#ifndef CM_CONTRACT_H
-#define CM_CONTRACT_H
-
-#include <cm_blocks.h>
-#include <cm_container.h>
-#include <ul_gavl.h>
-#include <cm_contract_type.h>
-#include <cm_contract_idl.h>
-
-struct cm_contract {
- cm_contract_id_t id;
- struct cm_container *container; /**< Pointer to the container (opaque type). */
- gavl_node_t node;
-};
-
-struct cm_contract *cm_contract_new(void);
-void cm_contract_destroy(struct cm_contract *contract);
-struct cm_contract *cm_contract_duplicate(struct cm_contract *src);
-
-#define CM_CONTRACT_ACCESSOR(type) \
- static inline int \
- cm_contract_add_##type(struct cm_contract *contract, \
- cm_block_##type *block) \
- { \
- return cm_container_add_##type(contract->container, \
- block); \
- } \
- static inline cm_block_##type * \
- cm_contract_get_##type(struct cm_contract *contract) \
- { \
- return cm_container_get_##type(contract->container); \
- } \
- static inline void \
- cm_contract_del_##type(struct cm_contract *contract) \
- { \
- cm_container_del_##type(contract->container); \
- }
-
-CM_CONTRACT_ACCESSOR(label)
-CM_CONTRACT_ACCESSOR(resource)
-CM_CONTRACT_ACCESSOR(basic)
-CM_CONTRACT_ACCESSOR(timing_reqs)
-CM_CONTRACT_ACCESSOR(spare_capacity)
-
-#endif
+++ /dev/null
-#ifndef CM_CONTRACT_TYPE_H
-#define CM_CONTRACT_TYPE_H
-
-#include <forb/basic_types.h>
-#include <forb/cdr_codec.h>
-
-/**
- * Data type for represenataion of contract (imcomplete declaration).
- */
-typedef struct cm_contract *cm_contract_ptr;
-
-CORBA_boolean
-cm_contract_ptr_serialize(CDR_Codec *codec,
- const cm_contract_ptr *contract);
-
-CORBA_boolean
-cm_contract_ptr_deserialize(CDR_Codec *codec,
- cm_contract_ptr *contract);
-
-void cm_contract_ptr_free(cm_contract_ptr contract);
-
-#endif
+++ /dev/null
-#include "contract/cm_contract_idl.idl"
-
-module cm {
- interface resource_manager {
- long reserve_contract(in contract_t contract);
- long commit_contract(in contract_handle_t handle, out contract_t contract_with_scheduler_data);
- long cancel_contract(in contract_handle_t handle);
- };
-};
+++ /dev/null
-#include "contract/cm_contract_idl.idl"
-
-module cm {
- interface resource_scheduler {
- long create_vres(in contract_t contract);
- long change_vres(in contract_handle_t handle);
- long cancel_vres(in contract_handle_t handle);
- };
-};
// covered by the GNU Public License. //
////////////////////////////////////////////////////////////////////////////
-#include "contract/cm_contract_idl.idl"
+#ifndef _CM_IDL
+#define _CM_IDL
-interface contract_manager {
- long negotiate_contract(in cm::contract_ptr contract, out cm::contract::id_t id);
+#include "contract/fres_contract_idl.idl"
+#include "contract/fres_blocks.idl"
+#include "rm.idl"
+#include "rs.idl"
+
+module fres {
+ interface contract_manager {
+ void register_manager(in frsh_resource_type_t restype,
+ in frsh_resource_id_t resid,
+ in resource_manager rm);
+ void register_scheduler(in frsh_resource_type_t restype,
+ in frsh_resource_id_t resid,
+ in resource_scheduler rs);
+
+ long negotiate_contract(in contract::ptr contract, out fres::contract::id_t id);
+ };
};
-
+
+#endif
--- /dev/null
+shared_LIBRARIES = contract
+
+contract_SOURCES = fres_contract.c fres_container.c
+contract_CLIENT_IDL = fres_contract_idl.idl fres_blocks.idl
+
+fres_contract_idl_IDLFLAGS = --include=fres_contract_type.h
+fres_blocks_IDLFLAGS = --include=idl_native.h
+
+include_HEADERS = fres_container.h fres_container_type.h \
+ fres_contract_type.h fres_container_internal.h \
+ idl_native.h fres_contract.h
+
+include_GEN_HEADERS = fres_contract_idl.h fres_blocks.h
+
+SUBDIRS=tests
/**
- * @file cm_contract_idl.idl
+ * @file fres_contract_idl.idl
* @author Michal Sojka <sojkam1@fel.cvut.cz>
* @date Sun Sep 7 17:24:37 2008
*
*
*/
-// FRSH mirrored types
+// FRSH mirrored types. For simplicity and compatibility with FRSH, we
+// use the values declared in FRSH headers instead of the values
+// declared here.
native fosa_rel_time_t;
native fosa_abs_time_t;
typedef long frsh_signal_t;
typedef long frsh_signal_info_t;
-module cm {
+module fres {
native container_ptr;
/// Blocks from which contracts are composed
/**
- * @file cm_contract_container.c
+ * @file fres_contract_container.c
* @author Michal Sojka <sojkam1@fel.cvut.cz>
*
* @brief Functions for manipulating with forb-based contracts.
*
*
*/
-#include <cm_container.h>
-#include "cm_container_internal.h"
+#include <fres_container.h>
+#include "fres_container_internal.h"
#include <stdbool.h>
#include <ul_list.h>
#include <string.h>
#include <forb/cdr.h>
static void *
-cm_block_duplicate_default(enum cm_block_type type, const void *block_data);
+fres_block_duplicate_default(enum fres_block_type type, const void *block_data);
static void *
-cm_block_duplicate_spare_capacity(enum cm_block_type type, const void *block_data);
+fres_block_duplicate_spare_capacity(enum fres_block_type type, const void *block_data);
#define desc_default(type) \
- struct cm_block_desc desc_default_##type = { \
- .size = sizeof(cm_block_##type), \
- .serialize = (cm_block_serialize_fnc_t*)cm_block_##type##_serialize, \
- .deserialize = (cm_block_deserialize_fnc_t*)cm_block_##type##_deserialize, \
- .duplicate = cm_block_duplicate_default \
+ struct fres_block_desc desc_default_##type = { \
+ .size = sizeof(fres_block_##type), \
+ .serialize = (fres_block_serialize_fnc_t*)fres_block_##type##_serialize, \
+ .deserialize = (fres_block_deserialize_fnc_t*)fres_block_##type##_deserialize, \
+ .duplicate = fres_block_duplicate_default \
}
static const desc_default(label);
static const desc_default(basic);
static const desc_default(timing_reqs);
-static const struct cm_block_desc desc_spare_capacity = {
- .size = sizeof(cm_block_spare_capacity),
- .serialize = (cm_block_serialize_fnc_t*)cm_block_spare_capacity_serialize, \
- .deserialize = (cm_block_deserialize_fnc_t*)cm_block_spare_capacity_deserialize, \
- .duplicate = cm_block_duplicate_spare_capacity
+static const struct fres_block_desc desc_spare_capacity = {
+ .size = sizeof(fres_block_spare_capacity),
+ .serialize = (fres_block_serialize_fnc_t*)fres_block_spare_capacity_serialize, \
+ .deserialize = (fres_block_deserialize_fnc_t*)fres_block_spare_capacity_deserialize, \
+ .duplicate = fres_block_duplicate_spare_capacity
};
/**
* Information about various block types
*
*/
-static const struct cm_block_desc *block_registry[CM_NUM_BLOCKS] = {
- [CM_BLOCK_LABEL] = &desc_default_label,
- [CM_BLOCK_RESOURCE] = &desc_default_resource,
- [CM_BLOCK_BASIC] = &desc_default_basic,
- [CM_BLOCK_TIMING_REQS] = &desc_default_timing_reqs,
+static const struct fres_block_desc *block_registry[FRES_NUM_BLOCKS] = {
+ [FRES_BLOCK_LABEL] = &desc_default_label,
+ [FRES_BLOCK_RESOURCE] = &desc_default_resource,
+ [FRES_BLOCK_BASIC] = &desc_default_basic,
+ [FRES_BLOCK_TIMING_REQS] = &desc_default_timing_reqs,
};
static void *
-cm_block_duplicate_default(enum cm_block_type type, const void *block_data)
+fres_block_duplicate_default(enum fres_block_type type, const void *block_data)
{
void *ret = NULL;
size_t size;
- if (!CM_BLOCK_TYPE_VALID(type) || !block_registry[type]) {
+ if (!FRES_BLOCK_TYPE_VALID(type) || !block_registry[type]) {
goto err;
}
size = block_registry[type]->size;
}
static void *
-cm_block_duplicate_spare_capacity(enum cm_block_type type, const void *block_data)
+fres_block_duplicate_spare_capacity(enum fres_block_type type, const void *block_data)
{
- const cm_block_spare_capacity *sc1 = block_data;
- cm_block_spare_capacity *sc2;
+ const fres_block_spare_capacity *sc1 = block_data;
+ fres_block_spare_capacity *sc2;
- sc2 = cm_block_duplicate_default(type, block_data);
+ sc2 = fres_block_duplicate_default(type, block_data);
if (sc2) {
unsigned i, len = sc1->variants._length;
sc2->variants._buffer =
- CORBA_sequence_cm_container_ptr_allocbuf(len);
+ CORBA_sequence_fres_container_ptr_allocbuf(len);
sc2->variants._maximum = len;
sc2->variants._length = len;
for (i=0; i<len; i++) {
sc2->variants._buffer[i] =
- cm_container_duplicate(sc1->variants._buffer[i]);
+ fres_container_duplicate(sc1->variants._buffer[i]);
}
}
return sc2;
/**
* Regsiteres a custom block type.
*
- * @param cm_block_type Type identifier
+ * @param fres_block_type Type identifier
* @param desc Description of the type
*
* @return Zero on success, -1 on error.
*/
int
-cm_block_register(enum cm_block_type type, const struct cm_block_desc *desc)
+fres_block_register(enum fres_block_type type, const struct fres_block_desc *desc)
{
- if (CM_BLOCK_TYPE_VALID(type) &&
+ if (FRES_BLOCK_TYPE_VALID(type) &&
block_registry[type] == NULL) {
block_registry[type] = desc;
return 0;
* @return Pointer to the container of NULL in case of error (errno is
* set appropriately).
*/
-struct cm_container *
-cm_container_new(void)
+struct fres_container *
+fres_container_new(void)
{
- struct cm_container *c;
+ struct fres_container *c;
c = malloc(sizeof(*c));
if (c) {
* @param container
*/
void
-cm_container_destroy(struct cm_container *container)
+fres_container_destroy(struct fres_container *container)
{
- enum cm_block_type i;
- for (i=0; i<CM_NUM_BLOCKS; i++) {
- cm_container_del_block(container, i);
+ enum fres_block_type i;
+ for (i=0; i<FRES_NUM_BLOCKS; i++) {
+ fres_container_del_block(container, i);
}
free(container);
* @return Pointer to the duplicated container or NULL in case of
* error.
*/
-struct cm_container *
-cm_container_duplicate(const struct cm_container *source)
+struct fres_container *
+fres_container_duplicate(const struct fres_container *source)
{
- struct cm_container *dest;
- enum cm_block_type type;
+ struct fres_container *dest;
+ enum fres_block_type type;
if (!source) return NULL;
- dest = cm_container_new();
+ dest = fres_container_new();
if (!dest) return NULL;
- for (type=0; type<CM_NUM_BLOCKS; type++) {
+ for (type=0; type<FRES_NUM_BLOCKS; type++) {
switch (source->blocks[type].state) {
- case CM_BLOCK_EMPTY:
+ case FRES_BLOCK_EMPTY:
/* nothing to do */
break;
- case CM_BLOCK_DATA: {
+ case FRES_BLOCK_DATA: {
void *dup;
dup = block_registry[type]->duplicate(
type,
source->blocks[type].u.data);
- cm_container_add_block(dest, type, dup);
+ fres_container_add_block(dest, type, dup);
break;
- case CM_BLOCK_STREAM:
+ case FRES_BLOCK_STREAM:
/* TODO: */
break;
}
* @return Zero on success, -1 on error and errno is set appropriately.
*/
int
-cm_container_add_block(struct cm_container *container,
- enum cm_block_type type,
+fres_container_add_block(struct fres_container *container,
+ enum fres_block_type type,
void *block)
{
- if (!CM_BLOCK_TYPE_VALID(type) ||
- container->blocks[type].state != CM_BLOCK_EMPTY)
+ if (!FRES_BLOCK_TYPE_VALID(type) ||
+ container->blocks[type].state != FRES_BLOCK_EMPTY)
{
errno = EINVAL;
return -1;
}
container->blocks[type].u.data = block;
- container->blocks[type].state = CM_BLOCK_DATA;
+ container->blocks[type].state = FRES_BLOCK_DATA;
return 0;
}
* @param type
*/
void
-cm_container_del_block(struct cm_container *container,
- enum cm_block_type type)
+fres_container_del_block(struct fres_container *container,
+ enum fres_block_type type)
{
- if (CM_BLOCK_TYPE_VALID(type)) {
+ if (FRES_BLOCK_TYPE_VALID(type)) {
switch (container->blocks[type].state) {
- case CM_BLOCK_EMPTY:
+ case FRES_BLOCK_EMPTY:
/* nothing to do */
break;
- case CM_BLOCK_DATA:
+ case FRES_BLOCK_DATA:
free(container->blocks[type].u.data);
- container->blocks[type].state = CM_BLOCK_EMPTY;
+ container->blocks[type].state = FRES_BLOCK_EMPTY;
break;
- case CM_BLOCK_STREAM:
+ case FRES_BLOCK_STREAM:
/* FIXME: IDL compiler should generate stream_free() */
forb_free(container->blocks[type].u.stream._buffer);
- container->blocks[type].state = CM_BLOCK_EMPTY;
+ container->blocks[type].state = FRES_BLOCK_EMPTY;
break;
}
}
* deserialized.
*/
void *
-cm_container_get_block(struct cm_container *container,
- enum cm_block_type type)
+fres_container_get_block(struct fres_container *container,
+ enum fres_block_type type)
{
if (container &&
- CM_BLOCK_TYPE_VALID(type) &&
- container->blocks[type].state == CM_BLOCK_DATA) {
+ FRES_BLOCK_TYPE_VALID(type) &&
+ container->blocks[type].state == FRES_BLOCK_DATA) {
return container->blocks[type].u.data;
} else {
return NULL;
}
static CORBA_boolean
-serialize_block(CDR_Codec *codec, enum cm_block_type type, const struct cm_block *b)
+serialize_block(CDR_Codec *codec, enum fres_block_type type, const struct fres_block *b)
{
CORBA_boolean ret;
switch (b->state) {
- case CM_BLOCK_DATA:
+ case FRES_BLOCK_DATA:
if (block_registry[type] &&
block_registry[type]->serialize) {
ret = block_registry[type]->serialize(codec, b->u.data);
ret = CORBA_FALSE;
}
break;
- case CM_BLOCK_STREAM:
- ret = cm_block_stream_serialize(codec, &b->u.stream);
+ case FRES_BLOCK_STREAM:
+ ret = fres_block_stream_serialize(codec, &b->u.stream);
break;
default:
ret = CORBA_FALSE;
CORBA_boolean
-cm_container_ptr_serialize(CDR_Codec *codec, const cm_container_ptr *container_ptr)
+fres_container_ptr_serialize(CDR_Codec *codec, const fres_container_ptr *container_ptr)
{
//CORBA_long l;
CORBA_long count;
- struct cm_container *container = *container_ptr;
+ struct fres_container *container = *container_ptr;
CORBA_boolean ret;
- enum cm_block_type type;
+ enum fres_block_type type;
if (!container) goto err;
count=0;
- for (type=0; type<CM_NUM_BLOCKS; type++) {
- if (container->blocks[type].state != CM_BLOCK_EMPTY)
+ for (type=0; type<FRES_NUM_BLOCKS; type++) {
+ if (container->blocks[type].state != FRES_BLOCK_EMPTY)
count++;
}
if (!CORBA_long_serialize(codec, &count)) goto err;
- for (type=0; type<CM_NUM_BLOCKS; type++) {
- struct cm_block *b = &container->blocks[type];
- if (b->state != CM_BLOCK_EMPTY) {
+ for (type=0; type<FRES_NUM_BLOCKS; type++) {
+ struct fres_block *b = &container->blocks[type];
+ if (b->state != FRES_BLOCK_EMPTY) {
CORBA_long_serialize(codec, &type);
CDR_put_align(codec, 8); /* All blocks are 8 byte aligned */
}
CORBA_boolean
-cm_container_ptr_deserialize(CDR_Codec *codec,
- cm_container_ptr *container)
+fres_container_ptr_deserialize(CDR_Codec *codec,
+ fres_container_ptr *container)
{
CORBA_boolean ret;
- struct cm_container *c;
+ struct fres_container *c;
CORBA_long count;
- enum cm_block_type type;
+ enum fres_block_type type;
int i;
- c = cm_container_new();
+ c = fres_container_new();
if (!c) goto err;
if (!CORBA_long_deserialize(codec, &count)) goto err;
for (i=0; i<count; i++) {
CORBA_long_deserialize(codec, (CORBA_long*)&type);
- if (!CM_BLOCK_TYPE_VALID(type)) goto free_err;
+ if (!FRES_BLOCK_TYPE_VALID(type)) goto free_err;
CDR_get_align(codec, 8); /* All blocks are 8 byte aligned */
if (block_registry[type] &&
block_registry[type]->deserialize) {
if (!block) goto free_err;
ret = block_registry[type]->deserialize(codec, block);
if (!ret) goto free_err;
- cm_container_add_block(c, type, block);
+ fres_container_add_block(c, type, block);
} else {
/* TODO: store it as stream */
}
*container = c;
return CORBA_TRUE;
free_err:
- cm_container_destroy(c);
+ fres_container_destroy(c);
err:
return CORBA_FALSE;
}
--- /dev/null
+/**
+ * @file fres_container.h
+ * @author Michal Sojka <sojkam1@fel.cvut.cz>
+ *
+ * @brief Container for managing contract blocks.
+ *
+ *
+ */
+#ifndef FRES_CONTAINER_H
+#define FRES_CONTAINER_H
+
+
+#include <fres_container_type.h>
+#include <fres_blocks.h>
+#include <forb/basic_types.h>
+#include <forb/cdr_codec.h>
+#include <fosa_types.h>
+
+/*============================================================================*/
+
+/**
+ * Identification of different contract blocks.
+ *
+ * All contract blocks 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
+ * block struture can occur at any place (.h or better .idl).
+ *
+ */
+enum fres_block_type {
+ FRES_BLOCK_LABEL,
+ FRES_BLOCK_RESOURCE,
+ FRES_BLOCK_BASIC,
+ FRES_BLOCK_TIMING_REQS,
+ FRES_BLOCK_SPARE_CAPACITY,
+ FRES_NUM_BLOCKS
+};
+
+typedef CORBA_boolean (fres_block_serialize_fnc_t)(CDR_Codec *codec, const void *block_data);
+typedef CORBA_boolean (fres_block_deserialize_fnc_t)(CDR_Codec *codec, void **block_data);
+
+struct fres_block_desc {
+ size_t size; /**< Size of the block (used by fres_block_duplicate_default() and fres_container_ptr_deserialize()) */
+ fres_block_serialize_fnc_t *serialize;
+ fres_block_deserialize_fnc_t *deserialize;
+ void *(*duplicate)(enum fres_block_type type, const void *block_data);
+};
+
+struct fres_container *
+fres_container_new(void);
+
+void
+fres_container_destroy(struct fres_container *container);
+
+struct fres_container *
+fres_container_duplicate(const struct fres_container *source);
+
+int
+fres_container_add_block(struct fres_container *container,
+ enum fres_block_type type,
+ void *block);
+
+void
+fres_container_del_block(struct fres_container *container,
+ enum fres_block_type type);
+
+void *
+fres_container_get_block(struct fres_container *container,
+ enum fres_block_type type);
+
+#define FRES_CONTAINER_ACCESSOR(TYPE, type) \
+ static inline int \
+ fres_container_add_##type(struct fres_container *container, \
+ fres_block_##type *block) \
+ { \
+ return fres_container_add_block( \
+ container, FRES_BLOCK_##TYPE, block); \
+ } \
+ static inline fres_block_##type * \
+ fres_container_get_##type(struct fres_container *container) \
+ { \
+ return fres_container_get_block( \
+ container, FRES_BLOCK_##TYPE); \
+ } \
+ static inline void \
+ fres_container_del_##type(struct fres_container *container) \
+ { \
+ fres_container_del_block(container, FRES_BLOCK_##TYPE); \
+ }
+
+FRES_CONTAINER_ACCESSOR(LABEL, label)
+FRES_CONTAINER_ACCESSOR(RESOURCE, resource)
+FRES_CONTAINER_ACCESSOR(BASIC, basic)
+FRES_CONTAINER_ACCESSOR(TIMING_REQS, timing_reqs)
+FRES_CONTAINER_ACCESSOR(SPARE_CAPACITY, spare_capacity)
+
+int
+fres_block_register(enum fres_block_type, const struct fres_block_desc *desc);
+
+#endif
--- /dev/null
+/**
+ * @file fres_container_internal.h
+ * @author Michal Sojka <sojkam1@fel.cvut.cz>
+ *
+ * @brief Internal interface to fres_container.
+ *
+ * This header should only be included by files in frsh/cm library.
+ *
+ */
+#ifndef FRES_CONTAINER_INTERNAL_H
+#define FRES_CONTAINER_INTERNAL_H
+
+#include <fres_contract_idl.h>
+
+enum fres_block_state {
+ /** There is no such block in the container. */
+ FRES_BLOCK_EMPTY,
+ /** The container contains the block in the deserialized
+ * form. */
+ FRES_BLOCK_DATA,
+ /** The container contains the block in the serialized form
+ * (sequence of octets).*/
+ FRES_BLOCK_STREAM
+};
+
+struct fres_block {
+ enum fres_block_state state;
+ union {
+ void *data; /**< Pointer to data according to param_type */
+ fres_block_stream stream; /**< Unserialized (unknown) data */
+ } u;
+};
+
+struct fres_container {
+ struct fres_block blocks[FRES_NUM_BLOCKS];
+};
+
+#define FRES_BLOCK_TYPE_VALID(type) \
+ ((type) < FRES_NUM_BLOCKS && \
+ (type) >= 0)
+
+
+#endif
--- /dev/null
+#ifndef FRES_CONTAINER_TYPE_H
+#define FRES_CONTAINER_TYPE_H
+
+#include <forb/basic_types.h>
+#include <forb/cdr_codec.h>
+
+/**
+ * Data type for represenataion of contract container (imcomplete declaration).
+ */
+typedef struct fres_container *fres_container_ptr;
+
+CORBA_boolean
+fres_container_ptr_serialize(CDR_Codec *codec,
+ const fres_container_ptr *container);
+
+CORBA_boolean
+fres_container_ptr_deserialize(CDR_Codec *codec,
+ fres_container_ptr *container);
+
+#endif
--- /dev/null
+#include <fres_contract.h>
+#include <fres_container_internal.h>
+#include <string.h>
+
+/**
+ * Allocates new fres_contract structure. Use fres_contract_destroy to
+ * deallocate the contract.
+ *
+ * @param contract
+ *
+ * @return Zero on succes, -1 on error and errno is set appropriately.
+ */
+struct fres_contract *
+fres_contract_new()
+{
+ struct fres_contract *c;
+
+ c = malloc(sizeof(*c));
+ if (!c) goto err;
+ memset(c, 0, sizeof(*c));
+ c->container = fres_container_new();
+ if (!c->container) goto free_err;
+ return c;
+free_err:
+ free(c);
+err:
+ return NULL;
+}
+
+void fres_contract_destroy(struct fres_contract *contract)
+{
+ fres_container_destroy(contract->container);
+ free(contract);
+}
+
+struct fres_contract *
+fres_contract_duplicate(struct fres_contract *src)
+{
+ struct fres_contract *dst;
+
+ dst = malloc(sizeof(*dst));
+ if (!dst) goto err;
+ memcpy(dst, src, sizeof(*dst));
+ dst->container = fres_container_duplicate(src->container);
+ if (!dst->container) goto free_err;
+
+ return dst;
+free_err:
+ free(dst);
+err:
+ return NULL;
+}
+
+CORBA_boolean
+fres_contract_ptr_serialize(CDR_Codec *codec,
+ const fres_contract_ptr *contract)
+{
+ CORBA_boolean cb;
+ cb = fres_contract_id_t_serialize(codec, &(*contract)->id);
+ if (!cb) goto err;
+ cb = fres_container_ptr_serialize(codec, &(*contract)->container);
+ if (!cb) goto err;
+ return CORBA_TRUE;
+err:
+ return CORBA_FALSE;
+}
+
+CORBA_boolean
+fres_contract_ptr_deserialize(CDR_Codec *codec,
+ fres_contract_ptr *contract)
+{
+ CORBA_boolean cb;
+ struct fres_contract *c;
+
+ c = malloc(sizeof(*c));
+ if (!c) goto err;
+
+ cb = fres_contract_id_t_deserialize(codec, &c->id);
+ if (!cb) goto free_err;
+ cb = fres_container_ptr_deserialize(codec, &c->container);
+ if (!cb) goto free_err;
+
+ *contract = c;
+ return CORBA_TRUE;
+free_err:
+ fres_contract_destroy(c);
+err:
+ return CORBA_FALSE;
+}
+
+void fres_contract_ptr_free(fres_contract_ptr contract)
+{
+ fres_contract_destroy(contract);
+}
--- /dev/null
+#ifndef FRES_CONTRACT_H
+#define FRES_CONTRACT_H
+
+#include <fres_blocks.h>
+#include <fres_container.h>
+#include <ul_gavl.h>
+#include <fres_contract_type.h>
+#include <fres_contract_idl.h>
+
+struct fres_contract {
+ fres_contract_id_t id;
+ struct fres_container *container; /**< Pointer to the container (opaque type). */
+ gavl_node_t node;
+};
+
+struct fres_contract *fres_contract_new(void);
+void fres_contract_destroy(struct fres_contract *contract);
+struct fres_contract *fres_contract_duplicate(struct fres_contract *src);
+
+#define FRES_CONTRACT_ACCESSOR(type) \
+ static inline int \
+ fres_contract_add_##type(struct fres_contract *contract, \
+ fres_block_##type *block) \
+ { \
+ return fres_container_add_##type(contract->container, \
+ block); \
+ } \
+ static inline fres_block_##type * \
+ fres_contract_get_##type(struct fres_contract *contract) \
+ { \
+ return fres_container_get_##type(contract->container); \
+ } \
+ static inline void \
+ fres_contract_del_##type(struct fres_contract *contract) \
+ { \
+ fres_container_del_##type(contract->container); \
+ }
+
+FRES_CONTRACT_ACCESSOR(label)
+FRES_CONTRACT_ACCESSOR(resource)
+FRES_CONTRACT_ACCESSOR(basic)
+FRES_CONTRACT_ACCESSOR(timing_reqs)
+FRES_CONTRACT_ACCESSOR(spare_capacity)
+
+#endif
/**
- * @file cm_contract_idl.idl
+ * @file fres_contract_idl.idl
* @author Michal Sojka <sojkam1@fel.cvut.cz>
* @date Sun Sep 7 17:24:37 2008
*
*
*/
-// FRSH mirrored types
-
-module cm {
- native contract_ptr;
-
+#ifndef _CONTRACT_IDL
+#define _CONTRACT_IDL
+module fres {
module contract {
+ /// Pointer to the contract type
+ native ptr;
+
/// Globaly unique contract ID
struct id_t {
char byte[8];
};
};
};
+
+#endif
--- /dev/null
+#ifndef FRES_CONTRACT_TYPE_H
+#define FRES_CONTRACT_TYPE_H
+
+#include <forb/basic_types.h>
+#include <forb/cdr_codec.h>
+
+/**
+ * Data type for represenataion of contract (imcomplete declaration).
+ */
+typedef struct fres_contract *fres_contract_ptr;
+
+CORBA_boolean
+fres_contract_ptr_serialize(CDR_Codec *codec,
+ const fres_contract_ptr *contract);
+
+CORBA_boolean
+fres_contract_ptr_deserialize(CDR_Codec *codec,
+ fres_contract_ptr *contract);
+
+void fres_contract_ptr_free(fres_contract_ptr contract);
+
+#endif
#define IDL_NATIVE_H
#include <fosa.h>
-#include <cm_container_type.h>
+#include <fres_container_type.h>
#include <frsh_core_types.h>
#include <forb/cdr.h>
-#include "contract/cm_contract_idl.idl"
+#ifndef _DTM_IDL
+#define _DTM_IDL
+
+#include "contract/fres_contract_idl.idl"
module cm {
interface transaction {
void register_scheduler(in resource_type restype, in resource_scheduler r);
};
};
+
+#endif
--- /dev/null
+#ifndef _RM_IDL
+#define _RM_IDL
+
+#include "contract/fres_contract_idl.idl"
+
+module fres {
+ interface resource_manager {
+ long reserve_contract(in fres::contract::ptr contract);
+ long commit_contract(in fres::contract::id_t id, out fres::contract::ptr contract_with_scheduler_data);
+ long cancel_contract(in fres::contract::id_t id);
+ };
+};
+
+#endif
--- /dev/null
+#ifndef _RS_IDL
+#define _RS_IDL
+
+#include "contract/fres_contract_idl.idl"
+
+module fres {
+ interface resource_scheduler {
+ long create_vres(in fres::contract::ptr contract);
+ long change_vres(in fres::contract::id_t id, in fres::contract::ptr contract);
+ long cancel_vres(in fres::contract::id_t id);
+ };
+};
+
+#endif
* @file frsh_contract.c
* @author Michal Sojka <sojkam1@fel.cvut.cz>
*
- * @brief Implementation of FRSH contract API on top of CM contracts.
+ * @brief Implementation of FRSH contract API on top of FRES contracts.
*
*
*/
-#include <cm_contract.h>
-#include <cm_contract_idl.h>
+#include <fres_contract.h>
+#include <fres_contract_idl.h>
#include <frsh_core.h>
#include <frsh_error.h>
-#include <cm_blocks.h>
+#include <fres_blocks.h>
#include <string.h>
/**********************************/
{
if (!contract) return FRSH_ERR_BAD_ARGUMENT;
- *contract = cm_contract_new();
+ *contract = fres_contract_new();
return (*contract) ? 0 : errno;
}
const frsh_workload_t workload,
const frsh_contract_type_t contract_type)
{
- cm_block_basic *b;
+ fres_block_basic *b;
int ret;
if (!contract ||
!*contract ||
b->workload = workload;
b->contract_type = contract_type;
- ret = cm_contract_add_basic(*contract, b);
+ ret = fres_contract_add_basic(*contract, b);
if (ret) {
free(b);
const frsh_resource_id_t resource_id,
const char *contract_label)
{
- cm_block_label *label;
- cm_block_resource *r;
+ fres_block_label *label;
+ fres_block_resource *r;
int ret;
if (!contract || !*contract) return FRSH_ERR_BAD_ARGUMENT;
r->resource_type = resource_type;
r->resource_id = resource_id;
- ret = cm_contract_add_resource(*contract, r);
+ ret = fres_contract_add_resource(*contract, r);
if (ret != 0) {
free(r);
if (!label) return ENOMEM;
strncpy(label->label, contract_label, sizeof(label->label));
label->label[sizeof(label->label)-1] = '\0';
- ret = cm_contract_add_label(*contract, label);
+ ret = fres_contract_add_label(*contract, label);
if (ret) {
free(label);
return errno;
const frsh_signal_info_t deadline_miss_siginfo)
{
int ret;
- cm_block_timing_reqs *t;
+ fres_block_timing_reqs *t;
if (!contract || !*contract)
return FRSH_ERR_BAD_ARGUMENT;
return FRSH_ERR_BAD_ARGUMENT;
}
}
- ret = cm_contract_add_timing_reqs(*contract, t);
+ ret = fres_contract_add_timing_reqs(*contract, t);
if (ret) {
free(t);
return errno;
#ifndef _FRSH_OPAQUE_TYPES_H_
#define _FRSH_OPAQUE_TYPES_H_
-#include <cm_contract_type.h>
+#include <fres_contract_type.h>
#include <frsh_cpp_macros.h>
FRSH_CPP_BEGIN_DECLS
**/
/** frsh_contract_parameters_t **/
-#define FRSH_CONTRACT_T_OPAQUE cm_contract_ptr
+#define FRSH_CONTRACT_T_OPAQUE fres_contract_ptr
typedef int FRSH_SYNCHOBJ_HANDLE_T_OPAQUE;