Problems using pulses !!!

Hi Community!!!

How is it possible to change the source code, that two or more pulses can be send.

Like in QNX4 with “trigger (proxy)”

Thank You !!!

---------------------------HEADER FILE---------------------------------
struct my_msg
{
short type;
char string[200]; /Message/
struct sigevent event;
};

#define MY_PULSE_CODE _PULSE_CODE_MINAVAIL+5
#define MSG_GIVE_PULSE _IO_MAX+4

/find server/
#define ATTACH_POINT “a”


------------------------SOURCE-----------------------------------------

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <sys/neutrino.h>
#include <sys/iomsg.h>
#include <sys/dispatch.h>

#include “my_hdr.h”
int main( int argc, char **argv)
{

struct my_msg msg;
struct _pulse pulse;

int rcvid,chid, coid, srv_coid;
name_attach_t *attach;
pid_t npid;

npid=fork();

if(npid){ // SERVER

		 /* attach the name the client will use to find us */
		  /* our channel will be in the attach structure */
		  if ( (attach = name_attach( NULL, ATTACH_POINT, 0 )) == NULL)
		{
		 printf("SERVER: failed to attach name, errno %d\n", errno );
			 exit(1);
		 }

		 /* wait for the message from the client */
		 rcvid = MsgReceive(attach->chid, &msg, sizeof( msg ), NULL );
		 
		 printf("DIE RCVID IST: %d\n",rcvid);
		 
		 if ( msg.type == MSG_GIVE_PULSE )
			 { 
			  /* wait until it is time to notify the client */
 				sleep(2);

				 /* deliver notification to client that client requested */
			 	MsgDeliverEvent( rcvid, &msg.event );
		  		printf("SERVER: delivered event\n");
		  		printf("SERVER :  Der inhalt des PULSES war:  %s\n",msg.string);
		} else

{
printf(“SERVER: unexpected message \n”);
}
return 0;

}else{ // CLIENT

	strcpy(msg.string,"PULSE PULSE PULSE PULSE "); 
	  
	 /* we need a channel to receive the pulse notification on */
	 chid = ChannelCreate( 0 ); 

	  /* and we need a connection to that channel for the pulse to be
	  delivered on */
	  
	  /*If flags contains _NTO_COF_CLOEXEC, the connection is closed
  		when your process calls an exec*() function to start a new process*/
	 coid = ConnectAttach( 0, 0, chid, _NTO_SIDE_CHANNEL, 0 );

	 /* fill in the event structure for a pulse (to send a pulse).*/
	 /*SIGEV_PULSE_INIT( event, coid, priority, code, value )*/
	 SIGEV_PULSE_INIT( &msg.event, coid, SIGEV_PULSE_PRIO_INHERIT, 
                MY_PULSE_CODE, 0 );
                
	 msg.type = MSG_GIVE_PULSE; /*"my_hdr.h" */

	 /* find the server */
	 if ( (srv_coid = name_open( ATTACH_POINT, 0 )) == -1)
	 {
		 printf("CLIENT: failed to find server, errno %d\n", errno );
 		 exit(1);
	 }

	  /* give the pulse event we initialized above to the server for
		 later delivery */
	 MsgSend( srv_coid, &msg, sizeof(msg), NULL, 0 );

	/* wait for the pulse from the server */
	 rcvid = MsgReceivePulse( chid, &pulse, sizeof( pulse ), NULL );
	
	
	printf("CLIENT: Receive Code %d waiting for %d  \n",
	pulse.code, MY_PULSE_CODE );

	return 0;
  }

}


What exactly about the code you provided do you think isn’t working ?

Obviously, in order to receive additional pulses you can’t exit() after receiving one, so I need clarification on what you are trying to do ?

Rennie

Thank you Renni !
I would like to use Pulses to send two or more messages from process A to process B.
Like as a Notification of something who is ready

struct msg1 {
short unsigned type;
char string [ZMAX];
};

union {
short unsigned type;
struct msg1 send_value;
} msg;

int main(void)
{
pid_t npid, proxy;

int i , flag=0;

msg.type = MSG_CODE;

strcpy(msg.send_value.string," Message");

proxy = qnx_proxy_attach(0,&msg.send_value,sizeof(msg.send_value),-1);

if (proxy == -1) {
printf (“No Proxy (%s)!\n”,strerror(errno));
return 2;
}
npid = fork() ;

if (npid) {

for ( i=1;i<=2;i++) { /* 2 Messages */

    printf ("Parent: Wait 2s ...\n");
    sleep(2) ;
    printf ("Parent: Receive \n");
    npid = Receive(0,&msg,sizeof(msg));
    
    if (npid != -1) {
             
             if (msg.type == MSG_CODE) {
                printf ("Parent: The Message:\n%s\n", msg.send_value.string);
             }else{
                printf ("Parent wrong Type of Message %d \n",msg.type);
                break;
             }
    }
}

printf (“Parent: EXIT\n”);
return 0;

} else {

Trigger(proxy);/Send Proxy/
printf (" Proxy Trigger\n");
printf (“Wait 3s …\n”);
sleep(3) ;
Trigger(proxy);
printf (" Proxy trigger new\n");
printf (“EXIT\n”);

return 0;
}