|
| 1 | +/** |
| 2 | + * @file plugin_types.h |
| 3 | + * @brief Common type definitions for OpenPLC plugins |
| 4 | + * |
| 5 | + * This header defines the essential types and structures shared between |
| 6 | + * the plugin driver system and native plugins. It provides: |
| 7 | + * - Logging function pointer types |
| 8 | + * - The plugin_runtime_args_t structure for runtime buffer access |
| 9 | + * |
| 10 | + * Both Python and native plugins receive a pointer to plugin_runtime_args_t |
| 11 | + * during initialization, giving them access to PLC I/O buffers, mutex |
| 12 | + * functions, and centralized logging. |
| 13 | + */ |
| 14 | + |
| 15 | +#ifndef PLUGIN_TYPES_H |
| 16 | +#define PLUGIN_TYPES_H |
| 17 | + |
| 18 | +#include "../lib/iec_types.h" |
| 19 | +#include <pthread.h> |
| 20 | + |
| 21 | +/** |
| 22 | + * @brief Logging function pointer types |
| 23 | + * |
| 24 | + * These function pointers are provided to plugins for routing log messages |
| 25 | + * through the central OpenPLC logging system. Messages logged through these |
| 26 | + * functions will appear in the OpenPLC Editor's log viewer. |
| 27 | + */ |
| 28 | +typedef void (*plugin_log_info_func_t)(const char *fmt, ...); |
| 29 | +typedef void (*plugin_log_debug_func_t)(const char *fmt, ...); |
| 30 | +typedef void (*plugin_log_warn_func_t)(const char *fmt, ...); |
| 31 | +typedef void (*plugin_log_error_func_t)(const char *fmt, ...); |
| 32 | + |
| 33 | +/** |
| 34 | + * @brief Runtime buffer access structure for plugins |
| 35 | + * |
| 36 | + * This structure is passed to plugins during initialization, providing |
| 37 | + * access to: |
| 38 | + * - PLC I/O buffers (bool, byte, int, dint, lint for inputs/outputs/memory) |
| 39 | + * - Mutex functions for thread-safe buffer access |
| 40 | + * - Plugin-specific configuration file path |
| 41 | + * - Buffer size information |
| 42 | + * - Centralized logging functions |
| 43 | + * |
| 44 | + * Plugins should use mutex_take/mutex_give when accessing buffers to ensure |
| 45 | + * thread safety with the PLC scan cycle. |
| 46 | + */ |
| 47 | +typedef struct |
| 48 | +{ |
| 49 | + /* Buffer pointers */ |
| 50 | + IEC_BOOL *(*bool_input)[8]; |
| 51 | + IEC_BOOL *(*bool_output)[8]; |
| 52 | + IEC_BYTE **byte_input; |
| 53 | + IEC_BYTE **byte_output; |
| 54 | + IEC_UINT **int_input; |
| 55 | + IEC_UINT **int_output; |
| 56 | + IEC_UDINT **dint_input; |
| 57 | + IEC_UDINT **dint_output; |
| 58 | + IEC_ULINT **lint_input; |
| 59 | + IEC_ULINT **lint_output; |
| 60 | + IEC_UINT **int_memory; |
| 61 | + IEC_UDINT **dint_memory; |
| 62 | + IEC_ULINT **lint_memory; |
| 63 | + IEC_BOOL *(*bool_memory)[8]; |
| 64 | + |
| 65 | + /* Mutex functions for thread-safe buffer access */ |
| 66 | + int (*mutex_take)(pthread_mutex_t *mutex); |
| 67 | + int (*mutex_give)(pthread_mutex_t *mutex); |
| 68 | + pthread_mutex_t *buffer_mutex; |
| 69 | + |
| 70 | + /* Plugin configuration */ |
| 71 | + char plugin_specific_config_file_path[256]; |
| 72 | + |
| 73 | + /* Buffer size information */ |
| 74 | + int buffer_size; |
| 75 | + int bits_per_buffer; |
| 76 | + |
| 77 | + /* Logging functions - route messages through central logging system */ |
| 78 | + plugin_log_info_func_t log_info; |
| 79 | + plugin_log_debug_func_t log_debug; |
| 80 | + plugin_log_warn_func_t log_warn; |
| 81 | + plugin_log_error_func_t log_error; |
| 82 | +} plugin_runtime_args_t; |
| 83 | + |
| 84 | +#endif /* PLUGIN_TYPES_H */ |
0 commit comments