MSG(FORB_EX_APPLICATION);
MSG(NO_RESOURCE_MANAGER);
MSG(ALLOCATOR_ALREADY_REGISTERED);
+ MSG(VRES_ALREADY_ALLOCATED);
+ MSG(VRES_PART_OF_TRANSACTION);
}
if (s == NULL) return FRSH_ERR_BAD_ARGUMENT;
FRES_ERR_FORB_EX_APPLICATION,
FRES_ERR_NO_RESOURCE_MANAGER,
FRES_ERR_ALLOCATOR_ALREADY_REGISTERED,
+ FRES_ERR_VRES_ALREADY_ALLOCATED,
+ FRES_ERR_VRES_PART_OF_TRANSACTION,
};
int fres_strerror (int error, char *message, size_t size);
#include <frsh.h>
#include <frsh_transaction.h>
+#include <fres_transaction.h>
+#include <fcb.h>
+#include "frsh_forb.h"
+int
+frsh_transaction_init(frsh_transaction_t *transaction,
+ char *name)
+{
+ int ret = 0;
+ if (!transaction) {
+ ret = FRSH_ERR_BAD_ARGUMENT;
+ goto err;
+ }
+ *transaction = fres_transaction_new();
+ (*transaction)->name = name;
+err:
+ return ret;
+}
+
+void
+frsh_transaction_destroy(frsh_transaction_t *transaction)
+{
+ fres_transaction_destroy(*transaction);
+}
+
+int
+frsh_transaction_add_contract(frsh_transaction_t *transaction,
+ frsh_contract_t *contract,
+ int id)
+{
+ int ret;
+ if (!transaction || !*transaction ||
+ !contract || !*contract ||
+ id < 0) {
+ ret = FRSH_ERR_BAD_ARGUMENT;
+ goto err;
+ }
+
+ ret = fres_transaction_add_contract(*transaction, *contract);
+ if (ret == -1)
+ ret = FRSH_ERR_INTERNAL_ERROR;
+ else
+ ret = 0;
+err:
+ return ret;
+}
int
frsh_transaction_negotiate(frsh_transaction_t *trans)
+{
+ int ret;
+ struct forb_env env;
+ if (!trans || !*trans) {
+ ret = FRSH_ERR_BAD_ARGUMENT;
+ goto err;
+ }
+ ret = fres_contract_broker_negotiate_transaction(
+ frsh_forb_global.fcb, *trans, &env);
+ if (forb_exception_occurred(&env)) {
+ ret = fres_forbex2err(&env);
+ goto err;
+ }
+err:
+ return ret;
+}
+
+int
+frsh_transaction_cancel(frsh_transaction_t *trans)
{
return FRSH_ERR_NOT_IMPLEMENTED;
}
+int
+frsh_transaction_wait_for_name(frsh_transaction_t *transaction,
+ const char *name)
+{
+ return FRSH_ERR_NOT_IMPLEMENTED;
+}
+
+int
+frsh_transaction_alloc_vres(frsh_transaction_t *t,
+ int id,
+ frsh_vres_id_t *vres)
+{
+ return FRSH_ERR_NOT_IMPLEMENTED;
+}
test_PROGRAMS += trans_nego
trans_nego_SOURCES = trans_nego.c
trans_nego_LIBS = wvtest
+test_PROGRAMS += trans_nego2
+trans_nego2_SOURCES = trans_nego2.c
+trans_nego2_LIBS = wvtest
test_PROGRAMS += negobench
negobench_SOURCES = negobench.c
#include <frsh.h>
#include <wvtest.h>
#include <res_dummy.h>
+#include "trans_nego.h"
WVTEST_MAIN("transaction negotiation")
{
frsh_contract_t contract[3];
- const frsh_resource_id_t id[3] = { 255, 0, 1 };
+ const frsh_resource_id_t id[3] = { 0, 1, 255 };
frsh_contract_label_t label[3];
frsh_rel_time_t budget, period;
int i;
- fres_transaction_t *t;
+ frsh_transaction_t t;
+ frsh_vres_id_t vres1, vres2;
WVFRSH(frsh_init());
- WVFRSH(fra_dummy_init_and_activate_id(0));
WVFRSH(fra_dummy_init_and_activate_id(1));
- WVPASS(t = fres_transaction_new());
+ WVFRSH(frsh_transaction_init(&t, "test"));
- for (i = 0; i < 3; i++) {
+ for (i = TEST_CONTRACT_1; i <= TEST_CONTRACT_3; i++) {
WVFRSH(frsh_contract_init(&contract[i]));
sprintf(label[i], "contract%d", i);
WVFRSH(frsh_contract_set_resource_and_label(
FRSH_WT_BOUNDED,
FRSH_CT_REGULAR));
- WVPASS(fres_transaction_add_contract(t, contract[i]) > 0);
+ WVFRSH(frsh_transaction_add_contract(&t, &contract[i], i));
}
- WVFRSH(frsh_transaction_negotiate(t));
+ WVFRSH(frsh_transaction_negotiate(&t));
+
+ WVFRSH(frsh_transaction_alloc_vres(&t, TEST_CONTRACT_1, &vres1));
+ WVFRSH(frsh_transaction_alloc_vres(&t, TEST_CONTRACT_2, &vres2));
+ /* TEST_CONTRACT_3 is allocated in trans_nego2.c */
+
+ WVPASS(frsh_contract_cancel(vres2) == FRES_ERR_VRES_PART_OF_TRANSACTION);
frsh_destroy();
}
--- /dev/null
+#ifndef TRANS_NEGO_H
+#define TRANS_NEGO_H
+
+enum {
+ TEST_CONTRACT_1 = 0,
+ TEST_CONTRACT_2 = 1,
+ TEST_CONTRACT_3 = 2,
+};
+
+#endif
' 0
WVPASS trans_nego
+WVPASS trans_nego2
--- /dev/null
+#include <frsh.h>
+#include <wvtest.h>
+#include <res_dummy.h>
+#include "trans_nego.h"
+
+WVTEST_MAIN("transaction negotiation - remote part")
+{
+ frsh_transaction_t t;
+ frsh_vres_id_t vres3;
+
+ WVFRSH(frsh_init());
+ WVFRSH(fra_dummy_init_and_activate_id(1));
+ WVFRSH(frsh_transaction_wait_for_name(&t, "test"));
+ WVPASS(frsh_transaction_alloc_vres(&t, TEST_CONTRACT_2, &vres3) ==
+ FRES_ERR_VRES_ALREADY_ALLOCATED);
+ WVFRSH(frsh_transaction_alloc_vres(&t, TEST_CONTRACT_3, &vres3));
+
+ frsh_destroy();
+}