]> rtime.felk.cvut.cz Git - frescor/fwp.git/blob - fwp/lib/mngt/fwp_contract.h
Added smal comment to contdata structure
[frescor/fwp.git] / fwp / lib / mngt / fwp_contract.h
1 #ifndef _FWP_CONTRACT_H
2 #define _FWP_CONTRACT_H
3
4 #include "fwp_vres.h"
5
6 /*
7  *typedef struct mfrsh_contract_ops{
8  *      fwp_contract_d_t (*create)(fwp_contract_t *contract);
9  *      int              (*destroy)(fwp_contract_t *contract);
10  *      int              (*reserve)(fwp_contract_d_t contractd);
11  *      int              (*commit)(fwp_contract_d_t contractd);
12  *      int              (*cancel)(fwp_contract_d_t contractd);
13  *      int              (*commute)(fwp_contract_d_t origin,
14  *                                      fwp_contract_d_t contractd);
15  *} mfrsh_contract_ops_t;
16  *
17  * typedef struct mfrsh_contract_d {
18  *      mfrsh_resource_id_t     resource_id;
19  *      mfrsh_contract_id_t     contract_id;
20  *}
21  */
22
23 /**
24  * FWP contract.
25  * It is an external representation of contract intented for application 
26  * programmer.
27  * 
28  */
29 typedef 
30 struct fwp_contract {
31         int budget;             /**< bytes per period */
32         int period_usec;        /**< all time units are in microseconds */
33 } fwp_contract_t;
34
35 struct fwp_contract_data;
36 typedef struct fwp_contract_data* fwp_contract_d_t;
37
38 fwp_contract_d_t fwp_contract_create(fwp_contract_t *contract);
39 int fwp_contract_destroy(fwp_contract_d_t contractd);
40 int fwp_contract_negotiate(fwp_contract_d_t contract, fwp_vres_d_t *vresdp);
41 int fwp_contract_cancel(fwp_contract_d_t contractd);
42 int fwp_contract_is_negotiated(fwp_contract_d_t contract);
43 int fwp_contract_cancel(fwp_contract_d_t contractd);
44
45 #ifdef _FWP_INTERNALS_
46
47 #include "ul_gavlcust.h"
48 #include "ul_list.h"
49 #include <stdlib.h>
50
51 /**< Contract Status */ 
52 /*typedef enum {
53         FWP_CONT_INVALID =      0,
54         FWP_CONT_REQUESTED =    1,
55         FWP_CONT_REJECTED =     2,
56         FWP_CONT_NEGOTIATED =   3,
57         FWP_CONT_ACCEPTED =     4
58 } fwp_contract_status_t;*/
59
60 typedef enum {
61         FWP_CONT_NOTNEGOTIATED  = 0,
62         FWP_CONT_RESERVED       = 1,    
63         FWP_CONT_NEGOTIATED     = 2
64 } fwp_contract_status_t;
65
66 typedef struct fwp_contract_data fwp_contract_data_t;
67 typedef fwp_vres_id_t fwp_contract_id_t;
68
69 /**
70  * FWP contract.
71  * It is an internal representation of contract.
72  * 
73  */
74 struct fwp_contract_data {
75         fwp_contract_id_t               id;     
76         /**< contract specified by user */
77         fwp_contract_t                  contract;
78         /**< parameters from contract negotiated for vres */
79         fwp_vres_params_t               vres_params;
80         /**< the address of agent from that the contract comes */
81         /*fwp_transaction_id_t          trans_id;*/     
82         /* pointer to fwp_vres or fwp_participant */
83         /*void                          *priv; */
84         fwp_vres_d_t                    vresd;
85         fwp_contract_status_t           status;
86         /**< For future: exclude (replaced) contract 
87         fwp_contract_d_t                contex; */
88
89         ul_list_node_t                  list_node;
90         gavl_node_t                     tree_node;      
91         /* owner,
92          *  acls*/
93 };
94
95 static inline fwp_contract_data_t* fwp_contract_data_new()
96 {
97         return memset(malloc(sizeof (fwp_contract_data_t)),'\0', 
98                         sizeof(fwp_contract_data_t));
99 }
100
101 static inline void fwp_contract_data_delete(fwp_contract_data_t* contdata)
102 {
103         free(contdata);
104 }
105
106 int fwp_contract_reserve(fwp_contract_d_t contractd);
107 int fwp_contract_commit(fwp_contract_d_t contractd, fwp_vres_d_t *vresdp);
108
109 /* TODO: Implement fwp_contract_set_state function 
110  * int fwp_contract_set_state(fwp_contract_state_t state)
111  * */
112
113 #endif /*_FWP_INTERNALS_ */
114 #endif /*_FWP_CONTRACT_H */