# The Application Kit: BMessageQueue

Derived from: none

Declared in: be/app/MessageQueue.h

Library: libbe.so

## Class Description

The BMessageQueue class completes the implementation of BLooper by providing a first-in/first-out stack in which the looper can place in-coming BMessages. In general, you should ignore the message queue--you're never forced to deal with it. But if you need to manipulate the queue directly, here you go.

## Constructor and Destructor

### BMessageQueue()

          BMessageQueue(void)

You never need to construct a BMessageQueue.

### ~BMessageQueue()

          virtual ~BMessageQueue()

Deletes all the objects in the queue and all the data structures used to manage the queue.

## Member Functions

### AddMessage(), RemoveMessage()

          void AddMessage(BMessage *message)

          void RemoveMessage(BMessage *message)

`AddMessage()` adds message to the far end of the queue. `RemoveMessage()` removes a particular message from the queue and deletes it.

### CountMessages(), IsEmpty()

          int32 CountMessages(void) const

          bool IsEmpty(void) const

`CountMessages()` returns the number of messages currently in the queue.

IsEmpty() returns `true` if the object contains no messages, and `false` otherwise.

### FindMessage()

          BMessage *FindMessage(int32 index) const
          BMessage *FindMessage(uint32 what, int32 index = 0) const

`FindMessage()` returns a pointer to the index'th BMessage in the queue, where index 0 signifies the message that's been in the queue the longest. The second version lets you specify a `what` field value; in this case, only messages that match the what argument are counted. If no message matches the criteria, the functions return `NULL`.

The message is not removed from the message queue.

### IsEmpty() see CountMessages()

### Lock(), Unlock()

          bool Lock(void)

          void Unlock(void)

These functions lock and unlock the BMessageQueue, so that another thread won't alter the contents of the queue while it's being read. `Lock()` doesn't return until it has the queue locked; it always returns `true`. `Unlock()` releases the lock so that someone else can lock it. Calls to these functions can be nested.

See also: `BLooper::Lock()`

### NextMessage()

          BMessage *NextMessage(void)

Removes the oldest message from the queue and returns it. If the queue is empty, the function returns `NULL`.

See also: `FindMessage()`

### RemoveMessage() see AddMessage()

### Unlock() see Lock()

The Be Book, in lovely HTML, for BeOS Release 3.

Copyright © 1998 Be, Inc. All rights reserved.

Last modified March 26, 1998.