예제 #1
0
/** @brief Init
  *
  * @todo: document this function
  */
bool Customizations::Init(const wxString& archive_name )
{
	//!TODO require blocking usync init if it's not loaded
	m_modname = archive_name;
    bool ret = m_customs.loadOptions( OptionsWrapper::ModCustomizations, m_modname );
    if ( ret ) {
#ifdef SL_QT_MODE
		m_shortname = ToQString( shortname );
#endif
		wxBitmap icon_bmp( wxNullBitmap );
		if ( GetBitmap( _T("icon"), icon_bmp ) )
		{
			wxIcon tmp;
			tmp.CopyFromBitmap( icon_bmp );
			m_app_icons = wxIconBundle( tmp );//replacing current
			int i = 1;
			while( GetBitmap( wxString::Format(_T("icon%d"), i ), icon_bmp ) )
			{
				tmp.CopyFromBitmap( icon_bmp );
				m_app_icons.AddIcon( tmp );
			}
		}
        m_help_url = m_customs.getSingleValue( _T("help_url") );
    }
	m_active =  ret;
    return ret;
}
예제 #2
0
QString Customizations::DataBasePath()
{
	static bool cached = false;
	if ( cached )
		return dataBasePath_;

	QList<QString> checked_paths;
	QString sub_path( "lobby/SpringLobby/customizations/" );
	sub_path.append( m_shortname );
	for ( int i = 0; i < susynclib().GetSpringDataDirCount(); ++i ) {
		QDir data ( ToQString( susynclib().GetSpringDataDirByIndex(i) ) );
		checked_paths.append( data.absolutePath().append("/").append( sub_path ) );
		if ( data.cd( sub_path ) ) {
			dataBasePath_ = data.absolutePath();
			break;
		}
	}
	if( dataBasePath_ != QString() )
		return dataBasePath_ ;

	checked_paths.prepend( QString("Couldn't find customization data in any of these directories:\n ") );
	throw DataException( checked_paths );

	return QString();
}
bool
khResourceManager::MakeFixedVolumeReservations(khTask *task,
                                               Reservations &reservations)
{
  const TaskDef& taskdef(task->taskdef());
  const TaskRequirements& req(task->GetRequirementsRef());

  // Try to make all the output reservations for the outputs with fixed
  // volumes
  for (uint i = 0; i < taskdef.outputs.size(); ++i) {
    const TaskDef::Output *defo          = &taskdef.outputs[i];
    const TaskRequirements::Output *reqo = &req.outputs[i];
    if (reqo->volume != "*anytmp*") {
      Reservation newres =
        MakeVolumeReservation(defo->path,
                              reqo->volume, reqo->path,
                              reqo->size);
      if (!newres) {
        // unable to acquire reservation
        task->activationError =
          kh::tr("Not enough disk space to make reservation for output files."
                 "Task %1: unable to make reservation %2/%3:%4")
          .arg(ToQString(task->verref()))
          .arg(ToQString(reqo->volume))
          .arg(ToQString(reqo->path))
          .arg(ToQString(reqo->size));
        notify(NFY_DEBUG, "    %s",
               task->activationError.latin1());
        reservations.clear();
        return false;
      } else {
        reservations.push_back(newres);
      }
    }
  }

  return true;
}
예제 #4
0
파일: KeyValue.cpp 프로젝트: Bullatov/gts
void KeyValue::AddTo( QDomElement& element, QDomDocument& domDocument ) const
{
    if ( IsMultiValued() )
    {
        for ( int i = 0; i < m_elementList.size(); ++i )
        {
            QDomElement newChildElement = domDocument.createElement( QString( "_%1" ).arg( i ) );
            newChildElement.appendChild( domDocument.createTextNode( m_elementList.at( i ) ) );
            element.appendChild( newChildElement );
        }
    }
    else
    {
        element.appendChild( domDocument.createTextNode( ToQString() ) );
    }
}
void
khResourceManager::InsertProvider(khResourceProviderProxy *proxy)
{
  std::string host = proxy->Host();
  if (providers.find(host) != providers.end()) {
    // collision
    throw khException(kh::tr("Already have resource provider named '%1'")
                      .arg(ToQString(host)));
  }

  providers.insert(std::make_pair(host, proxy));

  // instantiate the Volumes that this provider will manage
  std::vector<std::string> volnames;
  GetHostVolumes(host, volnames);
  for (std::vector<std::string>::const_iterator vn = volnames.begin();
       vn != volnames.end(); ++vn) {
    volumes[*vn] = new Volume(*vn, proxy);
  }

  // wake up the activate thread
  activateCondVar.signal_one();
}
bool
khResourceManager::CheckVolumeHosts(khTask *task)
{
  const TaskRequirements& req(task->GetRequirementsRef());

  // check to see that I have all the providers necessary for my
  // required volumes
  // NOTE: this checks all the providers that are connected, not just
  // those with avail CPUs
  for (std::set<std::string>::const_iterator rvh =
         req.requiredVolumeHosts.begin();
       rvh != req.requiredVolumeHosts.end(); ++rvh) {
    if (providers.find(*rvh) == providers.end()) {
      // missing a volume provider - can't process this task
      task->activationError = kh::tr("Volume host '%1' unavailable")
                              .arg(ToQString(*rvh));
      notify(NFY_DEBUG, "    %s",
             task->activationError.latin1());
      return false;
    }
  }

  return true;
}
예제 #7
0
파일: KeyValue.cpp 프로젝트: Bullatov/gts
bool KeyValue::ToBool() const
{
    return ( ToQString() == trueString );
}
예제 #8
0
파일: KeyValue.cpp 프로젝트: Bullatov/gts
int KeyValue::ToInt() const
{
    return ToQString().toInt();
}
예제 #9
0
파일: KeyValue.cpp 프로젝트: Bullatov/gts
double KeyValue::ToDouble() const
{
    return ToQString().toDouble();
}
예제 #10
0
파일: KeyValue.cpp 프로젝트: Bullatov/gts
const KeyId KeyValue::ToKeyId() const
{
    return KeyId( ToQString() );
}
예제 #11
0
파일: KeyValue.cpp 프로젝트: Bullatov/gts
const std::wstring KeyValue::ToWString() const
{
    return ToQString().toStdWString();
}
예제 #12
0
      }
      else
      {
        return QString();
      }
    }
  private:
    typedef std::map<String, QRadioButton*> IdToButton;

    void SetupButton(IdToButton::value_type but)
    {
      connect(but.second, SIGNAL(toggled(bool)), SIGNAL(SettingsChanged()));
      if (const Error status = Backends.GetStatus(but.first))
      {
        but.second->setEnabled(false);
        but.second->setToolTip(ToQString(status.GetText()));
      }
      else
      {
        but.second->setEnabled(true);
      }
      Parameters::ExclusiveValue::Bind(*but.second, *Options, Parameters::ZXTuneQT::UI::Export::TYPE, but.first);
    }
  private:
    const Parameters::Container::Ptr Options;
    const FileBackendsSet Backends;
    IdToButton Buttons;
  };
}

namespace UI
bool
khResourceManager::TryActivate(void) throw()
{
  notify(NFY_DEBUG, "===== TryActivate =====");
  notify(NFY_DEBUG, "     num blockers  = %d", numActivateBlockers);
  notify(NFY_DEBUG, "     tasks waiting = %lu",
         static_cast<long unsigned>(taskWaitingQueue.size()));
  notify(NFY_DEBUG, "     num providers = %lu",
         static_cast<long unsigned>(providers.size()));

  // do some quick short circuit tests to see if we need to check
  // in more detail
  if ((numActivateBlockers == 0) &&
      taskWaitingQueue.size() &&
      providers.size()) {
    // figure out which providers have CPU resources to spare
    Providers availProviders;
    for (Providers::iterator p = providers.begin();
         p != providers.end(); ++p) {
      if (p->second->usedCPUs < p->second->numCPUs) {
        availProviders.insert(*p);
      }
    }

    notify(NFY_DEBUG, "     avail providers = %lu",
           static_cast<long unsigned>(availProviders.size()));
    if (availProviders.size() != 0) {
      // walk through the waiting tasks (in order) trying to find
      // a processor to satisfy their needs
      for (TaskWaitingQueue::iterator t = taskWaitingQueue.begin();
           t != taskWaitingQueue.end(); ++t) {
        notify(NFY_DEBUG, "     trying \"%s\"",
               (*t)->verref().c_str());
        if (CheckVolumeHosts(*t)) {
          Reservations fixedReservations;
          if (MakeFixedVolumeReservations(*t, fixedReservations)) {
            Reservations localReservations;
            khResourceProviderProxy *provider =
              FindSatisfyingProvider(*t, availProviders,
                                     localReservations);
            if (provider) {
              // clear any previous activation error
              (*t)->activationError = QString();

              // combine fixed and local reservations
              std::copy(localReservations.begin(),
                        localReservations.end(),
                        back_inserter(fixedReservations));
              localReservations.clear();

              if ((*t)->bindOutfiles(fixedReservations)) {
                // this will either Start the task or
                // send a failed
                provider->StartTask(*t, fixedReservations);

                // we must exit here since *t has been removed
                // from taskWaitingQueue and the iterator could
                // now be invalid.
                // return true so the caller will come right
                // back in here and try some more
                return true;
              } else {
                (*t)->activationError =
                  kh::tr("Unable to bind outfiles.");
                notify(NFY_WARN, "    %s",
                       (*t)->activationError.latin1());
              }
            } else {
              (*t)->activationError =
                kh::tr("Unable to find a suitable resource provider:"
                       " no CPU(s) is available to start the task %1.")
                .arg(ToQString((*t)->verref()));
              notify(NFY_DEBUG, "    %s",
                     (*t)->activationError.latin1());
            }

            fixedReservations.clear();
          }
        }
      }
    }
  }

  return false;
}
예제 #14
0
void
khTask::buildCommands(std::vector<std::vector<std::string> > &outcmds,
                      const std::vector<Reservation> &res)
{
  // My outputs have already been bound, now just do the variable
  // substitution in the command line
  // $OUTPUT          -> alias for $OUTPUTS[0]
  // $OUTPUTS[<num>]
  // $OUTPUTS
  // $INPUT           -> alias for $INPUTS[0]
  // $INPUTS[<num>]
  // $INPUTS
  // also handle :basename, :dirname, :sansext
  // extensions on variable names
  // $OUTPUT:sansext
  // $INPUTS[3]:dirname

  // Other possible substitutions
  // $NUMCPU  -> number of CPUs assigned to the task


  std::vector<std::string> inputs;
  inputs.reserve(taskdef_.inputs.size());
  for (std::vector<TaskDef::Input>::const_iterator i =
         taskdef_.inputs.begin();
       i != taskdef_.inputs.end(); ++i) {

    inputs.push_back(i->path);
  }

  uint numcmds = taskdef_.commands.size();
#if 0 && defined(SUPPORT_TASK_RELOCATE)
  outcmds.resize(numcmds + relocateMap.size());
#else
  outcmds.resize(numcmds);
#endif
  for (uint cmdnum = 0; cmdnum < numcmds; ++cmdnum) {
    std::vector<std::string> &outcmd(outcmds[cmdnum]);

    for (std::vector<std::string>::const_iterator arg =
           taskdef_.commands[cmdnum].begin();
         arg != taskdef_.commands[cmdnum].end(); ++arg) {
      if (arg->empty()) continue;
      uint len = arg->size();
      bool used = false;
      if ((*arg)[0] == '$') {
        const std::vector<std::string> *vec = 0;
        uint i = 0;
        if (StartsWith(*arg, "$OUTPUT")) {
          vec = &boundOutfiles;
          i = 7;
        } else if (StartsWith(*arg, "$INPUT")) {
          vec = &inputs;
          i = 6;
        } else if (*arg == "$NUMCPU") {
          uint numcpu = 0;
          for (std::vector<Reservation>::const_iterator r = res.begin();
               r != res.end(); ++r) {
            const CPUReservationImpl *cpuimpl =
              dynamic_cast<const CPUReservationImpl*>(&**r);
            if (cpuimpl) {
              numcpu = cpuimpl->num();
              break;
            }
          }
          if (numcpu == 0) {
            throw khException(kh::tr("Internal error: can find CPU reservation"));
          }
          outcmd.push_back(ToString(numcpu));
          used = true;
        }

        if (vec) {
          int index = 0;
          if ((i < len) && ((*arg)[i] == 'S')) {
            ++i;
            if ((i < len) && ((*arg)[i] == '[')) {
              ++i;
              uint j = i;
              for (; j < len && ((*arg)[j] != ']'); ++j) ;
              if (j-i) {
                index = atoi(arg->substr(i, j-i).c_str());
              }
              i = j+1;
            } else {
              // no subscript, we want them all
              index = -1;
            }
          }
          std::string (*adapter)(const std::string &) = &passthrough;
          if ((i+1 < len) && ((*arg)[i] == ':')) {
            std::string subcmd = arg->substr(i+1, std::string::npos);
            if (subcmd == "basename")
              adapter = &khBasename;
            else if (subcmd == "dirname")
              adapter = &khDirname;
            else if (subcmd == "sansext")
              adapter = &khDropExtension;
            else
              adapter = 0;
          }
          if (adapter) {
            used = true;
            if (index >= 0) {
              if (index < (int)vec->size()) {
                outcmd.push_back((*adapter)((*vec)[index]));
              } else {
                throw khException(kh::tr("Invalid commandline arg: %1")
                                  .arg(ToQString(*arg)));
              }
            } else {
              std::transform(vec->begin(), vec->end(),
                             back_inserter(outcmd),
                             adapter);
            }
          }
        }
      }
      if (!used) {
        outcmd.push_back(*arg);
      }
    }
  } /* for cmdnum */

#if 0 && defined(SUPPORT_TASK_RELOCATE)
  uint cmdnum = numcmds;
  for (std::map<std::string, std::string>::const_iterator
         reloc = relocateMap.begin();
       reloc != relocateMap.end(); ++reloc) {
    std::vector<std::string> &outcmd(outcmds[cmdnum]);
    outcmd.resize(3);
    outcmd[0] = "khrelocate";
    outcmd[1] = reloc->first;
    outcmd[2] = reloc->second;
    ++cmdnum;
  }
#endif
}