]> rtime.felk.cvut.cz Git - frescor/fwp.git/commitdiff
Bug Fix: mngr_commit: fwp_msg_contracthdr_out( msgb->tail changed to msgb->data
authorMartin Molnar <molnar@sum.(none)>
Fri, 6 Jun 2008 14:02:55 +0000 (16:02 +0200)
committerMartin Molnar <molnar@sum.(none)>
Fri, 6 Jun 2008 14:02:55 +0000 (16:02 +0200)
fwp/lib/core/fwp_vres.c
fwp/lib/mngt/fwp_contract.c
fwp/lib/mngt/fwp_participant.h
fwp/mngr/fwp_mngr.c
fwp/tests/fwp_mngrtest/fwp_mngrtest.c

index 035050ad81ccad6110d256f611f1630448fffbc2..c7774ab90f4123bff200a6b5d3ecfdd48d9a50b5 100644 (file)
@@ -115,7 +115,8 @@ int fwp_vres_table_init(unsigned int nr_vres)
        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;
 }
@@ -124,7 +125,7 @@ fwp_vres_id_t fwp_vres_get_id(fwp_vres_d_t vresd)
 {
        fwp_vres_t *vres = vresd;
        
-       return (fwp_vres_table.entry - vres);
+       return (vres - fwp_vres_table.entry);
 }
 
 fwp_vres_d_t fwp_vres_alloc()
@@ -137,8 +138,9 @@ 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);
index 440bd95609a36cc031ff233a35bf349098759588..f98808554516abd5a4bbaaeb8a359c3892a54284 100644 (file)
@@ -22,6 +22,7 @@ int fwp_contract_negotiate(fwp_contract_d_t contractd, fwp_vres_d_t *vresdp)
        if (!fwp_contract_is_reserved(contractd)) {     
                return -EAGAIN;
        }       
+       
        fwp_contract_commit(contractd, vresdp);
        return 0;
 }
@@ -43,6 +44,8 @@ fwp_contract_d_t fwp_contract_create(fwp_contract_t *contract)
        /* 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;
 }
 
@@ -81,7 +84,8 @@ int fwp_contract_reserve(fwp_contract_d_t contractd)
                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;
 }
 
@@ -96,13 +100,17 @@ int fwp_contract_commit(fwp_contract_d_t contractd, fwp_vres_d_t *vresdp)
        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;
 }
index 6ad4a02b7be7cda1306826406af5e84e8adea014..f7776b193e22f2346174c0d94d06e637aaf40823 100644 (file)
@@ -42,6 +42,8 @@ fwp_participant_create(fwp_participant_info_t *participant_info)
 
        participant->id = participant_info->id;
        participant->stream_id = participant_info->stream_id;
+
+       fwp_contract_table_init(&participant->contract_table);  
        return participant;
 }
 
index 2a5c7d7e1199280e95279eacf4cf0759d8b8d95c..f4f89bfb8c1a53f9f07e5a8d0e512deee29b05d3 100644 (file)
@@ -32,7 +32,6 @@ int fwp_mngr_input(struct fwp_msgb **pmsgb)
        /* 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");
@@ -78,11 +77,11 @@ void fwp_mngr_hello(fwp_msgb_t *msgb, fwp_participant_id_t participant_id)
        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 
@@ -127,6 +126,7 @@ fwp_mngr_contract_reserve(fwp_msgb_t *msgb, fwp_participant_id_t participant_id)
                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);
@@ -151,8 +151,9 @@ fwp_mngr_contract_commit(fwp_msgb_t *msgb, fwp_participant_id_t participant_id)
                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; 
@@ -170,22 +171,22 @@ void fwp_mngr_msg_handler(fwp_msgb_t *msgb)
        
        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;  
index 2c58b9bcc748f92c7304bad0c47b77c15fafdff0..b917f5fb3e832d82a7efe333249d6cb67c8171c7 100644 (file)
@@ -7,10 +7,10 @@
 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;
 
@@ -30,12 +30,18 @@ int main()
        }       
 
        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) {