#include <AlMessage.h>
class AlMessageTypeHandle
AlMessageTypeHandle( void );
AlMessageTypeHandle( const AlMessageTypeHandle& );
~AlMessageTypeHandle();
AlMessageTypeHandle& operator =( const AlMessageTypeHandle& );
boolean isValid( void ) const;
int type( void ) const;
statusCode setPrologue( int (*)( int, void * ) );
statusCode setEpilogue( int (*)( int, void * ) );
statusCode addLock( boolean& );
statusCode setAddLock( boolean );
statusCode sendLock( boolean& );
statusCode setSendLock( boolean );
class AlMessage
enum AlPriorityType {
kImmediate,
kQueue,
kIdleQueue
};
static statusCode addMessageHandler( int, void * );
static statusCode removeMessageHandler( int, void * );
static AlMessageTypeHandle addMessageType( const char * );
static int getMessageType( const char * );
static statusCode sendMessage( int, void*, AlPriorityType = kImmediate );
A message handler is installed using the AlMessage::addMessageHandler() function. Below is a sample message handler to handle the deleting of DagNodes:
void myDagNodeDeleteHandler( int msgtype, AlDagNode *dagnode )
{
do_something_before_its_deleted( dagnode );
}
AlMessage::addMessageHandler( kMessageDagNodeDeleted, myDagNodeDeleteHandler );
In addition to being able receive standard messages from inside Alias, it is possible to define custom message types that extend the default set. Of course, Alias has no prior knowledge of these new types, so hooks cannot be added into existing code to send new messages, but plug-ins can define messages that can then be received by either the same plug-in, or different plug-ins altogether. This allows a collaborative paradigm between plug-ins, such as sharing of code or data.
To create a custom message type, call AlMessage::addMessageType. You must supply a name for this type, which is then used by others to find the type. You are returned an AlMessageTypeHandle, a receipt which the creator of the message type can then use to define specific properties of the message type. In particular, the owner can lock a message type against the addition of handlers, lock the type against the sending of messages, and set prologue and epilogue functions which get called automatically before and after the sending of a message. See the documentation for the individual member functions for more details.
Note that while a method is supplied to send a message, this method applies only to user-defined messages. Predefined Alias messages cannot be sent.
< func - A pointer to the function to install as a handler. Ensure the argument list of the handler matches this message type!
Return codes
sSuccess - Handler installed successfully. Comments
Below is a list of prototypes to use for the handler function for the various message types.
For custom message types, the type of the function is always the same
void (*)( int type, void * data )
where type is the type of the message and data is the data to send with the message. Notes
(*) not currently available
statusCode AlMessage::removeMessageHandler( int msg, void * func )
Description
Remove the callback handler corresponding to func, if it exists. Arguments
< msg - The type of the message for which func was installed.
< func - A pointer to the function to attempt to remove.
Return codes
sSuccess - Handler removed successfully. AlMessageTypeHandle AlMessage::addMessageType( const char * name )
Description
This function allows the creation of custom message types. Calling this function introduces a new message type of the given name into Alias, provided a message type of that name does not already exist. The caller is returned a 'receipt' which can then be used to fine-tune the message-passing capabilities of this message type (see AlMessageTypeHandle).
int AlMessage::getMessageType( const char * name )
Description
Searches the list of existing custom named message type for the given name. If a message type of that name is found, its number is returned, which can then be used to send and receive messages of that type. Otherwise, this function returns -1. statusCode AlMessage::sendMessage( int type, void *data,AlMessage::AlPriorityType p )
Description
Send a message. Arguments
< type - The type of the message to send. The type must correspond to a custom message type.