1
0

plugin.h 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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_INIT,
  13. CLISH_SYM_TYPE_FINI,
  14. CLISH_SYM_TYPE_ACCESS,
  15. CLISH_SYM_TYPE_CONFIG,
  16. CLISH_SYM_TYPE_LOG,
  17. CLISH_SYM_TYPE_MAX /* Number of elements */
  18. } clish_sym_type_e;
  19. typedef struct clish_sym_s clish_sym_t;
  20. typedef struct clish_plugin_s clish_plugin_t;
  21. /* Plugin types */
  22. /* Name of init function within plugin */
  23. #define CLISH_PLUGIN_INIT_FNAME clish_plugin_init
  24. #define CLISH_PLUGIN_INIT_NAME "clish_plugin_init"
  25. #define CLISH_PLUGIN_INIT_FUNC(name) int name(clish_plugin_t *plugin)
  26. #define CLISH_PLUGIN_INIT CLISH_PLUGIN_INIT_FUNC(CLISH_PLUGIN_INIT_FNAME)
  27. #define CLISH_PLUGIN_SYM(name) int name(void *clish_context, const char *script, char **out)
  28. #define CLISH_HOOK_INIT(name) int name(void *clish_context)
  29. #define CLISH_HOOK_FINI(name) int name(void *clish_context)
  30. #define CLISH_HOOK_ACCESS(name) int name(void *clish_context, const char *access)
  31. #define CLISH_HOOK_CONFIG(name) int name(void *clish_context)
  32. #define CLISH_HOOK_LOG(name) int name(void *clish_context, const char *line, int retcode)
  33. /* Default syms */
  34. #define CLISH_DEFAULT_SYM "clish_script@clish" /* Builtin symbol to use by default */
  35. #define CLISH_DEFAULT_ACCESS "clish_hook_access@clish"
  36. #define CLISH_DEFAULT_CONFIG "clish_hook_config@clish"
  37. #define CLISH_DEFAULT_LOG "clish_hook_log@clish"
  38. /* typedef void clish_shell_cmd_line_fn_t(clish_context_t *context, const char *cmd_line); */
  39. typedef CLISH_PLUGIN_INIT_FUNC(clish_plugin_init_t);
  40. typedef CLISH_PLUGIN_SYM(clish_hook_action_fn_t);
  41. typedef CLISH_HOOK_INIT(clish_hook_init_fn_t);
  42. typedef CLISH_HOOK_FINI(clish_hook_fini_fn_t);
  43. typedef CLISH_HOOK_ACCESS(clish_hook_access_fn_t);
  44. typedef CLISH_HOOK_CONFIG(clish_hook_config_fn_t);
  45. typedef CLISH_HOOK_LOG(clish_hook_log_fn_t);
  46. /* Helpers */
  47. #define SYM_FN(TYPE,SYM) (*((clish_hook_##TYPE##_fn_t *)(clish_sym__get_func(SYM))))
  48. /* Symbol */
  49. int clish_sym_compare(const void *first, const void *second);
  50. clish_sym_t *clish_sym_new(const char *name, void *func, int type);
  51. void clish_sym_free(clish_sym_t *instance);
  52. void clish_sym__set_func(clish_sym_t *instance, void *func);
  53. void *clish_sym__get_func(clish_sym_t *instance);
  54. void clish_sym__set_name(clish_sym_t *instance, const char *name);
  55. char *clish_sym__get_name(clish_sym_t *instance);
  56. void clish_sym__set_permanent(clish_sym_t *instance, bool_t permanent);
  57. bool_t clish_sym__get_permanent(clish_sym_t *instance);
  58. void clish_sym__set_plugin(clish_sym_t *instance, clish_plugin_t *plugin);
  59. clish_plugin_t *clish_sym__get_plugin(clish_sym_t *instance);
  60. void clish_sym__set_type(clish_sym_t *instance, int type);
  61. int clish_sym__get_type(clish_sym_t *instance);
  62. int clish_sym_clone(clish_sym_t *dst, clish_sym_t *src);
  63. /* Plugin */
  64. clish_plugin_t *clish_plugin_new(const char *name, const char *file);
  65. void clish_plugin_free(clish_plugin_t *instance);
  66. void *clish_plugin_load(clish_plugin_t *instance);
  67. clish_sym_t *clish_plugin_get_sym(clish_plugin_t *instance,
  68. const char *name, int type);
  69. clish_sym_t *clish_plugin_add_generic(clish_plugin_t *instance,
  70. void *func, const char *name, int type);
  71. clish_sym_t *clish_plugin_add_sym(clish_plugin_t *instance,
  72. clish_hook_action_fn_t *func, const char *name);
  73. clish_sym_t *clish_plugin_add_psym(clish_plugin_t *instance,
  74. clish_hook_action_fn_t *func, const char *name);
  75. clish_sym_t *clish_plugin_add_hook(clish_plugin_t *instance,
  76. void *func, const char *name, int type);
  77. void clish_plugin_dump(const clish_plugin_t *instance);
  78. char *clish_plugin__get_name(const clish_plugin_t *instance);
  79. char *clish_plugin__get_file(const clish_plugin_t *instance);
  80. #endif /* _clish_plugin_h */
  81. /** @} clish_plugin */