};
/**
- * Registered resource manager
+ * Registered resource
*/
-struct res_mng {
+struct resource {
gavl_node_t node;
- struct res_key resource;
- fres_resource_manager rm; /**< Object reference of the resource manager */
+ struct res_key key;
+ fres_resource_manager mng; /**< Object reference of the resource manager */
gavl_cust_root_field_t allocators; /**< Registered allocators for this resource (from multiple applications/nodes) */
};
fres_resource_allocator ra;
};
+/**
+ * Contract broker data
+ */
struct fcb {
gavl_cust_root_field_t resources;
};
GAVL_CUST_NODE_INT_DEC(fcb_resource /* cust_prefix */, \
struct fcb /* cust_root_t */, \
- struct res_mng /* cust_item_t */, \
+ struct resource/* cust_item_t */, \
struct res_key /* cust_key_t */, \
resources /* cust_root_node */, \
node /* cust_item_node */, \
- resource /* cust_item_key */, \
+ key /* cust_item_key */, \
res_key_cmp /* cust_cmp_fnc */);
GAVL_CUST_NODE_INT_IMP(fcb_resource /* cust_prefix */, \
struct fcb /* cust_root_t */, \
- struct res_mng /* cust_item_t */, \
+ struct resource/* cust_item_t */, \
struct res_key /* cust_key_t */, \
resources /* cust_root_node */, \
node /* cust_item_node */, \
- resource /* cust_item_key */, \
+ key /* cust_item_key */, \
res_key_cmp /* cust_cmp_fnc */);
GAVL_CUST_NODE_INT_DEC(fcb_alloc /* cust_prefix */, \
- struct res_mng /* cust_root_t */, \
+ struct resource /* cust_root_t */, \
struct res_alloc /* cust_item_t */, \
forb_server_id /* cust_key_t */, \
allocators /* cust_root_node */, \
fres_contract_id_cmp /* cust_cmp_fnc */);
GAVL_CUST_NODE_INT_IMP(fcb_alloc /* cust_prefix */, \
- struct res_mng /* cust_root_t */, \
+ struct resource /* cust_root_t */, \
struct res_alloc /* cust_item_t */, \
forb_server_id /* cust_key_t */, \
allocators /* cust_root_node */, \
CORBA_Environment *ev)
{
struct fcb *fcb = o2fcb(obj);
- fres_block_resource *res;
+ fres_block_resource *block_res;
struct res_key res_key;
- struct res_mng *rm;
+ struct resource *resource;
struct res_alloc *ra;
int ret;
forb_server_id app;
fres_contract_id_seq ids;
- res = fres_contract_get_resource(contract);
- if (!res) {
+ block_res = fres_contract_get_resource(contract);
+ if (!block_res) {
ul_logerr("No resource specified\n");
ret = FRSH_ERR_RESOURCE_ID_INVALID;
goto err;
}
- res_key.type = res->resource_type;
- res_key.id = res->resource_id;
+ res_key.type = block_res->resource_type;
+ res_key.id = block_res->resource_id;
- rm = fcb_resource_find(fcb, &res_key);
- if (!rm) {
+ resource = fcb_resource_find(fcb, &res_key);
+ if (!resource) {
ul_logerr("No resource manager for %d.%d registered\n",
res_key.type, res_key.id);
ret = -1;
contract->id = *id;
forb_get_req_source(obj, &app);
- ra = fcb_alloc_find(rm, &app);
+ ra = fcb_alloc_find(resource, &app);
if (!ra) {
char str[60];
forb_server_id_to_string(str, &app, sizeof(str));
contracts._length = 1;
contract_seq_buf = contract;
contracts._buffer = &contract_seq_buf;
- ret = fres_resource_manager_reserve_contracts(rm->rm, &contracts, ev);
+ ret = fres_resource_manager_reserve_contracts(resource->mng, &contracts, ev);
if (forb_exception_occurred(ev) || ret < 0) {
goto err;
}
/* Commit contract */
ids._length = ids._maximum = 1;
ids._buffer = id;
- fres_resource_manager_commit_contracts(rm->rm, &ids, &schedulable_contracts, ev);
+ fres_resource_manager_commit_contracts(resource->mng, &ids,
+ &schedulable_contracts, ev);
if (forb_exception_occurred(ev)) {
ret = FRES_ERR_FORB_EXCEPTION;
goto err;
CORBA_Environment *ev)
{
struct fcb *fcb = o2fcb(obj);
- struct res_mng *rm, *rm2;
-
- rm = malloc(sizeof(*rm));
- if (!rm) goto err;
- memset(rm, 0, sizeof(*rm));
- rm->resource.type = restype;
- rm->resource.id = resid;
- rm2 = fcb_resource_find(fcb, &rm->resource);
- if (rm2) {
- if (forb_object_is_stale(rm2->rm)) {
+ struct resource *res, *res2;
+
+ res = malloc(sizeof(*res));
+ if (!res) goto err;
+ memset(res, 0, sizeof(*res));
+ res->key.type = restype;
+ res->key.id = resid;
+ res2 = fcb_resource_find(fcb, &res->key);
+ if (res2) {
+ if (forb_object_is_stale(res2->mng)) {
ul_logmsg("Removing stale manager for resource %d.%d\n",
restype, resid);
- forb_object_release(rm2->rm);
- fcb_resource_delete(fcb, rm2);
+ forb_object_release(res2->mng);
+ fcb_resource_delete(fcb, res2);
/* TODO: Delete also all allocators associated
* with this stale resource manager. */
- free(rm);
- rm = rm2;
+ free(res);
+ res = res2;
} else {
ul_logerr("Resource manager %d.%d already registered\n",
restype, resid);
goto free_err;
}
}
- rm->rm = forb_object_duplicate(desc->manager);
+ res->mng = forb_object_duplicate(desc->manager);
- fcb_alloc_init_root_field(rm);
+ fcb_alloc_init_root_field(res);
ul_logmsg("Registering manager for resource %d.%d\n",
restype, resid);
- fcb_resource_insert(fcb, rm);
+ fcb_resource_insert(fcb, res);
return 0;
free_err:
- free(rm);
+ free(res);
err:
return -1;
}
CORBA_Environment *ev)
{
struct fcb *fcb = o2fcb(obj);
- struct res_mng *rm;
+ struct resource *res;
struct res_alloc *ra;
struct res_key resource;
forb_server_id server_id;
resource.type = restype;
resource.id = resid;
- rm = fcb_resource_find(fcb, &resource);
- if (!rm) {
+ res = fcb_resource_find(fcb, &resource);
+ if (!res) {
ul_logerr("No manager found for %d.%d. Unable to register the allocator!\n",
restype, resid);
goto err;
}
- ra = fcb_alloc_find(rm, &server_id);
+ ra = fcb_alloc_find(res, &server_id);
if (ra) {
char *str = forb_object_to_string(ra_obj);
ul_logerr("Allocator from already registered (%s)\n",
}
ra->app = server_id;
ra->ra = forb_object_duplicate(ra_obj);
- fcb_alloc_insert(rm, ra);
+ fcb_alloc_insert(res, ra);
return 0;
err:
return -1;