Ejemplo n.º 1
0
/**
 * free memory reserved by demultiplexer's instance
 */
Demultiplexer::~Demultiplexer() {
#ifdef DEBUG_
	cout << "Demultiplexer deleted" << endl;
#endif

	delete demultiplexer_instance_;
	// detach connection channel if it has been created
	if (con_id_) {
		ConnectDetach(con_id_);
		ChannelDestroy(channel_id_);
	}
}
Ejemplo n.º 2
0
void
omap_fini(void *hdl)
{
    omap_dev_t  *dev = hdl;

    out16(dev->regbase + OMAP_I2C_CON, 0);
    out16(dev->regbase + OMAP_I2C_IE, 0);
	InterruptDetach(dev->iid);
	ConnectDetach(dev->coid);
	ChannelDestroy(dev->chid);
	munmap_device_io (dev->regbase, dev->reglen);
	free (hdl);
}
Ejemplo n.º 3
0
void Sensorik::stop() {
	HAWThread::stop(); // super.stop();

	if (-1 == ConnectDetach(isr_coid)) {
		perror("SensorCtrl: ConnectDetach isr_coid failed");
	}
	if (-1 == ChannelDestroy(isr_Chid)) {
		perror("SensorCtrl: ChannelDestroy isr_chid failed");
	}
	// in Simulation: bleibt hier haengen
	//    if (-1 == InterruptDetach(interruptId)) {
	//        perror("SensorCtrl: InterruptDetach failed");
	//    }
}
Ejemplo n.º 4
0
void
SocketDestroy(TSocket * const socketP) {

    assert(socketP->signature == socketSignature);

    if (socketP->channelP) {
        ChannelDestroy(socketP->channelP);
        free(socketP->channelInfoP);
    }

    if (socketP->chanSwitchP)
        ChanSwitchDestroy(socketP->chanSwitchP);

    socketP->signature = 0;  /* For debuggability */

    free(socketP);
}
Ejemplo n.º 5
0
void SensorHAL::stopInterrupt() {
	if (-1 == ThreadCtl(_NTO_TCTL_IO, 0)) {
		printf("ThreadCtl access failed\n");
		exit(EXIT_FAILURE);
	}

	if (InterruptDetach(interruptId) == -1) {
		printf("SensorHAL: Error InterruptDetach\n");
	}

	if (ConnectDetach(coid) == -1) {
		printf("SensorHAL: Error in ConnectDetach\n");
	}

	if (ChannelDestroy(chid) == -1) {
		printf("SensorHAL: Error in ChannelDestroy\n");
	}
}
Ejemplo n.º 6
0
inline int
isr_setup(omapl1xx_context_t *omapl1xx)
{
	int	err;

	if ((omapl1xx->lcd_chid = ChannelCreate(_NTO_CHF_DISCONNECT |
		_NTO_CHF_UNBLOCK)) == -1) {
		return -1;
	}

	if ((omapl1xx->lcd_coid = ConnectAttach(0, 0,
		omapl1xx->lcd_chid, _NTO_SIDE_CHANNEL, 0)) == -1) {
		err = errno;
		goto fail;
	}

	SIGEV_PULSE_INIT(&omapl1xx->lcd_event, omapl1xx->lcd_coid,
		omapl1xx->adapter->pulseprio, OMAPL1xx_LCD_INTERRUPT_PULSE, 0);

	omapl1xx->lcd_iid = InterruptAttach(_NTO_INTR_CLASS_EXTERNAL |
		omapl1xx->irq, omapl1xx_lcd_isr, (void *)omapl1xx, sizeof(*omapl1xx),  _NTO_INTR_FLAGS_END |
		_NTO_INTR_FLAGS_TRK_MSK | _NTO_INTR_FLAGS_PROCESS);

	if (omapl1xx->lcd_iid == -1) {
		err = errno;
		goto fail2;
	}

	return 0;

fail2:
	ConnectDetach(omapl1xx->lcd_coid);
fail:
	ChannelDestroy(omapl1xx->lcd_chid);

	errno = err;

	return -1;
}
Ejemplo n.º 7
0
int _waitfor( __const char *path, int delay_ms, int poll_ms, int (*checkfunc)(__const char *, void *), void *handle )
{
	int					notify_id = -1;
    struct sigevent     event;
    int                 chid = -1, coid = -1;
    struct _pulse       pulse;
	int					ret_val = -1;
	uint64_t			polltimeout = 100 * (uint64_t)1000000;
	uint64_t			timeout_nsec;

	timeout_nsec = _syspage_time(CLOCK_MONOTONIC);
	timeout_nsec += delay_ms * (uint64_t)1000000;

    /* Check to make sure we don't wait for something already there... */
    ret_val = checkfunc( path, handle );
	if ( ret_val >= 0 || ret_val == WAITFOR_CHECK_ABORT ) {
		return ret_val;
    }

	if ( poll_ms > 0 ) {
		polltimeout = poll_ms * (uint64_t)1000000;
	}

	/* 
	 * We make the channel fixed since we want to remain at the current
	 * thread's priority
	 */
    chid = ChannelCreate(_NTO_CHF_FIXED_PRIORITY);
	if ( chid == -1 ) {
		goto fail1;
	}
    coid = ConnectAttach( ND_LOCAL_NODE, 0, chid, _NTO_SIDE_CHANNEL, 0 );
	if ( coid == -1 ) {
		goto fail2;
	}

    SIGEV_PULSE_INIT( &event, coid, SIGEV_PULSE_PRIO_INHERIT, PULSE_CODE_PATHSPACE, 0 );
    notify_id = procmgr_event_notify_add( PROCMGR_EVENT_PATHSPACE, &event );
	if ( notify_id == -1 ) {
		goto fail3;
	}

    while(_syspage_time(CLOCK_MONOTONIC) < timeout_nsec) {

		/* we need to poll in case we are checking for a subdirectory/file,
		 * since we won't get a pathmgr event for those.
		 */
		SIGEV_UNBLOCK_INIT(&event);
		if ( TimerTimeout( CLOCK_MONOTONIC, _NTO_TIMEOUT_RECEIVE, &event, &polltimeout, NULL) == -1 ) {
			ret_val = -1;
			break;
		}
	   	if ( MsgReceivePulse( chid, &pulse, sizeof(pulse), NULL ) != -1 || errno == ETIMEDOUT ) {
			ret_val = checkfunc( path, handle );
			if ( ret_val >= 0 || ret_val == WAITFOR_CHECK_ABORT ) {
				break;
            }
		} else {
			break;
		}
    }

	(void)procmgr_event_notify_delete( notify_id );
fail3:
	(void)ConnectDetach(coid);
fail2:
	(void)ChannelDestroy(chid);
fail1:
    return ret_val;
}
Ejemplo n.º 8
0
int asyncmsg_connect_attach(uint32_t nd, pid_t pid, int chid, unsigned index, unsigned flags, const struct _asyncmsg_connection_attr *attr)
{
	struct _asyncmsg_connect_context *acc;
	struct _asyncmsg_connection_descriptor *acd;
	int id, size;
	static pthread_mutex_t _async_init_mutex = PTHREAD_MUTEX_INITIALIZER;

	_mutex_lock(&_async_init_mutex);
	if (!_async_ev) {
		int chid;
		
		if ((_async_ev = malloc(sizeof(*_async_ev))) == NULL) {
			_mutex_unlock(&_async_init_mutex);
			return -1;
		}
			
		if ((chid = ChannelCreate(0)) == -1) 
		{
			free(_async_ev);
			_async_ev = NULL;
			_mutex_unlock(&_async_init_mutex);
			return -1;
		}
		
		if ((_async_ev->sigev_coid = ConnectAttach(0, 0, chid, _NTO_SIDE_CHANNEL, 0)) == -1)
		{
			ChannelDestroy(chid);
			free(_async_ev);
			_async_ev = NULL;
			_mutex_unlock(&_async_init_mutex);
			return -1;
		}
		
		_async_ev->sigev_notify = SIGEV_PULSE;
		_async_ev->sigev_priority = SIGEV_PULSE_PRIO_INHERIT;
		
		if ((errno = pthread_create(&_async_ev_tid, NULL, _async_event_thread, (void *)chid)) != EOK) 
		{
			ConnectDetach(_async_ev->sigev_coid);
			ChannelDestroy(chid);
			free(_async_ev);
			_async_ev = NULL;
			_mutex_unlock(&_async_init_mutex);
			return -1;
		}
	}
	_mutex_unlock(&_async_init_mutex);

	size = sizeof(*acc) + sizeof(struct _asyncmsg_put_header) * attr->max_num_buffer;
	acc = mmap(0, size, PROT_READ|PROT_WRITE, MAP_PRIVATE | MAP_ANON | MAP_PHYS, NOFD, 0);
	if (acc == (struct _asyncmsg_connect_context *)MAP_FAILED) {
	  return -1;
	}
	memset(acc, 0, sizeof(*acc));
	acd = &acc->acd;

	flags |= _NTO_COF_NOSHARE;
	acd->attr = *attr;
	acd->flags = flags;
	acd->sendq_size = attr->max_num_buffer;
	acd->sendq = (struct _asyncmsg_put_header *)((char *)acc + sizeof(*acc));

	if ((id = ConnectAttachExt(nd, pid, chid, index, flags, acd)) == -1) {
		return -1;
	}
	
	acd->sendq_head = acd->sendq_tail = acd->sendq_free = 0;
	acd->ev = *_async_ev;
	acd->ev.sigev_value.sival_int = id;
	acd->ev.sigev_code = 'T';
	if ((acd->ttimer = TimerCreate(CLOCK_REALTIME, &acd->ev)) == (timer_t)-1) {
		asyncmsg_connect_detach(id);
		return -1;
	}
	acc->flags = _ASYNCMSG_CONNECT_TIMEROFF;
	
	acd->ev.sigev_code = 'P';
	if ((errno = pthread_mutex_init(&acd->mu, 0)) != EOK)
	{
		asyncmsg_connect_detach(id);
		return -1;	
	}
	
	if ((errno = pthread_cond_init(&acd->block_con, 0)) != EOK)
	{
		asyncmsg_connect_detach(id);
		return -1;
	}
	
	if (_asyncmsg_handle(id, _ASYNCMSG_HANDLE_ADD, acc) == NULL) {
		asyncmsg_connect_detach(id);
		return -1;
	}
	
	return id;
}
Ejemplo n.º 9
0
void
zz_xr_serverRunOnce (TServer * const serverP) {
/*----------------------------------------------------------------------------
   Accept a connection from the channel switch and do the HTTP
   transaction that comes over it.

   If no connection is presently waiting at the switch, wait for one.
   But return immediately if we receive a signal during the wait.
-----------------------------------------------------------------------------*/
    struct _TServer * const srvP = serverP->srvP;

    const char * error;
    TChannel *   channelP;
    void *       channelInfoP;

    extern void  ChanSwitchAccept ();
    extern void  ChannelFormatPeerInfo ();
    extern void  ServerSetKeepaliveMaxConn ();
    extern void  serverRunChannel ();
    extern void  xmlrpc_strfree ();


/*
    ServerSetKeepaliveMaxConn (serverP, 1);
    ChanSwitchAccept (srvP->chanSwitchP, &channelP, &channelInfoP, &error);
*/

    if (error) {
        TraceMsg ("Failed to accept the next connection from a client "
                  "at the channel level.  %s", error);
        xmlrpc_strfree (error);
    } else {

	/* Handle connection in the background.
    	 */
    	switch (fork ()) {
    	case 0:
            break; 				/* We are the child 	*/
    	default:
            return; 				/* We are the parent 	*/
    	}

        if (channelP) {
            const char * error;

            serverRunChannel (serverP, channelP, channelInfoP, &error);

            if (error) {
                const char * peerDesc;
                ChannelFormatPeerInfo (channelP, &peerDesc);
                TraceExit ("Got a connection from '%s', but failed to "
                           "run server on it.  %s", peerDesc, error);
                xmlrpc_strfree (peerDesc);
                xmlrpc_strfree (error);
            }
            ChannelDestroy (channelP);
            free (channelInfoP);
        }
    }

    exit (0);
}
main (void)
{
	pid_t	pid_gui;
	pid_t	pid_sim;
	pid_t	pid_pport;
	
	int		simChid;

	
	int		kill_gui;
	int		kill_sim;
	int		kill_pport;
	
	int		s_return;	
	
	//---thread paramters--------------//
	pthread_attr_t attr;
	pthread_t timerThreadID;
	pthread_t keyboardThreadID;
	pthread_t blockIDThreadID;
	
	do
	{
	printf("\n=========================================================\n");
	printf("Please Selet the Operating Mode:\n");
	printf("1: Basic Orientation Mode for Block: 0-10).\n");
	printf("2: Rotated Orientation Mode for Block:0-6). (alaph version)\n");
	printf("===========================================================\n");
	flushall();
	scanf ("%c",&programMode);
	printf("You have selected: Mode %c.\n\n",programMode);
	flushall();
	if((programMode != '1' )&&(programMode !='2'))
	{
		printf("Invalid Selection, Please Enter!\n");
		flushall();
	}
	}
	while(programMode != '1'&&programMode !='2');
	
	


// ----------------Share Memory----------------------------------------
	shMem=shm_open("shared_memory", OFLAGS, 0777);
	if (shMem == -1)
	{
		printf("shared_memory failed to open...\n");
		flushall();
	}
	else
	{
		if (ftruncate (shMem,SIZE) == -1)
		{
			printf ("Failed to set size for -- shmem -- \n");
			flushall();
		}
		else
		{
			//mapping a shared memory location
			memLocation = mmap (0,  SIZE, PROT, MFLAGS, shMem, 0);
			if (memLocation == MAP_FAILED)
			{
				printf (" Failed to map to shared memory...\n");
				flushall();
			}
		}	
	}
// ---------------Semorphore-------------------------------------
	// semorphore for shared memory
	sem = sem_open ("shared_sem", O_CREAT, S_IRWXG | S_IRWXO | S_IRWXU, 0);
	if (sem == (sem_t *)(-1)) 
	{
	   	printf ("User: Memory Semaphore failed to open....\n");
	  	flushall();
	}
	else
	{
		sem_post(sem);
	}
// -----------------------channel creation---------------------------
    // Create a channels for the simulator and Gui
    // The ChannelCreate function returns the channel ID
	ChannelCreate(0);
	ChannelCreate(0);
	//ChannelCreate(0);//for pport
	
	simChid = 1;
	sleep(1);
	
	// Spawing a process for the GUI and Simulator
	pid_gui = spawnl(P_NOWAIT, "/usr/local/bin/gui_g", "gui_g", NULL);
	pid_sim = spawnl(P_NOWAIT, "/usr/local/bin/newGUIPport_g", "sim", NULL);
	pid_pport = spawnl(P_NOWAIT, "/usr/local/bin/testPport_g", "pport",NULL);
	
	sleep(1);
	//The Gui process automatically connect to the channel
	//Thus we only need to attach the simulator process to the created channel
	coidsim = ConnectAttach(0,pid_sim,simChid,0,0);
	// Display error message if connection failed
	if (coidsim == -1)
	{
		printf("coidsim error\n");
		flushall();
		exit(EXIT_FAILURE);
	}
	coidpport = ConnectAttach(0,pid_pport,simChid,0,0);
	// Display error message if connection failed
	if (coidpport == -1)
	{
		printf("coidpport error\n");
		flushall();
		exit(EXIT_FAILURE);
	}

// --------------------------timer code----------------------------------
	// Create a channel for sending a pulse to myself when timer expires
	timerChid = ChannelCreate(_NTO_CHF_UNBLOCK);
	if(timerChid == -1)
	{
		printf("timer Channel create failed\n");		
	    	flushall();
	}
	timerCoid = ConnectAttach ( 0, getpid ( ), timerChid, 0, 0);
   	if(timerCoid == -1 ) 
   	{
       	printf ("Channel attach failed!\n");
		flushall();
		perror ( NULL ); 
		exit ( EXIT_FAILURE);
   	}
	//	Set up pulse event for delivery when the first timer expires; pulse code = 8, pulse value  = 0;
	SIGEV_PULSE_INIT (&timerEvent, timerCoid, SIGEV_PULSE_PRIO_INHERIT, 8, 0);
	//	Create Timer
	if (timer_create (CLOCK_REALTIME, &timerEvent, &timerid) == -1) 
   	{
   		printf ( "Failed to create a timer for pulse delivery\n");
		flushall();
   		perror (NULL);
   		exit ( EXIT_FAILURE);
   	}
	// Setup one time timer for 2 second
	timer.it_value.tv_sec = 2;
	timer.it_value.tv_nsec = 0;
	timer.it_interval.tv_sec = 0;
	timer.it_interval.tv_nsec = 0;
// --------------------------timer2 code----------------------------------
	// Create a channel for sending a pulse to myself when timer expires
	timerChid2 = ChannelCreate(_NTO_CHF_UNBLOCK);
	if(timerChid2 == -1)
	{
		printf("timer Channel create failed\n");		
	    	flushall();
	}
	timerCoid2 = ConnectAttach ( 0, getpid ( ), timerChid2, 0, 0);
   	if(timerCoid2 == -1 ) 
   	{
       	printf ("Channel attach failed!\n");
		flushall();
		perror ( NULL ); 
		exit ( EXIT_FAILURE);
   	}
	// Set up pulse event for delivery when the first timer expires; pulse code = 8, pulse value  = 0;
	SIGEV_PULSE_INIT (&timerEvent2, timerCoid2, SIGEV_PULSE_PRIO_INHERIT, 8, 0);
	// Create Timer
	if (timer_create (CLOCK_REALTIME, &timerEvent2, &timerid2) == -1) 
   	{
   		printf ( "Failed to create a timer for pulse delivery\n");
		flushall();
   		perror (NULL);
   		exit ( EXIT_FAILURE);
   	}
//-------------------timer monitor thread--------------------
	pthread_attr_init(&attr);
	pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
	pthread_create(&timerThreadID,&attr,timer_thread,NULL);
	if(timerThreadID == -1)
	{
		printf("Fail to create timer thread!");
		flushall();
	}
	else
	{
		printf("The timer thread ID is %i \n",timerThreadID);
		flushall();
	}
	pthread_create(&timerThreadID,&attr,timer2_thread,NULL);
	if(timerThreadID == -1)
	{
		printf("Fail to create timer thread2!");
		flushall();
	}
	else
	{
		printf("The timer thread2 ID is %i \n",timerThreadID);
		flushall();
	}
//
//----start the block Identification thread-----------------
//	pFile = fopen("Blocks.txt","w+");
	pthread_create(&blockIDThreadID,&attr,blockID,NULL);
		if(blockIDThreadID == -1)
	{
		printf("Fail to create block indeptification thread!");
		flushall();
	}
	else
	{
		printf("The BlockID's thread ID is %i \n",blockIDThreadID);
		flushall();
	}
	delay(10);
//---------------------keyboard thread------------------------
	pthread_create(&keyboardThreadID,&attr,keyboard_input,NULL);
		if(keyboardThreadID == -1)
	{
		printf("Fail to create keyboard input!");
		flushall();
	}
	else
	{
		printf("The keyboard_input ID is %i \n",timerThreadID);
		flushall();
	}
	delay(10);
//----------------GUI Monitor Thread---------------------
	pthread_create(NULL,&attr,GUI_thread,NULL);
	delay(10);
// --------------------SIM pulse Handler Loop Thread----------
	pthread_create(NULL,&attr,Handlerloop_thread,NULL);
	delay(10);
// --------------------SIM Monitor Thread---------------------
	pthread_create(NULL,&attr,SIM_thread,NULL);
	delay(10);
// --------------------Auto mode thread-----------------------
	pthread_create(NULL,&attr,auto_thread,NULL);
	delay(10);
// --------------------others---------------------------------
	// call mainLoop()
	mainLoop();
	// sleep for 10sec
	printf("Sleep the program for 10 seconds\n");
	flushall;
	sleep(10);
	// start release system resourse
	printf("Clean up and release system resourse\n");
	flushall;
	// Kill the existing processes
	kill_gui = kill(pid_gui, 0);
	kill_sim = kill(pid_sim, 0);
	kill_pport = kill(pid_pport, 0);
    if (kill_gui == -1)
	{
		printf("GUI Kill failed\n");
		flushall();
	}
	if (kill_sim == -1)
	{
		printf("SIM Kill failed\n");
		flushall();
	} 
	if (kill_pport == -1)
	{
		printf("PPort Kill failed\n");
		flushall();
	}
	// Close and unlink Semorphore
	sem_close(sem);
	s_return = sem_unlink("/dev/sem/home/quad6/workspace/Project_S1/shared_sem");
	// Display error messae if semorphonre unlink is failed
	if (s_return == -1)
	{
		printf("a: %s\n", strerror( errno ));
		flushall();
	}
	// Close, unmap, and unlink shared memory
	shm_close(shMem);
	munmap(shmLocation,SIZE);
	shm_unlink("shared_memory");
	// Detach the connections and destroy the channels
	ConnectDetach(coidGui);
    ConnectDetach(coidsim);
    ConnectDetach(coidpport);
    ChannelDestroy(guiChid);
    ChannelDestroy(simChid);
    
//    fclose(pFile);
}	
PeriodicThreadImplQNX::~PeriodicThreadImplQNX()
{
  ChannelDestroy(m_chid);
}