#define _FRSH_TRANSACTION_H_
#include "frsh_cpp_macros.h"
-#include <fres_transaction.h>
+#include "frsh_core_types.h"
FRSH_CPP_BEGIN_DECLS
-typedef fres_transaction_t frsh_transaction_t;
+struct fres_transaction_t_type;
+
+/* frsh_transaction_t is a pointer to resemble how frsh_contract_t is
+ * defined. */
+typedef struct fres_transaction_t_type *frsh_transaction_t;
+
+/**
+ * Initialize a transaction.
+ *
+ * @param transaction
+ *
+ * @param name The name of the transaction which can be used in
+ * frsh_transaction_wait_for_name().
+ *
+ * @return Zero on success, non-zero error code on return.
+ */
+int
+frsh_transaction_init(frsh_transaction_t *transaction,
+ char *name);
+
+/**
+ * Deallocates memory of the transaction object.
+ *
+ * @param transaction
+ */
+void
+frsh_transaction_destroy(frsh_transaction_t *transaction);
+
+/**
+ * Add a contract to the transaction.
+ *
+ * @param transaction Transaction
+ * @param contract Contract to add
+ *
+ * @param id ID of the contract within the transaction. The ID is used
+ * in frsh_transaction_alloc_vres(). The ID of the first added
+ * contract must be zero, of the second contract one, etc.
+ *
+ * @return Zero on success, non-zero error code on return.
+ */
+int
+frsh_transaction_add_contract(frsh_transaction_t *transaction,
+ frsh_contract_t *contract,
+ int id);
/**
* Negotiates a multi-resource transaction.
+ *
+ * No resource is allocated in this step of negotiation. Use
+ * frsh_transaction_alloc_vres() to allocate resource and use it in
+ * application.
*
- * @param trans
+ * @param trans Transaction with added contracts.
*
- * @return Zero on success, non-zere error code on return.
+ * @return Zero on success, non-zero error code on return.
*/
int
frsh_transaction_negotiate(frsh_transaction_t *trans);
+/**
+ * Cancels a negotiated transaction.
+ *
+ * @param trans
+ *
+ * @return Zero on success, non-zero error code on return.
+ */
+int
+frsh_transaction_cancel(frsh_transaction_t *trans);
+
+/**
+ * Retrieves a negotiated transaction by name.
+ *
+ * Applications that do not initiate transaction negotiation need a
+ * way to participate in the transaction. This function waits until
+ * the transaction with a given @a name is negotiated and then returns
+ * the @a transaction object.
+ *
+ * @param name
+ * @param transaction
+ *
+ * @return Zero on success, non-zero error code on return.
+ */
+int
+frsh_transaction_wait_for_name(frsh_transaction_t *transaction,
+ const char *name);
+/**
+ * Allocates VRES from the negotiated transaction.
+ *
+ * Given the transaction object and an ID (see
+ * frsh_transaction_add_contract()) this function requests allocation
+ * of the
+ *
+ * @param t
+ * @param vres
+ * @param id
+ *
+ * @return
+ */
+int
+frsh_transaction_alloc_vres(frsh_transaction_t *t,
+ int id,
+ frsh_vres_id_t *vres);
+
FRSH_CPP_END_DECLS
#endif // _FRSH_TRANSACTION_H_