Esempio n. 1
0
void ExitHandler::dispose()
{
	checkLock();
	lock->lock();
	handlerIdx--;
	if(handlerIdx < 0)
		signal(SIGINT, SIG_DFL);
	lock->unlock();
}
Esempio n. 2
0
afs_int32
writeText(struct ubik_trans *ut, int fid, int textType)
{
    struct textBlock *tbPtr;
    afs_int32 textSize, writeSize;
    dbadr dbAddr;
    struct block block;
    afs_int32 code = 0;

    /* check lock is free */
    code = checkLock(textType);
    if (code)
	ERROR(code);

    /* ensure that this block has the correct type */
    code = checkText(ut, textType);
    if (code) {
	LogError(0, "writeText: text type %d damaged\n", textType);
	ERROR(code);
    }

    tbPtr = &db.h.textBlock[textType];
    textSize = ntohl(tbPtr->size);
    dbAddr = ntohl(tbPtr->textAddr);

    if (!dbAddr)
	goto error_exit;	/* Don't save anything if no blocks */

    writeTextHeader(fid, textType);

    while (dbAddr) {
	code = cdbread(ut, text_BLOCK, dbAddr, (char *)&block, sizeof(block));
	if (code)
	    ERROR(code);

	writeSize = MIN(textSize, BLOCK_DATA_SIZE);
	if (!writeSize)
	    break;

	if (canWrite(fid) <= 0)
	    ERROR(BUDB_DUMPFAILED);

	if (write(fid, &block.a[0], writeSize) != writeSize)
	    ERROR(BUDB_IO);

	haveWritten(writeSize);
	textSize -= writeSize;

	dbAddr = ntohl(block.h.next);
    }

  error_exit:
    return (code);
}
Esempio n. 3
0
void ExitHandler::atExit(Runnable *inHandl)
{
	checkLock();
	if(handlerIdx >= MAX_HANDLERS - 1)
	{
		printf("INTERNAL ERROR: ExitHandler overflow\n");
		return;
	}

	lock->lock();
	exitHandlers[++handlerIdx] = inHandl;
	signal(SIGINT, linHandler);
	lock->unlock();
}
Esempio n. 4
0
uint_8 
CmtSpiSdCard::Read( uint32 *dest, uint32 block, uint32 count ) {
  uint_8 res = CMTE_OK;
  checkLock( CMTE_BD_NO_DEV );
  while( count-- ) {
    res = ReadBlock( dest, block );
    if( res != CMTE_OK ) break;
    //Переходим к следующему блоку
    dest += mBlockSize >> 2;
    block++;
    }
  devUnLock();
  return res;
  }
Esempio n. 5
0
/*-------------------------------------------------------------*/
void AzDmat::_read(AzFile *file) 
{
  const char *eyec = "AzDmat::_read"; 
  checkLock(eyec); 
  col_num = file->readInt(); 
  row_num = file->readInt(); 
  if (col_num > 0) {
    a.alloc(&column, col_num, eyec, "column"); 
    int cx; 
    for (cx = 0; cx < col_num; ++cx) {
      column[cx] = AzObjIOTools::read<AzDvect>(file); 
    }
  }
}
Esempio n. 6
0
uint_8 
CmtSpiSdCard::Write( const uint32 *src, uint32 block, uint32 count ) {
  uint_8 res = CMTE_OK;
  checkLock( CMTE_BD_NO_DEV );
  while( count-- ) {
    res = WriteBlock( src, block );
    if( res != CMTE_OK ) break;
    //Переходим к следующему блоку
    src += mBlockSize >> 2;
    block++;
    }
  devUnLock();
  return res;
  }
void torpedoCallback(const std_msgs::UInt8::ConstPtr& msg)
{
  //launch a torpedo
  uint8_t data[] = {'S', 'T', '0', '0', 'E'};
  data[2] = msg->data + '0';

  //mutex lock
  if (checkLock(true) && getLock())
  {
    if (write(fd, data, 5) < 5)
    {
      printf("Failed to write LaunchTorpedo message to sensorBoard\n");
    }
    releaseLock();
  }
}
Esempio n. 8
0
//enter a new room
bool Room::enter(Agent * a)
{
	// cout<<a->getName()<<" is entering a new room"<<endl;

	//check if room is locked
	if (checkLock() && (a->getSize() != 5))
	{	
		bool open = false;
		cout<<"The room is locked,";
		//look for the key in player's things
		int k (0);//index players objects
		while ( k < (a->getThings()).size() )
		{
			if ((a->getThings())[k]->getName() == "key")
				{
					//unlock the room
					cout<<" but you had a key and unlocked the room."<<endl;
					locked(0);

					//enter the room
					open = true;
				}
			k++;
		}

		if (open)
		{
			enter (a);
			return (true);
		}
		else
		{
			cout<<" you need to go find the key."<<endl;
			return(false);
		}
	}
	else
	{
		//add self to occupants and continue
		occupants.insert(a);
				
		return (true);
	}


}
Esempio n. 9
0
/*-------------------------------------------------------------*/
void AzDmat::initialize(const AzReadOnlyMatrix *inp)
{
  const char *eyec = "AzDmat::initialize(inp)"; 
  checkLock(eyec); 

  if (inp == NULL) {
    throw new AzException(eyec, "null input"); 
  }
  col_num = inp->colNum(); 
  row_num = inp->rowNum(); 

  a.alloc(&column, col_num, eyec, "column"); 
  int cx; 
  for (cx = 0; cx < col_num; ++cx) {
    column[cx] = new AzDvect(inp->col(cx)); 
  }
  dummy_zero.reform(row_num); 
}
Esempio n. 10
0
/*-------------------------------------------------------------*/
void AzDmat::resize(int new_col_num) 
{
  const char *eyec = "AzDmat::resize"; 
  checkLock(eyec); 
  if (new_col_num == col_num) {
    return; 
  } 
  if (new_col_num < 0) {
    throw new AzException(eyec, "new #columns must be non-negative"); 
  }

  int old_col_num = col_num; 
  a.realloc(&column, new_col_num, eyec, "column"); 
  int cx; 
  for (cx = old_col_num; cx < new_col_num; ++cx) {
    column[cx] = new AzDvect(row_num); 
  }
  col_num = new_col_num; 
}
Esempio n. 11
0
/*-------------------------------------------------------------*/
void AzDmat::_set(const AzDmat *m_inp)
{
  const char *eyec = "AzDmat::set(Dmat)";   
  checkLock(eyec); 
  if (row_num != m_inp->row_num || col_num != m_inp->col_num) {
    _release(); 
    if (m_inp->col_num < 0 || m_inp->row_num < 0) {
      throw new AzException(eyec, "# columns or row must be non-negative"); 
    }
    col_num = m_inp->col_num; 
    row_num = m_inp->row_num; 
    a.alloc(&column, col_num, eyec, "column"); 
    dummy_zero.reform(row_num);   
  }
  int cx; 
  for (cx = 0; cx < col_num; ++cx) {
    delete column[cx]; 
    column[cx] = new AzDvect(m_inp->col(cx)); 
  }
}
Esempio n. 12
0
void dropperCallback(const std_msgs::UInt8MultiArray::ConstPtr& msg)
{
  //set dropper
  if (msg->data.size() >= 2)
  {
    uint8_t data[] = {'S', 'D', '0', '0', 'E'};
    data[2] = msg->data[0] + '0';
    data[3] = msg->data[1] + '0';

    //mutex lock
    if (checkLock(true) && getLock())
    {
      if (write(fd, data, 5) < 5)
      {
        printf("Failed to write LaunchTorpedo message to sensorBoard\n");
      }
      releaseLock();
    }
  }
}
Esempio n. 13
0
/*-------------------------------------------------------------*/
void AzDmat::_reform(int new_row_num, int new_col_num, 
                     bool do_zeroOut) 
{
  const char *eyec = "AzDmat::_reform";  
  checkLock(eyec); 
  if (row_num == new_row_num && col_num == new_col_num) {
    if (do_zeroOut) zeroOut(); 
    return; 
  }
 
  _release(); 
  if (new_col_num < 0 || new_row_num < 0) {
    throw new AzException(eyec, "# columns or row must be non-negative"); 
  }
  col_num = new_col_num; 
  row_num = new_row_num; 
  a.alloc(&column, col_num, eyec, "column"); 
  dummy_zero.reform(row_num);   
  
  int cx; 
  for (cx = 0; cx < col_num; ++cx) {
    column[cx] = new AzDvect(this->row_num); 
  }
}
Esempio n. 14
0
int main(){
	int _l[LC_LEN]; char c[2];

	initLock(_l);

	printf(	"\nSecurity Lock v1.0\n"
			"-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n"
			"Make all the lock values %i\n\n"
			"Key: 1-8 turns locks\n"
			"     r Resets the locks\n"
			"     q exits the program\n\n",
			LC_TARG);

	while(!checkLock(_l)) {
		printLock(_l);
		
		do {
			printf("Move < 1-8, r, q >: "); fflush(NULL);
			read(STDIN_FILENO, c, 2);
		} while (!validateInput(c[0]));

		if(c[0] == 'r' || c[0] == 'R') {
			initLock(_l);
			continue;
		}

		moveLock(_l, c[0]-0x30);
	}

	printLock(_l);
	printf("All locks are open!\n");
	printf("Your password is d%kj1//..");


	return EXIT_SUCCESS;
}
Esempio n. 15
0
void TableItem::onHideTriggered()
{
    if (checkLock()) return; //Can't hide locked items
    QSound::play("Sound/itemMenu.wav");
    emit requestHideDialog(this);
}
Esempio n. 16
0
void TableItem::onRotateTriggered()
{
    if (checkLock()) return; //Can't rotate locked items
    QSound::play("Sound/itemMenu.wav");
    emit requestRotation(this, rotation + 90);
}
Esempio n. 17
0
void TableItem::onShuffleTriggered()
{
    if (checkLock()) return; //Can't shuffle locked items
    emit requestShuffle(this);
}
Esempio n. 18
0
 void _release() {
   checkLock("_release"); 
   a.free(&column); col_num = 0; 
   row_num = 0; 
   dummy_zero.reform(0); 
 }
Esempio n. 19
0
void TableItem::onRemoveTriggered()
{
    if (checkLock()) return; //Can't remove locked items
    QSound::play("Sound/itemRemove.wav");
    emit requestRemoval(this);
}
Esempio n. 20
0
int main(int argc, char **argv)
{
  std::string file = "/dev/controller_sensor";
  UInt32 baudrate = 115200;
  SerialInterface usb("/dev/controller_sensor", baudrate);


  if (argc > 1)
  {
    file = argv[1];
    printf("%s info: Opening %s\n", argv[0], file.c_str());
  }

  if (pthread_mutex_init(&myMutex, NULL) != 0)
  {
    printf("Failed to get mutex: %s\n", strerror(errno));
    exit(-1);
  }

  name = argv[0];

  float temp[3] = {0.0};
  float pressure = 0.0;
  int motorKilled = 0, waterDetected, dropperLeft= 0, dropperRight= 0;
  float curVolt[2] = {0.0};
  int numVariables = 10;

  float ttemp[3] = {0.0};
  float tpressure = 0.0;
  int tmotorKilled = 0, twaterDetected= 0, tdropperLeft= 0, tdropperRight= 0;
  float tcurVolt[2] = {0.0};

  timer tempTimer, pressureTimer, motorTimer, currentTimer, waterTimer, dropperTimer;

  tempTimer.start(1, 0);
  pressureTimer.start(1, 0);
  motorTimer.start(1, 0);
  currentTimer.start(1, 0);
  waterTimer.start(1, 0);
  dropperTimer.start(1, 0);

  ros::init(argc, argv, "SubSensorController");
  ros::NodeHandle nh;

  ros::Publisher temperatuerPub = nh.advertise<std_msgs::Float32MultiArray>("Controller_Box_Temp", 1000);
  ros::Publisher pressurePub = nh.advertise<std_msgs::Float32>("Pressure_Data", 1000);
  ros::Publisher MotorPub = nh.advertise<std_msgs::UInt8>("Motor_State", 1000);
  ros::Publisher computerPub = nh.advertise<std_msgs::Float32MultiArray>("Computer_Cur_Volt", 1000);
  ros::Publisher waterPub = nh.advertise<std_msgs::UInt8>("Water_Detected", 1000);
  ros::Publisher dropperPub = nh.advertise<std_msgs::UInt8MultiArray>("Dropper_States", 1000);

  ros::Subscriber torpedoSub = nh.subscribe("Torpedo_Launch", 1000, torpedoCallback);
  ros::Subscriber dropperSub = nh.subscribe("Dropper_Activate", 1000, dropperCallback);

  ros::Rate loop_rate(1);

  while (ros::ok())
  {
    if (controllerState == STATE_WAITING_ON_FD)
    {
      if (checkLock() && getLock())
      {
        controllerState = STATE_WORKING;
        sleep(5);
        
        //fd = open(file.c_str(), O_RDWR | O_NOCTTY | O_NDELAY);
        // if (fd == -1)
        // {
        //   printf("%s Error: System failed to open %s: %s(%d)\n", argv[0], file.c_str(), strerror(errno), errno);
        //   sleep(1);
        // }
        // else
        // {
        //   if (setupTTY(fd) == 0) 
        //   {
        //     controllerState = STATE_WORKING;

        //     sleep(5); //wait for sensor to boot and stabilize
        //   }
        //   else
        //     close(fd);
        // }
        releaseLock();
      }
    }
    else if (controllerState == STATE_WORKING)
    {
      std::string line = "";
      if (checkLock() && getLock())
      {
        UInt8 aBuf[baudrate];
        usb.recv(aBuf,baudrate);
        std::string temp ((const char*)aBuf,baudrate);
        line = temp;
        //line = getTTYLine(fd);
        //printf("got line %s\n", line.c_str());
        releaseLock();
      }

      if (line != "")
      {
        //printf("line: %s\n", line.c_str());
        if (line.length() > 0 && goodLine(line, numVariables))
        {
          int scanfVal;

          if ((scanfVal = sscanf(line.c_str(), "S%f,%f,%f,%d,%f,%f,%f,%d,%d,%dE", &ttemp[0], &ttemp[1], &ttemp[2], &tmotorKilled,
              &tcurVolt[0], &tcurVolt[1], &tpressure, &twaterDetected, &tdropperLeft, &tdropperRight)) == numVariables)
          {
            if ((temp[0] != ttemp[0]) || (temp[1] != ttemp[1]) || (temp[2] != ttemp[2]) || tempTimer.isTimeout())
            {
              //temperature
              std_msgs::Float32MultiArray tempMsg;
              temp[0] = ttemp[0];
              temp[1] = ttemp[1];
              temp[2] = ttemp[2];
              tempMsg.data.push_back(temp[0]);
              tempMsg.data.push_back(temp[1]);
              tempMsg.data.push_back(temp[2]);
              temperatuerPub.publish(tempMsg);
              tempTimer.start(1, 0);
              ros::spinOnce();
            }

            if (motorKilled != tmotorKilled || motorTimer.isTimeout())
            {
              //motorkilled
              std_msgs::UInt8 motorMsg;
              motorKilled = tmotorKilled;
              motorMsg.data = motorKilled;
              MotorPub.publish(motorMsg);
              motorTimer.start(1, 0);
              ros::spinOnce();
            }

            if ((curVolt[0] != tcurVolt[0]) || (curVolt[1] != tcurVolt[1] || currentTimer.isTimeout()))
            {
              //curvolt
              std_msgs::Float32MultiArray curMsg;
              curVolt[0] = tcurVolt[0];
              curVolt[1] = tcurVolt[1];
              curMsg.data.push_back(curVolt[0]);
              curMsg.data.push_back(curVolt[1]);
              computerPub.publish(curMsg);
              currentTimer.start(1, 0);
              ros::spinOnce();
            }

            if (pressure != tpressure || pressureTimer.isTimeout())
            {
              //depth
              std_msgs::Float32 pressureMsg;
              pressure = tpressure;
              pressureMsg.data = pressure;
              pressurePub.publish(pressureMsg);
              pressureTimer.start(1, 0);
              ros::spinOnce();
            }

            if (waterDetected != twaterDetected || waterTimer.isTimeout())
            {
              //water detected
              std_msgs::UInt8 waterMsg;
              waterDetected = twaterDetected;
              waterMsg.data = waterDetected;
              waterPub.publish(waterMsg);
              waterTimer.start(1, 0);
              ros::spinOnce();
            }

            if (tdropperLeft != dropperLeft || tdropperRight != dropperRight || dropperTimer.isTimeout())
            {
              //water detected
              std_msgs::UInt8MultiArray dropperMsg;
              dropperLeft = tdropperLeft;
              dropperRight = tdropperRight;
              dropperMsg.data.push_back(dropperLeft);
              dropperMsg.data.push_back(dropperRight);
              dropperPub.publish(dropperMsg);
              dropperTimer.start(1, 0);
              ros::spinOnce();
            }

            if (VERBOSE)
              ROS_INFO("published");
          }
          else
          {
            printf("%s info: Throwing away %d:\"%s\"\n", argv[0], scanfVal, line.c_str());
            fflush(stdout);
          }
        }
      }
    }
  }

  pthread_mutex_destroy(&myMutex);
  close(fd);
  return 0;
}
Esempio n. 21
0
bool checkLock(bool loop)
{
  while (!checkLock());
  return true;
}