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

  • From: Joseph Groover <looncraz@xxxxxxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Sun, 29 Jan 2012 17:58:25 -0600

On 1/29/2012 11:55, fano il primo wrote:
Ahh I _DO love_ this API!

Let's see if I've understood correctly, sirs:

This is the MessageReceived of my main application (that's the class that extended beApplication, a special case of BLooper as it is not a thread but it's the main() that continues as an unique thread of execution, correct?):
|MessageReceived|(BMessage*|  msg) {
switch(msg->what) {
||case btn1:
     NetHandler->||||PostMessage|(new|BMessage|(|DO_SOMETHING|), NULL);|||

}|||

And this my MessageReceived() of my looper class that is another thread in the same memory space of my beApp:
|MessageReceived|(BMessage*|  msg) {

switch(msg->what) {
||case||DO_SOMETHIN||:
     /* well.. DO send something in the Network, right?||
}|||

....

I'm not sure what is posting the BMessage, however it is likely to have the SetTarget() method, so you should consider using SetTarget() so that the messages are posted directly to your custom BLooper.

I usually use BMessages as control messages for a thread via the receive_data() function in the thread loop (if applicable, naturally). In your case, the messages being sent to the BLooper's MessageReceived() hook would be used to create an asynchronous control for the work thread - or, if the work is light enough, you can do the work right from MessageReceived().

Might help if you posted some code online for perusal ;-)

--The loon

Other related posts: