Example #1
0
 MyTimer()
     {
         connect(this, SIGNAL(timeout()),
                 this, SLOT(timedout()));
         start(10000);
         setSingleShot(true);
     }
		foreach (PieceDownloader* pd,pdown)
		{
			pd->release();
			sendCancels(pd);
			disconnect(pd,SIGNAL(timedout(bt::Request)),this,SLOT(onTimeout(bt::Request)));
			disconnect(pd,SIGNAL(rejected(bt::Request)),this,SLOT(onRejected(bt::Request)));
		}
Example #3
0
void AgentPNS::stop_threads(){
	if(threadstate != Thread_Wait_Start){
		timedout();
		runbarrier.wait();
		CAS(threadstate, Thread_Wait_End, Thread_Wait_Start);
		assert(threadstate == Thread_Wait_Start);
	}
}
Example #4
0
void
read_first_move(int fd)
{
	if (EXP_TIMEOUT == exp_expectl(fd,exp_glob,"first\r\n1.*\r\n",0,exp_end)) {
		timedout();
	}
	sscanf(exp_match,"%*s 1. %s",move);
}
CommandTimer::CommandTimer(QUndoCommand * command, int delayMS, WaitPushUndoStack * undoStack) : QTimer()
{
	m_undoStack = undoStack;
	m_command = command;
	m_undoStack->addTimer(this);
	setSingleShot(true);
	setInterval(delayMS);
	connect(this, SIGNAL(timeout()), this, SLOT(timedout()));
	start();
}
Example #6
0
void
read_move(int fd)
{
	switch (exp_expectl(fd,exp_glob,"*...*\r\n*.*\r\n",0,exp_end)) {
	case EXP_TIMEOUT: timedout();
	case EXP_EOF: exit(-1);
	}

	sscanf(exp_match,"%*s %*s ... %*s %*s %s",move);
}
bool Magnetic::prepareUpdate(State &state, const Update &update) {
  // reset reference position if Magnetic has not been updated for a while
  if (timedout()) reference_.reset();

  if (reference_ != GlobalReference::Instance()) {
    reference_ = GlobalReference::Instance();
    if (auto_heading_) reference_->setCurrentHeading(state, getModel()->getTrueHeading(state, update.getVector()));
  }

  getModel()->setReference(reference_->heading());
  return true;
}
Example #8
0
void QgsGPSInformationWidget::connectGps()
{
  // clear position page fields to give better indication that something happened (or didn't happen)
  mTxtLatitude->clear();
  mTxtLongitude->clear();
  mTxtAltitude->clear();
  mTxtDateTime->clear();
  mTxtSpeed->clear();
  mTxtDirection->clear();
  mTxtHdop->clear();
  mTxtVdop->clear();
  mTxtPdop->clear();
  mTxtFixMode->clear();
  mTxtFixType->clear();
  mTxtQuality->clear();
  mTxtSatellitesUsed->clear();
  mTxtStatus->clear();

  mLastGpsPosition = QgsPoint( 0.0, 0.0 );

  QString port;

  if ( mRadUserPath->isChecked() )
  {
    port = mCboDevices->itemData( mCboDevices->currentIndex() ).toString();

    if ( port.isEmpty() )
    {
      QMessageBox::information( this, tr( "/gps" ), tr( "No path to the GPS port "
                                "is specified. Please enter a path then try again." ) );
      //toggle the button back off
      mConnectButton->setChecked( false );
      return;
    }
  }
  else if ( mRadGpsd->isChecked() )
  {
    port = QString( "%1:%2:%3" ).arg( mGpsdHost->text() ).arg( mGpsdPort->text() ).arg( mGpsdDevice->text() );
  }
  else if ( mRadInternal->isChecked() )
  {
    port = QString( "internalGPS" );
  }

  mGPSPlainTextEdit->appendPlainText( tr( "Connecting..." ) );
  showStatusBarMessage( tr( "Connecting to GPS device..." ) );

  QgsGPSDetector *detector = new QgsGPSDetector( port );
  connect( detector, SIGNAL( detected( QgsGPSConnection * ) ), this, SLOT( connected( QgsGPSConnection * ) ) );
  connect( detector, SIGNAL( detectionFailed() ), this, SLOT( timedout() ) );
  detector->advance();   // start the detection process
}
bool GPS::beforeUpdate(PoseEstimation &estimator, const GPSUpdate &update) {
  // reset reference position if GPS has not been updated for a while
  if (timedout()) reference_ = 0;

  // find new reference position
  if (!reference_) {
    reference_ = estimator.globalReference();
    reference_->latitude  = update.latitude;
    reference_->longitude = update.longitude;
    reference_->updated();

    StateVector state = estimator.getState();
    double north =  state(POSITION_X) * reference_->cos_heading + state(POSITION_Y) * reference_->sin_heading;
    double east  =  state(POSITION_X) * reference_->sin_heading - state(POSITION_Y) * reference_->cos_heading;
    reference_->latitude  = update.latitude  - north / reference_->radius_north;
    reference_->longitude = update.longitude - east  / reference_->radius_east;
    reference_->updated();

    ROS_INFO("Set new GPS reference position: %f/%f", reference_->latitude * 180.0/M_PI, reference_->longitude * 180.0/M_PI);
  }

  return true;
}
Example #10
0
char*
SocketInputStream::gets(char * buf, int bufLen) {
  if(timedout())
    return 0;
  assert(bufLen >= 2);
  int offset= 0;
  if(m_startover)
  {
    buf[0]= '\0';
    m_startover= false;
  }
  else
    offset= strlen(buf);

  int time= 0;
  int res = readln_socket(m_socket, m_timeout_remain, &time,
                          buf+offset, bufLen-offset, m_mutex);

  if(res >= 0)
    m_timeout_remain-=time;
  if(res == 0 || m_timeout_remain<=0)
  {
    m_timedout= true;
    buf[0]=0;
    return buf;
  }

  m_startover= true;

  if(res == -1)
  {
    return 0;
  }

  return buf;
}
Example #11
0
File: main.c Project: dsqmoore/dsra
int start_listening(const char * port)
{
    struct addrinfo hints, *res,*p;
    int sockfd;
	int socks[100];
	int nsocks = 0;
	int i;
	
    // first, load up address structs with getaddrinfo():
	
    memset(&hints, 0, sizeof hints);
    hints.ai_family = AF_UNSPEC;  // use IPv4 or IPv6, whichever
    hints.ai_socktype = SOCK_DGRAM;
    hints.ai_flags = AI_PASSIVE;     // fill in my IP for me
	
	int r;
    if ((r = getaddrinfo(NULL, port, &hints, &res))!=0)
	{
		fprintf(stderr,"getaddrinfo: %s",gai_strerror(r));
		return -1;
	}
	
	for (p=res; p; p=p->ai_next)
	{
	
		// make a socket, bind it, and listen on it:
	
		if ((sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol))<0)
			continue;
		
		if (fcntl(sockfd, F_SETFL, O_NONBLOCK)<0)
		{
			close(sockfd);
			continue;
		}
		
		if (bind(sockfd, res->ai_addr, res->ai_addrlen)<0)
		{
			close(sockfd);
			continue;
		}
		
		socks[nsocks++]=sockfd;
		if (nsocks==100)
			break;
	}
	
	if (nsocks==0)
	{
		fprintf(stderr,"no valid interfaces to listen on found\n");
		return -1;
	}
	
	pthread_mutex_init(&queue_mutex,NULL);

	int asocks = nsocks;
	while (asocks)
	{
		fd_set fds;
		int max=0;
		FD_ZERO(&fds);
		for (i=0; i<nsocks; i++)
		{
			if (socks[i]<0) continue;
			FD_SET(socks[i],&fds);
			if (socks[i]+1>max)
				max=socks[i]+1;
		}
		struct timeval timeout;
		timeout.tv_sec = 1;
		timeout.tv_usec = 0;
		if ((select(max,&fds,NULL,NULL,&timeout)<0)&&(errno!=EINTR))
		{
			fprintf(stderr,"select(): %s\n",strerror(errno));
			for (i=0; i<nsocks; i++)
				close(socks[i]);
			return -1;
		}
		for (i=0; i<nsocks; i++)
		{
			if (socks[i]<0) continue;
			if (FD_ISSET(socks[i],&fds))
			{
				struct sockaddr_storage their_addr;
				socklen_t addr_size = sizeof their_addr;
				
				uint8_t * buffer = memory[memory_pointer];
				ssize_t ret = recvfrom(socks[i],buffer,MAX_BUFFER_SIZE,0,(struct sockaddr *)&their_addr,&addr_size);
				if (ret == -1)
				{
					fprintf(stderr,"recvfrom(): %s\n",strerror(errno));
					close(socks[i]);
					socks[i] = -1;
					asocks--;
				} else {
					if (!parse_data(buffer,(size_t)ret))
						memory_pointer++;
				}
			}
		}
		if (timedout(&last_data_packet_time,1000000))
			stop_audio();
	}
	for (i=0; i<nsocks; i++)
		if (socks[i]>=0)
			close(socks[i]);
	stop_audio();
    return 0;
}
/* *****************************************
 *  C O N S T R U C T O R                  *
 *  Sets up program environment.           *
 ******************************************/
Puzzle::Puzzle()
 {
     scene = new QGraphicsScene;
     scene->setSceneRect(0,0,WIDTH,LENGTH);
     
     setScene(scene);
     setFixedSize(WIDTH,LENGTH);
     
     setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
     setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
     setWindowTitle(tr("8 Puzzle Solver"));
     
     solveButton = new UIButton;
     solveButton->setObjectName(QStringLiteral("solveButton"));
     solveButton->setDefault(true);
     solveButton->setText(QApplication::translate("Dialog", "&Solve", 0));
     solveButton->setGeometry(WIDTH - 200,LENGTH/2 - 50, 100, 50);
     
     solver = new Solve();
     
     playButton = new UIButton;
     playButton->setObjectName(QStringLiteral("playButton"));
     playButton->setDefault(true);
     playButton->setText(QApplication::translate("Dialog", "&Play", 0));
     playButton->setGeometry(WIDTH - 200,LENGTH/2 - 100, 100, 50);
     
     randomizer = new Randomize;
     
     randButton = new UIButton;
     randButton->setObjectName(QStringLiteral("randButton"));
     randButton->setDefault(true);
     randButton->setText(QApplication::translate("Dialog", "&Random", 0));
     randButton->setGeometry(WIDTH - 200,LENGTH/2 - 150, 100, 50);
     
     exitButton = new UIButton;
     exitButton->setObjectName(QStringLiteral("exitButton"));
     exitButton->setDefault(true);
     exitButton->setText(QApplication::translate("Dialog", "E&xit", 0));
     exitButton->setGeometry(WIDTH - 200,LENGTH/2, 100, 50);
     
     scene->addWidget(solveButton);
     scene->addWidget(playButton);
     scene->addWidget(randButton);
     scene->addWidget(exitButton);
     
     
     matrix = new Matrix();
     matrix->setPos(150, 150);
     scene->addItem(matrix);
     
     for (int i = 0; i < matrix->size(); ++i) {
         Cell *cell = (*matrix)[i];
         cell->setPos(cell->x() + 150,
                      cell->y() + 150);
         cell->setFlag(QGraphicsItem::ItemIsFocusable);
         cell->setFocus();
         scene->addItem(cell);
         QObject::connect(cell, SIGNAL(moved()), solveButton, SLOT(enable()));
         QObject::connect(cell, SIGNAL(moved()), playButton, SLOT(disable()));
     }
     
     msg = new Message;
     msg->setPos(10, 10);
     scene->addItem(msg);
     
     playButton->setEnabled(false);
     
     QObject::connect(randButton, SIGNAL(clicked()), randomizer, SLOT(accept()));
     QObject::connect(solveButton, SIGNAL(clicked()), solver, SLOT(accept()));
     QObject::connect(playButton, SIGNAL(clicked()), solver, SLOT(play()));
     QObject::connect(exitButton, SIGNAL(clicked()), solver, SLOT(reject()));
     
     QObject::connect(solveButton, SIGNAL(clicked()), randButton, SLOT(disable()));
     QObject::connect(solveButton, SIGNAL(released()), playButton, SLOT(enable()));
     
     QObject::connect(randButton, SIGNAL(clicked()), playButton, SLOT(disable()));
     QObject::connect(randButton, SIGNAL(clicked()), solveButton, SLOT(enable()));
     
     QObject::connect(playButton, SIGNAL(clicked()), playButton, SLOT(disable()));
     QObject::connect(playButton, SIGNAL(clicked()), solveButton, SLOT(disable()));
     QObject::connect(solver, SIGNAL(timedout()), randButton, SLOT(enable()));
     QObject::connect(solver, SIGNAL(timedout()), solveButton, SLOT(enable()));
     
     show();
 }