clap

CLAP Audio Plugin API
Log | Files | Refs | README | LICENSE

posix-fd-support.h (1586B)


      1 #pragma once
      2 
      3 #include "../plugin.h"
      4 
      5 // This extension let your plugin hook itself into the host select/poll/epoll/kqueue reactor.
      6 // This is useful to handle asynchronous I/O on the main thread.
      7 static CLAP_CONSTEXPR const char CLAP_EXT_POSIX_FD_SUPPORT[] = "clap.posix-fd-support";
      8 
      9 #ifdef __cplusplus
     10 extern "C" {
     11 #endif
     12 
     13 enum {
     14    // IO events flags, they can be used to form a mask which describes:
     15    // - which events you are interested in (register_fd/modify_fd)
     16    // - which events happened (on_fd)
     17    CLAP_POSIX_FD_READ = 1 << 0,
     18    CLAP_POSIX_FD_WRITE = 1 << 1,
     19    CLAP_POSIX_FD_ERROR = 1 << 2,
     20 };
     21 typedef uint32_t clap_posix_fd_flags_t;
     22 
     23 typedef struct clap_plugin_posix_fd_support {
     24    // This callback is "level-triggered".
     25    // It means that a writable fd will continuously produce "on_fd()" events;
     26    // don't forget using modify_fd() to remove the write notification once you're
     27    // done writing.
     28    //
     29    // [main-thread]
     30    void(CLAP_ABI *on_fd)(const clap_plugin_t *plugin, int fd, clap_posix_fd_flags_t flags);
     31 } clap_plugin_posix_fd_support_t;
     32 
     33 typedef struct clap_host_posix_fd_support {
     34    // Returns true on success.
     35    // [main-thread]
     36    bool(CLAP_ABI *register_fd)(const clap_host_t *host, int fd, clap_posix_fd_flags_t flags);
     37 
     38    // Returns true on success.
     39    // [main-thread]
     40    bool(CLAP_ABI *modify_fd)(const clap_host_t *host, int fd, clap_posix_fd_flags_t flags);
     41 
     42    // Returns true on success.
     43    // [main-thread]
     44    bool(CLAP_ABI *unregister_fd)(const clap_host_t *host, int fd);
     45 } clap_host_posix_fd_support_t;
     46 
     47 #ifdef __cplusplus
     48 }
     49 #endif