--- /dev/null
+/**************************************************************************/
+/* ---------------------------------------------------------------------- */
+/* 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 frsh_spare_capacity.c
+ * @author Dario Faggioli <faggioli@gandalf.sssup.it>
+ *
+ * @brief Implementation of FRSH contract API on top of FRES contracts.
+ *
+ *
+ */
+#include <fres_contract.h>
+#include <fres_contract_idl.h>
+#include <frsh_core.h>
+#include <frsh_error.h>
+#include <fres_blocks.h>
+#include <string.h>
+#include <fcb.h>
+#include "frsh_forb.h"
+#include <fra_generic.h>
+
+int frsh_contract_set_reclamation_params
+ (frsh_contract_t *contract,
+ const struct timespec *stability_time,
+ const struct timespec *budget_max,
+ const struct timespec *period_min,
+ frsh_granularity_t granularity,
+ const frsh_utilization_set_t *utilization_set,
+ int importance,
+ int weight)
+{
+ fres_block_spare_capacity *s;
+ int ret;
+
+ if (!contract || !*contract ||
+ !stability_time || !budget_max || !period_min)
+ return FRSH_ERR_BAD_ARGUMENT;
+
+ if (fosa_rel_time_is_null(*budget_max) ||
+ fosa_rel_time_is_null(*period_min) ||
+ fosa_rel_time_smaller(*period_min, *budget_max))
+ return FRSH_ERR_BAD_ARGUMENT;
+
+ if ((granularity == FRSH_GR_CONTINUOUS && utilization_set != NULL) ||
+ (granularity == FRSH_GR_DISCRETE && utilization_set == NULL))
+ return FRSH_ERR_BAD_ARGUMENT;
+
+ if (granularity != FRSH_GR_CONTINUOUS)
+ return FRSH_ERR_NOT_IMPLEMENTED;
+
+ s = malloc(sizeof(*s));
+ if (!s) return ENOMEM;
+
+ s->budget = *budget_max;
+ s->period = *period_min;
+ s->granularity = granularity;
+ /*
+ * TODO:
+ * support utilization-set for discrete spare
+ * capacity distribution.
+ */
+ s->importance = importance;
+ s->weight = weight;
+ s->stability_time = *stability_time;
+
+ fres_contract_del_spare_capacity(*contract);
+ ret = fres_contract_add_spare_capacity(*contract, s);
+
+ if (ret) {
+ free(s);
+ return errno;
+ }
+
+ return FRSH_NO_ERROR;
+}
+
+int frsh_contract_get_reclamation_params
+ (const frsh_contract_t *contract,
+ struct timespec *stability_time,
+ struct timespec *budget_max,
+ struct timespec *period_min,
+ frsh_granularity_t *granularity,
+ frsh_utilization_set_t *utilization_set,
+ int *importance,
+ int *weight)
+{
+ fres_block_spare_capacity *s;
+
+ if (!contract || !*contract)
+ return FRSH_ERR_BAD_ARGUMENT;
+
+ s = fres_contract_get_spare_capacity(*contract);
+
+ if (budget_max)
+ *budget_max = s->budget;
+ if (period_min)
+ *period_min = s->period;
+ if (granularity)
+ *granularity = s->granularity;
+ /*
+ * TODO:
+ * support utilization-set for discrete spare
+ * capacity distribution.
+ */
+ if (importance)
+ *importance = s->importance;
+ if (weight)
+ *weight = s->weight;
+ if (stability_time)
+ *stability_time = s->stability_time;
+
+ return FRSH_NO_ERROR;
+}
+
+int frsh_vres_get_remaining_stability_time
+ (frsh_vres_id_t vres,
+ struct timespec *stability_time)
+{
+ return FRSH_ERR_NOT_IMPLEMENTED;
+}
+
+int frsh_resource_get_capacity
+ (const frsh_resource_type_t resource_type,
+ const frsh_resource_id_t resource_id,
+ const int importance,
+ uint32_t *capacity)
+{
+ return FRSH_ERR_NOT_IMPLEMENTED;
+}
+
+int frsh_resource_get_total_weight
+ (const frsh_resource_type_t resource_type,
+ const frsh_resource_id_t resource_id,
+ const int importance,
+ uint32_t *total_weight)
+{
+ return FRSH_ERR_NOT_IMPLEMENTED;
+}
+
+int frsh_vres_decrease_capacity
+ (frsh_vres_id_t vres_id,
+ struct timespec new_budget,
+ struct timespec new_period)
+{
+ return FRSH_ERR_NOT_IMPLEMENTED;
+}
+