[haiku-3rdparty-dev] Re: Replicants connection to BApplication

  • From: Stephan Assmus <superstippi@xxxxxx>
  • To: haiku-3rdparty-dev@xxxxxxxxxxxxx
  • Date: Thu, 04 Feb 2010 07:57:35 +0100

On 2010-02-04 at 04:24:05 [+0100], Michael Armida <michael@xxxxxxxxx> wrote:
> Sevcsik András wrote:
> > Or do I have to implement all functions in the replicant?
> 
> I agree with everything Rene mentioned in his reply, and wanted to add 
> that this is a design flexibility, not a limitation: if you want, you can 
> move code to be triggered by the view, or you can put it in the app. 
>   With replicants, you're loading any exports into the new host app, so 
> you can do whatever portion of work you deem necessary on either the 
> replicant side, or another looper.
> 
> Because you have identified some possible locking issues with holding the 
> Deskbar looper captive while waiting for network dust to settle, it 
> sounds like yours is a perfect use for the BMessage facility that Rene 
> described -- your replicant won't do anything but dial home, and all the 
> work gets done on your own app's loooper's time.  But there's no 
> technical barrier stopping you from putting all that work into the BView 
> (or code called by it) that gets exported and run in the host app.
> 
> Things like this are, to me, the best highlights of the BeOS API design. 
>   Unfortunately for Koki, they're kind of impossible to advertise in a 
> flier.

If the network code is still to be handled in the be_app looper, the 
replicant can be made self contained by attaching a BHandler to the be_app 
and start sending messages to it:

class MyAppHandler : public BHandler {
        [...]

        virtual void MessageReceived(BMessage* message)
        {
                switch (message->what) {
                        // Move all your code from your application's 
MessageReceived()
                        // <- here
                        default:
                                BHandler::MessageReceived(message);
                }
        }
};

And in your replicant BView:

fAppHandler = new MyAppHandler();
if (be_app->Lock()) {
        be_app->AddHandler(fAppHandler);
        be_app->Unlock();
}

And then replace every call to "be_app->PostMessage(message)" with 
"be_app->PostMessage(message, fAppHandler)".

You can remove the handler again in DetachedFromWindow() (with locking).

A third option is to run your own BLooper and otherwise do the same as 
above or send messages to the looper directly and move your code from your 
application to the looper class.

Best regards,
-Stephan

Other related posts: