PerformFrontflip(Jumper* jumper) : 
     Instructor::Notification( 
         jumper, 
         wstrformat(
             Gameplay::iLanguage->getUnicodeString(679),
             Gameplay::iGameplay->getActionChannel( ::iaForward )->getInputActionHint(),
             Gameplay::iGameplay->getActionChannel( ::iaPhase )->getInputActionHint()                    
         ).c_str(),
         1 
     )
 {
     setLock( true );
     jumper->enablePhase( true );
 }
Exemplo n.º 2
0
bool LLPumpIO::sleepChain(F64 seconds)
{
	// Much like the call to setLock(), this should only be called
	// from one chain during processing, so there is no need to
	// acquire a mutex.
	if(seconds <= 0.0) return false;
	S32 key = setLock();
	if(!key) return false;
	LLRunner::run_handle_t handle = mRunner.addRunnable(
		LLChainSleeper::build(this, key),
		LLRunner::RUN_IN,
		seconds);
	if(0 == handle) return false;
	return true;
}
Exemplo n.º 3
0
        virtual void onUpdateOrder(float dt)
        {
            Notification::onUpdateOrder( dt );

            // retrieve suit info
            database::Suit* suit = database::Suit::getRecord( getJumper()->getVirtues()->equipment.suit.id );
            if( !suit->wingsuit )
            {
                setLock( false );
            }
            else
            {
                setMessage( Gameplay::iLanguage->getUnicodeString(643) );
            }
        }
        virtual void onUpdateRoutine(float dt)
        {
            Script::Message::onUpdateRoutine( dt );

            // retrieve suit info
            database::Suit* suit = database::Suit::getRecord( getJumper()->getVirtues()->equipment.suit.id );
            if( !suit->wingsuit )
            {
                setLock( false );
                getJumper()->enablePhase( true );
            }
            else
            {
                setMessage( Gameplay::iLanguage->getUnicodeString(643) );
            }
        }
Exemplo n.º 5
0
void GameBox::afterAllMoveDone()
{
    if(check())
        return;
    if(haveMore())
        setLock(false);
    else
    {
        for (int y=0; y< kBoxHeight; y++) {
            for (int x=0; x< kBoxWidth; x++) {
                GameTile* tile = objectAtXandY(x, y);
                tile->value = 0;
            }
        }
        check();
    }
    
}
Exemplo n.º 6
0
//====================================
// setPassword
//------------------------------------
void SaXManipulateVNC::setPassword (const QString& pwd) {
	// .../
	//! restricted access can be set up by creating a
	//! password file. This file is set within the rfbauth
	//! option. This method is used to create the password
	//! file by using the vncpasswd program
	// ----
	if (! setLock()) {
		return;
	}
	QProcess* proc = new QProcess ();
	proc -> addArgument ( SAX_CREATE_VNC_PWD );
	proc -> addArgument ( pwd );
	if ( ! proc -> start() ) {
		excProcessFailed();
		qError (errorString(),EXC_PROCESSFAILED);
		unsetLock();
		return;
	}
	while (proc->isRunning()) {
		usleep (1000);
	}
	unsetLock();
}
static jboolean com_opennfc_extension_engine_VirtualTagAdapter_setVirtualTagMode(JNIEnv * e, jobject o, jboolean enable)
{
	W_ERROR error;
	bool_t vReaderLock = W_FALSE;
	bool_t vCardLock = W_FALSE;
	if (enable == JNI_TRUE)
	{
		WNFCControllerGetRFLock(W_NFCC_STORAGE_VOLATILE, &vReaderLock, &vCardLock);
		setLock (vReaderLock, vCardLock);
		error = WNFCControllerSetRFLockSync(W_NFCC_STORAGE_VOLATILE, W_TRUE, W_FALSE);
		error = WNFCControllerSwitchStandbyMode(W_FALSE);
	}
	else
	{
		vReaderLock = getReaderLock();
		vCardLock = getCardLock();
		error = WNFCControllerSetRFLockSync(W_NFCC_STORAGE_VOLATILE, vReaderLock, vCardLock);
		error = WNFCControllerSwitchStandbyMode(W_TRUE);
	}
	if (error == W_SUCCESS)
		return JNI_TRUE;

	return JNI_FALSE;
}
PROCESS_THREAD(doorAutoOpeningProcess, ev, data)
{
	static struct etimer initialDelay;
	static struct etimer blinkingTimer;
	static int blinkings;
	static clock_time_t remainingDelay;
	
	PROCESS_BEGIN();
		
		printf("Door auto opening: started\n");

		remainingDelay = DOOR_AUTO_OPENING_DELAY * CLOCK_SECOND;

		while(1)
		{
			printf("Door auto opening: waiting initial delay\n");
			etimer_set(&initialDelay, remainingDelay);
			PROCESS_WAIT_EVENT();
			if(ev == PROCESS_EVENT_TIMER && etimer_expired(&initialDelay))
				break;
			else if( ev == alarm_toggled_event)
			{
				printf("Door auto opening: delay interrupted by alarm\n");
				remainingDelay = etimer_expiration_time(&initialDelay) - clock_time();
				etimer_stop(&initialDelay);
				PROCESS_WAIT_EVENT_UNTIL(ev == alarm_toggled_event);
				printf("Door auto opening: alarm stopped, resuming delay\n");
			}
		}
		
		printf("Door auto opening: door opened\n");
		setLock(UNLOCKED);
		
		printf("Door auto opening: blinking started\n");
		
		blinkings = 0;
		
		leds_on(LEDS_BLUE);
		
		while(blinkings < AUTO_OPENING_BLINKINGS - 1)
		{
			etimer_set(&blinkingTimer, (AUTO_OPENING_LED_PERIOD / 2) * CLOCK_SECOND);
			PROCESS_WAIT_EVENT();
			if(ev == PROCESS_EVENT_TIMER && etimer_expired(&blinkingTimer))
			{
				printf("Door auto opening: blinking\n");
				leds_toggle(LEDS_BLUE);
				etimer_reset(&blinkingTimer);
				blinkings++;
			}
			else if(ev == alarm_toggled_event)
			{
				printf("Door auto opening: blinking interrupted by alarm\n");
				etimer_stop(&blinkingTimer);
				PROCESS_WAIT_EVENT_UNTIL(ev == alarm_toggled_event);
				printf("Door auto opening: alarm stopped, resuming blinking\n");
			}
		}
		
		printf("Door auto opening: blinking stopped\n");
		printf("Gate auto opening: door locked\n");
		setLock(LOCKED);
	PROCESS_END();
}
 Disqualification(Jumper* jumper) : Message( jumper, L"", 1.0f ) 
 {
     jumper->enablePhase( false );
     setLock( true );
 }
Exemplo n.º 10
0
 Disqualification(Jumper* jumper) : Notification( jumper, L"", 1.0f ) 
 {
     setLock( true );
 }
void BMDVideohubClient::forceUnlock(uint8_t forceIndex) {
	setLock(forceIndex, 'F');
}
Exemplo n.º 12
0
void udbase_init()
{
    udb = (udbase*)malloc(sizeof(udbase));
    udb->user_n = 0;
    udb->first = NULL;
    setLock(udb);
    user* cur = NULL;
    int user_num = 0;
    impFriend_t status;
    char buf[IMP_NAME_MAXLEN + 20];

    /* scan all usernames and friends */
    if(fgets(buf, IMP_NAME_MAXLEN + 20, filer)){
        char* k = strchr(buf, ' ');
        *k = '\0';
        user_num= atoi(buf);
    }
    char* end;
    cur = NULL;
    while (fgets(buf, IMP_NAME_MAXLEN + 20, filer)) {
        switch(buf[0]) {
        case '.':
            cur = NULL;
            break;
        case '-':
            if (strstr(buf, "requested")) {
                status = IMP_FRIEND_REQUESTED;
            } else if (strstr(buf, "toanswer")) {
                status = IMP_FRIEND_TOANSWER;
            } else {
                status = IMP_FRIEND_YES;
            }
            end = buf+2;
            while (*end != ' ' && *end != '\n') {
                end++;
            }
            *end = '\0';
            udbase_addFriend(cur, buf + 2, status);
            break;
        default:
            buf[strlen(buf) - 1] = '\0';
            cur = udbase_addUser(buf);
        }
    }
    if (user_num != udb->user_n) {
        perror("user number not correct");
        exit(1);
    }
    cur = udb->first;
    friends* cur_f;
    while (cur) {
        cur_f = cur->friends;
        while (cur_f) {
            if (!(cur_f->user)) {
                cur_f->user = udbase_findUser(cur_f->name);
            }
            cur_f = cur_f->next;
        }
        cur = cur->next;
    }
}
Exemplo n.º 13
0
 main(int argc, char **argv)
{
  int fd;
  char buffer[buffer_size];

  /* Open our file for read/write access.  Note that normally this
     file will already be open for r/w access by locker. */

  if((fd = open(file_name, O_RDWR)) < 0)
  {
    perror("open");
    exit(EXIT_FAILURE);
  }

  /* Acquire a read lock. */

  if(setLock(fd,F_RDLCK) == 0)
  {
    printf("Read lock has been acquired, as expected.\n\nHit ENTER... ");
    getchar();
  }
  else
  {
    printf("Unable to set read lock.  Program is terminating.\n");
    close(fd);
    exit(EXIT_FAILURE);
  }

  /* Release the shared lock. */

  if(setLock(fd,F_UNLCK) == 0)
    printf("Read lock has been released\n\n");
  else
  {
    printf("Unable to release read lock.  Program is terminating.\n");
    close(fd);
    exit(EXIT_FAILURE);
  }

  /* Try to acquire a write lock. */

  if(setLock(fd,F_WRLCK) == 0)
  {
    printf("Acquired a write lock--this shouldn't happen! Program is terminating.\n");
    setLock(fd,F_UNLCK);
    close(fd);
    exit(EXIT_FAILURE);
  }

  printf("Failed to acquire the write lock, as expected.\n\n");
  printf("Go hit ENTER in the locker terminal to let it switch to\n");
  printf("a write lock, then come back here and hit ENTER.\n");
  getchar();

  /* Try to acquire a read lock. */

  if(setLock(fd,F_RDLCK) == 0)
  {
    printf("Acquired a read lock--this shouldn't happen! Program is terminating.\n");
    setLock(fd,F_UNLCK);
    close(fd);
    exit(EXIT_FAILURE);
  }

  printf("Failed to acquire the write lock, as expected.\n\n");
  printf("Hit ENTER and we'll try to read the file.  This call should\n");
  printf("block and hang this program until locker releases its lock\n");
  printf("on the file.  Once this program hangs, go hit ENTER in the\n");
  printf("locker terminal.\n");
  getchar();

  printf("Attempting to read file... \n\n");
  if(read(fd,buffer,buffer_size) == buffer_size)
  {
    printf("Successfully read from the file.\n");
    buffer[buffer_size - 1] = '\0';
    printf("Data read: \"%s\"\n",buffer);
  }
  else
    printf("Could not read from the file.\n");

  close(fd);

  /* Indicate normal termination via the 
     EXIT_SUCCESS constant from stdlib.h */

  return EXIT_SUCCESS;
}
int SerialPortMacOS::openLink()
{
    struct termios tty;
    //memset(&tty, 0, sizeof(tty));

    // Make sure no tty connection is already running (in that case, openLink() will do a reconnection)
    closeLink();

    // Check if another instance is using this port
    if (isLocked() == true)
    {
        TRACE_ERROR(SERIAL, "Cannot connect to serial port: '%s': interface is locked!\n", ttyDevicePath.c_str());
        goto OPEN_LINK_LOCKED;
    }

    // Open tty device
    // O_RDWR: Request opening the file read/write
    // O_NOCTTY: If the named file is a terminal device, don't make it the controlling terminal for the process
    // O_EXLOCK: Acquire an exclusive lock on the file.

    ttyDeviceFileDescriptor = open(ttyDevicePath.c_str(), O_RDWR | O_NOCTTY);
    if (ttyDeviceFileDescriptor < 0)
    {
        TRACE_ERROR(SERIAL, "Unable to open device on serial port: '%s', %s(%d)\n",
                    ttyDevicePath.c_str(), strerror(errno), errno);
        goto OPEN_LINK_ERROR;
    }

    // Lock device
    setLock();

    // Get the current options and save them so we can restore the default settings later.
    if (tcgetattr(ttyDeviceFileDescriptor, &tty) == -1)
    {
        TRACE_ERROR(SERIAL, "Error getting tty attributes %s - %s(%d).\n",
                    ttyDevicePath.c_str(), strerror(errno), errno);
        goto OPEN_LINK_ERROR;
    }

    // ttyDeviceBaudRateFlag: flag from termios.h
    // CS8: setting the character size
    // CLOCAL: ?
    // CREAD: input can be read from the terminal
    // IGNPAR: ignore bit parity

    // Set newtio attributes
    tty.c_cflag     = CS8 | CLOCAL | CREAD;
    tty.c_iflag     = IGNPAR;
    tty.c_oflag     = 0;
    tty.c_lflag     = 0;
    tty.c_cc[VTIME] = 0;
    tty.c_cc[VMIN]  = 0;

    sleep(1); // FIXME why is this necessary for our serial port to work?

    tcflush(ttyDeviceFileDescriptor, TCIFLUSH);
    // Cause the new options to take effect immediately.
    if (tcsetattr(ttyDeviceFileDescriptor, TCSANOW, &tty) == -1)
    {
       TRACE_ERROR(SERIAL, "Error setting tty attributes %s - %s(%d).\n",
                  ttyDevicePath.c_str(), strerror(errno), errno);
       goto OPEN_LINK_ERROR;
    }

    TRACE_1(SERIAL, "Current input baud rate is %d\n", (int)cfgetispeed(&tty));
    TRACE_1(SERIAL, "Current output baud rate is %d\n", (int)cfgetospeed(&tty));

    sleep(1); // FIXME why is this necessary for our serial port to work?

    if (ttyDeviceBaudRate < 1)
    {
        TRACE_ERROR(SERIAL, "Unable to set baud rate to '%i'bps: invalid value\n", ttyDeviceBaudRate);
        goto OPEN_LINK_ERROR;
    }

    // Set custom serial infos?
    {
        cfsetspeed(&tty, ttyDeviceBaudRateFlag);

        // The IOSSIOSPEED ioctl can be used to set arbitrary baud rates
        // other than those specified by POSIX. The driver for the underlying serial hardware
        // ultimately determines which baud rates can be used. This ioctl sets both the input
        // and output speed.

        if (ioctl(ttyDeviceFileDescriptor, IOSSIOSPEED, &(ttyDeviceBaudRate)) == -1)
        {
            TRACE_ERROR(SERIAL, "Error calling ioctl(..., IOSSIOSPEED, ...) %s - %s(%d).\n",
                        ttyDevicePath.c_str(), strerror(errno), errno);
        }

        // Print the new input and output baud rates. Note that the IOSSIOSPEED ioctl interacts with the serial driver
        // directly bypassing the termios struct. This means that the following two calls will not be able to read
        // the current baud rate if the IOSSIOSPEED ioctl was used but will instead return the speed set by the last call
        // to cfsetspeed.

        TRACE_1(SERIAL, "Input baud rate changed to %d\n", (int) cfgetispeed(&tty));
        TRACE_1(SERIAL, "Output baud rate changed to %d\n", (int) cfgetospeed(&tty));

        unsigned long mics = 1UL;
        if (ioctl(ttyDeviceFileDescriptor, IOSSDATALAT, &mics) == -1)
        {
            // set latency to 1 microsecond
            TRACE_ERROR(SERIAL, "Error setting read latency %s - %s(%d).\n",
                        ttyDevicePath.c_str(), strerror(errno), errno);
            goto OPEN_LINK_ERROR;
        }
    }
/*
    // Set custom serial infos?
    if (ttyCustomSpeed == true || ttyLowLatency == true)
    {
        struct serial_struct serinfo;
        memset(&serinfo, 0, sizeof(serinfo));

        // Get current serial_struct values
        if (ioctl(ttyDeviceFileDescriptor, TIOCGSERIAL, &serinfo) < 0)
        {
            TRACE_ERROR(SERIAL, "Cannot get serial infos structure from serial port: '%s'\n", ttyDevicePath.c_str());
            goto OPEN_LINK_ERROR;
        }

        if (ttyCustomSpeed == true)
        {
            serinfo.flags &= ~ASYNC_SPD_MASK;
            serinfo.flags |= ASYNC_SPD_CUST;
            serinfo.custom_divisor = serinfo.baud_base / ttyDeviceBaudRate;
            if (serinfo.custom_divisor < 1)
            {
                serinfo.custom_divisor = 1;
            }
        }

        if (ttyLowLatency == true)
        {
            serinfo.flags |= ASYNC_LOW_LATENCY;
        }

        // Set serial_struct
        if (ioctl(ttyDeviceFileDescriptor, TIOCSSERIAL, &serinfo) < 0)
        {
            TRACE_ERROR(SERIAL, "Cannot set serial infos structure with custom baud divisor (%s) to serial port: '%s'\n", ttyDeviceBaudRate, ttyDevicePath.c_str());
            goto OPEN_LINK_ERROR;
        }
    }
*/
    return 1;

OPEN_LINK_ERROR:
    closeLink();
    return 0;

OPEN_LINK_LOCKED:
    closeLink();
    return -1;
}
int SerialPortWindows::openLink()
{
    DCB Dcb;
    COMMTIMEOUTS Timeouts;
    DWORD dwError;

    // Make sure no tty connection is already running
    closeLink();

    // Check if another instance is using this port
    if (isLocked() == true)
    {
        TRACE_ERROR(SERIAL, "Cannot connect to serial port: '%s': interface is locked!\n", ttyDevicePath.c_str());
        goto OPEN_LINK_LOCKED;
    }

    // Open tty device
#ifdef UNICODE
    ttyDeviceFileDescriptor = CreateFileW(stringToLPCWSTR(ttyDeviceName), GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
#else
    ttyDeviceFileDescriptor = CreateFileA(ttyDeviceName.c_str(), GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
#endif
    if (ttyDeviceFileDescriptor == INVALID_HANDLE_VALUE)
    {
        TRACE_ERROR(SERIAL, "Unable to open device: '%s' error: '%i'\n", ttyDeviceName.c_str(), GetLastError());
        goto OPEN_LINK_ERROR;
    }

    // Lock device
    setLock();

    // Setting communication property
    Dcb.DCBlength = sizeof(DCB);
    if (GetCommState(ttyDeviceFileDescriptor, &Dcb) == FALSE)
    {
        TRACE_ERROR(SERIAL, "Unable to get communication state on '%s'\n", ttyDevicePath.c_str());
        goto OPEN_LINK_ERROR;
    }

    // Set baudrate
    Dcb.BaudRate            = (DWORD)ttyDeviceBaudRate;
    Dcb.ByteSize            = 8;                    // Data bit = 8bit
    Dcb.Parity              = NOPARITY;             // No parity
    Dcb.StopBits            = ONESTOPBIT;           // Stop bit = 1
    Dcb.fParity             = NOPARITY;             // No Parity check
    Dcb.fBinary             = 1;                    // Binary mode
    Dcb.fNull               = 0;                    // Get Null byte
    Dcb.fAbortOnError       = 1;
    Dcb.fErrorChar          = 0;
    // Not using XOn/XOff
    Dcb.fOutX               = 0;
    Dcb.fInX                = 0;
    // Not using H/W flow control
    Dcb.fDtrControl         = DTR_CONTROL_DISABLE;
    Dcb.fRtsControl         = RTS_CONTROL_DISABLE;
    Dcb.fDsrSensitivity     = 0;
    Dcb.fOutxDsrFlow        = 0;
    Dcb.fOutxCtsFlow        = 0;

    if (SetCommState(ttyDeviceFileDescriptor, &Dcb) == FALSE)
    {
        TRACE_ERROR(SERIAL, "Unable to set communication state on '%s'\n", ttyDevicePath.c_str());
        goto OPEN_LINK_ERROR;
    }
    if (SetCommMask(ttyDeviceFileDescriptor, 0) == FALSE) // Not using Comm event
    {
        TRACE_ERROR(SERIAL, "Unable to set communication mask on '%s'\n", ttyDevicePath.c_str());
        goto OPEN_LINK_ERROR;
    }
    if (SetupComm(ttyDeviceFileDescriptor, 8192, 8192) == FALSE) // Buffer size (Rx,Tx)
    {
        TRACE_ERROR(SERIAL, "Unable to setup communication on '%s'\n", ttyDevicePath.c_str());
        goto OPEN_LINK_ERROR;
    }
    if (PurgeComm(ttyDeviceFileDescriptor, PURGE_TXABORT|PURGE_TXCLEAR|PURGE_RXABORT|PURGE_RXCLEAR) == FALSE) // Clear buffer
    {
        TRACE_ERROR(SERIAL, "Unable to purge communication on '%s'\n", ttyDevicePath.c_str());
        goto OPEN_LINK_ERROR;
    }
    if (ClearCommError(ttyDeviceFileDescriptor, &dwError, NULL) == FALSE)
    {
        TRACE_ERROR(SERIAL, "Unable to clear communication errors on '%s'\n", ttyDevicePath.c_str());
        goto OPEN_LINK_ERROR;
    }
    if (GetCommTimeouts(ttyDeviceFileDescriptor, &Timeouts) == FALSE)
    {
        TRACE_ERROR(SERIAL, "Unable to get communication timeouts on '%s'\n", ttyDevicePath.c_str());
        goto OPEN_LINK_ERROR;
    }

    // Timeout (Not using timeout)
    // Immediatly return
    Timeouts.ReadIntervalTimeout         = 0;
    Timeouts.ReadTotalTimeoutMultiplier  = 0;
    Timeouts.ReadTotalTimeoutConstant    = 1; // Must not be zero
    Timeouts.WriteTotalTimeoutMultiplier = 0;
    Timeouts.WriteTotalTimeoutConstant   = 0;

    if (SetCommTimeouts(ttyDeviceFileDescriptor, &Timeouts) == FALSE)
    {
        TRACE_ERROR(SERIAL, "Unable to set communication timeouts on '%s'\n", ttyDevicePath.c_str());
        goto OPEN_LINK_ERROR;
    }

    return 1;

OPEN_LINK_ERROR:
    closeLink();
    return 0;

OPEN_LINK_LOCKED:
    closeLink();
    return -1;
}