1
0

plugin.h 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * plugin.h
  3. */
  4. #ifndef _clish_plugin_h
  5. #define _clish_plugin_h
  6. #include "lub/types.h"
  7. /* Symbol */
  8. /* Symbol types. Functions with different definition. */
  9. typedef enum {
  10. CLISH_SYM_TYPE_NONE = 0, /* None */
  11. CLISH_SYM_TYPE_ACTION, /* Common builtin symbol */
  12. CLISH_SYM_TYPE_ACCESS,
  13. CLISH_SYM_TYPE_CONFIG,
  14. CLISH_SYM_TYPE_LOG,
  15. CLISH_SYM_TYPE_MAX /* Number of elements */
  16. } clish_sym_type_e;
  17. typedef struct clish_sym_s clish_sym_t;
  18. typedef struct clish_plugin_s clish_plugin_t;
  19. /* Plugin types */
  20. /* Name of init function within plugin */
  21. #define CLISH_PLUGIN_INIT_FNAME clish_plugin_init
  22. #define CLISH_PLUGIN_INIT_NAME "clish_plugin_init"
  23. #define CLISH_PLUGIN_INIT_FUNC(name) int name(void *clish_shell, clish_plugin_t *plugin)
  24. #define CLISH_PLUGIN_INIT CLISH_PLUGIN_INIT_FUNC(CLISH_PLUGIN_INIT_FNAME)
  25. /* Name of fini function within plugin */
  26. #define CLISH_PLUGIN_FINI_FNAME clish_plugin_fini
  27. #define CLISH_PLUGIN_FINI_NAME "clish_plugin_fini"
  28. #define CLISH_PLUGIN_FINI_FUNC(name) int name(void *clish_shell, clish_plugin_t *plugin)
  29. #define CLISH_PLUGIN_FINI CLISH_PLUGIN_FINI_FUNC(CLISH_PLUGIN_FINI_FNAME)
  30. #define CLISH_PLUGIN_SYM(name) int name(void *clish_context, const char *script, char **out)
  31. #define CLISH_HOOK_ACCESS(name) int name(void *clish_context, const char *access)
  32. #define CLISH_HOOK_CONFIG(name) int name(void *clish_context)
  33. #define CLISH_HOOK_LOG(name) int name(void *clish_context, const char *line, int retcode)
  34. typedef CLISH_PLUGIN_INIT_FUNC(clish_plugin_init_t);
  35. typedef CLISH_PLUGIN_FINI_FUNC(clish_plugin_fini_t);
  36. typedef CLISH_PLUGIN_SYM(clish_hook_action_fn_t);
  37. typedef CLISH_HOOK_ACCESS(clish_hook_access_fn_t);
  38. typedef CLISH_HOOK_CONFIG(clish_hook_config_fn_t);
  39. typedef CLISH_HOOK_LOG(clish_hook_log_fn_t);
  40. /* Helpers */
  41. #define SYM_FN(TYPE,SYM) (*((clish_hook_##TYPE##_fn_t *)(clish_sym__get_func(SYM))))
  42. /* Symbol */
  43. int clish_sym_compare(const void *first, const void *second);
  44. clish_sym_t *clish_sym_new(const char *name, void *func, int type);
  45. void clish_sym_free(clish_sym_t *instance);
  46. void clish_sym__set_func(clish_sym_t *instance, void *func);
  47. void *clish_sym__get_func(clish_sym_t *instance);
  48. void clish_sym__set_name(clish_sym_t *instance, const char *name);
  49. char *clish_sym__get_name(clish_sym_t *instance);
  50. void clish_sym__set_permanent(clish_sym_t *instance, bool_t permanent);
  51. bool_t clish_sym__get_permanent(clish_sym_t *instance);
  52. void clish_sym__set_plugin(clish_sym_t *instance, clish_plugin_t *plugin);
  53. clish_plugin_t *clish_sym__get_plugin(clish_sym_t *instance);
  54. void clish_sym__set_type(clish_sym_t *instance, int type);
  55. int clish_sym__get_type(clish_sym_t *instance);
  56. int clish_sym_clone(clish_sym_t *dst, clish_sym_t *src);
  57. /* Plugin */
  58. clish_plugin_t *clish_plugin_new(const char *file, const char *alias);
  59. void clish_plugin_free(clish_plugin_t *instance, void *userdata);
  60. int clish_plugin_load(clish_plugin_t *instance, void *userdata);
  61. clish_sym_t *clish_plugin_get_sym(clish_plugin_t *instance,
  62. const char *name, int type);
  63. clish_sym_t *clish_plugin_add_generic(clish_plugin_t *instance,
  64. void *func, const char *name, int type, bool_t permanent);
  65. clish_sym_t *clish_plugin_add_sym(clish_plugin_t *instance,
  66. clish_hook_action_fn_t *func, const char *name);
  67. clish_sym_t *clish_plugin_add_psym(clish_plugin_t *instance,
  68. clish_hook_action_fn_t *func, const char *name);
  69. clish_sym_t *clish_plugin_add_hook(clish_plugin_t *instance,
  70. void *func, const char *name, int type);
  71. clish_sym_t *clish_plugin_add_phook(clish_plugin_t *instance,
  72. void *func, const char *name, int type);
  73. void clish_plugin_dump(const clish_plugin_t *instance);
  74. void clish_plugin__set_name(clish_plugin_t *instance, const char *name);
  75. char *clish_plugin__get_name(const clish_plugin_t *instance);
  76. void clish_plugin__set_alias(clish_plugin_t *instance, const char *alias);
  77. char *clish_plugin__get_alias(const clish_plugin_t *instance);
  78. char *clish_plugin__get_pubname(const clish_plugin_t *instance);
  79. char *clish_plugin__get_file(const clish_plugin_t *instance);
  80. void clish_plugin__set_conf(clish_plugin_t *instance, const char *conf);
  81. char *clish_plugin__get_conf(const clish_plugin_t *instance);
  82. #endif /* _clish_plugin_h */
  83. /** @} clish_plugin */