Wojtek:
I have been using the technique suggested by Norbert using the name_attach
and then the PhChannelAttach() without any problems. However, since you had
pointed out that this was really a hack and not guaranteed, I looked for
another way to accomplish something similar - i.e. easily publish the main
channel of a Photon app via the “name_xxxx” capability. Unfortunately, I ran
into a problem that perhaps you can explain.
The basic idea is to
(a) - In the initialization function, determine the channel id - using
PtChannelCreate() and record it in a global
(b) - Start off a separate thread that creates its own channel/published
name combination through name_attach()
(c) - Any client can then MsgSend to the subordinate thread requesting the
“main” channel id and can then communicate directly using this main channel
id.
Unfortunately - doing the following:
pid_t gMainChannel;
int Init( int argc, char *argv[] ) // PhAB Initialization function
{
name_attach_t *pInfo;
/* eliminate ‘unreferenced’ warnings */
argc = argc, argv = argv;
gMainChannel = PtChannelCreate();
pInfo = name_attach(NULL,MYNAME,0);
if ( pInfo == NULL )
{
printf ( “Name attach failed on %s - errno: %d\n”, MYNAME, errno);
PtExit(-1);
}
…
causes the name_attach to fail with an errno 16, (EBUSY) - whether I call it
here or in a separate thread
Strangely enough, if I do the following:
int Init( int argc, char *argv[] )
{
name_attach_t *pInfo;
/* eliminate ‘unreferenced’ warnings */
argc = argc, argv = argv;
// Create my own channel from a name and use it as the main photon thread
pInfo = name_attach(NULL,MYNAME_MAIN,0);
if ( pInfo == NULL )
{
printf ( “Name attach failed on %s - errno: %d\n”, MYNAME_MAIN, errno);
PtExit(-1);
}
gMainChannel = pInfo->chid;
PhChannelAttach(gMainChannel, -1, NULL);
gpInputApp = PtAppAddInput(NULL,0,InputFunc,NULL);
pInfo = name_attach(NULL,MYNAME_OTHER,0);
if ( pInfo == NULL )
{
printf ( “Name attach failed on %s - errno: %d\n”, MYNAME_OTHER, errno);
PtExit(-1);
}
…
So, If I allow the Photon library to do its thing and get its channel
through PtChannelCreate(), I am prevented from successfully calling
name_attach(). However if I use name_attach(), get a channel and tell the
Photon library to make use of that channel, I’m able to continue using
name_attach to create other channels.
Also, if I try the name_attach() first and then call PtChannelCreate(), the
latter returns a (-1).
What am I missing here
Thanks
Lionel
“Wojtek Lerch” <wojtek@qnx.com> wrote in message
news:93pr29$jf8$1@nntp.qnx.com…
Wojtek Lerch <> wojtek@qnx.com> > wrote:
attach = name_attach( NULL, “myname”, 0 );
PhChannelAttach( attach->chid, -1, NULL );
… but I have never made sure that the channel that
name_attach() or the dispatch functions create has all the setting
required to support all the functionality of the Photon library.
I guess what I really meant is that I doubt anybody has ever made sure
that name_attach() creates its channel with 100% Photon-compatible
settings. While it seems to work, some more exotic features have never
been tested. My main suspicion is that the channel flags are not quite
right, the PtConnection API might fail to report certain errors. But
you probably won’t be mixing name_attach() with PtConnection anyway…
–
Wojtek Lerch (> wojtek@qnx.com> ) QNX Software Systems Ltd.