/usr/include/openturns/WrapperInterface.h is in libopenturns-dev 1.5-7build2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 | // -*- C -*-
/**
* @file WrapperInterface.h
* @brief This file provides an interface for external code C wrappers
*
* Copyright 2005-2015 Airbus-EDF-IMACS-Phimeca
*
* Permission to copy, use, modify, sell and distribute this software
* is granted provided this copyright notice appears in all copies.
* This software is provided "as is" without express or implied
* warranty, and with no claim as to its suitability for any purpose.
*
*
* @author schueller
* @date 2012-02-17 19:35:43 +0100 (Fri, 17 Feb 2012)
*/
#ifndef OPENTURNS_WRAPPERINTERFACE_H
#define OPENTURNS_WRAPPERINTERFACE_H
#include "OTdebug.h"
#include "OTconfig.hxx"
#ifdef OPENTURNS_HAVE_PTHREAD_H
#include "OTthread.hxx"
#include <signal.h>
#endif /* OPENTURNS_HAVE_PTHREAD_H */
BEGIN_C_DECLS
/**
* Error codes and type that can be returned by the wrapper
*/
enum WrapperErrorCode {
WRAPPER_OK = 0,
WRAPPER_MEMORY_ERROR,
WRAPPER_INITIALIZATION_ERROR,
WRAPPER_EXECUTION_ERROR,
WRAPPER_FINALIZATION_ERROR,
WRAPPER_CANNOT_CREATE_STATE,
WRAPPER_CANNOT_DELETE_STATE,
WRAPPER_CANNOT_PROVIDE_INFORMATION,
WRAPPER_INTERNAL_ERROR,
WRAPPER_WRONG_ARGUMENT,
WRAPPER_USAGE_ERROR,
WRAPPER_NOT_IMPLEMENTED,
WRAPPER_EXECUTION_ERROR_NO_RETRY,
WRAPPER_BIND_ERROR,
UNUSED_ERROR
};
/**
* All those structures and definitions are designed for being exchanged
* through the wrapper C API.
*/
/**
* @struct WrapperInformation
*
* This structure is returned by the wrapper when the platform Open TURNS
* asks it to detail its internal function.
* There is one WrapperInformation structure for each internal function.
*/
struct WrapperInformation {
unsigned long inSize_; /* size of the in numerical point of the function */
unsigned long outSize_; /* size of the out numerical point of the function */
};
/**
* @struct point
*
* This structure holds the numerical point that is consumed or produced
* by the internal function.
* Remember to allocate or free the data_ pointer. The memory management
* policy is : When you allocate memory, you have to deallocate it !
* So if you pass a point structure for which you have allocated memory
* to a function, the function should not free the memory when called,
* so you MUST free it when the function returns. OK ?
*/
struct point {
unsigned long size_; /* size of data vector */
double * data_; /* data of the numerical point ordered as a vector */
};
/**
* @struct sample
*
* This structure holds the numerical sample that is consumed or produced
* by the internal function.
* Remember to allocate or free the data_ pointer. The memory management
* policy is : When you allocate memory, you have to deallocate it !
* So if you pass a sample structure for which you have allocated memory
* to a function, the function should not free the memory when called,
* so you MUST free it when the function returns. OK ?
*/
struct sample {
unsigned long size_; /* size of data sample */
unsigned long dimension_; /* dimension of data sample */
double * data_; /* data of the numerical sample ordered as a vector */
};
/**
* @struct field
*
* This structure holds the field that is consumed or produced
* by the internal function.
* Remember to allocate or free the data_ pointer. The memory management
* policy is : When you allocate memory, you have to deallocate it !
* So if you pass a sample structure for which you have allocated memory
* to a function, the function should not free the memory when called,
* so you MUST free it when the function returns. OK ?
*/
struct field {
unsigned long size_; /* size of data sample */
unsigned long dimension_; /* dimension of data sample. Important note: see Field.hxx */
double * data_; /* data of the field ordered as a vector */
};
/**
* @struct matrix
*
* This structure holds the matrix that produced
* by the internal gradient.
* Remember to allocate or free the data_ pointer. The memory management
* policy is : When you allocate memory, you have to deallocate it !
* So if you pass a matrix structure for which you have allocated memory
* to a function, the function should not free the memory when called,
* so you MUST free it when the function returns. OK ?
*/
struct matrix {
unsigned long nbrows_; /* number of rows into data vector */
unsigned long nbcols_; /* number of columns into data vector */
double * data_; /* data of the matrix ordered as a vector */
};
/**
* @struct tensor
*
* This structure holds the tensor that produced
* by the internal hessian.
* Remember to allocate or free the data_ pointer. The memory management
* policy is : When you allocate memory, you have to deallocate it !
* So if you pass a tensor structure for which you have allocated memory
* to a function, the function should not free the memory when called,
* so you MUST free it when the function returns. OK ?
*/
struct tensor {
unsigned long nbrows_; /* number of rows into data vector */
unsigned long nbcols_; /* number of columns into data vector */
unsigned long nbsheets_; /* number of sheets into data vector */
double * data_; /* data of the tensor ordered as a vector */
};
/**
* @enum WrapperListElementType
*
* This simple enumeration holds the type (input or output) of elements
* used by the wrapper.
*/
enum WrapperListElementType { WRAPPER_IN=0, WRAPPER_OUT, WRAPPER_INTERNAL, UNUSED_LISTELEMENT };
enum WrapperProvided { WRAPPER_NO=0, WRAPPER_YES, UNUSED_PROVIDED };
enum WrapperLocationType { WRAPPER_LINE=0, WRAPPER_REGEXP, UNUSED_LOCATION };
/**
* @ struct WrapperFileListElement
*
* This structure is a shell for all information about files
* used by the wrapper.
*/
struct WrapperFileListElement {
char * id_; /* The id of the file (for human reading) */
char * name_; /* The name of the file (for human reading) */
char * path_; /* The path of the file */
char * subst_; /* The substitution list of the file */
enum WrapperListElementType type_; /* The type (input or output) of the file */
};
/**
* @struct WrapperFileList
*
* This is the link of a chained list. This list holds all the files
* exchanged with the wrapper.
*/
struct WrapperFileList {
struct WrapperFileList * next_; /* Points to the next element in list */
struct WrapperFileListElement * file_; /* The file passed to the wrapper */
};
/**
* @struct WrapperVariableListElement
*
* This structure is a shell for all information about variables
* used by the wrapper.
*/
struct WrapperVariableListElement {
char * id_; /* The identifier of the variable */
char * comment_; /* The comment informs on the variable (for human reading) */
char * unit_; /* The unit which the variable is expressed in */
char * regexp_; /* The regular expression used to find the variable location in files */
char * format_; /* The format in which the variable must be printed in files */
enum WrapperListElementType type_; /* The type (input or output) of the variable */
enum WrapperProvided gradient_; /* The gradient of this variable is computed if non-zero */
enum WrapperLocationType fromType_; /* The type of information stored in from_ member */
char * from_; /* The location in file where substitution should start */
enum WrapperLocationType toType_; /* The type of information stored in to_ member */
char * to_; /* The location in file where substitution should stop */
};
/**
* @struct WrapperVariableList
*
* This is the link of a chained list. This list holds all the variables
* exchanged with the wrapper.
*/
struct WrapperVariableList {
struct WrapperVariableList * next_; /* Points to the next element in list */
struct WrapperVariableListElement * variable_; /* The variable passed to the wrapper */
};
enum WrapperConfigurationState { WRAPPER_SHAREDSTATE=0, WRAPPER_SPECIFICSTATE, UNUSED_CONFIGURATIONSTATE };
enum WrapperConfigurationMode { WRAPPER_STATICLINK=0, WRAPPER_DYNAMICLINK, WRAPPER_FORK, UNUSED_CONFIGURATIONMODE };
enum WrapperDataTransferMode { WRAPPER_FILES=0, WRAPPER_PIPE, WRAPPER_ARGUMENTS, WRAPPER_SOCKET, WRAPPER_CORBA, UNUSED_DATATRANSFERMODE };
/**
* @struct WrapperConfiguration
*
* This structure contains general information about the wrapper
*/
struct WrapperConfiguration {
enum WrapperConfigurationState state_; /* The mode of sharing of the internal state */
enum WrapperConfigurationMode mode_; /* The wrapping mode */
enum WrapperDataTransferMode in_; /* The input transfer mode */
enum WrapperDataTransferMode out_; /* The output transfer mode */
char * command_; /* The command invoqued by the wrapper to run the external code */
char * userPrefix_; /* The prefix that helps the user to find its compute dir */
};
/**
* @struct PlatformConfiguration
*
* This structure contains some information about the platform configuration
* at the time the wrapper is loaded.
*/
struct PlatformConfiguration {
char * generalTemporaryDirectory_; /* The main temporary directory in which wrappers can work */
char * realRegexpShortcut_; /* The shortcut for regular expression that match reals */
char * integerRegexpShortcut_; /* The shortcut for regular expression that match integers */
char * separatorRegexpShortcut_; /* The shortcut for regular expression that match blanks */
unsigned long nbCpus_; /* The number of virtual CPUs on the system */
unsigned long outputFilesTimeout_; /* The timeout when waiting for output files to be read */
long retries_; /* The number of retries for a failed command */
char * command_path_; /* The path to the script file to run with multithreading */
};
/**
* @struct WrapperExchangedData
*
* This is the main structure that holds all the informations
* that can be exchanged with the wrapper.
*/
struct WrapperExchangedData {
struct WrapperFileList * fileList_; /* A chained list of files for the wrapper */
struct WrapperVariableList * variableList_; /* A chained list of variables for the wrapper */
struct WrapperConfiguration * parameters_; /* The configuration of the wrapper */
struct PlatformConfiguration * platform_; /* The configuration of the platform */
pthread_mutex_t * p_lock_; /* The mutex that locks this structure */
};
/**
* This is the wrapper C API.
* Every wrapper that intends to plug into the Open TURNS platform should
* provide those functions. They may do nothing if the wrapper does not
* need it.
*
* Anyway, always remember that THE WRAPPER IS TO BE CALLED CONCURRENTLY
* by the platform, so be careful with data sharing and global variable.
* If not protected with critical sections, it is almost sure that something
* will break one day or another.
*
* Because there is no internal synchronisation mechanism in C, it is UP TO YOU
* to do the work.
*
* So keep cool. Do simple things. And if things come to be tough, have a break !
* If at last, you always stands with global or static variables, shared data or
* things leaving outside of your functions, then you have to enter the wonderful
* but terrible world or parallelism. Do you have a talisman ?
*/
/**
* StateCreationFunctionPointer : a function that creates a reserved memory space
* StateDeletionFunctionPointer : a function that frees the reserved memory space
* GetWrapperInformationFunctionPointer : a function that gives information about
* the wrapper internal function
* InitializationFunctionPointer : a function that prepare the wrapper before the
* first call of the wrapper internal function
* ExecutionFunctionPointer : a function that calls the internal wrapper function
* which is the purpose of the wrapper
* GradientFunctionPointer : a function that calls the internal wrapper gradient
* which is the purpose of the wrapper
* HessianFunctionPointer : a function that calls the internal wrapper hessian
* which is the purpose of the wrapper
* FinalizationFunctionPointer : a function that clean everything up after the last
* call of the wrapper internal function
*/
typedef enum WrapperErrorCode RETURNCODE;
typedef void (* METHODS)();
typedef void * STATE;
typedef void ** NEW_STATE;
typedef void * ERROR;
typedef const struct WrapperExchangedData * EXCHANGEDDATA;
typedef struct WrapperInformation * INFORMATION;
typedef const struct point * INPOINT;
typedef const struct sample * INSAMPLE;
typedef const struct field * INFIELD;
typedef struct point * OUTPOINT;
typedef struct sample * OUTSAMPLE;
typedef struct field * OUTFIELD;
typedef struct matrix * OUTMATRIX;
typedef struct tensor * OUTTENSOR;
typedef RETURNCODE ( * BindMethodsFunctionPointer )( METHODS[] );
typedef RETURNCODE ( * StateCreationFunctionPointer )( NEW_STATE, EXCHANGEDDATA, ERROR );
typedef RETURNCODE ( * StateDeletionFunctionPointer )( STATE, EXCHANGEDDATA, ERROR );
typedef RETURNCODE ( * GetWrapperInformationFunctionPointer )( STATE, INFORMATION, EXCHANGEDDATA, ERROR );
typedef RETURNCODE ( * InitializationFunctionPointer )( STATE, EXCHANGEDDATA, ERROR );
typedef RETURNCODE ( * ExecutionFunctionPointer )( STATE, INPOINT, OUTPOINT, EXCHANGEDDATA, ERROR );
typedef RETURNCODE ( * ExecutionSampleFunctionPointer )( STATE, INSAMPLE, OUTSAMPLE, EXCHANGEDDATA, ERROR );
typedef RETURNCODE ( * ExecutionFieldFunctionPointer )( STATE, INFIELD, OUTFIELD, EXCHANGEDDATA, ERROR );
typedef RETURNCODE ( * GradientFunctionPointer )( STATE, INPOINT, OUTMATRIX, EXCHANGEDDATA, ERROR );
typedef RETURNCODE ( * HessianFunctionPointer )( STATE, INPOINT, OUTTENSOR, EXCHANGEDDATA, ERROR );
typedef RETURNCODE ( * FinalizationFunctionPointer )( STATE, EXCHANGEDDATA, ERROR );
END_C_DECLS
/* For compatibility with old wrappers */
#include "WrapperInterface_V0.h"
#endif /* OPENTURNS_WRAPPERINTERFACE_H */
|