]> rtime.felk.cvut.cz Git - frescor/frsh.git/blobdiff - fres/contract/fres_contract.h
Add convenient functions to get contract budget and period
[frescor/frsh.git] / fres / contract / fres_contract.h
index 72a47e9e2c4b940ff061d09ef2f0873d67c222a6..15087077ac425f9795148c1096722b8b6afb4b51 100644 (file)
@@ -1,3 +1,58 @@
+/**************************************************************************/
+/* ---------------------------------------------------------------------- */
+/* 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   fres_contract.h
+ * @author Michal Sojka <sojkam1@fel.cvut.cz>
+ * @date   Sun Nov  9 22:15:09 2008
+ * 
+ * @brief  Declaration of contract type and functions
+ * 
+ * 
+ */
 #ifndef FRES_CONTRACT_H
 #define FRES_CONTRACT_H
 
 #include <ul_gavl.h>
 #include <fres_contract_type.h>
 #include <fres_contract_idl.h>
+#include <forb/server_id.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
 
+/**
+ * Contract data type.
+ * 
+ */
 struct fres_contract {
-       fres_contract_id_t id;
-       struct fres_container *container;       /**< Pointer to the container (opaque type). */
-       gavl_node_t node;
+       fres_contract_id_t id;  /**< Global contract ID */
+       struct fres_container *container;       /**< Pointer to the block container (opaque type). */
 };
 
+static inline int fres_contract_id_cmp(const fres_contract_id_t *a,
+                                      const fres_contract_id_t *b)
+{
+       return forb_server_id_cmp((forb_server_id*)a,
+                                 (forb_server_id*)b);
+}
+
+static inline bool fres_contract_id_is_empty(const fres_contract_id_t *id)
+{
+       bool empty = true;
+       unsigned i;
+
+       for (i=0; i<sizeof(id->byte); i++) {
+               if (id->byte[i] != 0) {
+                       empty = false;
+                       break;
+               }
+       }
+       return empty;
+}
+
+static inline char *fres_contract_id_to_string(char *dest,
+                                              const fres_contract_id_t *id,
+                                              size_t n)
+{
+       return forb_server_id_to_string(dest, (forb_server_id*)id, n);
+}
+
 struct fres_contract *fres_contract_new(void);
 void fres_contract_destroy(struct fres_contract *contract);
+
+/** Destructor for easy use in forb_sequence_free() */
+static inline void fres_contract_ptr_destroy(struct fres_contract **p)
+{
+       fres_contract_destroy(*p);
+}
+
+
 struct fres_contract *fres_contract_duplicate(struct fres_contract *src);
 
+/** 
+ * Adds a block of the given type to the contract.
+ *
+ * This function uses fres_container_add_block() to do its job.
+ * 
+ * @param contract Where to add the @a block.
+ * @param type Type of contract being added.
+ * @param block Pointer to the malloced block of given @a type.
+ * 
+ * @return Zero on success, -1 on error and errno is set appropriately.
+ */
+static inline int
+fres_contract_add_block(struct fres_contract *contract,
+                       enum fres_block_type type, void *block)
+{
+       return fres_container_add_block(contract->container, type, block);
+}
+/** 
+ * Deletes a block from the contract and frees it from memory.
+ *
+ * This function uses fres_container_del_block() to do its job.
+ * 
+ * @param contract Where to delete the block.
+ * @param type Type of contract to delete.
+ */
+static inline void
+fres_contract_del_block(struct fres_contract *contract,
+                       enum fres_block_type type)
+{
+       fres_container_del_block(contract->container, type);
+}
+
+/** 
+ * Returns pointer to a contract block of a particular @a type.
+ * 
+ * This function uses fres_container_get_block() to do its job.
+ * 
+ * @param contract
+ * @param type Type of the block to be returned.
+ * 
+ * @return Pointer to the block or NULL if the block is not present or
+ * deserialized. The memory area pointed by this pointer is owned by
+ * the contract. If the user needs to store the block, it must be
+ * duplicated.
+ */
+static inline void *
+fres_contract_get_block(struct fres_contract *contract,
+                       enum fres_block_type type)
+{
+       return fres_container_get_block(contract->container, type);
+}
+
+int
+fres_contract_to_string(char *dest, size_t size, const struct fres_contract *c);
+
+/* #define FRES_C2S_FL_FMT_ONELINE */
+/* #define FRES_C2S_FL_FMT_BLOCKPERLINE */
+int
+fres_contract_to_string2(char *dest, size_t size, const struct fres_contract *c, int indent, uint32_t flags);
+
+bool
+fres_contract_get_deadline(const frsh_contract_t *contract,
+                          frsh_rel_time_t       *deadline);
+bool
+fres_contract_get_budget(const frsh_contract_t *contract,
+                        frsh_rel_time_t       *budget);
+bool
+fres_contract_get_period(const frsh_contract_t *contract,
+                        frsh_rel_time_t       *period);
+frsh_contract_type_t
+fres_contract_get_type(const frsh_contract_t *contract);
+
+void
+fres_contract_print(char *prefix, const struct fres_contract *c);
+
+static inline int
+fres_contract_get_num_blocks(const struct fres_contract *c)
+{
+       return fres_container_get_num_blocks(c->container);
+}
+
+static inline int
+fres_contract_merge(struct fres_contract *dest,
+                    const struct fres_contract *src)
+{
+       return fres_container_merge(dest->container, src->container);
+}
+
+
+/**
+ * Macro which defines type-safe contract "accessor" functions for
+ * various blocks.
+ *
+ * This macro declares the following inline functions:
+ * - fres_contract_add_<type>
+ * - fres_contract_get_<type>
+ * - fres_contract_del_<type>
+ *
+ * The defined functions simply use the container "accessor" functions
+ * (usually defined) by #FRES_CONTAINER_ACCESSOR and are equivalent to
+ * fres_contract_add_block(), fres_contract_del_block() and
+ * fres_contract_get_block() with appropriate parameters.
+ */
 #define FRES_CONTRACT_ACCESSOR(type)                                   \
        static inline int                                               \
-       fres_contract_add_##type(struct fres_contract *contract,                \
-                              fres_block_##type *block)                        \
+       fres_contract_add_##type(struct fres_contract *contract,        \
+                                fres_block_##type *block)              \
        {                                                               \
                return fres_container_add_##type(contract->container,   \
-                                              block);                  \
+                                                block);                \
        }                                                               \
-       static inline fres_block_##type *                                       \
-       fres_contract_get_##type(struct fres_contract *contract)                \
+       static inline fres_block_##type *                               \
+       fres_contract_get_##type(const struct fres_contract *contract)  \
        {                                                               \
                return fres_container_get_##type(contract->container);  \
        }                                                               \
        static inline void                                              \
-       fres_contract_del_##type(struct fres_contract *contract)                \
+       fres_contract_del_##type(struct fres_contract *contract)        \
        {                                                               \
                fres_container_del_##type(contract->container);         \
        }
@@ -40,6 +242,12 @@ FRES_CONTRACT_ACCESSOR(label)
 FRES_CONTRACT_ACCESSOR(resource)
 FRES_CONTRACT_ACCESSOR(basic)
 FRES_CONTRACT_ACCESSOR(timing_reqs)
+FRES_CONTRACT_ACCESSOR(csects)
 FRES_CONTRACT_ACCESSOR(spare_capacity)
+FRES_CONTRACT_ACCESSOR(power_management)
+
+#ifdef __cplusplus
+} /* extern "C"*/
+#endif
 
 #endif