AEMainThreadEndpoint Class Reference

Main thread message endpoint. More...

#import <AEMainThreadEndpoint.h>

Inherits NSObject.

Instance Methods

(instancetype _Nullable) - initWithHandler:
 Default initializer.
 
(instancetype _Nullable) - initWithHandler:bufferCapacity:
 Initializer with custom buffer capacity.
 
(BOOL) - AEMainThreadEndpointSend
 Send a message to the main thread endpoint.
 
(void *_Nullable) - AEMainThreadEndpointCreateMessage
 Prepare a new message.
 
(void) - AEMainThreadEndpointDispatchMessage
 Dispatch a message created with AEMainThreadEndpointCreateMessage.
 

Detailed Description

Main thread message endpoint.

This class implements a mechanism to receive messages from the audio thread upon the main thread. Initialize an instance, and pass in a block to call to handle incoming messages. Then use AEMainThreadEndpointSend from the audio thread to send a message to the main thread.

Use this utility to perform synchronization across the audio and main threads.

You can also use the AEAudioThreadEndpoint class to perform messaging in the reverse direction.

Method Documentation

- (instancetype _Nullable) initWithHandler: (AEMainThreadEndpointHandler _Nonnull)  handler

Default initializer.

Parameters
handlerThe handler block to use for incoming messages
- (instancetype _Nullable) initWithHandler: (AEMainThreadEndpointHandler _Nonnull)  handler
bufferCapacity: (size_t)  bufferCapacity 

Initializer with custom buffer capacity.

Parameters
handlerThe handler block to use for incoming messages
bufferCapacityThe buffer capacity, in bytes (default is 8192 bytes). Note that due to the underlying implementation, actual capacity may be larger.
- (BOOL) AEMainThreadEndpointSend (__unsafe_unretained AEMainThreadEndpoint *_Nonnull)  endpoint
(const void *_Nullable)  data
(size_t)  length 

Send a message to the main thread endpoint.

Use this on the audio thread to send messages to the endpoint instance. It will be received and handled on the main thread.

Parameters
endpointThe endpoint instance
dataMessage data (or NULL) to copy
lengthLength of message data
Returns
YES if message sent successfully, NO if there was insufficient buffer space
- (void* _Nullable) AEMainThreadEndpointCreateMessage (__unsafe_unretained AEMainThreadEndpoint *_Nonnull)  endpoint
(size_t)  length 

Prepare a new message.

Use this function to gain access to a writable message buffer of the given length, to assemble the message in multiple parts. Then call AEMainThreadEndpointDispatchMessage to dispatch.

Parameters
endpointThe endpoint instance
lengthLength of message data
Returns
A pointer to message bytes ready for writing, or NULL if there was insufficient buffer space
- (void) AEMainThreadEndpointDispatchMessage (__unsafe_unretained AEMainThreadEndpoint *_Nonnull)  endpoint

Dispatch a message created with AEMainThreadEndpointCreateMessage.

Parameters
endpointThe endpoint instance

The documentation for this class was generated from the following file: