PDI 1.12.0-alpha.2026-05-07

the PDI data interface

pdi.h
1/*******************************************************************************
2* Copyright (C) 2015-2026 Commissariat a l'energie atomique et aux energies alternatives (CEA)
3* All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of CEA nor the names of its contributors may be used to
13* endorse or promote products derived from this software without specific
14* prior written permission.
15*
16* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22* THE SOFTWARE.
23******************************************************************************/
24
54
55#ifndef PDI_H_
56#define PDI_H_
57
58#include <paraconf.h>
59
60#include <pdi/export.h>
61#include <pdi/version.h>
62
63#ifdef __cplusplus
64extern "C" {
65#define PDI_UNAVAILABLE_DEPRECATED [[deprecated("PDI_UNAVAILABLE is never used")]]
66#define PDI_ERR_CONFIG_DEPRECATED [[deprecated("Use PDI_ERR_SPECTREE instead")]]
67#define PDI_ERR_RIGHT_DEPRECATED [[deprecated("Use PDI_ERR_PERMISSION instead")]]
68#else
69#define PDI_UNAVAILABLE_DEPRECATED
70#define PDI_ERR_CONFIG_DEPRECATED
71#define PDI_ERR_RIGHT_DEPRECATED
72#endif
73
77
80typedef enum PDI_status_e {
82 PDI_OK = 0,
84 // initialize the value to workaround a bug in AppleClang 15
85 PDI_UNAVAILABLE PDI_UNAVAILABLE_DEPRECATED = (PDI_OK + 1),
88 PDI_ERR_CONFIG PDI_ERR_CONFIG_DEPRECATED = PDI_ERR_SPECTREE,
103 PDI_ERR_RIGHT PDI_ERR_RIGHT_DEPRECATED = PDI_ERR_PERMISSION,
111 // it should also always remain last
114
115static
116#ifdef __cplusplus
117 constexpr
118#endif
119 char const * const PDI_STATUS_MSG[]
120 = {"Not an error",
121 "Data unavailable",
122 "Invalid entry in specification tree",
123 "Invalid value expression",
124 "Invalid plugin",
125 "Missing feature",
126 "System error",
127 "Precondition not respected",
128 "Permission issue",
129 "Incorrect type",
130 "Invalid action requested",
131 "Multiple errors"};
132
138typedef void (*PDI_errfunc_f)(PDI_status_t status, const char* message, void* context);
139
142typedef struct PDI_errhandler_s {
145
147 void* context;
148
150
153extern const PDI_errhandler_t PDI_EXPORT PDI_ASSERT_HANDLER;
154
157extern const PDI_errhandler_t PDI_EXPORT PDI_WARN_HANDLER;
158
161extern const PDI_errhandler_t PDI_EXPORT PDI_NULL_HANDLER;
162
163
166const char PDI_EXPORT * PDI_errmsg(void);
167
176
178
185
190PDI_status_t PDI_EXPORT PDI_init(PC_tree_t conf);
191
195PDI_status_t PDI_EXPORT PDI_finalize(void);
196
204PDI_status_t PDI_EXPORT PDI_version(unsigned long* provided, unsigned long expected);
205
207
211
215typedef enum PDI_inout_e {
224
226
241PDI_status_t PDI_EXPORT PDI_share(const char* name, const void* data, PDI_inout_t access);
242
251PDI_status_t PDI_EXPORT PDI_access(const char* name, void** buffer, PDI_inout_t inout);
252
260PDI_status_t PDI_EXPORT PDI_release(const char* name);
261
269PDI_status_t PDI_EXPORT PDI_reclaim(const char* name);
270
275PDI_status_t PDI_EXPORT PDI_event(const char* event);
276
284PDI_status_t PDI_EXPORT PDI_expose(const char* name, const void* data, PDI_inout_t access);
285
301PDI_status_t PDI_EXPORT PDI_multi_expose(const char* event_name, const char* name, const void* data, PDI_inout_t access, ...);
302
303#ifdef PDI_WITH_DEPRECATED
304
319PDI_status_t PDI_DEPRECATED_EXPORT PDI_transaction_begin(const char* name);
320
331PDI_status_t PDI_DEPRECATED_EXPORT PDI_transaction_end(void);
332
333#endif // PDI_WITH_DEPRECATED
334
336
337#ifdef __cplusplus
338} // extern C
339#endif
340
341
342#endif // PDI_H_
PDI_status_t PDI_release(const char *name)
Releases ownership of a data shared with PDI.
PDI_inout_t
Access directions.
Definition pdi.h:215
PDI_status_t PDI_multi_expose(const char *event_name, const char *name, const void *data, PDI_inout_t access,...)
Performs multiple exposes at once.
PDI_status_t PDI_access(const char *name, void **buffer, PDI_inout_t inout)
Requests for PDI to access a data buffer.
PDI_status_t PDI_share(const char *name, const void *data, PDI_inout_t access)
Shares some data with PDI.
PDI_status_t PDI_event(const char *event)
Triggers a PDI "event".
PDI_status_t PDI_reclaim(const char *name)
Reclaims ownership of a data buffer shared with PDI.
PDI_status_t PDI_expose(const char *name, const void *data, PDI_inout_t access)
Shortly exposes some data to PDI.
@ PDI_OUT
data transfer from the main code to PDI
Definition pdi.h:221
@ PDI_INOUT
data transfer in both direction
Definition pdi.h:223
@ PDI_IN
data tranfer from PDI to the main code
Definition pdi.h:219
@ PDI_NONE
No data transfert.
Definition pdi.h:217
PDI_errfunc_f func
The function to handle the error (none if NULL).
Definition pdi.h:144
void * context
the context that will be provided to the function
Definition pdi.h:147
PDI_errhandler_t PDI_errhandler(PDI_errhandler_t handler)
Sets the error handler to use.
const PDI_errhandler_t PDI_ASSERT_HANDLER
Prints the error message and aborts if the status is invalid.
const PDI_errhandler_t PDI_NULL_HANDLER
Does nothing.
PDI_status_t
Error codes of PDI.
Definition pdi.h:80
const char * PDI_errmsg(void)
Return a human-readabe message describing the last error that occured in PDI.
const PDI_errhandler_t PDI_WARN_HANDLER
Prints the error message and continue if the status is invalid.
void(* PDI_errfunc_f)(PDI_status_t status, const char *message, void *context)
Type of a callback function used when an error occurs.
Definition pdi.h:138
@ PDI_ERR_VALUE
A value expression is invalid.
Definition pdi.h:90
@ PDI_ERR_SPECTREE
Invalid entry in the specification tree.
Definition pdi.h:87
@ PDI_ERR_STATE
A call to a function has been made at a wrong time (e.g.
Definition pdi.h:100
@ PDI_OK
everything went well
Definition pdi.h:82
@ PDI_ERR_TYPE
Invalid type error.
Definition pdi.h:105
@ PDI_ERR_PERMISSION
A conflict of ownership over a content has been raised.
Definition pdi.h:102
@ PDI_ERR_SYSTEM
A system error occurred (OS, etc.).
Definition pdi.h:96
@ PDI_ERR_INVALIDACTION
Action described in the specification tree is invalid.
Definition pdi.h:107
@ PDI_ERR_MULTIPLE
Multiple errors of different types append.
Definition pdi.h:109
@ PDI_ERR_IMPL
Implementation limitation (typically an unimplemented feature).
Definition pdi.h:94
@ PDI_NB_STATUSES_DEFINED
The amount of distinct error codes defined. This should not be used as an error code.
Definition pdi.h:112
@ PDI_ERR_PLUGIN
Tried to load a non-existing plugin.
Definition pdi.h:92
Definition of an error handler.
Definition pdi.h:142
PDI_status_t PDI_init(PC_tree_t conf)
Initializes PDI.
PDI_status_t PDI_finalize(void)
Finalizes PDI.
PDI_status_t PDI_version(unsigned long *provided, unsigned long expected)
Checks PDI API version.