the problem with pulse and HAM

I am trying to use HAM to send a pulse while heartbeat missed.
but MsgReceivePulse can only receive the pulse once ! then nothing can be received.
I don’t know why!

Thanks,
Jiang Min
jmtree@126.com

the source code is :
#include
#include
#include <ha/ham.h>//for ham
#include <signal.h>
#include <fcntl.h> //for open()
#include <sys/stat.h>
#include <sys/neutrino.h>
#include <sys/iomsg.h>
#include <sys/netmgr.h>
#include <signal.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define REALTIMEMODELBLOCK _PULSE_CODE_MINAVAIL+1
int doheartbeat=0;
struct sigevent event;
int main(int argc, char *argv[]) {
////////////////////////////////////////////////////////////
//varialble for ham
pthread_attr_t attrib;
struct sched_param param;
ham_entity_t *ehdl;
ham_condition_t *chdl;
ham_action_t *ahdl;
int chid, coid, rcvid;
struct _pulse pulse;
pid_t pid;
int status;
int value;

//////////////////////////////////////////////////////////////////////////
//HAM INIT
// test if ham is accessable 
if (access("/proc/ham",F_OK) == 0)
{
	doheartbeat=1;
} 

// attach to ham 
if (doheartbeat) 
{
	/// 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
	coid = ConnectAttach( 0, 0, chid, _NTO_SIDE_CHANNEL, 0 );
	/// fill in the event structure for a pulse 
	pid = getpid();
	value = 13;
	ham_connect(0);
    
    ehdl = ham_attach_self("OCend",1000000000UL,10 ,10, 0);
    if(ehdl!=NULL)
    {
    	chdl = ham_condition(ehdl, CONDHBEATMISSEDHIGH, "heartbeat-missed-high", HREARMAFTERRESTART);
    	if(chdl!=NULL)
    	{
	    ahdl = ham_action_notify_pulse(chdl, "notifyrestart_thread", ND_LOCAL_NODE, pid, chid, REALTIMEMODELBLOCK, value, HREARMAFTERRESTART|HACTIONKEEPONFAIL);
       	if(ahdl==NULL)
         {
           	printf("%s\n",strerror(errno));
         }
         ham_action_handle_free(ahdl);
     	}
    }
    else
    {
    	printf("%s\n",strerror(errno));
    }
    
}    
ham_heartbeat();
//to deal with  ham Pulse

while (1) 
{
	rcvid = MsgReceivePulse( chid, &pulse, sizeof( pulse ), NULL );
		if (rcvid < 0) 
		{
  		if (errno != EINTR) 
  		{
    			exit(-1);
  		}
		}
		else 
		{
        switch (pulse.code) 
        {
            case REALTIMEMODELBLOCK:
                printf("BLOCK\n");
        }
		}
}
return EXIT_SUCCESS;

}

If you install a default to the switch case, are you receving other pulses. ALWAYS have default for switch case ;-0

Actually, in the first loop, MsgReceivePulse() can receive a pulse, in the second loop, MsgReceivePulse() is blocked! No more pulse can be received!

Don’t know much about HAM but should you really call ham_action_handle_free(ahdl);

Please help me ! I don’t know why!

Maybe you need to call ham_action_notify_pulse() again after receiving the pulse?

jmtree,

Have you tried starting the ham process with extra verbosity and logging to a file so you can see what’s going on?

ie ham -V3 -f mylogfile

Technically what you have looks correct from the doc’s. But then all the examples they have there are for monitoring external processs’s, never yourself. So there may be something tricky that increasing the verbosity may show.

You might also try doing adding a ham_action_fail_notify_pulse() with a diffferent ‘value’ in the pulse and see if that comes thru after the first successful pulse does.

Tim