opening a message handler in the same process

I’m trying to do something that seems very straightforward.

I’ve made a photon application with Phab that starts up a message handler
thread in it’s init.c file.

Then, from that photon application I create a button callback function to
open the message handler from it’s filespace name. When I run this callback
function I get a file descriptor of -1 and the open command returns an error
of ‘No such file or directory’.

Just to assure you that the message handler side is working correctly I
wrote the following simple program that I can run from the command prompt
while the photon application (and it’s message handler) is running. And
everything works fine, the open command returns a valid file descriptor.

The button callback function is almost identical to the function below (the
open statement IS identical).

I’ve created non-photon applications that similarly have one thread as a
message handler and another thread in the same process passing messages to
it. But I’ve never done it in photon.

Does anyone know what could be going on?

Thanks in advance.

-Dan


#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>


int main(){
int telMsgFd;

telMsgFd = open("/dev/telemetry", O_RDWR);

printf (“telMsgFd = %d\n”, telMsgFd);

close (telMsgFd);

return 0;
}

If your message handler is a resource manager, you will need to pass the
_RESMGR_FLAG_SELF flags to the resmgr_attach call. This flag will let
a resource manager attach to itself.

-Peter

Dan Helmick <danielhelmick@earthlink.net> wrote:

I’m trying to do something that seems very straightforward.

I’ve made a photon application with Phab that starts up a message handler
thread in it’s init.c file.

Then, from that photon application I create a button callback function to
open the message handler from it’s filespace name. When I run this callback
function I get a file descriptor of -1 and the open command returns an error
of ‘No such file or directory’.

Just to assure you that the message handler side is working correctly I
wrote the following simple program that I can run from the command prompt
while the photon application (and it’s message handler) is running. And
everything works fine, the open command returns a valid file descriptor.

The button callback function is almost identical to the function below (the
open statement IS identical).

I’ve created non-photon applications that similarly have one thread as a
message handler and another thread in the same process passing messages to
it. But I’ve never done it in photon.

Does anyone know what could be going on?

Thanks in advance.

-Dan



#include <stdio.h
#include <fcntl.h
#include <sys/stat.h
#include <sys/types.h



int main(){
int telMsgFd;

telMsgFd = open("/dev/telemetry", O_RDWR);

printf (“telMsgFd = %d\n”, telMsgFd);

close (telMsgFd);

return 0;
}

I’ve already tried this to no avail. I get the same exact error with
this flag enabled. I’ve already posted this problem to comp.os.qnx and
gotten some replies, so you can check there for reference as well.

Here is the resmgr setup code and the function that tries to open the
resmgr.

Thanks for your help.

  • Dan

int telMsgServer::loop(char * path)
{
resmgr_attr_t resmgr_attr;
message_attr_t message_attr;
dispatch_t *dpp;
int resmgr_id = 0;
int message_id = 0;
dispatch_context_t *ctp, *ctp_ret;

static resmgr_connect_funcs_t ConnectFuncs;
static resmgr_io_funcs_t IoFuncs;
iofunc_attr_t IoFuncAttr;



/* Create the Dispatch Interface */
dpp = dispatch_create();
if( dpp == NULL )
{
fprintf( stderr, “dispatch_create() failed: %s\n”,
strerror( errno ) );
return EXIT_FAILURE;
}

memset( &resmgr_attr, 0, sizeof( resmgr_attr ) );
resmgr_attr.nparts_max = 1;
resmgr_attr.msg_max_size = 255;
resmgr_attr.flags = _RESMGR_FLAG_SELF;

/* Setup the default I/O functions to handle open/read/write/… */
iofunc_func_init( _RESMGR_CONNECT_NFUNCS, &ConnectFuncs,
_RESMGR_IO_NFUNCS, &IoFuncs );

/* Setup the attribute for the entry in the filesystem */
iofunc_attr_init( &IoFuncAttr, S_IFNAM | 0666, 0, 0 );

resmgr_id = resmgr_attach( dpp, &resmgr_attr, path, _FTYPE_ANY,
0, &ConnectFuncs, &IoFuncs, &IoFuncAttr );
if( resmgr_id == -1 )
{
char errMsg[255];
sprintf(errMsg, “resmgr_attach() failed: %s\n”, strerror( errno ) );
PtEnter(Pt_EVENT_PROCESS_PREVENT);
PtMultiTextModifyText(ABW_msgTxt, 1, 1, -1, errMsg,
sizeof(errMsg), NULL, 0);
PtLeave(Pt_EVENT_PROCESS_PREVENT);
return EXIT_FAILURE;
}

/* Setup our message handler */
memset( &message_attr, 0, sizeof( message_attr ) );
message_attr.nparts_max = 1;
message_attr.msg_max_size = 255;

/* Attach a handler for all command messages /
message_id = message_attach( dpp, &message_attr, _IO_MAX + 1,
_IO_MAX + 20, &msgHandlerWrapper, (void
)this );
if( message_id == -1 )
{
fprintf( stderr, “message_attach() failed: %s\n”, strerror( errno ) );
return EXIT_FAILURE;
}

/* Setup a context for the dispatch layer to use */
ctp = dispatch_context_alloc( dpp );
if( ctp == NULL )
{
fprintf( stderr, “dispatch_context_alloc() failed: %s\n”,
strerror( errno ) );
return EXIT_FAILURE;
}

/* The “Data Pump” - get and process messages */

while( 1 )
{
ctp_ret = dispatch_block( ctp );
if( ctp_ret )
{
dispatch_handler( ctp );
}
else
{
fprintf( stderr, “dispatch_block() failed: %s\n”,
strerror( errno ) );
return EXIT_FAILURE;
}
}

return EXIT_SUCCESS;
}


int
openResMgr( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo )
{
char post[255];
int telMsgFd;
char telPath[20];

sprintf(telPath, “/dev/telemetry”);
telMsgFd = open(telPath, O_RDWR);

sprintf(post,“path = %s\ntelMsgFd = %d\nerr = %s\n”, telPath, telMsgFd,
strerror(errno));

PtMultiTextModifyText(ABW_msgTxt, 1, 1, -1, post,
strlen(post), NULL, 0);

/* eliminate ‘unreferenced’ warnings */
widget = widget, apinfo = apinfo, cbinfo = cbinfo;

return (Pt_CONTINUE);

}

dan helmick <danielhelmick@earthlink.net> wrote:

I’ve already tried this to no avail. I get the same exact error with
this flag enabled. I’ve already posted this problem to comp.os.qnx and
gotten some replies, so you can check there for reference as well.

Here is the resmgr setup code and the function that tries to open the
resmgr.

You mis-read the library reference.

_RESMGR_FLAG_SELF is not a resmgr_attr.flag, it is the “flags” paramater
in resmgr_attach() call, ie:

resmgr_attach(…, _FTYPE_ANY, _RESMGR_FLAG_SELF, …);

-xtang

Thanks for your help.

  • Dan

int telMsgServer::loop(char * path)
{
resmgr_attr_t resmgr_attr;
message_attr_t message_attr;
dispatch_t *dpp;
int resmgr_id = 0;
int message_id = 0;
dispatch_context_t *ctp, *ctp_ret;

static resmgr_connect_funcs_t ConnectFuncs;
static resmgr_io_funcs_t IoFuncs;
iofunc_attr_t IoFuncAttr;



/* Create the Dispatch Interface */
dpp = dispatch_create();
if( dpp == NULL )
{
fprintf( stderr, “dispatch_create() failed: %s\n”,
strerror( errno ) );
return EXIT_FAILURE;
}

memset( &resmgr_attr, 0, sizeof( resmgr_attr ) );
resmgr_attr.nparts_max = 1;
resmgr_attr.msg_max_size = 255;
resmgr_attr.flags = _RESMGR_FLAG_SELF;

/* Setup the default I/O functions to handle open/read/write/… */
iofunc_func_init( _RESMGR_CONNECT_NFUNCS, &ConnectFuncs,
_RESMGR_IO_NFUNCS, &IoFuncs );

/* Setup the attribute for the entry in the filesystem */
iofunc_attr_init( &IoFuncAttr, S_IFNAM | 0666, 0, 0 );

resmgr_id = resmgr_attach( dpp, &resmgr_attr, path, _FTYPE_ANY,
0, &ConnectFuncs, &IoFuncs, &IoFuncAttr );
if( resmgr_id == -1 )
{
char errMsg[255];
sprintf(errMsg, “resmgr_attach() failed: %s\n”, strerror( errno ) );
PtEnter(Pt_EVENT_PROCESS_PREVENT);
PtMultiTextModifyText(ABW_msgTxt, 1, 1, -1, errMsg,
sizeof(errMsg), NULL, 0);
PtLeave(Pt_EVENT_PROCESS_PREVENT);
return EXIT_FAILURE;
}

/* Setup our message handler */
memset( &message_attr, 0, sizeof( message_attr ) );
message_attr.nparts_max = 1;
message_attr.msg_max_size = 255;

/* Attach a handler for all command messages /
message_id = message_attach( dpp, &message_attr, _IO_MAX + 1,
_IO_MAX + 20, &msgHandlerWrapper, (void
)this );
if( message_id == -1 )
{
fprintf( stderr, “message_attach() failed: %s\n”, strerror( errno ) );
return EXIT_FAILURE;
}

/* Setup a context for the dispatch layer to use */
ctp = dispatch_context_alloc( dpp );
if( ctp == NULL )
{
fprintf( stderr, “dispatch_context_alloc() failed: %s\n”,
strerror( errno ) );
return EXIT_FAILURE;
}

/* The “Data Pump” - get and process messages */

while( 1 )
{
ctp_ret = dispatch_block( ctp );
if( ctp_ret )
{
dispatch_handler( ctp );
}
else
{
fprintf( stderr, “dispatch_block() failed: %s\n”,
strerror( errno ) );
return EXIT_FAILURE;
}
}

return EXIT_SUCCESS;
}



int
openResMgr( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo )
{
char post[255];
int telMsgFd;
char telPath[20];

sprintf(telPath, “/dev/telemetry”);
telMsgFd = open(telPath, O_RDWR);

sprintf(post,“path = %s\ntelMsgFd = %d\nerr = %s\n”, telPath, telMsgFd,
strerror(errno));

PtMultiTextModifyText(ABW_msgTxt, 1, 1, -1, post,
strlen(post), NULL, 0);

/* eliminate ‘unreferenced’ warnings */
widget = widget, apinfo = apinfo, cbinfo = cbinfo;

return (Pt_CONTINUE);

}

Thanks guys (Chris McKillop came up with the same answer in comp.os.qnx).

That fixed my problem.

Just a side note for anyone who cares… I had to do a PtLeave and then a
PtEnter, around my MsgSend call.

-Dan