]> rtime.felk.cvut.cz Git - frescor/frsh.git/blobdiff - resources/cluster_tree/frm_cluster_tree.c
forb: added scripts executing dynamic shared libraries
[frescor/frsh.git] / resources / cluster_tree / frm_cluster_tree.c
index 37e991298c9cef6a57cdd54a32a711765835030d..785e233d0bd97694a39cf3c327dca7bc192e6d50 100644 (file)
@@ -1,3 +1,59 @@
+/**************************************************************************/
+/* ---------------------------------------------------------------------- */
+/* Copyright (C) 2006 - 2008 FRESCOR consortium partners:                */
+/*                                                                       */
+/*   Universidad de Cantabria,              SPAIN                        */
+/*   University of York,                    UK                           */
+/*   Scuola Superiore Sant'Anna,            ITALY                        */
+/*   Kaiserslautern University,             GERMANY                      */
+/*   Univ. Politécnica  Valencia,           SPAIN                       */
+/*   Czech Technical University in Prague,  CZECH REPUBLIC               */
+/*   ENEA                                   SWEDEN                       */
+/*   Thales Communication S.A.              FRANCE                       */
+/*   Visual Tools S.A.                      SPAIN                        */
+/*   Rapita Systems Ltd                     UK                           */
+/*   Evidence                               ITALY                        */
+/*                                                                       */
+/*   See http://www.frescor.org for a link to partners' websites         */
+/*                                                                       */
+/*          FRESCOR project (FP6/2005/IST/5-034026) is funded            */
+/*       in part by the European Union Sixth Framework Programme         */
+/*       The European Union is not liable of any use that may be         */
+/*       made of this code.                                              */
+/*                                                                       */
+/*                                                                       */
+/*  This file is part of FRSH (FRescor ScHeduler)                        */
+/*                                                                       */
+/* FRSH is free software; you can redistribute it and/or modify it       */
+/* under terms of the GNU General Public License as published by the     */
+/* Free Software Foundation; either version 2, or (at your option) any   */
+/* later version.  FRSH is distributed in the hope that it will be       */
+/* useful, but WITHOUT ANY WARRANTY; without even the implied warranty   */
+/* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   */
+/* General Public License for more details. You should have received a   */
+/* copy of the GNU General Public License along with FRSH; see file      */
+/* COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,  */
+/* Cambridge, MA 02139, USA.                                             */
+/*                                                                       */
+/* As a special exception, including FRSH header files in a file,        */
+/* instantiating FRSH generics or templates, or linking other files      */
+/* with FRSH objects to produce an executable application, does not      */
+/* by itself cause the resulting executable application to be covered    */
+/* by the GNU General Public License. This exception does not            */
+/* however invalidate any other reasons why the executable file might be  */
+/* covered by the GNU Public License.                                    */
+/**************************************************************************/
+
+/**
+ * @file   frm_cluster_tree.c
+ * @author Michal Sojka <sojkam1@fel.cvut.cz>
+ * @date   Wed Feb 18 16:14:35 2009
+ * 
+ * @brief  Resource manager for cluster tree WSN
+ * 
+ */
+
+
 #include <frm_generic.h>
 #include <forb.h>
 #include <error.h>
@@ -32,38 +88,27 @@ int admission_test(struct fres_sa_scenario *scenario, void *priv, bool *schedula
        TOPOLOGY_PARAMS *topology = &configuration->topology;
        struct fres_sa_contract *c;
        APPLICATION_PARAMS application_params;
-       int i, ret;
+       int ret;
        OUTPUT_PARAMS output_params;
-       ALPHA alpha_data_max;
        TRAFFIC cum_traffic;
        frsh_rel_time_t min_deadline = fosa_msec_to_rel_time(0);
        
        cum_traffic.length = 0;
        cum_traffic.p_nodes = NULL;
 
-       fres_sa_scenario_for_each_contract(scenario, c) {
+       fres_sa_scenario_for_each_no_cancel_contract(scenario, c) {
                fres_block_cluster_tree_traffic *contract_traffic;
-               fres_block_timing_reqs *timing;
+               frsh_rel_time_t deadline;
 
                /* Extract the cumulative traffic through all contracts */
-               contract_traffic = fres_contract_get_block(c->contract,
-                                                 FRES_BLOCK_CLUSTER_TREE_TRAFFIC);
-                                                 
-               if(traffic_fill(contract_traffic->nodes, &cum_traffic) == -1)
-                       return -1;
-               
+               contract_traffic = fres_contract_get_cluster_tree_traffic(c->contract);
+               if(traffic_fill(&contract_traffic->nodes, &cum_traffic) == -1) {
+                       ret = -1;
+                       goto err_free_traffic;
+               }               
 
                /* Find the most restricting deadline */
-               timing = fres_contract_get_timing_reqs(c->contract);
-               if (timing) {
-                       fosa_rel_time_t deadline;
-                       if (timing->d_equals_t) {
-                               fres_block_basic *basic;
-                               basic = fres_contract_get_basic(c->contract);
-                               deadline = basic->period;
-                       } else {
-                               deadline = timing->deadline;
-                       }
+               if (fres_contract_get_deadline(&c->contract, &deadline)) {
                        if (fosa_rel_time_is_null(min_deadline) ||
                            fosa_rel_time_smaller(deadline, min_deadline)) {
                                min_deadline = deadline;
@@ -74,15 +119,19 @@ int admission_test(struct fres_sa_scenario *scenario, void *priv, bool *schedula
        application_params.ack_enable = FALSE;
        application_params.alpha_data = max_alpha(cum_traffic); /* Find the maximal arrival curve from sensory traffic */
        
-       output_params.buffer_requirements =
+       output_params.p_buffer_requirements =
                (int *) malloc((topology->height+topology->h_sink+2)*sizeof(int));
-       if (output_params.buffer_requirements == NULL)
-               return -1;
+       if (output_params.p_buffer_requirements == NULL) {
+               ret = -1;
+               goto err_free_traffic;
+       }
 
-       output_params.number_of_time_slots =
-               (int *) malloc((topology->height+topology->h_sink)*sizeof(int));
-       if(output_params.number_of_time_slots == NULL) 
-               return -1;
+       output_params.p_number_of_time_slots =
+               (unsigned short *) malloc((topology->height+topology->h_sink)*sizeof(int));
+       if(output_params.p_number_of_time_slots == NULL) {
+               ret = -1;
+               goto err_free_req;
+       }
 
        /* Call the real admission test */
        ret = ct_wsn(*topology, application_params, &output_params);
@@ -99,11 +148,14 @@ int admission_test(struct fres_sa_scenario *scenario, void *priv, bool *schedula
                }
        }
 
-       free((void *)output_params.number_of_time_slots);
-       free((void *)output_params.buffer_requirements);
-       free((void *)application_params.alpha_data);
-               
-       return 0;
+       ret = 0;
+
+       free((void *)output_params.p_number_of_time_slots);
+err_free_req:
+       free((void *)output_params.p_buffer_requirements);
+err_free_traffic:
+       free(cum_traffic.p_nodes);
+       return ret;
 }
 
 static const struct fres_res_manager frm = {
@@ -114,14 +166,9 @@ static const struct fres_res_manager frm = {
 };
 
 
-int main(int argc, char *argv[])
+int forb_main(forb_orb orb, int argc, char *argv[])
 {
-       forb_orb orb;
        int ret;
-
-       orb = forb_init(&argc, &argv, "frm_cluster_tree");
-       if (!orb) error(1, errno, "forb_init");
-
        fres_block_register_cluster_tree();
 
        ret = frm_register_and_run(orb, &frm);