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