[haiku-development] Re: Intercepting messages between the applications and App. Server

  • From: Rene Gollent <anevilyak@xxxxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Mon, 18 May 2009 09:15:01 -0500

On Mon, May 18, 2009 at 9:00 AM, Yashasvi A.C. <yashasviac@xxxxxxxxx> wrote:
> I am new to this process and dont really understand how it works. So, what
> is the best way of using BMessageFilter?
> I have added the following code snippet to the "Help Window" that pops up.

No need to override MessageReceived in order to use the filter, just
do AddFilter(fMessageFilter); and it will implicitly be called on
message receipt. One of BMessageFilter's means of construction is by
passing it a filter hook function. In this form your code would look
something like:


filter_result message_print_hook(BMessage *msg, BHandler *handler,
BMessageFilter *filter)
{
printf("Received message for handler %s\n", handler->Name());
msg->PrintToStream();

return B_DISPATCH_MESSAGE;
}

And then construct your filter as: fMessageFilter = new
BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE, message_print_hook);
AddFilter(fMessageFilter);

Regards,

Rene

Other related posts: