Пример #1
0
  //Runs a thread
void FuseTracker::run()
{
  QPair<FuseCppInterface::NotableAction, QString> item;
  QStringList list;
  int fails = 0;

    //My main thread loopto handle data
  Thread_Running = true;
  Thread_Idle = true;
  while ( Thread_Running )
  {
      //Run these commands while there is data
    while ( Data_Read.count() > 0 )
    {
        //Set that the thread isn't idel right now
      Thread_Idle = false;
  
        //Reset my failed read count
      fails = 0;

        //Pull a line from the data list
      if ( (item = Data_Read.takeFirst()).second.isEmpty() )
        continue;

        //Remove any existances of this guy from the hash
      Data_Hash.remove( item.second );

        //Handle the command
      gotCommand( item.first, item.second );
    }

      //Set that the thread isn't doing anything
    Thread_Idle = true;

      //Remove any status stuff that might exists
    removeStatus( SYNC_PUSH );
    removeStatus( SYNC_PULL );
    removeStatus( ADDING_ITEMS );

      //Sleep for a little while waiting for more data
    usleep( THREAD_SLEEP );

      //Check if we've failed too many times
    if ( ++fails >= THREAD_FAILED )
      Thread_Running = false;
  }

    //Ensure that the thread is idle, this is over kill and probably not needed
  Thread_Idle = true;
}
Пример #2
0
int Entity::addHP(int amount) {
	int excess = 0;
	attributes[HP] += amount;
	if (attributes[HP] > attributes[HPMAX]) {
		// hp exceeds maxhp
		excess = attributes[HP] - attributes[HPMAX];
		attributes[HP] = attributes[HPMAX];
	} else if (attributes[HP] < 0) {
		// hp fell below 0
		excess = attributes[HP];
		attributes[HP] = 0;
	}

	// update KO status
	if (attributes[HP] <= 0) {
		setStatus(KO);
	} else {
		removeStatus(KO);
	}

	// update most recent change
	change = amount - excess;
	if (amount >= 0) {
		// hp was added, green text
		textColor = GREEN;
	} else {
		// hp was lost, white text
		textColor = WHITE;
	}

	// start displaying text
	textTicks = SDL_GetTicks();

	// return amount of hp actually added
	return change;
}
Пример #3
0
  //Called when a new command is sent to me
void FuseTracker::gotCommand( FuseCppInterface::NotableAction action, 
                              QString path )
{
  int rm;
  int add;
  QString my_path;
  bool avoid_update = false;

    //If the path is doubling up on the dupfs sync, then kill one
  path = path.replace( RegEx_Dup, "");
  my_path = QString("%1%2").arg( Mounted).arg( path).replace( RegEx_Special, "\\\\\\1");

    //handle an actino
  switch ( action )
  {
      //Delete
    case FuseCppInterface::UNLINK:
    case FuseCppInterface::RMDIR:
      addStatus( ADDING_ITEMS );

        //Run the svn command
      rm = runCmd( QString("/usr/bin/svn remove %1").arg(my_path) );

        //Add this new item
      if ( rm != 0 )
        Updated_Items.remove(my_path);
      break;

      //Add new files
    case FuseCppInterface::SYMLINK:
    case FuseCppInterface::HARDLINK:

    case FuseCppInterface::MKNOD:
    case FuseCppInterface::MKDIR:
    case FuseCppInterface::CREATE:
    case FuseCppInterface::OPEN:
      addStatus( ADDING_ITEMS );

        //Run the svn command
      add = runCmd( QString("/usr/bin/svn add %1").arg(my_path) );

        //Add this new item
      if ( add == 0 )
        Updated_Items[my_path] = OrmLight();
      break;

      //These operations mean we need to update our data at some point
    case FuseCppInterface::CHMOD:
    case FuseCppInterface::CHOWN:
    case FuseCppInterface::TRUNCATE:
    case FuseCppInterface::FTRUNCATE:
    case FuseCppInterface::UTIMES:
    case FuseCppInterface::WRITE:
    case FuseCppInterface::FLUSH:
    case FuseCppInterface::CLOSE:
    case FuseCppInterface::FSYNC:
    case FuseCppInterface::SETXATTR:
    case FuseCppInterface::REMOVEXATTR:
        //Add this new item for update
      Updated_Items[my_path] = OrmLight();
      break;

      //Handle an svn update
    case FuseCppInterface::SVN_COMMIT:
      //qDebug("Running svn commit");
        //Don't allow this action to cause a new commit
      avoid_update = true;

      removeStatus( SYNC_PUSH_REQUIRED );
      addStatus( SYNC_PUSH );

        //If there aren't any updated items, quit out now
      if ( Updated_Items.count() <= 0 )
        return;

        //handle our sync mode
      if ( Op_Mode == OP_SYNC_MODE )
      {
        updateRev();

          //Conduct an update before we commit to avoid conflicts
        QStringList list = updateFiles();
        if ( list.size() > 0 )
          runCmd( QString("/usr/bin/svn update --force --non-interactive --accept mine-full %1").arg(list.join(" ")));

          //Make a list of all the files to be updated
        QString files = QStringList( Updated_Items.keys() ).join(" ");

          //Make it happen
        runCmd( QString("/usr/bin/svn ci -m \\\"Updated %1 Items\\\" --non-interactive --depth immediates %2").arg( Updated_Items.count() ).arg( files ) );

          //Clear out all the now updated items
        QFile::remove( QString("%1/.dupfs_action_log").
                              arg((*Config)["svn_dir"]));
        Updated_Items.clear();
      }
            //Store a local file of the changes to be made at a later time
      else if ( Op_Mode == OP_OFFLINE_MODE )
      {
          //save my list of files requiring a change to the FS
        QString filename = QString("%1/.dupfs_action_log").
                                arg((*Config)["svn_dir"]);
        Updated_Items.saveToFile( filename );
      }

        //Remove my push stats
      removeStatus( SYNC_PUSH );
      break;

      //Check if its a special command
    case FuseCppInterface::SVN_UPDATE:
      //qDebug("Running svn update");
        //Don't allow this action to cause a new commit
      avoid_update = true;

        //Only do this if we aren't offline
      if ( Op_Mode != OP_OFFLINE_MODE )
      {
        removeStatus( SYNC_PULL_REQUIRED );
        addStatus( SYNC_PULL );

          //Issue my update command
        QStringList list = updateFiles();
        runCmd( QString("/usr/bin/svn update --force --non-interactive --accept mine-full %1").arg(list.join(" ")));

        removeStatus( SYNC_PULL );
      }
      break;


      //not sure, just ignore
    case FuseCppInterface::RENAME:
    default:
      return;
      break;
  };

    //If we got here, we know we got a valid command
    //If timer isn't started, start it and then quit out
  if ( !avoid_update && !Timer_Commit_Started )
  {
    addStatus( SYNC_PUSH_REQUIRED );
    Timer_Count = 0;
    Timer_Commit_Started = true;
  }
}