]> rtime.felk.cvut.cz Git - frescor/fwp.git/blob - fwp/lib/mngt/fwp_msg.c
5c399dbe3b34e6b49cfbd259b22e1f25b01cc5f3
[frescor/fwp.git] / fwp / lib / mngt / fwp_msg.c
1 #include "fwp_msg.h"
2
3 /*
4  * general serializing and deserializing should be in separate library
5  *
6  */
7
8 void fwp_msg_header_deflate(unsigned char *data, unsigned int type, 
9                                 fwp_participant_id_t participant_id)
10 {
11         struct fwp_msg_header* msg_header;
12
13         msg_header = (struct fwp_msg_header*) data;
14         /*header = (struct fwp_msg_header*) 
15                  fwp_msgb_put(msgb, sizeof(struct fwp_msg_header));*/
16
17         msg_header->type = htons(type);
18         msg_header->node_id = htonl(participant_id.node_id);
19         msg_header->app_id = htonl(participant_id.app_id);
20 }
21
22 void fwp_msg_header_inflate(unsigned char *data, unsigned int *type, 
23                                 fwp_participant_id_t *participant_id)
24 {
25         struct fwp_msg_header *msg_header;
26         
27         msg_header = (struct fwp_msg_header*) data;
28         /*fwp_msgb_pull(msgb,sizeof(struct fwp_msg_header));*/
29         *type = ntohs(msg_header->type);
30         participant_id->node_id = ntohl(msg_header->node_id);
31         participant_id->app_id = ntohl(msg_header->app_id);
32 }
33
34 void fwp_msg_contract_deflate(unsigned char *data, struct fwp_contract *cont)
35 {
36         struct fwp_msg_contract* msg_contract;
37
38         msg_contract = (struct fwp_msg_contract*) data;
39         /*msgcnt = (struct fwp_msg_contract*) 
40                  fwp_msgb_put(msgb,sizeof(struct fwp_msg_contract));*/
41         msg_contract->budget = htons(cont->budget);
42         msg_contract->period_usec = htonl(cont->period_usec);
43 }
44
45 void fwp_msg_contract_inflate(unsigned char *data, struct fwp_contract *cont)
46 {
47         struct fwp_msg_contract* msg_contract;
48
49         msg_contract = (struct fwp_msg_contract*) data;
50         /*fwp_msgb_pull(msgb,sizeof(struct fwp_msg_contract));*/
51         cont->budget = ntohs(msg_contract->budget);
52         cont->period_usec = ntohl(msg_contract->period_usec);
53 }
54
55 void fwp_msg_vres_params_deflate(unsigned char *data, unsigned int status,
56                                  fwp_vres_params_t *vparams)
57 {
58         struct fwp_msg_vres_params* msg_vparams;
59
60         msg_vparams = (struct fwp_msg_vres_params*) data;
61         /*msgcnt = (struct fwp_msg_contract*) 
62                  fwp_msgb_put(msgb,sizeof(struct fwp_msg_contract));*/
63
64         msg_vparams->id = htons(vparams->id);
65         msg_vparams->ac_id = vparams->ac_id;
66         msg_vparams->status = status;
67
68         msg_vparams->budget = htons(vparams->budget);
69         msg_vparams->period_usec = htonl(vparams->period_usec);
70 }
71
72 void fwp_msg_vres_params_inflate(unsigned char *data, unsigned int *status,
73                                  fwp_vres_params_t *vparams)
74 {
75         struct fwp_msg_vres_params* msg_vparams;
76
77         msg_vparams = (struct fwp_msg_vres_params*) data;
78         /*fwp_msgb_pull(msgb,sizeof(struct fwp_msg_contract));*/
79
80         vparams->id = ntohs(msg_vparams->id);
81         vparams->ac_id = msg_vparams->ac_id;
82         *status = msg_vparams->status;  
83         
84         vparams->budget = ntohs(msg_vparams->budget);
85         vparams->period_usec = ntohl(msg_vparams->period_usec);
86 }
87
88 void fwp_msg_hello_deflate(unsigned char *data, 
89                                 fwp_participant_info_t *participant_info)
90 {
91         struct fwp_msg_hello* msg_hello;
92
93         msg_hello = (struct fwp_msg_hello*) data;
94         /*header = (struct fwp_msg_header*) 
95                  fwp_msgb_put(msgb, sizeof(struct fwp_msg_header));*/
96
97         msg_hello->node_id = htonl(participant_info->id.node_id);
98         msg_hello->app_id = htonl(participant_info->id.app_id);
99         msg_hello->stream_id= htons(participant_info->stream_id);
100 }
101
102 void fwp_msg_hello_inflate(unsigned char *data,
103                                  fwp_participant_info_t *participant_info)
104 {
105         struct fwp_msg_hello *msg_hello;
106         
107         msg_hello = (struct fwp_msg_hello*) data;
108         /*fwp_msgb_pull(msgb,sizeof(struct fwp_msg_header));*/
109         participant_info->id.node_id = ntohl(msg_hello->node_id);
110         participant_info->id.app_id = ntohl(msg_hello->app_id);
111         participant_info->stream_id = ntohs(msg_hello->stream_id);
112 }