Create a listener thread
Learn about create a listener thread.
Read time 1 minuteLast updated 16 days ago
Goal: Process Vivox messages on a separate thread. Set up Vivox to handle responses and events with a common callback. Set this callback function with the pf_sdk_message_callback part of the vx_sdk_config_t parameter passed into vx_initialize3(). The void *callback_handle, which is also registered with vx_sdk_config_t, will call the bound method. This can be a pointer to a singleton class that tracks the Vivox state. When the callback occurs, call vx_get_message() (non-blocking) until no more messages are processed. It is unnecessary to handle messages on the thread that generated the notification callback, but you can if you want to. The below is an example implementation of this process:
For more details, refer to Message callback. Next step, call initialize.void OnResponseOrEventFromSdk() {int status;vx_message_base_t *msg;for (;;) {status = vx_get_message(&msg);if (status == VX_GET_MESSAGE_AVAILABLE) {if (msg->type == msg_event) {DispatchEvent(reinterpret_cast<vx_evt_base_t *>(msg));}else {DispatchResponse(reinterpret_cast<vx_resp_base_t *>(msg));}vx_destroy_message(msg);}else if (status == VX_GET_MESSAGE_FAILURE) {// Handle error here. Occurs if vx_initialize3() hasn't been called.}else { /* VX_GET_MESSAGE_NO_MESSAGE */break;}}}