fwp_vres_table.entry = (fwp_vres_t*) malloc(table_size);
if (!fwp_vres_table.entry)
return -ENOMEM;
- memset(fwp_vres_table.entry, 0, table_size);
+
+ memset((void*) fwp_vres_table.entry, 0, table_size);
fwp_vres_table.nr_vres = nr_vres;
return 0;
}
{
fwp_vres_t *vres = vresd;
- return (fwp_vres_table.entry - vres);
+ return (vres - fwp_vres_table.entry);
}
fwp_vres_d_t fwp_vres_alloc()
i = 0;
nr_vres = fwp_vres_table.nr_vres;
while ((i < nr_vres) &&
- (fwp_vres_table.entry[i].status != FWP_VRES_FREE))
+ (fwp_vres_table.entry[i].status != FWP_VRES_FREE)) {
i++;
+ }
if (i == nr_vres) {
pthread_mutex_unlock(&fwp_vres_table.lock);
if (!fwp_contract_is_reserved(contractd)) {
return -EAGAIN;
}
+
fwp_contract_commit(contractd, vresdp);
return 0;
}
/* Add to contract table */
fwp_contract_table_insert(&fwp_participant_this->contract_table,
contdata);
+
+ FWP_DEBUG("Contract id=%d stored in table\n", contdata->id);
return contdata;
}
fwp_msg_vres_params_out(msgb->data, &contdata->vres_params);
fwp_msgb_pull(msgb, sizeof(struct fwp_msg_vres_params));
}
-
+
+ FWP_DEBUG("STATUS = %d\n", contdata->status);
return 0;
}
fwp_msgb_reserve(msgb, sizeof(struct fwp_msg_header));
fwp_msg_contracthdr_in(msgb->tail, contdata->id, contdata->status);
fwp_msgb_put(msgb, sizeof(struct fwp_msg_contracthdr));
+ FWP_DEBUG("Commit contract id =%d\n", contdata->id);
fwp_mngt_send(FWP_MSG_COMMIT, msgb,
fwp_participant_this, fwp_participant_mngr);
+
+ contdata->status = FWP_CONT_NEGOTIATED;
/* Set parameters of vres
* and activate it if needed */
fwp_vres_set_params(contdata->vresd, &contdata->vres_params);
*vresdp = contdata->vresd;
+
/*TODO: error handling */
return 0;
}
participant->id = participant_info->id;
participant->stream_id = participant_info->stream_id;
+
+ fwp_contract_table_init(&participant->contract_table);
return participant;
}
/* TODO: consider to replace with fwp_mngt_recv call */
size = fwp_recv(fwp_participant_this->epointd, buffer, BUFFSIZE);
- FWP_DEBUG("Creating fwp msgb len=%d\n", size);
/* For future: fwp_socket could be allocated behind data in msgb*/
if (!(msgb = fwp_msgb_alloc(size))) {
perror("No memory available.\n");
fwp_msgb_put(msgb, sizeof(struct fwp_msg_hello));
/* Send hello to manager */
- FWP_DEBUG("nodeid = %d\n", fwp_participant_this->id.node_id);
fwp_mngt_send(FWP_MSG_HELLO, msgb,
fwp_participant_this, participant);
- FWP_DEBUG("Sent HELLO msg \n");
+ FWP_DEBUG("Sent HELLO msg from nodeid= %d appid= %d\n",
+ participant_id.node_id, participant_id.app_id);
}
int
fwp_msgb_put(msgb, sizeof(struct fwp_msg_vres_params));
/* Add contract to contract table */
fwp_contract_table_insert(&participant->contract_table,contdata);
+ FWP_DEBUG("Contract id=%d stored in table\n", contdata->id);
} else {
free(contdata);
return -EPERM;
}
- fwp_msg_contracthdr_out(msgb->tail, &id, &status);
+ fwp_msg_contracthdr_out(msgb->data, &id, &status);
fwp_msgb_pull(msgb, sizeof(struct fwp_msg_contracthdr));
+ FWP_DEBUG("Contract id=%d to commit\n", contdata->id);
contdata = fwp_contract_table_find(&participant->contract_table, id);
contdata->status = FWP_CONT_NEGOTIATED;
switch (msg_type) {
case FWP_MSG_HELLO:
- FWP_DEBUG("Message HELLO received from nodeid = %d\
- appid = %d\n", participant_id.node_id,
+ FWP_DEBUG("Message HELLO received from nodeid = %d "
+ "appid = %d\n", participant_id.node_id,
participant_id.app_id);
fwp_mngr_hello(msgb, participant_id);
break;
case FWP_MSG_RESERVE:
- FWP_DEBUG("Message RESERVE received from nodeid = %d\
- appid = %d\n", participant_id.node_id,
+ FWP_DEBUG("Message RESERVE received from nodeid = %d "
+ "appid = %d\n", participant_id.node_id,
participant_id.app_id);
fwp_mngr_contract_reserve(msgb, participant_id);
break;
case FWP_MSG_COMMIT:
- FWP_DEBUG("Message COMMIT received from nodeid = %d\
- appid = %d\n", participant_id.node_id,
+ FWP_DEBUG("Message COMMIT received from nodeid = %d "
+ "appid = %d\n", participant_id.node_id,
participant_id.app_id);
fwp_mngr_contract_commit(msgb, participant_id);
break;
int main()
{
int i,rc;
- fwp_vres_d_t vres_d;
- fwp_contract_t cnt1;
- fwp_contract_d_t cnt1d;
+ fwp_vres_d_t vres_d1, vres_d2;
+ fwp_contract_d_t cnt1d, cnt2d;
+ fwp_contract_t cnt1;
fwp_contract_t cnt2;
fwp_contract_t cnt3;
}
cnt1d = fwp_contract_create(&cnt1);
- fwp_contract_negotiate(cnt1d, &vres_d);
+ fwp_contract_negotiate(cnt1d, &vres_d1);
if (fwp_contract_is_negotiated(cnt1d)) {
printf("Contract1 negotiated.\n");
}else
printf("Contract1 not negotiated.\n");
+ cnt2d = fwp_contract_create(&cnt2);
+ fwp_contract_negotiate(cnt2d, &vres_d2);
+ if (fwp_contract_is_negotiated(cnt2d)) {
+ printf("Contract2 negotiated.\n");
+ }else
+ printf("Contract2 not negotiated.\n");
#if 0
rc = fwp_contract_negotiate(&cnt1, &vres_d);
if (rc == FWP_CONTNEGT_ACCEPTED) {