1 /* 2 * fb_cvar.h 3 * 4 * Include file for code using custom variables. 5 * 6 * @Author Santhosh Kumar Koundinya (santhosh@fsl.cs.sunysb.edu) 7 */ 8 9 #ifndef _FB_CVAR_H 10 #define _FB_CVAR_H 11 12 #include <stdint.h> 13 #include <sys/types.h> 14 15 /* Function (symbol) names within custom variable libraries. */ 16 #define FB_CVAR_MODULE_INIT "cvar_module_init" 17 #define FB_CVAR_ALLOC_HANDLE "cvar_alloc_handle" 18 #define FB_CVAR_REVALIDATE_HANDLE "cvar_revalidate_handle" 19 #define FB_CVAR_NEXT_VALUE "cvar_next_value" 20 #define FB_CVAR_FREE_HANDLE "cvar_free_handle" 21 #define FB_CVAR_MODULE_EXIT "cvar_module_exit" 22 #define FB_CVAR_USAGE "cvar_usage" 23 #define FB_CVAR_VERSION "cvar_version" 24 25 /* Information about each library supporting a custom variable. This structure 26 * is rooted in the shared memory segment. */ 27 typedef struct cvar_library_info { 28 char *filename; /* The fully qualified path to the library. */ 29 /* The type name of the library is the soname without the "lib" prefix and 30 * the ".so.XXX.XXX" suffix. */ 31 char *type; 32 /* The index is a sequentially increasing count. It helps seek within global 33 * variable cvar_library_array. */ 34 int index; 35 struct cvar_library_info *next; 36 } cvar_library_info_t; 37 38 /* Structure that encapsulates access to a custom variable. A var_t points to a 39 * cvar_t (and not vice versa). */ 40 typedef struct cvar { 41 /* Used to provide exclusive access to this custom variable across threads 42 * and processes. */ 43 pthread_mutex_t cvar_lock; 44 /* The custom variable handle returned by cvar_alloc() */ 45 void *cvar_handle; 46 double min; 47 double max; 48 uint64_t round; 49 cvar_library_info_t *cvar_lib_info; 50 struct cvar *next; 51 } cvar_t; 52 53 /* The operations vector for a library. Each member is populated by a call to 54 * dlsym(). */ 55 typedef struct cvar_operations { 56 int (*cvar_module_init)(void); 57 void *(*cvar_alloc_handle)(const char *cvar_parameters, 58 void *(*cvar_malloc)(size_t size), void (*cvar_free)(void *ptr)); 59 int (*cvar_revalidate_handle)(void *cvar_handle); 60 int (*cvar_next_value)(void *cvar_handle, double *value); 61 void (*cvar_free_handle)(void *cvar_handle, void (*cvar_free)(void *ptr)); 62 void (*cvar_module_exit)(); 63 const char *(*cvar_usage)(void); 64 const char *(*cvar_version)(void); 65 } cvar_operations_t; 66 67 /* Structure that represents a library. This structure is "per-process" and 68 * "per-library" (and not in the shared memory). There is a one to one mapping 69 * between cvar_library_t and cvar_library_info_t. */ 70 typedef struct cvar_library { 71 cvar_library_info_t *cvar_lib_info; 72 void *lib_handle; /* The handle returned by dlopen(). */ 73 cvar_operations_t cvar_op; /* The operations vector of the library. */ 74 } cvar_library_t; 75 76 /* Points to the head of an array of pointers to cvar_library_t. */ 77 extern cvar_library_t **cvar_libraries; 78 79 cvar_t * cvar_alloc(void); 80 int init_cvar_library_info(const char *dirpath); 81 int init_cvar_libraries(); 82 int init_cvar_handle(cvar_t *cvar, const char *type, const char *parameters); 83 double get_cvar_value(cvar_t *cvar); 84 int revalidate_cvar_handles(); 85 86 #endif /* _FB_CVAR_H */ 87