From 50039b135f322d70076ea03932f60080ae4b286b Mon Sep 17 00:00:00 2001 From: Martin Molnar Date: Wed, 9 Jul 2008 02:20:02 +0200 Subject: [PATCH] Added frsh_resource.c --- frsh/frsh_contract.h | 9 +++++++-- frsh/frsh_resource.c | 20 ++++++++++++++++++++ frsh/frsh_resource.h | 21 +++++++++++---------- 3 files changed, 38 insertions(+), 12 deletions(-) create mode 100644 frsh/frsh_resource.c diff --git a/frsh/frsh_contract.h b/frsh/frsh_contract.h index 0483dd2..860abd6 100644 --- a/frsh/frsh_contract.h +++ b/frsh/frsh_contract.h @@ -11,17 +11,22 @@ typedef struct frsh_contract_params { frsh_period_t period; } frsh_contract_params_t; +typedef frsh_contract{ + frsh_resource_type type; + frsh_vres_d_t vresd; + frsh_contract_status_t status; +} frsh_contract_t; + typedef frsh_contract_t* frsh_contract_d_t; typedef struct frsh_contract_ops { - /*frsh_contract_d_t* (*create)(frsh_resource_t* resource);*/ int (*reserve)(frsh_contract_params_t* params, frsh_contract_d_t* contractdp); int (*commit)(frsh_contract_d_t contractd); /* just for compability, combination of previous functions */ int (*negotiate)(frsh_contract_params_t* params, frsh_contract_d_t* contractdp); - int (*create_vres)(frsh_contract_d_t contractd, frsh_vresd_t* vresdp); + int (*get_vres)(frsh_contract_d_t contractd, frsh_vres_d_t* vresdp); } #endif /* FRSH_CONTRACT_H */ diff --git a/frsh/frsh_resource.c b/frsh/frsh_resource.c new file mode 100644 index 0000000..92e7c66 --- /dev/null +++ b/frsh/frsh_resource.c @@ -0,0 +1,20 @@ +#include "frsh_resource.h" + +frsh_resource_t* frsh_resources[FRSH_RESOURCE_NUM+1]; + +int frsh_resource_register(frsh_resource_type_t type, frsh_resource_t* resource) +{ + if (frsh_resources[type]) { + errno = EPERM; + return (-errno); + } else + frsh_resources[type] = resource; + + return 0; +} + +int frsh_resource_unregister(frsh_resource_type_t type) +{ + frsh_resources[type] = NULL; + return 0; +} diff --git a/frsh/frsh_resource.h b/frsh/frsh_resource.h index b2ea10d..55c7b00 100644 --- a/frsh/frsh_resource.h +++ b/frsh/frsh_resource.h @@ -9,20 +9,21 @@ #ifndef _FRSH_RESOURCE_H #define _FRSH_RESOURCE_H -typedef struct frsh_resource_id { - unsigned int type; /* cpu, wlan */ - unsigned int unit; /* 0, 1, 2 */ -} frsh_resource_id_t; +#define FRSH_RESOURCE_NUM 5 + +typedef enum { + FRSH_CPU = 1, + FRSH_MEMORY = 2, + FRSH_DISK = 3, + FRSH_CAN = 4, + FRSH_WIFI = 5, +} frsh_resource_type; typedef struct frsh_resource { - frsh_resource_id_t id; frsh_contract_ops_t *contract_ops; } frsh_resource_t; -/* Resource descriptor - * ( Yes , we could just use frsh_resource_t* but in case of changes - * in API ..) - **/ -typedef frsh_resource_t* frsh_resource_d_t; +int frsh_resource_register(frsh_resource_type_t type, frsh_resource_t* resource); +int frsh_resource_unregister(frsh_resource_type_t type); #endif /* _FRSH_RESOURCE_H */ -- 2.39.2