pdserv  3.4
Process data server
pdserv.h
Go to the documentation of this file.
1 /*****************************************************************************
2  *
3  * vim:ft=c:tw=78
4  *
5  * Copyright 2010 - 2016 Richard Hacker (lerichi at gmx dot net)
6  * 2025 Florian Pose <fp@igh.de>
7  *
8  * This file is part of the pdserv library.
9  *
10  * The pdserv library is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Lesser General Public License as published
12  * by the Free Software Foundation, either version 3 of the License, or (at
13  * your option) any later version.
14  *
15  * The pdserv library is distributed in the hope that it will be useful, but
16  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18  * License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with the pdserv library. If not, see <http://www.gnu.org/licenses/>.
22  *
23  ****************************************************************************/
24 
29 #ifndef PDSERV_H
30 #define PDSERV_H
31 
34 #include <stddef.h>
35 
36 #ifdef pdserv_EXPORTS
37 # define PDSERV_EXPORT __attribute__((__visibility__("default")))
38 #else
39 # define PDSERV_EXPORT
40 #endif
41 
59 #define PDSERV_VERSION(major, minor, patchlevel) \
60  (((major) << 16) + ((minor) << 8) + (patchlevel))
61 
62 #define PDSERV_VERSION_MAJOR 3
63 #define PDSERV_VERSION_MINOR 4
64 #define PDSERV_VERSION_PATCH 1
65 
66 #define PDSERV_VERSION_CODE PDSERV_VERSION( \
67  PDSERV_VERSION_MAJOR, PDSERV_VERSION_MINOR, PDSERV_VERSION_PATCH)
68 
69 #ifdef __cplusplus
70 extern "C" {
71 #endif
72 
82 #define HAS_VERSION_CODE
83 PDSERV_EXPORT extern const char* const pdserv_version_str;
84 PDSERV_EXPORT extern const char* const pdserv_full_version;
85 
86 /* Data type definitions. */
161 /* Let the enumeration start at 1 so that an unset data type could be
162  * detected.*/
163 #define pd_double_T 1
164 #define pd_single_T 2
165 #define pd_uint8_T 3
166 #define pd_sint8_T 4
167 #define pd_uint16_T 5
168 #define pd_sint16_T 6
169 #define pd_uint32_T 7
170 #define pd_sint32_T 8
171 #define pd_uint64_T 9
172 #define pd_sint64_T 10
173 #define pd_boolean_T 11
174 #define pd_schar_T 12
175 #define pd_char_T 13
176 #define pd_uchar_T 14
177 #define pd_short_T 15
178 #define pd_ushort_T 16
179 #define pd_int_T 17
180 #define pd_uint_T 18
181 #define pd_long_T 19
182 #define pd_ulong_T 20
183 #define pd_longlong_T 21
184 #define pd_ulonglong_T 22
185 #define pd_ssize_T 23
186 #define pd_size_T 24
187 
188 #define pd_datatype_end 25
189 
190 struct timespec;
191 
194 /* Structure declarations.
195  */
196 struct pdserv;
197 struct pdtask;
198 struct pdvariable;
199 struct pdevent;
202 typedef int (*gettime_t)(struct timespec*);
203 
213 PDSERV_EXPORT struct pdserv* pdserv_create(
214  const char *name,
215  const char *version,
216  gettime_t gettime_cb
221  );
222 
234 PDSERV_EXPORT void pdserv_config_file(
235  struct pdserv* pdserv,
236  const char *file
237  );
238 
249 PDSERV_EXPORT void pdserv_set_parameter_writelock_cb(
250  struct pdserv* pdserv,
251  void (*fn)(int lock, void* priv_data),
252  void* priv_data
253  );
254 
264 PDSERV_EXPORT struct pdtask* pdserv_create_task(
265  struct pdserv* pdserv,
266  double tsample,
267  const char *name
268  );
269 
280 PDSERV_EXPORT void pdserv_set_signal_readlock_cb(
281  struct pdtask* pdtask,
282  void (*fn)(int lock, void* priv_data),
283  void* priv_data
284  );
285 
294 PDSERV_EXPORT int pdserv_create_compound(
295  const char *name,
296  size_t size
297  );
298 
301 PDSERV_EXPORT void pdserv_compound_add_field(
302  int compound,
303  const char *name,
304  int data_type,
308  size_t offset,
309  size_t ndim,
310  const size_t *dim
311  );
312 
341 PDSERV_EXPORT struct pdvariable *pdserv_signal(
342  struct pdtask* pdtask,
343  unsigned int decimation,
345  const char *path,
346  int datatype,
350  const void *addr,
351  size_t n,
354  const size_t *dim
356  );
357 
361 typedef int (*read_signal_t)(const struct pdvariable *signal, void *dst,
362  const void *src, size_t len, struct timespec* time, void *priv_data);
363 
364 PDSERV_EXPORT void pdserv_signal_set_read_cb(struct pdvariable* signal,
365  read_signal_t read_signal_cb, void* priv_data
366  ) __attribute__((deprecated("use pdserv_signal() instead")));
367 
368 PDSERV_EXPORT struct pdvariable *pdserv_signal_cb( struct pdtask* pdtask,
369  unsigned int decimation, const char *path, int datatype,
370  const void *addr, size_t n, const size_t *dim,
371  read_signal_t read_signal_cb, void* priv_data
372  ) __attribute__((deprecated("use pdserv_signal() instead")));;
403 #define RESET_EVENT 0
404 #define EMERG_EVENT 1
405 #define ALERT_EVENT 2
406 #define CRIT_EVENT 3
407 #define ERROR_EVENT 4
408 #define WARN_EVENT 5
409 #define NOTICE_EVENT 6
410 #define INFO_EVENT 7
411 #define DEBUG_EVENT 8
412 
424 PDSERV_EXPORT struct pdevent *pdserv_event(
425  struct pdserv* pdserv,
426  const char *path,
427  size_t n
428  );
429 
437 PDSERV_EXPORT void pdserv_event_set_text(
438  struct pdevent* event,
439  const char * const *text
450  );
451 
457 PDSERV_EXPORT void pdserv_event_set(
458  const struct pdevent *event,
459  size_t element,
460  int priority,
470  const struct timespec *t
471  );
472 
478 PDSERV_EXPORT void pdserv_event_reset(
479  const struct pdevent *event,
480  size_t element,
481  const struct timespec *t
482  );
483 
497 PDSERV_EXPORT void pdserv_event_set_all(
498  const struct pdevent *event,
499  const unsigned int * level,
514  const struct timespec *t
515  );
516 
521 PDSERV_EXPORT int pdserv_event_export(
522  const struct pdserv* pdserv,
523  const char *path
524  );
525 
552 typedef int (*write_parameter_t)(
553  const struct pdvariable *param,
554  void *dst,
555  const void *src,
556  size_t len,
557  struct timespec* time,
558  void *priv_data
559  );
560 
577 PDSERV_EXPORT struct pdvariable *pdserv_parameter(
578  struct pdserv* pdserv,
579  const char *path,
580  unsigned int mode,
581  int datatype,
585  void *addr,
586  size_t n,
589  const size_t *dim,
591  write_parameter_t write_cb,
593  void *priv_data
595  );
596 
603 PDSERV_EXPORT void pdserv_set_alias(
604  struct pdvariable *variable,
605  const char *alias
606  );
607 
609 PDSERV_EXPORT void pdserv_set_unit(
610  struct pdvariable *variable,
611  const char *unit
612  );
613 
615 PDSERV_EXPORT void pdserv_set_comment(
616  struct pdvariable *variable,
617  const char *comment
618  );
619 
627 PDSERV_EXPORT const char *pdserv_get_variable_path(
628  const struct pdvariable *variable
629  );
630 
650 PDSERV_EXPORT int pdserv_prepare(
651  struct pdserv* pdserv
652  );
653 
659 PDSERV_EXPORT void pdserv_update_statistics(
660  struct pdtask* pdtask,
661  double exec_time,
662  double cycle_time,
663  unsigned int overrun
664  );
665 
671 PDSERV_EXPORT void pdserv_update(
672  struct pdtask* pdtask,
673  const struct timespec *t
675  );
676 
682 PDSERV_EXPORT void pdserv_exit(
683  struct pdserv*
684  );
685 
686 #ifdef __cplusplus
687 }
688 #endif /* __cplusplus */
689 
690 #endif /* PDSERV_H */
int(* gettime_t)(struct timespec *)
Definition: pdserv.h:202
PDSERV_EXPORT const char *const pdserv_version_str
String of pdserv version code "major.minor.patch".
PDSERV_EXPORT void pdserv_compound_add_field(int compound, const char *name, int data_type, size_t offset, size_t ndim, const size_t *dim)
PDSERV_EXPORT void pdserv_event_reset(const struct pdevent *event, size_t element, const struct timespec *t)
PDSERV_EXPORT void pdserv_set_comment(struct pdvariable *variable, const char *comment)
PDSERV_EXPORT void pdserv_event_set_all(const struct pdevent *event, const unsigned int *level, const struct timespec *t)
PDSERV_EXPORT struct pdtask * pdserv_create_task(struct pdserv *pdserv, double tsample, const char *name)
PDSERV_EXPORT void pdserv_config_file(struct pdserv *pdserv, const char *file)
PDSERV_EXPORT struct pdvariable * pdserv_parameter(struct pdserv *pdserv, const char *path, unsigned int mode, int datatype, void *addr, size_t n, const size_t *dim, write_parameter_t write_cb, void *priv_data)
PDSERV_EXPORT void pdserv_update_statistics(struct pdtask *pdtask, double exec_time, double cycle_time, unsigned int overrun)
PDSERV_EXPORT const char *const pdserv_full_version
Full String of pdserv version, generated by git describe.
PDSERV_EXPORT int pdserv_event_export(const struct pdserv *pdserv, const char *path)
PDSERV_EXPORT struct pdvariable * pdserv_signal(struct pdtask *pdtask, unsigned int decimation, const char *path, int datatype, const void *addr, size_t n, const size_t *dim)
PDSERV_EXPORT struct pdevent * pdserv_event(struct pdserv *pdserv, const char *path, size_t n)
PDSERV_EXPORT void pdserv_set_signal_readlock_cb(struct pdtask *pdtask, void(*fn)(int lock, void *priv_data), void *priv_data)
int(* write_parameter_t)(const struct pdvariable *param, void *dst, const void *src, size_t len, struct timespec *time, void *priv_data)
Definition: pdserv.h:552
PDSERV_EXPORT int pdserv_create_compound(const char *name, size_t size)
PDSERV_EXPORT struct pdserv * pdserv_create(const char *name, const char *version, gettime_t gettime_cb)
PDSERV_EXPORT void pdserv_event_set_text(struct pdevent *event, const char *const *text)
PDSERV_EXPORT void pdserv_exit(struct pdserv *)
PDSERV_EXPORT int pdserv_prepare(struct pdserv *pdserv)
PDSERV_EXPORT void pdserv_set_unit(struct pdvariable *variable, const char *unit)
PDSERV_EXPORT void pdserv_update(struct pdtask *pdtask, const struct timespec *t)
PDSERV_EXPORT void pdserv_set_parameter_writelock_cb(struct pdserv *pdserv, void(*fn)(int lock, void *priv_data), void *priv_data)
PDSERV_EXPORT void pdserv_set_alias(struct pdvariable *variable, const char *alias)
PDSERV_EXPORT void pdserv_event_set(const struct pdevent *event, size_t element, int priority, const struct timespec *t)
PDSERV_EXPORT const char * pdserv_get_variable_path(const struct pdvariable *variable)