You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

ipc_imp.h 1.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #pragma once
  2. #undef _LITE_SUPPORT_IPC
  3. #if __linux__ || __unix__ || __APPLE__
  4. #define _LITE_SUPPORT_IPC
  5. #endif
  6. #ifdef _LITE_SUPPORT_IPC
  7. #include <sys/mman.h>
  8. #include <sys/time.h>
  9. #include <sys/types.h>
  10. #endif
  11. #include "misc.h"
  12. namespace ipc_imp {
  13. //! server call api ret
  14. enum MsgType {
  15. IPC_SERVER_RESPONSE = 1,
  16. IPC_CALL_REMOTE_API = 2,
  17. IPC_SERVER_EXIT = 3,
  18. IPC_CONFIG_REMOTE_HANDLE_API = 4,
  19. };
  20. struct MsgBody {
  21. enum MsgType type;
  22. //! remote call handle callback
  23. void* cb;
  24. //! remote call function emum, define by user
  25. size_t remote_func_id;
  26. //! mmap region ptr
  27. void* shm_ptr;
  28. };
  29. //! block wait server return response msg
  30. struct MsgBody send_msg(struct MsgBody* msg, struct timeval* timeout);
  31. //! wait server exit
  32. void join_server();
  33. typedef void (*remote_call_cb)(struct MsgBody* msg);
  34. //! register remote call
  35. void register_remote_call_cb(remote_call_cb cb);
  36. //! is server or not, server or do not enable ipc mode will return true
  37. bool is_server();
  38. //! is enable ipc or not
  39. bool is_enable_ipc();
  40. //! get shm ptr
  41. void* base_get_shm_ptr(size_t index);
  42. //! get shm count
  43. size_t base_get_shm_count();
  44. // get shm size
  45. size_t base_get_shm_size();
  46. // enable fork ipc debug
  47. void enable_lite_ipc_debug();
  48. } // namespace ipc_imp