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

Hey guys,

I have started the implementation stage of the project and have a few
questions. So, I am looking into trying to capture messages/events that
occur when I perform an action in Haiku.
For example, I am currently using the ALM (Auckland Layout Manager)
application in Haiku. I need to develop an application that registers and
saves the actions that I am doing. So, if I move the mouse, I am expecting a
message like "MOUSE_MOVE" or something to be generated and passed.
Similarly, if I click a mouse, something like the"MOUSE_UP" or "MOUSE_DOWN"
is generated.
The first step that I need to do next is be able to print them out in the
console using printf. So, what is the best way of viewing the messages? From
my understanding of the replies, the best way is to use BMessageFilter.

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.
In the constructor:
<code-snippet>
HelpWindow::HelpWindow
(BView* parent, BALMLayout* aLMEngine)
:BWindow(BRect(25,50,250,280),"AIMHelp",B_TITLED_WINDOW,B_NOT_RESIZEABLE)
{
....
...
      fMessageFilter = new BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE);
....
....
}
</code-snippet>

Then, in a function MessageReceived, I added:
<code-snippet>
void HelpWindow::MessageReceived(BMessage* message) {
        printf("Yash, the message is: %s\n", fMessageFilter->Filter(message,
this));
        ......
}
</code-snippet>

When I compile the code, it gives an error saying:
"no matching function for call to Filter(BMessage*, HelpWindow*), candidates
are: enum filter_result Filter(BMessage*, BHandler**).
So, I understand that I am missing BHandler that refers to my current
window. I assumed that HelpWindow referred to BHandler as it inherited the
MessageReceived function but maybe not. How do I assign a BHandler to my
current window?

I am sorry but I am confused on what to do here. :s Do you think this is the
right way to start off? What I am looking for is a simple application that
will print out a message like "Yash, the message is: MOUSE_DOWN" or
something of that sort when I click a mouse. Pretty much confirming that I
am capturing the messages.

I would really appreciate it if anyone could help me out here.

Thanks a lot guys!
Cheers,
Yash

P.S. Yea, we are looking into adding modules into Haiku over here at
Auckland. :) Pretty neat OS. Currently working on adding a dynamic help
system plugged in with Haiku but its still on-going. Thanks!

On Sat, Mar 21, 2009 at 11:03 AM, Stephan Assmus <superstippi@xxxxxx> wrote:

> Hi,
>
> > On Fri, Mar 20, 2009 at 3:53 PM, Yashasvi A.C. <yashasviac@xxxxxxxxx>
> > wrote:
> > > I just built Haiku on Ubuntu and am opening Haiku through the VMWare
> > virtual
> > > machine. I have a few questions that I wanted to ask:
> > > (1) How do you intercept messages between the App. Server and the
> > > application?
> > > (2) How do you intercept messages between and within applications?
> >
> > For a given window, view, etc. (actually BHandler), you can attach an
> > object called a BMessageFilter. This can look at any message the
> > target receives, modify it, prevent it from being passed on to the
> > target, etc. In this case you'd mainly just be interested in looking
> > at them though. As such you could make a filter that looks for
> > B_MOUSE_DOWN messages, checks who the target is, and otherwise doesn't
> > interfere with message processing, which should give you the
> > information you need (which you can then send to another app or
> > wherever you need it to go for your implementation.
> >
> > c.f. http://www.haiku-os.org/legacy-docs/bebook/BHandler_Overview.html
> > and
> > http://www.haiku-os.org/legacy-docs/bebook/BMessageFilter_Overview.html
> > .
> >
> > BView and BWindow are both BHandler subclasses and as such all the
> > message processing described there applies to them as well.
>
> It sounds a bit like you need to intercept all messages that are going to
> other applications/windows/views. This may be better achieved by using a
> BView and using SetEventMask() to configure it to receive all messages.
> BMessageFilters are most useful if you are already the target of the
> message. But to find out more about the original target of the message (you
> receive copies), you probably need to use scripting techniques. In another
> words, you need to send messages to the original target of the message to
> find out what kind of object the target is. So you should look into the
> scripting sections in the BeBook to see what is possible using that API and
> messaging protocols. There is a command line tool called "hey", which does a
> lot of cool stuff using scripting. It may or may not be easy to achieve, I
> would need to look at this closer to say for sure. In any case, it's always
> an option to just add the feature, if it isn't already possible. :-D
>
> Best regards,
> -Stephan
>
> P.S. Awesome to see all this activity around Haiku in the University of
> Auckland! I've been to New Zealand a couple of times and love it very much!
>
>

Other related posts: