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