]> rtime.felk.cvut.cz Git - frescor/frsh.git/blob - frsh_api/frsh_transaction.c
Small fixes
[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
39 int
40 frsh_transaction_init(frsh_transaction_t *transaction,
41                       char *name)
42 {
43         int ret = 0;
44         if (!transaction) {
45                 ret = FRSH_ERR_BAD_ARGUMENT;
46                 goto err;
47         }
48         *transaction = fres_transaction_new();
49         (*transaction)->name = name;
50 err:
51         return ret;
52 }
53
54 void
55 frsh_transaction_destroy(frsh_transaction_t *transaction)
56 {
57         fres_transaction_destroy(*transaction);
58 }
59
60 int
61 frsh_transaction_add_contract(frsh_transaction_t *transaction,
62                               frsh_contract_t *contract,
63                               int id)
64 {
65         int ret;
66         if (!transaction || !*transaction ||
67             !contract || !*contract ||
68             id < 0) {
69                 ret = FRSH_ERR_BAD_ARGUMENT;
70                 goto err;
71         }
72         
73         ret = fres_transaction_add_contract(*transaction, *contract);
74         if (ret == -1)
75                 ret = errno;
76         else
77                 ret = 0;
78 err:    
79         return ret;
80 }
81
82 int
83 frsh_transaction_negotiate(frsh_transaction_t *trans)
84 {
85         int ret;
86         struct forb_env env;
87         if (!trans || !*trans) {
88                 ret = FRSH_ERR_BAD_ARGUMENT;
89                 goto err;
90         }
91         ret = fres_contract_broker_negotiate_transaction(
92                 frsh_forb_global.fcb, *trans, &env);
93         if (forb_exception_occurred(&env)) {
94                 ret = fres_forbex2err(&env);
95                 goto err;
96         }
97 err:
98         return ret;
99 }
100
101 int
102 frsh_transaction_cancel(frsh_transaction_t *trans)
103 {
104         return FRSH_ERR_NOT_IMPLEMENTED;
105 }
106
107 int
108 frsh_transaction_wait_for_name(frsh_transaction_t *transaction,
109                                const char *name)
110 {
111         return FRSH_ERR_NOT_IMPLEMENTED;
112 }
113
114 int
115 frsh_transaction_alloc_vres(frsh_transaction_t *t,
116                             int id,
117                             frsh_vres_id_t *vres)
118 {
119         return FRSH_ERR_NOT_IMPLEMENTED;
120 }