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 0
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
446  );
447 
453 PDSERV_EXPORT void pdserv_event_set(
454  const struct pdevent *event,
455  size_t element,
456  int priority,
466  const struct timespec *t
467  );
468 
474 PDSERV_EXPORT void pdserv_event_reset(
475  const struct pdevent *event,
476  size_t element,
477  const struct timespec *t
478  );
479 
493 PDSERV_EXPORT void pdserv_event_set_all(
494  const struct pdevent *event,
495  const unsigned int * level,
510  const struct timespec *t
511  );
512 
517 PDSERV_EXPORT int pdserv_event_export(
518  const struct pdserv* pdserv,
519  const char *path
520  );
521 
548 typedef int (*write_parameter_t)(
549  const struct pdvariable *param,
550  void *dst,
551  const void *src,
552  size_t len,
553  struct timespec* time,
554  void *priv_data
555  );
556 
573 PDSERV_EXPORT struct pdvariable *pdserv_parameter(
574  struct pdserv* pdserv,
575  const char *path,
576  unsigned int mode,
577  int datatype,
581  void *addr,
582  size_t n,
585  const size_t *dim,
587  write_parameter_t write_cb,
589  void *priv_data
591  );
592 
599 PDSERV_EXPORT void pdserv_set_alias(
600  struct pdvariable *variable,
601  const char *alias
602  );
603 
605 PDSERV_EXPORT void pdserv_set_unit(
606  struct pdvariable *variable,
607  const char *unit
608  );
609 
611 PDSERV_EXPORT void pdserv_set_comment(
612  struct pdvariable *variable,
613  const char *comment
614  );
615 
623 PDSERV_EXPORT const char *pdserv_get_variable_path(
624  const struct pdvariable *variable
625  );
626 
646 PDSERV_EXPORT int pdserv_prepare(
647  struct pdserv* pdserv
648  );
649 
655 PDSERV_EXPORT void pdserv_update_statistics(
656  struct pdtask* pdtask,
657  double exec_time,
658  double cycle_time,
659  unsigned int overrun
660  );
661 
667 PDSERV_EXPORT void pdserv_update(
668  struct pdtask* pdtask,
669  const struct timespec *t
671  );
672 
678 PDSERV_EXPORT void pdserv_exit(
679  struct pdserv*
680  );
681 
682 #ifdef __cplusplus
683 }
684 #endif /* __cplusplus */
685 
686 #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:548
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)