]> rtime.felk.cvut.cz Git - frescor/fwp.git/blob - fwp/lib/mngt/fwp_contract.h
Added support for contract negotiation
[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         int deadline_usec;
34 } fwp_contract_t;
35
36 struct fwp_contract_data;
37 typedef struct fwp_contract_data* fwp_contract_d_t;
38
39 fwp_contract_d_t fwp_contract_create(fwp_contract_t *contract);
40 int fwp_contract_destroy(fwp_contract_d_t contractd);
41 int fwp_contract_negotiate(fwp_contract_d_t contract, fwp_vres_d_t *vresdp);
42 int fwp_contract_cancel(fwp_contract_d_t contractd);
43 int fwp_contract_is_negotiated(fwp_contract_d_t contract);
44 int fwp_contract_cancel(fwp_contract_d_t contractd);
45
46 #ifdef _FWP_INTERNALS_
47
48 #include "ul_gavlcust.h"
49 #include "ul_list.h"
50 #include <stdlib.h>
51
52 /**< Contract Status */ 
53 /*typedef enum {
54         FWP_CONT_INVALID =      0,
55         FWP_CONT_REQUESTED =    1,
56         FWP_CONT_REJECTED =     2,
57         FWP_CONT_NEGOTIATED =   3,
58         FWP_CONT_ACCEPTED =     4
59 } fwp_contract_status_t;*/
60
61 typedef enum {
62         FWP_CONT_NOTNEGOTIATED  = 0,
63         FWP_CONT_RESERVED       = 1,    
64         FWP_CONT_NEGOTIATED     = 2
65 } fwp_contract_status_t;
66
67 typedef struct fwp_contract_data fwp_contract_data_t;
68 typedef fwp_vres_id_t fwp_contract_id_t;
69
70 /**
71  * FWP contract.
72  * This is an internal representation of contract in every FWP application.
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         fwp_contract_data_t *contdata = malloc(sizeof (fwp_contract_data_t));
98         if (!contdata)
99                 return NULL;
100         return memset(contdata,'\0', sizeof(fwp_contract_data_t));
101 }
102
103 static inline void fwp_contract_data_delete(fwp_contract_data_t* contdata)
104 {
105         free(contdata);
106 }
107
108 int fwp_contract_reserve(fwp_contract_d_t contractd);
109 int fwp_contract_commit(fwp_contract_d_t contractd, fwp_vres_d_t *vresdp);
110
111 /* TODO: Implement fwp_contract_set_state function 
112  * int fwp_contract_set_state(fwp_contract_state_t state)
113  * */
114
115 #endif /*_FWP_INTERNALS_ */
116 #endif /*_FWP_CONTRACT_H */