The Application Kit Table of Contents | The Application Kit Index |
Derived from: none
Declared in: be/app/Messenger.h
Library: libbe.so
Allocation: Stack or constructor
A BMessenger represents and sends messages to a message target, where the target is a BLooper and, optionally, a specific BHandler within that looper. The target can live in the same application as the BMessenger (a local target), or it can live in some other application (a remote target).
BMessenger's most significant function is SendMessage(), which sends its argument BMessage to the target.
![]() |
For a local target, SendMessage() is roughly equivalent, in terms of efficiency, to posting a message directly to the BMessenger's target (i.e BLooper::PostMessage()). |
The global be_app_messenger BMessenger pointer, which targets be_app's main message loop, is automatically initialized for you when you create your BApplication object. You can use it wherever BMessengers are called for.
|
Creates a new BMessenger and sets its target to a local looper/handler, to the (running) application identified by signature or team, or to the target of some other messenger.
Messages sent to a remote target are received and handled by the remote application's BApplication object.
The BMessenger doesn't own its target.
RETURN CODES
The constructor places an error code in error (if provided).
|
Frees the BMessenger; the target isn't affected.
|
Returns true if the target looper, whether local or remote, still exists.
![]() |
This function doesn't tell you whether the looper is actually ready to receive messages, or whether the handler (if it was specified in the constructor) exists. In other words, a valid BMessenger is no guarantee that a message will actually get to the target. |
|
![]() |
These functions apply to local targets only. |
These functions attempt to lock the target looper in the manner of the similarly named BLooper functions (see BLooper::LockTarget()). In addition to the error codes reported there, these functions return false and B_BAD_VALUE (respectively) if the target isn't local, or if the looper is otherwise invalid.
|
Sends a copy of message (or a BMessage based on a command constant) to the object's target. The caller retains ownership of message. The function doesn't return until the message has been delivered; if you're sending a message (as opposed to a command constant) you can set a microsecond delivery timeout through deliveryTimeout.
The target can respond to the message:
![]() |
Use caution when requesting a synchronous reply: If you call SendMessage() from the target looper's thread, you'll deadlock (or, at best, time out). |
RETURN CODES
B_OK. The message was delivered (and the synchronous reply was received, if applicable).
B_TIMED_OUT. deliveryTimeout expired; the message never made it to the target.
B_WOULD_BLOCK. You requested a 0 deliveryTimeout, and the target's message queue is full.
B_BAD_PORT_ID. The messenger's target is invalid, or the reply port was deleted while waiting for a reply (synchronous response requests only).
B_NO_MORE_PORTS. You asked for a synchronous reply, but there are no more reply ports.
![]() |
If you specified a handler when you constructed your BMessenger, and if that handler has since changed loopers, SendMessage() won't deliver its message, but it doesn't complain (it returns B_OK). |
|
Target() returns the BMessenger's handler (directly) and looper (by reference in looper). This function only works for local targets. If Target() returns NULL, it can mean one of four things:
IsTargetLocal() returns true if the target is local. Team() returns a target's team.
|
Sets the left-side BMessenger's target to that of the right-side object.
|
Two BMessengers are equal if they have the same target.
The Application Kit Table of Contents | The Application Kit Index |
Copyright © 1999 Be, Inc. All rights reserved.
Text last modified