]> rtime.felk.cvut.cz Git - frescor/fwp.git/blobdiff - fwp/lib/frsh_fwp/fwp_fra.c
Merge branch 'master' of molnam1@rtime.felk.cvut.cz:/var/git/frescor/fwp
[frescor/fwp.git] / fwp / lib / frsh_fwp / fwp_fra.c
index 9073d8d6240e12e828452327c4c0958c312e3f98..451df78e8fa7d75e46a13e80c6ed59dc9747d84b 100644 (file)
@@ -44,6 +44,7 @@
 /* covered by the GNU Public License.                                    */
 /**************************************************************************/
 #include <ul_log.h>
+#include <ul_logreg.h>
 #include <fra_generic.h>
 #include <fwp.h>
 //#include <fwp_fna.h>
@@ -55,6 +56,7 @@
 
 UL_LOG_CUST(ulogd_fra_fwp);
 ul_log_domain_t ulogd_fra_fwp = {UL_LOGL_MSG, "fra_fwp"};
+UL_LOGREG_SINGLE_DOMAIN_INIT_FUNCTION(fra_fwp_logreg_domains, ulogd_fra_fwp);
 
 static int create_vres(fres_vres_t *vres, void *priv)
 {
@@ -64,13 +66,14 @@ static int create_vres(fres_vres_t *vres, void *priv)
        fwp_vres_params_t vparams;
        fwp_vres_d_t      fwp_vresd;
        int rv;
+       size_t bytes;
        
        /* Prepare vres parameters */
        basic = fres_contract_get_basic(vres->new);
        fwp_sched = fres_contract_get_block(vres->new, FRES_BLOCK_FWP_SCHED);
 
-       //fwp_fna_network_budget_to_bytes(FRSH_NETPF_FWP, &basic->budget, &vparams.budget);
-       vparams.budget = basic->budget.tv_nsec/1000000;
+       frsh_network_budget_to_bytes(FRSH_NETPF_FWP, &basic->budget, &bytes);
+       vparams.budget = bytes;
        vparams.period = basic->period;
        vparams.ac_id = fwp_sched->ac_id;       
        /* Create vres */
@@ -80,7 +83,7 @@ static int create_vres(fres_vres_t *vres, void *priv)
        vres->priv = fwp_vresd;
 
        fres_contract_id_to_string(id, &vres->id, sizeof(id));
-       printf("Creating FWP VRes (id=%s, period=%ld ms, budget=%ld bytes AC=%d)\n",
+       ul_logmsg("Creating FWP VRes (id=%s, period=%ld ms, budget=%ld bytes AC=%d)\n",
                id, fosa_rel_time_to_msec(basic->period), 
                vparams.budget, vparams.ac_id);
        
@@ -98,7 +101,7 @@ static int cancel_vres(fres_vres_t *vres, void *priv)
 
        basic = fres_contract_get_basic(vres->allocated);
        fres_contract_id_to_string(id, &vres->id, sizeof(id));
-       printf("Creating FWP VRes (id=%s, period=%ld ms, budget=%ld bytes)\n",
+       ul_logmsg("Canceling FWP VRes (id=%s, period=%ld ms, budget=%ld bytes)\n",
               id, fosa_rel_time_to_msec(basic->period), basic->budget.tv_sec);
 
        return 0;
@@ -106,6 +109,34 @@ static int cancel_vres(fres_vres_t *vres, void *priv)
 
 int change_vres(fres_vres_t *vres, void *priv)
 {
+       char id[40];
+       fres_block_basic *basic;
+       fres_block_fwp_sched *fwp_sched;
+       fwp_vres_params_t vparams;
+       fwp_vres_d_t      fwp_vresd;
+       int rv;
+       size_t bytes;
+       
+       /* Prepare vres parameters */
+       basic = fres_contract_get_basic(vres->new);
+       fwp_sched = fres_contract_get_block(vres->new, FRES_BLOCK_FWP_SCHED);
+
+       frsh_network_budget_to_bytes(FRSH_NETPF_FWP, &basic->budget, &bytes);
+       vparams.budget = bytes;
+       vparams.period = basic->period;
+       vparams.ac_id = fwp_sched->ac_id;
+       fwp_vresd = vres->priv;
+
+       /* Changing vres */
+       if ((rv = fwp_vres_set_params(fwp_vresd, &vparams))) {
+               return  rv;
+       }
+
+       fres_contract_id_to_string(id, &vres->id, sizeof(id));
+       printf("Changing FWP VRes (id=%s, period=%ld ms, budget=%ld bytes AC=%d)\n",
+               id, fosa_rel_time_to_msec(basic->period), 
+               vparams.budget, vparams.ac_id);
+       
        return 0;
 }
 
@@ -118,8 +149,8 @@ static struct fres_allocator fwp_allocator = {
        .priv = NULL
 };
 
-int fra_fwp_init(forb_orb orb, fres_contract_broker fcb, forb_executor_t *executor)
+int fra_fwp_init(void)
 {
        fres_block_register_fwp();
-       return fra_register(orb, fcb, executor, &fwp_allocator);
+       return fra_register(&fwp_allocator);
 }