コード例 #1
0
ファイル: example_03.cpp プロジェクト: j0sete/hanfun
int main(int argc, char **argv)
{
   UNUSED(argc);
   UNUSED(argv);

   LOG(INFO) << "Use case : Alert interface usage" << NL;

   /*
    * Each node variable is a remote device, i.e.,
    * the Node variables are declared on the remote device
    * code and are not used on the base code.
    */
   LOG(INFO) << "Create the node instances ..." << NL;

   Node node1;

   LOG(INFO) << "Add unit to node1 instance ..." << NL;
   SimpleDetector simple_detector(1, node1);

   Node node2;

   LOG(INFO) << "Add unit to node2 instance ..." << NL;
   AlertSink alert_sink(1, node2);

   /*
    * This instance represents the base application.
    */
   LOG(INFO) << "Create the base instance ..." << NL;
   Base base;

   LOG(INFO) << "Create transport instance" << NL;
   Localloop loop;

   /*
    * Setup the network.
    *
    * This simulates the devices connecting to the base using for
    * example a TCP/IP connection or a DECT ULE PVC.
    */
   LOG(INFO) << "Network setup ..." << NL;

   loop.set_base(&base);
   loop.add_node(&node1, "node_1");
   loop.add_node(&node2, "node_2");

   // Register the two devices.

   // Node 1 is unregistered.
   assert(node1.address() == HF::Protocol::BROADCAST_ADDR);

   LOG(INFO) << "Registering node1 ... " << NL;
   node1.unit0()->device_management()->register_device();
   LOG(INFO) << "Node1 address ... " << node1.address() << NL;

   // Node 1 is registered
   assert(node1.address() == 1);

   // Node 2 is unregistered.
   assert(node2.address() == HF::Protocol::BROADCAST_ADDR);

   LOG(INFO) << "Registering node2 ... " << NL;
   node2.unit0()->device_management()->register_device();
   LOG(INFO) << "Node2 address ... " << node2.address() << NL;

   // Node 2 is registered
   assert(node2.address() == 2);

   LOG(INFO) << "There should be two registered devices ... "
             << base.unit0()->device_management()->entries().size() << NL;

   assert(base.unit0()->device_management()->entries().size() == 2);

   // =============================================================================
   // Send alerts a specific device/unit.
   // =============================================================================

   LOG(INFO) << "Send alerts to a specific device/unit ... " << NL;

   HF::Protocol::Address addr(2, 1);

   LOG(INFO) << "Send alert on ..." << NL;
   simple_detector.alert(addr, true);

   LOG(INFO) << "Send alert off ... " << NL;
   simple_detector.alert(addr, false);

   // =============================================================================
   // Send alerts to the broadcast device/unit.
   // =============================================================================

   LOG(INFO) << "Send alerts to the broadcast device/unit ... " << NL;

   // Create a bind entry.
   LOG(INFO) << "Create bind entry on the base ... " << NL;
   HF::Protocol::Address source(1, 1);
   HF::Protocol::Address destination(2, 1);
   HF::Common::Interface itf(HF::Interface::ALERT, HF::Interface::CLIENT_ROLE);

   base.unit0()->bind_management()->add(source, destination, itf);
   LOG(INFO) << "There should be one bind entry ... "
             << base.unit0()->bind_management()->entries().size() << NL;
   assert(base.unit0()->bind_management()->entries().size() == 1);

   LOG(INFO) << "Send alert on to the broadcast device/unit ... " << NL;
   simple_detector.alert(true);

   LOG(INFO) << "Send alert off to the broadcast device/unit ... " << NL;
   simple_detector.alert(false);

   return 0;
}
コード例 #2
0
ファイル: analyserqueue.cpp プロジェクト: abhinavtankha/mixxx
void AnalyserQueue::run() {
    unsigned static id = 0; //the id of this thread, for debugging purposes
    QThread::currentThread()->setObjectName(QString("AnalyserQueue %1").arg(++id));

    // If there are no analyzers, don't waste time running.
    if (m_aq.size() == 0)
        return;

    m_progressInfo.current_track = TrackPointer();
    m_progressInfo.track_progress = 0;
    m_progressInfo.queue_size = 0;
    m_progressInfo.sema.release(); // Initalise with one

    while (!m_exit) {
        TrackPointer nextTrack = dequeueNextBlocking();

        // It's important to check for m_exit here in case we decided to exit
        // while blocking for a new track.
        if (m_exit)
            return;

        // If the track is NULL, try to get the next one.
        // Could happen if the track was queued but then deleted.
        // Or if dequeueNextBlocking is unblocked by exit == true
        if (!nextTrack) {
            m_qm.lock();
            m_queue_size = m_tioq.size();
            m_qm.unlock();
            if (m_queue_size == 0) {
                emit(queueEmpty()); // emit asynchrony for no deadlock
            }
            continue;
        }

        Trace trace("AnalyserQueue analyzing track");

        // Get the audio
        SoundSourceProxy soundSource(nextTrack);
        soundSource.open(); //Open the file for reading
        int iNumSamples = soundSource.length();
        int iSampleRate = soundSource.getSampleRate();

        if (iNumSamples == 0 || iSampleRate == 0) {
            qDebug() << "Skipping invalid file:" << nextTrack->getLocation();
            continue;
        }

        QListIterator<Analyser*> it(m_aq);
        bool processTrack = false;
        while (it.hasNext()) {
            // Make sure not to short-circuit initialise(...)
            if (it.next()->initialise(nextTrack, iSampleRate, iNumSamples)) {
                processTrack = true;
            }
        }

        m_qm.lock();
        m_queue_size = m_tioq.size();
        m_qm.unlock();

        if (processTrack) {
            emitUpdateProgress(nextTrack, 0);
            bool completed = doAnalysis(nextTrack, &soundSource);
            if (!completed) {
                //This track was cancelled
                QListIterator<Analyser*> itf(m_aq);
                while (itf.hasNext()) {
                    itf.next()->cleanup(nextTrack);
                }
                queueAnalyseTrack(nextTrack);
                emitUpdateProgress(nextTrack, 0);
            } else {
                // 100% - FINALIZE_PERCENT finished
                emitUpdateProgress(nextTrack, 1000 - FINALIZE_PERCENT);
                // This takes around 3 sec on a Atom Netbook
                QListIterator<Analyser*> itf(m_aq);
                while (itf.hasNext()) {
                    itf.next()->finalise(nextTrack);
                }
                emit(trackDone(nextTrack));
                emitUpdateProgress(nextTrack, 1000); // 100%
            }
        } else {
            emitUpdateProgress(nextTrack, 1000); // 100%
            qDebug() << "Skipping track analysis because no analyzer initialized.";
        }

        m_qm.lock();
        m_queue_size = m_tioq.size();
        m_qm.unlock();
        if (m_queue_size == 0) {
            emit(queueEmpty()); // emit asynchrony for no deadlock
        }
    }
    emit(queueEmpty()); // emit in case of exit;
}
コード例 #3
0
void QFFitFunctionSelectDialog::init(const QString &filter, const QString &current)
{
    QFFitFunctionManager* manager=QFFitFunctionManager::getInstance();
    bool upd=updatesEnabled();
    /*int idx=ui->lstModels->currentIndex().row();
    if (idx<0) idx=0;*/
    QModelIndex idx=ui->lstModels->currentIndex();
    bool widVisible=isVisible(); if (widVisible) setUpdatesEnabled(false);

    filterModel.setSourceModel(NULL);
    if (model) delete model;
    //model=new QFSimpleTreeModel(this);
    model=new QFSimpleTreeModel(this);
    //QMap<QString, QFFitFunction*> m_fitFunctions=manager->getModels(filter, this);

    QMap<QString, QFFitFunction*> m_fitFunctions;
    if (filter.contains(",")) {
        QStringList fl=filter.split(",");
        for (int i=0; i<fl.size(); i++) {
            QMap<QString, QFFitFunction*> ff=manager->getModels(fl[i]);
            QMapIterator<QString, QFFitFunction*> itf(ff);
            while (itf.hasNext()) {
                itf.next();
                if (!m_fitFunctions.contains(itf.key()))  m_fitFunctions[itf.key()]=itf.value();
                else delete itf.value();
            }
        }
    } else {
        m_fitFunctions=manager->getModels(filter);
    }

    QFSimpleTreeModel *m = model;
    //QFSimpleTreeModel *m = model;

    QMapIterator<QString, QFFitFunction*> it(m_fitFunctions);
    int i=0;

    while (it.hasNext())  {
        it.next();
        if (it.value()) {

            QFSimpleTreeModelItem* item=model->addFolderedItem(it.value()->category(), it.value()->shortName(), it.key());
            //QFPseudoTreeModelItem* item=model->addFolderedItem(it.value()->category(), it.value()->shortName(), it.key());
            item->setData(it.key(), Qt::UserRole+1);
            item->setIcon(QIcon(":/lib/fitfunc_icon.png"));
            item->setData(it.value()->category()+QString("/")+it.value()->shortName()+QString("/")+it.key(), Qt::UserRole+10);
            if (it.value()->isDeprecated() && m) {
                item->setForeground(QColor("darkgrey"));
                item->setText(tr("[DEPRECATED]: %1").arg(item->text()));

            }

            if (it.key()==current) idx=model->index(item);//idx=i;
            i++;
            delete it.value();
        }
    }
    filterModel.setSourceModel(model);
    ui->lstModels->setModel(&filterModel);
    ui->lstModels->expandAll();
    //model->sort(0);
    model->sortTree();
    if (widVisible) setUpdatesEnabled(upd);
    ui->lstModels->expandAll();
    ui->lstModels->setCurrentIndex(idx);//model->index(idx, 0));
    ui->edtFilter->clear();
}
コード例 #4
0
ファイル: collect4output.cpp プロジェクト: aoloe/scribus
bool CollectForOutput::collectFonts()
{
    PrefsManager *prefsManager = PrefsManager::instance();
    QMap<QString,int>::Iterator it3;
    QMap<QString,int>::Iterator it3end = m_Doc->UsedFonts.end();
    int c=0;
    for (it3 = m_Doc->UsedFonts.begin(); it3 != it3end; ++it3)
    {
        QFileInfo itf(prefsManager->appPrefs.fontPrefs.AvailFonts[it3.key()].fontFilePath());
        QString oldFileITF(prefsManager->appPrefs.fontPrefs.AvailFonts[it3.key()].fontFilePath());
        QString outFileITF(m_outputDirectory + "fonts/" + itf.fileName());
        bool success = copyFileAtomic(oldFileITF, outFileITF);
        if (!success)
            qDebug()<<"CollectForOutput::collectFile copyFileAtomic failed for"<<oldFileITF<<"to"<<outFileITF;
#ifndef Q_OS_WIN32
        else
        {
            QFile of(outFileITF);
            if (of.exists())
            {
                bool permsSet=of.setPermissions(QFile::permissions(oldFileITF));
                if (!permsSet)
                    qDebug()<<"Unable to set permissions successfully while collecting for output on"<<outFileITF;
            }
            else
                qDebug()<<"Unable to set permissions successfully while collecting for output on"<<outFileITF<<"as the file does not exist";
        }
#endif
        if (prefsManager->appPrefs.fontPrefs.AvailFonts[it3.key()].type() == ScFace::TYPE1)
        {
            QStringList metrics;
            QString fontDir  = itf.absolutePath();
            QString fontFile = itf.fileName();
            metrics += findFontMetrics(fontDir, fontFile);
            if ( metrics.size() <= 0 )
            {
                QDir dir;
                if (dir.exists(fontDir + "/AFMs"))
                    metrics += findFontMetrics(fontDir + "/AFMs", fontFile);
                if (dir.exists(fontDir + "/afm") && metrics.size() <= 0)
                    metrics += findFontMetrics(fontDir + "/afm", fontFile);
                if (dir.exists(fontDir + "/Pfm") && metrics.size() <= 0)
                    metrics += findFontMetrics(fontDir + "/Pfm", fontFile);
                if (dir.exists(fontDir + "/pfm") && metrics.size() <= 0)
                    metrics += findFontMetrics(fontDir + "/pfm", fontFile);
            }
            for (int a = 0; a < metrics.size(); a++)
            {
                QString origAFM = metrics[a];
                QFileInfo fi(origAFM);
                QString outFileAFM(m_outputDirectory + "fonts/" + fi.fileName());
                bool success = copyFileAtomic(origAFM, outFileAFM);
                if (!success)
                    qDebug()<<"CollectForOutput::collectFile copyFileAtomic failed for"<<origAFM<<"to"<<outFileAFM;
#ifndef Q_OS_WIN32
                else
                {
                    QFile of(outFileAFM);
                    if (of.exists())
                    {
                        bool permsSet=of.setPermissions(QFile::permissions(origAFM));
                        if (!permsSet)
                            qDebug()<<"Unable to set permissions successfully while collecting for output on"<<outFileAFM;
                    }
                    else
                        qDebug()<<"Unable to set permissions successfully while collecting for output on"<<outFileAFM<<"as the file does not exist";
                }
#endif
            }
        }
        if (uiCollect)
            emit fontsCollected(c++);
    }
    return true;
}
コード例 #5
0
ファイル: dune-uctk.cpp プロジェクト: FreddyFox/dune
int
main(int argc, char** argv)
{
  OptionParser options;
  options.executable(argv[0])
  .program("DUNE UCTK Flash Programmer")
  .copyright(DUNE_COPYRIGHT)
  .email("Ricardo Martins <*****@*****.**>")
  .version(getFullVersion())
  .date(getCompileDate())
  .arch(DUNE_SYSTEM_NAME)
  .description("Utility to update the firmware of UCTK based devices.")
  .add("-d", "--dev",
       "System device", "DEVICE")
  .add("-t", "--dev-type",
       "System device type", "TYPE")
  .add("-f", "--file",
       "iHEX file", "IHEX_FILE");

  // Parse command line arguments.
  if (!options.parse(argc, argv))
  {
    if (options.bad())
      std::cerr << "ERROR: " << options.error() << std::endl;
    options.usage();
    return 1;
  }

  // Get iHEX file.
  std::string ihex = options.value("--file");
  if (ihex.empty())
  {
    std::cerr << "ERROR: you must specify one iHEX file." << std::endl;
    return 1;
  }

  if (Path(ihex).type() != Path::PT_FILE)
  {
    std::cerr << "ERROR: no such file: '" << ihex << "'" << std::endl;
    return 1;
  }

  // Get system device.
  std::string sys_dev = options.value("--dev");
  if (sys_dev.empty())
  {
    std::cerr << "ERROR: you must specify one system device." << std::endl;
    return 1;
  }

  // Get device type.
  IO::Handle* handle = NULL;
  std::string dev_type = options.value("--dev-type");
  if (dev_type == "escc")
    handle = new ESCC(sys_dev);
  else
    handle = new SerialPort(sys_dev, c_baud_rate);

  UCTK::Interface itf(handle);
  UCTK::Bootloader* boot = new UCTK::Bootloader(&itf, true);
  boot->program(ihex);
  delete boot;
  delete handle;

  return 0;
}