]> rtime.felk.cvut.cz Git - frescor/frsh.git/blob - frsh_api/frsh_transaction.c
frsh_transaction_alloc_vres works
[frescor/frsh.git] / frsh_api / frsh_transaction.c
1 /**************************************************************************/
2 /* Copyright (C) 2010 Czech Technical University in Prague                */
3 /*                                                                        */
4 /*  This file is part of FRSH (FRescor ScHeduler)                         */
5 /*                                                                        */
6 /* FRSH is free software; you can redistribute it and/or modify it        */
7 /* under terms of the GNU General Public License as published by the      */
8 /* Free Software Foundation; either version 2, or (at your option) any    */
9 /* later version.  FRSH is distributed in the hope that it will be        */
10 /* useful, but WITHOUT ANY WARRANTY; without even the implied warranty    */
11 /* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU    */
12 /* General Public License for more details. You should have received a    */
13 /* copy of the GNU General Public License along with FRSH; see file       */
14 /* COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,  */
15 /* Cambridge, MA 02139, USA.                                              */
16 /*                                                                        */
17 /* As a special exception, including FRSH header files in a file,         */
18 /* instantiating FRSH generics or templates, or linking other files       */
19 /* with FRSH objects to produce an executable application, does not       */
20 /* by itself cause the resulting executable application to be covered     */
21 /* by the GNU General Public License. This exception does not             */
22 /* however invalidate any other reasons why the executable file might be  */
23 /* covered by the GNU Public License.                                     */
24 /**************************************************************************/
25
26 /**
27  * @file   frsh_transaction.c
28  * @author Michal Sojka <sojkam1@fel.cvut.cz>
29  * 
30  * @brief  Implementation of FRSH transaction negotiation.
31  */
32
33 #include <frsh.h>
34 #include <frsh_transaction.h>
35 #include <fres_transaction.h>
36 #include <fcb.h>
37 #include "frsh_forb.h"
38 #include <fra_generic.h>
39
40 int
41 frsh_transaction_init(frsh_transaction_t *transaction,
42                       char *name)
43 {
44         int ret = 0;
45         if (!transaction) {
46                 ret = FRSH_ERR_BAD_ARGUMENT;
47                 goto err;
48         }
49         *transaction = fres_transaction_new();
50         (*transaction)->name = name;
51 err:
52         return ret;
53 }
54
55 void
56 frsh_transaction_destroy(frsh_transaction_t *transaction)
57 {
58         fres_transaction_destroy(*transaction);
59 }
60
61 int
62 frsh_transaction_add_contract(frsh_transaction_t *transaction,
63                               frsh_contract_t *contract,
64                               int id)
65 {
66         int ret;
67         if (!transaction || !*transaction ||
68             !contract || !*contract ||
69             id < 0) {
70                 ret = FRSH_ERR_BAD_ARGUMENT;
71                 goto err;
72         }
73         
74         ret = fres_transaction_add_contract(*transaction, *contract);
75         if (ret == -1)
76                 ret = errno;
77         else
78                 ret = 0;
79 err:    
80         return ret;
81 }
82
83 int
84 frsh_transaction_negotiate(frsh_transaction_t *trans)
85 {
86         int ret;
87         struct forb_env env;
88
89         if (!trans || !*trans) {
90                 ret = FRSH_ERR_BAD_ARGUMENT;
91                 goto err;
92         }
93         ret = fres_contract_broker_negotiate_transaction(
94                 frsh_forb_global.fcb, *trans, &env);
95         if (forb_exception_occurred(&env)) {
96                 ret = fres_forbex2err(&env);
97                 goto err;
98         }
99 err:
100         return ret;
101 }
102
103 int
104 frsh_transaction_cancel(frsh_transaction_t *trans)
105 {
106         return FRSH_ERR_NOT_IMPLEMENTED;
107 }
108
109 int
110 frsh_transaction_wait_for_name(frsh_transaction_t *transaction,
111                                const char *name)
112 {
113         return FRSH_ERR_NOT_IMPLEMENTED;
114 }
115
116 int
117 frsh_transaction_alloc_vres(frsh_transaction_t *t,
118                             int index,
119                             frsh_vres_id_t *vres)
120 {
121         int ret;
122         struct forb_env env;
123         fres_contract_id_t id;
124         ret = fres_contract_broker_allocate_transaction_vres(
125                 frsh_forb_global.fcb, (*t)->name, index, &id, &env);
126         if (forb_exception_occurred(&env)) {
127                 ret = fres_forbex2err(&env);
128                 goto err;
129         }
130         if (ret)
131                 goto err;
132         *vres = fra_get_vres(&id);
133         assert(*vres != NULL);
134
135 err:
136         return ret;
137 }