Not using PtMainLoop

I am writing a simple application where I do not want to use the widget
library or PtMainLoop(). My code looks like the following:

:
PhAttach(NULL,NULL);
chid = PhChannelAttach(0,-1,NULL);
:
photon_rid = PhWindowOpen(…); // Open one and only one window
:
PhEventArm();
:
// Next, get photon and non-photon messages.
// The only photon messages I’m interested in are mouse movement and mouse
button
// presses when the above window is in focus.
rcvid = MsgReceive(chid,&msg,sizeof(msg),NULL);
:
if (rcvid == 0 ) // see comment below for problem.
handle_pulse();
else
handle_photon_events(); // invokes PhEventRead() code.
:

PROBLEM:
What happens above is that the rcvid for the mouse events is 0 (a pulse)
with pulse->code equal to -6. I am expecting the mouse events to not be
pulses in order to call PhEventRead(). One other note is that I modeled
this after the PhEventRead() reference page code example. I compiled the
reference page code example and had the same exact problem.

What’s the correct setup? Please note that I don’t want to use the widget
library or PtMainLoop.

–Mark.

CORRECTION: The code fragment and problem statement are modified below.


“Mark Weber” <mweber@nanosphere-inc.com> wrote in message
news:9qmso4$id9$1@inn.qnx.com

I am writing a simple application where I do not want to use the widget
library or PtMainLoop(). My code looks like the following:

:
PhAttach(NULL,NULL);
chid = PhChannelAttach(0,-1,NULL);
:
photon_rid = PhWindowOpen(…); // Open one and only one window
:
PhEventArm();
:
// Next, get photon and non-photon messages.
// The only photon messages I’m interested in are mouse movement and mouse
button
// presses when the above window is in focus.
rcvid = MsgReceive(chid,&msg,sizeof(msg),NULL);

handle_photon_events(); // invokes PhEventRead().

// PhEventRead is always returning
0 (non-photon event).
if (not_photon_event)
handle_app_message();

:

PROBLEM:
What happens above is that the rcvid for the mouse events is 0 (a pulse)
with pulse->code equal to -6. I know that these are photon events but
when passed to PhEventRead() it’s returned as a non-photon event. One other

note is that I modeled this after the PhEventRead() reference page code
example.
I compiled the reference page code example and had the same exact problem.

What’s the correct setup? Please note that I don’t want to use the widget
library or PtMainLoop.

–Mark.

Mark Weber <mweber@nanosphere-inc.com> wrote:

What happens above is that the rcvid for the mouse events is 0 (a pulse)
with pulse->code equal to -6. I know that these are photon events but
when passed to PhEventRead() it’s returned as a non-photon event. One other
note is that I modeled this after the PhEventRead() reference page code
example.
I compiled the reference page code example and had the same exact problem.

There was a bug in QNX 6.0 that caused PhEventRead() to return 0 instead
of failing with ENOMSG, but that bug was fixed in QNX 6.1. Are you
using 6.0?


Wojtek Lerch QNX Software Systems Ltd.

I’m using QNX RTP 6.1.0.


“Wojtek Lerch” <wojtek_l@ottawa.com> wrote in message
news:9qn3lu$5g1$1@nntp.qnx.com

Mark Weber <> mweber@nanosphere-inc.com> > wrote:

What happens above is that the rcvid for the mouse events is 0 (a
pulse)
with pulse->code equal to -6. I know that these are photon events but
when passed to PhEventRead() it’s returned as a non-photon event. One
other
note is that I modeled this after the PhEventRead() reference page code
example.
I compiled the reference page code example and had the same exact
problem.

There was a bug in QNX 6.0 that caused PhEventRead() to return 0 instead
of failing with ENOMSG, but that bug was fixed in QNX 6.1. Are you
using 6.0?


Wojtek Lerch QNX Software Systems Ltd.

Mark Weber <mweber@nanosphere-inc.com> wrote:

CORRECTION: The code fragment and problem statement are modified below.



“Mark Weber” <> mweber@nanosphere-inc.com> > wrote in message
news:9qmso4$id9$> 1@inn.qnx.com> …
I am writing a simple application where I do not want to use the widget
library or PtMainLoop(). My code looks like the following:

:
PhAttach(NULL,NULL);
chid = PhChannelAttach(0,-1,NULL);
:
photon_rid = PhWindowOpen(…); // Open one and only one window
:
PhEventArm();
:
// Next, get photon and non-photon messages.
// The only photon messages I’m interested in are mouse movement and mouse
button
// presses when the above window is in focus.
rcvid = MsgReceive(chid,&msg,sizeof(msg),NULL);

handle_photon_events(); // invokes PhEventRead().
// PhEventRead is always returning
0 (non-photon event).
if (not_photon_event)
handle_app_message();
:

PROBLEM:
What happens above is that the rcvid for the mouse events is 0 (a pulse)
with pulse->code equal to -6. I know that these are photon events but
when passed to PhEventRead() it’s returned as a non-photon event. One other
note is that I modeled this after the PhEventRead() reference page code
example.
I compiled the reference page code example and had the same exact problem.

What’s the correct setup? Please note that I don’t want to use the widget
library or PtMainLoop.

The example code is broken. What happens is photon sends a pulse to
your channel, the pulse code of -6 is the photon code which lets
PhEventRead know a photon message is available.

The problem with the example is that it uses two different buffers, one
for the MsgReceive, and another for PhEventRead. You need to use the
same buffer for both calls, so that PhEventRead can check the pulse
code. Also, when no more photon messages are available, I think photon
sends a pulse with a code of 0, and PhEventRead will return -1 on that
message.

Good luck
Julian Kinraid

jkinraid@clear.net.nz wrote:

The example code is broken. What happens is photon sends a pulse to
your channel, the pulse code of -6 is the photon code which lets
PhEventRead know a photon message is available.

That’s correct. -6 is the value of SI_NOTIFY.

If you use the widget library, the same pulse code is also used for
“Photon pulses”. The pulse value tells PhEventRead() whether a pulse is
an event notification or a Photon pulse.

The problem with the example is that it uses two different buffers, one
for the MsgReceive, and another for PhEventRead. You need to use the
same buffer for both calls, so that PhEventRead can check the pulse

Yes, that’s what the problem is. The sample code in the docs was
incorrectly ported from QNX4 to Neutrino… Sorry about that.

code. Also, when no more photon messages are available, I think photon
sends a pulse with a code of 0, and PhEventRead will return -1 on that
message.

No. When no Photon messages are available, Photon sends nothing, and
your MsgReceive() blocks.


Wojtek Lerch QNX Software Systems Ltd.