From: Michal Sojka Date: Thu, 24 Jun 2010 22:41:01 +0000 (+0200) Subject: Do not use random contract IDs X-Git-Url: http://rtime.felk.cvut.cz/gitweb/frescor/frsh.git/commitdiff_plain/668fdf45338b2be908d36c6d76d862310d44d2c0 Do not use random contract IDs Instead use a counter in FCB which is used as a value of a contracts ID. Currently, we have a centralized FCB, so this is no harm for us and we get a more readable log output as well as repeatable ID for testing. --- diff --git a/fres/cbroker/fcb.c b/fres/cbroker/fcb.c index 6d58792..1e65541 100644 --- a/fres/cbroker/fcb.c +++ b/fres/cbroker/fcb.c @@ -77,6 +77,10 @@ #include #endif +#define COMPILE_TIME_ASSERT(cond, msg) \ + typedef char msg[(cond) ? 1 : -1] + + UL_LOG_CUST(ulogd_fcb); ul_log_domain_t ulogd_fcb = {UL_LOGL_MSG, "main"}; UL_LOGREG_SINGLE_DOMAIN_INIT_FUNCTION(init_ulogd_fcb, ulogd_fcb); @@ -142,6 +146,7 @@ struct fcb_contract { * Contract broker data */ struct fcb { + fres_contract_id_t contract_counter; gavl_cust_root_field_t resources; /**< Registered resources */ gavl_cust_root_field_t contracts; /**< Contracts negotiated by this FCB */ }; @@ -343,7 +348,9 @@ prepare_fcb_contracts(struct fcb *fcb, struct fcb_contract *fcb_contracts[], if (fres_contract_id_is_empty(&c->id)) { /* Normal negotiation request */ - forb_uuid_generate((forb_uuid_t *)&c->id); + COMPILE_TIME_ASSERT(sizeof(c->id) == sizeof(fcb->contract_counter), + wrong_size_of_contract_id); + c->id = ++fcb->contract_counter; fc = fcb_contract_new(&c->id); if (!fc) return errno; @@ -1304,6 +1311,7 @@ int main(int argc, char *argv[]) } } + memset(&fcb_data, 0, sizeof(fcb_data)); fosa_clock_get_time(CLOCK_REALTIME, &start_time); if (opt_daemon) diff --git a/fres/contract/fres_contract.h b/fres/contract/fres_contract.h index 1508707..74e5306 100644 --- a/fres/contract/fres_contract.h +++ b/fres/contract/fres_contract.h @@ -62,6 +62,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { @@ -85,23 +86,26 @@ static inline int fres_contract_id_cmp(const fres_contract_id_t *a, static inline bool fres_contract_id_is_empty(const fres_contract_id_t *id) { - bool empty = true; - unsigned i; - - for (i=0; ibyte); i++) { - if (id->byte[i] != 0) { - empty = false; - break; - } - } - return empty; +/* bool empty = true; */ +/* unsigned i; */ + +/* for (i=0; ibyte); i++) { */ +/* if (id->byte[i] != 0) { */ +/* empty = false; */ +/* break; */ +/* } */ +/* } */ +/* return empty; */ + return *id == 0; } static inline char *fres_contract_id_to_string(char *dest, const fres_contract_id_t *id, size_t n) { - return forb_server_id_to_string(dest, (forb_server_id*)id, n); + snprintf(dest, n, "%llx", *id); +/* return forb_server_id_to_string(dest, (forb_server_id*)id, n); */ + return dest; } struct fres_contract *fres_contract_new(void); diff --git a/fres/contract/fres_contract_idl.idl b/fres/contract/fres_contract_idl.idl index 336ef0b..c2cdc08 100644 --- a/fres/contract/fres_contract_idl.idl +++ b/fres/contract/fres_contract_idl.idl @@ -73,9 +73,10 @@ module fres { typedef sequence ptr_seq; /// Globaly unique contract ID - struct id_t { - char byte[8]; - }; + typedef unsigned long long id_t; +// struct id_t { +// char byte[8]; +// }; typedef sequence id_seq;