3
3
4
4
5
5
#ifdef __cplusplus
6
+
7
+ #include " fdp.hxx"
8
+
6
9
extern " C" {
10
+
7
11
#endif
8
12
13
+ /* *
14
+ * @brief Struct providing an interface to the pipeline.
15
+ *
16
+ * Defined in the implementation file, as it depends on C++ features. A pointer to this
17
+ * struct should be passed to functions in the C API. Set up by the function fdp_init,
18
+ * and finalised by fdp_finalise. Can also be generated from a C++ DataPipeline
19
+ * using to_c_struct.
20
+ */
21
+ struct FdpDataPipeline ;
22
+ typedef struct FdpDataPipeline FdpDataPipeline;
9
23
10
24
/* *
11
25
* @brief Enumeration used to denote different error types.
12
26
*
13
27
* The underlying C++ API will raise a number of different exception types. These map to
14
28
* integer error codes for C compatibility.
15
29
*/
16
- enum FDP_ERR_T {
30
+ enum FdpError {
17
31
FDP_ERR_NONE = 0 ,
18
32
FDP_ERR_CONFIG_PARSE = 1 ,
19
33
FDP_ERR_REST_API_QUERY = 2 ,
20
34
FDP_ERR_JSON_PARSE = 3 ,
21
35
FDP_ERR_VALIDATION = 4 ,
22
36
FDP_ERR_SYNC = 5 ,
23
37
FDP_ERR_WRITE = 6 ,
24
- FDP_ERR_TOML = 6 ,
25
- FDP_ERR_OTHER = 7
38
+ FDP_ERR_TOML = 7 ,
39
+ FDP_ERR_OTHER = 8
26
40
};
27
- typedef enum FDP_ERR_T FDP_ERR_T ;
41
+ typedef enum FdpError FdpError ;
28
42
29
43
30
44
/* *
@@ -33,6 +47,10 @@ typedef enum FDP_ERR_T FDP_ERR_T;
33
47
* Should be called once before any calls to fdp_link_read or fdp_link_write. If called
34
48
* more than once, returns FDP_ERR_OTHER.
35
49
*
50
+ * @param data_pipeline Pointer-to-pointer of a FdpDataPipeline object. The user
51
+ * should declare a pointer to a FdpDataPipeline, and pass its
52
+ * address to this function. This function will then initialise
53
+ * the pipeline.
36
54
* @param config_file_path Path to the `config.yaml` file for this FDP run. Should
37
55
* be at the location `${FDP_CONFIG_DIR}/config.yaml`.
38
56
* @param script_file_path Path to the script which initiates this FDP run. Should
@@ -42,7 +60,8 @@ typedef enum FDP_ERR_T FDP_ERR_T;
42
60
*
43
61
* @return Error code.
44
62
*/
45
- FDP_ERR_T fdp_init (
63
+ FdpError fdp_init (
64
+ FdpDataPipeline **data_pipeline,
46
65
const char *config_file_path,
47
66
const char *script_file_path,
48
67
const char *token
@@ -56,10 +75,13 @@ FDP_ERR_T fdp_init(
56
75
*
57
76
* Record all data products and meta data to the registry. Update the code run with all
58
77
* appropriate meta data.
78
+ *
79
+ * @param data_pipeline Pointer-to-pointer of a FdpDataPipeline object. This function
80
+ * finalises the FdpDataPipeline, and sets its pointer to NULL.
59
81
*
60
82
* @return Error code.
61
83
*/
62
- FDP_ERR_T fdp_finalise ();
84
+ FdpError fdp_finalise (FdpDataPipeline **data_pipeline );
63
85
64
86
65
87
/* *
@@ -68,12 +90,17 @@ FDP_ERR_T fdp_finalise();
68
90
*
69
91
* Must be called after fdp_init and before fdp_finalise.
70
92
*
93
+ * @param data_pipeline Pointer to a FdpDataPipeline object.
71
94
* @param data_product Path to the input file.
72
95
* @param data_store_path Path to the assigned data store location. The user should
73
96
* allocate sufficient memory beforehand.
74
97
* @return Error code
75
98
*/
76
- FDP_ERR_T fdp_link_read (const char * data_product , char * data_store_path );
99
+ FdpError fdp_link_read (
100
+ FdpDataPipeline *data_pipeline,
101
+ const char *data_product,
102
+ char *data_store_path
103
+ );
77
104
78
105
79
106
/* *
@@ -82,12 +109,17 @@ FDP_ERR_T fdp_link_read(const char *data_product, char *data_store_path);
82
109
*
83
110
* Must be called after fdp_init and before fdp_finalise.
84
111
*
112
+ * @param data_pipeline Pointer to a FdpDataPipeline object.
85
113
* @param data_product Path to the output file.
86
114
* @param data_store_path Path to the assigned data store location. The user should
87
115
* allocate sufficient memory beforehand.
88
116
* @return Error code
89
117
*/
90
- FDP_ERR_T fdp_link_write (const char * data_product , char * data_store_path );
118
+ FdpError fdp_link_write (
119
+ FdpDataPipeline *data_pipeline,
120
+ const char *data_product,
121
+ char *data_store_path
122
+ );
91
123
92
124
93
125
/* *
@@ -97,7 +129,7 @@ FDP_ERR_T fdp_link_write(const char *data_product, char *data_store_path);
97
129
* level to `DEBUG` will include all log types except `TRACE`. These correspond to
98
130
* the C++ logging levels `FairDataPipeline::logging::LOG_LEVEL`.
99
131
*/
100
- enum FDP_LOG_LEVEL {
132
+ enum FdpLogLevel {
101
133
FDP_LOG_TRACE = 0 ,
102
134
FDP_LOG_DEBUG = 1 ,
103
135
FDP_LOG_INFO = 2 ,
@@ -106,23 +138,23 @@ enum FDP_LOG_LEVEL {
106
138
FDP_LOG_CRITICAL = 5 ,
107
139
FDP_LOG_OFF = 6
108
140
};
109
- typedef enum FDP_LOG_LEVEL FDP_LOG_LEVEL ;
141
+ typedef enum FdpLogLevel FdpLogLevel ;
110
142
111
143
112
144
/* *
113
145
* @brief Set the log level. Must call `fdp_init` first.
114
146
*
115
147
* @param log_level
116
148
*/
117
- void fdp_set_log_level (FDP_LOG_LEVEL log_level );
149
+ void fdp_set_log_level (FdpLogLevel log_level);
118
150
119
151
120
152
/* *
121
153
* @brief Get the current log level. Must call fdp_init first.
122
154
*
123
155
* @return Log level
124
156
*/
125
- FDP_LOG_LEVEL fdp_get_log_level ();
157
+ FdpLogLevel fdp_get_log_level ();
126
158
127
159
128
160
/* *
@@ -135,11 +167,33 @@ FDP_LOG_LEVEL fdp_get_log_level();
135
167
*
136
168
* @return Error code. 1 if logging unsuccessful, 0 otherwise.
137
169
*/
138
- int fdp_log (FDP_LOG_LEVEL log_level , const char * msg );
170
+ int fdp_log (FdpLogLevel log_level, const char * msg);
139
171
140
172
141
173
#ifdef __cplusplus
174
+
142
175
} // close extern "C"
176
+
177
+ namespace FairDataPipeline {
178
+
179
+ /* *
180
+ * @brief Convert data pipeline from the C API to one in the C++ API.
181
+ */
182
+ DataPipeline::sptr from_c_struct (FdpDataPipeline *data_pipeline);
183
+
184
+ /* *
185
+ * @brief Convert data pipeline from the C++ API to one in the C API.
186
+ *
187
+ * If the pipeline is set up using the C++ method DataPipeline::construct, this may be
188
+ * used to generate a C-compatible struct. Note that this uses 'new' to allocate the
189
+ * returned pointer, so the user should 'delete` the pointer after use to avoid memory
190
+ * leaks. It is not recommended to mix usage of the C and C++ APIs for init and finalise
191
+ * functions.
192
+ */
193
+ FdpDataPipeline* to_c_struct (DataPipeline::sptr data_pipeline);
194
+
195
+ } // close namespace FairDataPipeline
196
+
143
197
#endif
144
198
145
199
0 commit comments