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.
#include <forb/proto_inet.h>
#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);
* 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 */
};
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;
}
}
+ memset(&fcb_data, 0, sizeof(fcb_data));
fosa_clock_get_time(CLOCK_REALTIME, &start_time);
if (opt_daemon)
#include <fres_contract_type.h>
#include <fres_contract_idl.h>
#include <forb/server_id.h>
+#include <stdio.h>
#ifdef __cplusplus
extern "C" {
static inline bool fres_contract_id_is_empty(const fres_contract_id_t *id)
{
- bool empty = true;
- unsigned i;
-
- for (i=0; i<sizeof(id->byte); i++) {
- if (id->byte[i] != 0) {
- empty = false;
- break;
- }
- }
- return empty;
+/* bool empty = true; */
+/* unsigned i; */
+
+/* for (i=0; i<sizeof(id->byte); 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);
typedef sequence<ptr> 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_t> id_seq;