1 /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2    Copyright (c) 2018-2021 The plumed team
3    (see the PEOPLE file at the root of the distribution for a list of names)
4 
5    See http://www.plumed.org for more information.
6 
7    This file is part of plumed, version 2.
8 
9    plumed is free software: you can redistribute it and/or modify
10    it under the terms of the GNU Lesser General Public License as published by
11    the Free Software Foundation, either version 3 of the License, or
12    (at your option) any later version.
13 
14    plumed is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU Lesser General Public License for more details.
18 
19    You should have received a copy of the GNU Lesser General Public License
20    along with plumed.  If not, see <http://www.gnu.org/licenses/>.
21 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
22 #ifndef __PLUMED_core_PlumedMainInitializer_h
23 #define __PLUMED_core_PlumedMainInitializer_h
24 // !!!!!!!!!!!!!!!!!!!!!!    DANGER   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!11
25 // THE FOLLOWING ARE DEFINITIONS WHICH ARE NECESSARY FOR DYNAMIC LOADING OF THE PLUMED KERNEL:
26 // This section should be consistent with the Plumed.h file.
27 // Since the Plumed.h file may be included in host MD codes, **NEVER** MODIFY THE CODE IN THIS FILE
28 // unless you know exactly what you are doing
29 
30 /**
31   Container for plumedmain function pointers (create, cmd and finalize).
32 */
33 typedef struct {
34   void*(*create)();
35   void(*cmd)(void*,const char*,const void*);
36   void(*finalize)(void*);
37 } plumed_plumedmain_function_holder;
38 
39 typedef struct {
40   void* ptr;
41   void (*handler)(void*,int,const char*,const void*);
42 } plumed_nothrow_handler;
43 
44 /**
45   Container for symbol table. Presently only contains a version number and a plumed_plumedmain_function_holder object.
46   The definition of this structure might change in the future. In particular, the structure might grow adding
47   new fields. However, in that case the version number should be updated as well.
48 */
49 typedef struct {
50   int version;
51   plumed_plumedmain_function_holder functions;
52   void (*cmd_nothrow)(void*plumed,const char*key,const void*val,plumed_nothrow_handler nothrow);
53 } plumed_symbol_table_type;
54 
55 
56 // additional definitions
57 typedef void*(*plumed_create_pointer)(void);
58 typedef void(*plumed_cmd_pointer)(void*,const char*,const void*);
59 typedef void(*plumed_finalize_pointer)(void*);
60 
61 /* These functions should be accessible from C, since they might be statically
62    used from Plumed.c (for static binding) */
63 
64 /**
65   Constructs a plumed object.
66   This function returns a void pointer that can be used in \ref plumed_plumedmain_cmd and \ref plumed_plumedmain_finalize.
67 */
68 extern "C" void*plumed_plumedmain_create();
69 
70 /**
71   Send a command `key` and a pointer `val` to a void pointer returned by \ref plumed_plumedmain_create.
72 */
73 extern "C" void plumed_plumedmain_cmd(void*plumed,const char*key,const void*val);
74 
75 /**
76   Finalize a void pointer returned by \ref plumed_plumedmain_create
77 */
78 extern "C" void plumed_plumedmain_finalize(void*plumed);
79 
80 /**
81   Static symbol table that is accessed by the plumed loader.
82   Notice that this table is initialized with a static object construction.
83   In principle, it should be accessed by other programs dlopening the plumed kernel.
84   In that case, it is guaranteed to be already initialized.
85   However, when accessed directly it might be safer to first call \ref plumed_symbol_table_init.
86 */
87 
88 extern "C" plumed_symbol_table_type plumed_symbol_table;
89 
90 /**
91   Function that makes sure that \ref plumed_symbol_table is initialized.
92   Can be called multiple times.
93 */
94 extern "C" void plumed_symbol_table_init();
95 
96 namespace PLMD {
97 // This is just to avoid plumedcheck warnings.
98 // Notice that the only define C-style objects here, so namespace is not needed
99 }
100 
101 
102 #endif
103