plugin.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. #define CLISH_SYM_TYPE_NONE 0 /* None */
  10. #define CLISH_SYM_TYPE_FN 1 /* Common builtin symbol */
  11. #define CLISH_SYM_TYPE_INIT 2
  12. #define CLISH_SYM_TYPE_FINI 3
  13. #define CLISH_SYM_TYPE_ACCESS 4
  14. #define CLISH_SYM_TYPE_CONFIG 5
  15. #define CLISH_SYM_TYPE_LOG 6
  16. typedef struct clish_sym_s clish_sym_t;
  17. typedef struct clish_plugin_s clish_plugin_t;
  18. /* Plugin types */
  19. /* Name of init function within plugin */
  20. #define CLISH_PLUGIN_INIT_FNAME clish_plugin_init
  21. #define CLISH_PLUGIN_INIT_NAME "clish_plugin_init"
  22. #define CLISH_PLUGIN_INIT_FUNC(name) int name(clish_plugin_t *plugin)
  23. #define CLISH_PLUGIN_INIT CLISH_PLUGIN_INIT_FUNC(CLISH_PLUGIN_INIT_FNAME)
  24. #define CLISH_PLUGIN_SYM(name) int name(void *clish_context, const char *script, char **out)
  25. #define CLISH_DEFAULT_SYM "clish_script@clish" /* Builtin symbol to use by default */
  26. typedef CLISH_PLUGIN_SYM(clish_plugin_fn_t);
  27. typedef CLISH_PLUGIN_INIT_FUNC(clish_plugin_init_t);
  28. /* Symbol */
  29. int clish_sym_compare(const void *first, const void *second);
  30. clish_sym_t *clish_sym_new(const char *name, void *func, int type);
  31. void clish_sym_free(clish_sym_t *instance);
  32. void clish_sym__set_func(clish_sym_t *instance, void *func);
  33. clish_plugin_fn_t *clish_sym__get_func(clish_sym_t *instance);
  34. void clish_sym__set_name(clish_sym_t *instance, const char *name);
  35. char *clish_sym__get_name(clish_sym_t *instance);
  36. void clish_sym__set_permanent(clish_sym_t *instance, bool_t permanent);
  37. bool_t clish_sym__get_permanent(clish_sym_t *instance);
  38. void clish_sym__set_plugin(clish_sym_t *instance, clish_plugin_t *plugin);
  39. clish_plugin_t *clish_sym__get_plugin(clish_sym_t *instance);
  40. void clish_sym__set_type(clish_sym_t *instance, int type);
  41. int clish_sym__get_type(clish_sym_t *instance);
  42. int clish_sym_clone(clish_sym_t *dst, clish_sym_t *src);
  43. /* Plugin */
  44. clish_plugin_t *clish_plugin_new(const char *name, const char *file);
  45. void clish_plugin_free(clish_plugin_t *instance);
  46. void *clish_plugin_load(clish_plugin_t *instance);
  47. clish_sym_t *clish_plugin_get_sym(clish_plugin_t *instance,
  48. const char *name, int type);
  49. clish_sym_t *clish_plugin_add_generic(clish_plugin_t *instance,
  50. void *func, const char *name, int type);
  51. clish_sym_t *clish_plugin_add_sym(clish_plugin_t *instance,
  52. clish_plugin_fn_t *func, const char *name);
  53. clish_sym_t *clish_plugin_add_psym(clish_plugin_t *instance,
  54. clish_plugin_fn_t *func, const char *name);
  55. void clish_plugin_dump(const clish_plugin_t *instance);
  56. char *clish_plugin__get_name(const clish_plugin_t *instance);
  57. char *clish_plugin__get_file(const clish_plugin_t *instance);
  58. #endif /* _clish_plugin_h */
  59. /** @} clish_plugin */