Multi-ApplicationOnlineProfiling  2.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
MALP_Blackboard_Level.c
Go to the documentation of this file.
1 /* ############################ MALP License ############################## */
2 /* # Fri Jan 18 14:00:00 CET 2013 # */
3 /* # Copyright or (C) or Copr. Commissariat a l'Energie Atomique # */
4 /* # # */
5 /* # This software is governed by the CeCILL-C license under French law # */
6 /* # and abiding by the rules of distribution of free software. You can # */
7 /* # use, modify and/ or redistribute the software under the terms of # */
8 /* # the CeCILL-C license as circulated by CEA, CNRS and INRIA at the # */
9 /* # following URL http://www.cecill.info. # */
10 /* # # */
11 /* # The fact that you are presently reading this means that you have # */
12 /* # had knowledge of the CeCILL-C license and that you accept its # */
13 /* # terms. # */
14 /* # # */
15 /* # Authors: # */
16 /* # - BESNARD Jean-Baptiste jean-baptiste.besnard@cea.fr # */
17 /* # # */
18 /* ######################################################################## */
19 #include "MALP_Blackboard.h"
20 
21 #include <dlfcn.h>
22 
23 uint64_t MALP_Blackboard_level_id( char *MALP_Blackboard_level_name, char *object1_name, char *object2_name )
24 {
25  uint64_t tab[3];
26 
27  tab[0] = MALP_Trace_crc64( MALP_Blackboard_level_name, strlen(MALP_Blackboard_level_name) );
28  tab[1] = MALP_Trace_crc64( object1_name, strlen(object1_name) );
29  tab[2] = MALP_Trace_crc64( object2_name, strlen(object2_name) );
30 
31  return MALP_Trace_crc64( (char *)tab, sizeof( uint64_t ) * 3 );
32 }
33 
34 
35 
36 struct MALP_Blackboard_level * MALP_Blackboard_level_load( struct MALP_blackboard *bb , char *plugin_soname, void *arg )
37 {
38  void *lib_handle = dlopen(plugin_soname, RTLD_NOW);
39 
40  if( !lib_handle )
41  {
42  printf("Failed to load %s BB plugin\n", plugin_soname );
43  perror("dlopen");
44  return NULL;
45  }
46 
47  struct MALP_Blackboard_level *ret = malloc( sizeof( struct MALP_Blackboard_level ) );
48 
49  if( !ret )
50  {
51  perror("Failled to allocate BLackboard level");
52  dlclose( lib_handle );
53  return NULL;
54  }
55 
56  ret->BB_level_setup = dlsym(lib_handle, "BB_level_setup");
57 
58  if( !ret->BB_level_setup )
59  {
60  perror("Could not load 'BB_level_setup' function from plugin" );
61  dlclose( lib_handle );
62  return NULL;
63  }
64 
65  ret->BB_level_teardown = dlsym(lib_handle, "BB_level_teardown");
66 
67  if( !ret->BB_level_teardown )
68  {
69  perror("Could not load 'BB_level_teardown' function from plugin" );
70  dlclose( lib_handle );
71  return NULL;
72  }
73 
74  ret->arg = arg;
75  ret->lib_handle = lib_handle;
76 
77  printf("MALP Blackboard sucessfully loaded plugin %s\n", plugin_soname );
78 
79  int tmp = (ret->BB_level_setup)( bb, arg );
80 
81  if( tmp )
82  {
83  printf("Error setting up %s plugin\n", plugin_soname );
84  dlclose( lib_handle );
85  return NULL;
86  }
87 
88 
89  return ret;
90 }
91 
92 
94  int (*BB_level_setup)( struct MALP_blackboard *bb, void *arg ),
95  int (*BB_level_teardown)( struct MALP_blackboard *bb, void *arg ) , void *arg )
96 {
97 
98  struct MALP_Blackboard_level *ret = malloc( sizeof( struct MALP_Blackboard_level ) );
99 
100  if( !ret )
101  {
102  perror("Failled to allocate BLackboard level");
103  return NULL;
104  }
105 
106 
107  ret->arg = arg;
110  ret->lib_handle = NULL;
111 
112  if( (ret->BB_level_setup)( bb, arg ) )
113  {
114  printf("Error setting up plugin\n" );
115  return NULL;
116  }
117 
118  return ret;
119 }
120 
121 
123 {
124  if( !level )
125  return 0;
126 
127  int ret = (level->BB_level_teardown)( bb, level->arg );
128 
129  if( ret )
130  {
131  printf("Error releasing a plugin\n");
132  }
133 
134  dlclose( level->lib_handle );
135  level->lib_handle = NULL;
136 
137  free( level );
138 
139  return 1;
140 }
struct MALP_Blackboard_level * MALP_Blackboard_level(struct MALP_blackboard *bb, int(*BB_level_setup)(struct MALP_blackboard *bb, void *arg), int(*BB_level_teardown)(struct MALP_blackboard *bb, void *arg), void *arg)
Create a MALP_Blackboard_level structure using the parameters with NULL value for the handler's mappi...
The MALP_Blackboard_level structure.
static uint64_t MALP_Trace_crc64(char *source, uint64_t size)
Computes the hash of a given data.
Definition: CRC64.h:54
The MALP_blackboard structure.
struct MALP_Blackboard_level * MALP_Blackboard_level_load(struct MALP_blackboard *bb, char *plugin_soname, void *arg)
MALP_Blackboard_level_load [UNUSED?].
int MALP_Blackboard_level_unload(struct MALP_blackboard *bb, struct MALP_Blackboard_level *level)
MALP_Blackboard_level_unload [UNUSED?].
int(* BB_level_teardown)(struct MALP_blackboard *bb, void *arg)
int(* BB_level_setup)(struct MALP_blackboard *bb, void *arg)
uint64_t MALP_Blackboard_level_id(char *MALP_Blackboard_level_name, char *object1_name, char *object2_name)
Generate the hashcode for a 3 dimensions table buffer containing a blackboard level and two object na...