Other Event Broker Activities


Although the event broker's primary activity is monitoring pod table events for listeners, it performs other activities such as checking on connected listeners and pods, finding out where the focus lies, and controlling individual pods, such as stereoscopic glasses and audio controllers.

Getting Lists of Listeners and Connected Pods

There are many times when a task needs a list of pods connected to the control port or listeners connected to the event broker. There are two flavors of messages that retrieve this kind of information: EB_DescribePods asks for a list of connected pods; EB_GetListeners asks for a list of connected listeners.

Asking for a List of Connected Pods

When a task uses an EB_DescribePods message to ask the event broker for a list of connected pods, the message data block contains only the EventBrokerHeader data structure specifying the flavor EB_DescribePods. The message sent to the event broker should be a buffered message, created with CreateBufferedMsg(), which contains sufficient room to hold the complete list of connected pods.

Reading a Returned List of Connected Pods

When the event broker replies to an EB_DescribePods message, it turns the message into an EB_DescribePodsReply message. The message's data buffer contains a list of pods currently attached to the control port. Those pods are described in the data structure PodDescriptionList, which is defined as follows:

typedef struct               PodDescriptionList
{
  EventBrokerHeader           pdl_Header;
  int32                       pdl_PodCount;
  PodDescription              pdl_Pod[1];
} PodDescriptionList;

typedef struct PodDescription
{
  uint8            pod_Number;
  uint8            pod_Position;
  uint8            rfu[2];
  uint32           pod_Type;
  uint32           pod_BitsIn;
  uint32           pod_BitsOut;
  uint32           pod_Flags;
  uint8            pod_GenericNumber[16];
  Item             pod_LockHolder;
} PodDescription;

Asking for a List of Connected Listeners

When a task asks for a list of connected listeners, it uses an EB_GetListeners message, whose data block contains only the EventBrokerHeader data structure specifying the flavor EB_GetListeners. Messages used for this purpose must be created with CreateBufferedMsg() in the same way as messages used with the EB_DescribePods command. CreateBufferedMsg() is described in Creating a Configuration Message.

Reading a Returned List of Connected Listeners

When the event broker replies to an EB_GetListeners message, it turns the message into an EB_GetListenersReply message. The message buffer contains a list of listeners currently connected to the event broker. The list is contained in the data structure ListenerList, defined as follows:

typedef struct ListenerList
{
  EventBrokerHeader                        ll_Header; /* { EB_GetListenersReply } */
  int32                        ll_Count;
  struct {
    Item                        li_PortItem;
    enum ListenerCategory                        li_Category;
  } ll_Listener[1];
} ListenerList;


Working With Input Focus

It is often important for a listener to know which task currently has the input focus or to be able to change the input focus from one task to another without user intervention. The event broker can handle both of these requests.

Finding the Current Focus Holder

To find the current focus holder, a listener can inquire with an EB_GetFocus message. Its data block is an EventBrokerHeader data structure set to the message flavor EB_GetFocus.

When the event broker receives an EB_GetFocus message, it gets the item number of the task currently holding the focus, writes that value in the error field of the message, and returns the message to the task. The task receiving the message reads the current focus holder's item number from the error field. The error field will contain a negative number (an error code) if the operation failed.

Setting the Current Focus Holder

Warning: Although the event broker currently allows any user task to set the current focus holder, in the future this request may restricted to only privileged tasks.

To move the focus from one task to another without input from the user, a listener can use an EB_SetFocus message. The data block for this message uses the SetFocus data structure, defined as follows:

typedef struct SetFocus
{
  EventBrokerHeader sf_Header; /* { EB_SetFocus } */
  Item            sf_DesiredFocusListener;
} SetFocus;

When the event broker receives the message, it changes the input focus to the requested task and writes that task's item number into the error field of the message. It returns the message to the sending task. That task can now read the error field to get the item number of the focus-holding task (if successful) or an error code (if unsuccessful).

Commanding a Pod

Sometimes a task may want to control a pod through the event broker. For example, a task may wish to alternate lens opaqueness in a pair of stereoscopic glasses, or mute the sound coming through an audio controller. To issue commands to a pod, the task uses a message of the flavor EB_IssuePodCmd. It accompanies the message with a data block that uses the PodData data structure, defined as follows:

typedef struct PodData
{
  EventBrokerHeader                        pd_Header;
  int32             pd_PodNumber;
  int32             pd_WaitFlag;
  int32             pd_DataByteCount;
  uint8             pd_Data[4];
} PodData;

Generic Device Class

The include file event.h currently defines the following constants to specify generic device classes:

The array element pd_Data[0] should hold the constant appropriate to the commanded pod.

Audio Controller Subcodes

The audio controller accepts commands defined by audio controller subcodes. At present, Portfolio offers one audio subcode, specified by the following constant:

This subcode goes in the array element pd_Data[1]. It requires one byte of data following it in pd_Data[2]. This data specifies how the stereo channels are controlled. The four options, defined by the following constants, are:

Glasses Controller Subcodes

The stereoscopic glasses controller accepts commands defined by glasses controller subcodes. At present, Portfolio offers one glasses subcode, specified by the following constant:

This subcode goes into the array element pd_Data[1]. It requires two bytes of data following it in pd_Data[2] and pd_Data[3]. The first of the two data bytes controls the left lens of the glasses, the second byte controls the right lens. The four possible values for each lens, defined by the following constants, are:

Lightgun Controller Subcode

Currently, Portfolio offers one light gun controller subcode, which is specified by the following constant:

The possible options, defined by the following constants, are:

The Event Broker's Reply to a Command

After the event broker processes a pod command message, it returns the message to the sending task to report on the command execution. The returned message is of the flavor EB_IssuePodCmdReply, and contains a reply portion that is a negative number if there was an error executing the command, or is 0 or a positive number if the command execution was successful.