proc.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright (c) 2023 Lain Bailey <[email protected]>
  3. *
  4. * Permission to use, copy, modify, and distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #pragma once
  17. #include "../util/c99defs.h"
  18. #include "calldata.h"
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. /*
  23. * Procedure handler
  24. *
  25. * This handler is used to allow access to one or more procedures that can be
  26. * added and called without having to have direct access to declarations or
  27. * procedure callback pointers.
  28. */
  29. struct proc_handler;
  30. typedef struct proc_handler proc_handler_t;
  31. typedef void (*proc_handler_proc_t)(void *, calldata_t *);
  32. EXPORT proc_handler_t *proc_handler_create(void);
  33. EXPORT void proc_handler_destroy(proc_handler_t *handler);
  34. EXPORT void proc_handler_add(proc_handler_t *handler, const char *decl_string, proc_handler_proc_t proc, void *data);
  35. /**
  36. * Calls a function in a procedure handler. Returns false if the named
  37. * procedure is not found.
  38. */
  39. EXPORT bool proc_handler_call(proc_handler_t *handler, const char *name, calldata_t *params);
  40. #ifdef __cplusplus
  41. }
  42. #endif