[haiku-development] Re: A BMessage w/o a BApplication?

  • From: Pete Goodeve <pete.goodeve@xxxxxxxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Sun, 29 Jan 2012 15:31:09 -0800

On Sun, Jan 29, 2012 at 06:55:49PM +0100, fano il primo wrote:
> Ahh I *DO love* this API!
Me too... (:-), but...
> 
> Let's see if I've understood correctly, sirs:
 I think some important details got skipped in the replies so far.

The thing is, I don't think you can use a BLooper in your suggested
application.  A Blooper is pretty much what it says it is -- it loops through
its code contimually -- *but* it waits at the beginning of each loop for
a BMessage to arrive.  It really is only intended for doing something
in response to BMessages.

If you want to wait for something else -- e.g. a network event -- it will
clash with BLooper's normal wait scheme.  If the looper is waiting for
a BMessage, it won't see the network event, and if you have added code
in the loop to wait for a network event, it won't be responding to
BMessages at that point.

So basically your network thread has to work the other way round.
It should loop (not a BLooper -- just use a 'while' or whatever is
appropriate) but wait with a 'select' or whatever [sorry -- I've forgotten
most of what I might have once known about sockets] for the network.

So you can't directly send a BMessage to that thread.  You would have
to send an interrupt signal to the thread to get out of the select and
handle the new information in some convenient way.  I suspect you
could just fill in a data block (even create a BMessage to be accessed
directly -- via pointer, not MessageReceived) before sending the signal.

OTOH, you can always send a BMessage *from* your thread *to* 'be_app'
or any other BLooper.  Either have a pointer to the looper, and
directly do:

        looper->PostMessage(msg);

or use a BMessenger and its SendMessage().  The former is simpler
if you're *sure* your looper exists, but the latter is a bit safer.

        -- Pete --

Other related posts: