/* player thread; for every song a new thread is started * @param audioPlayer structure * @return PLAYER_RET_* */ void *BarPlayerThread (void *data) { assert (data != NULL); player_t * const player = data; uintptr_t pret = PLAYER_RET_OK; bool retry; do { retry = false; if (openStream (player)) { if (openFilter (player) && openDevice (player)) { player->mode = PLAYER_PLAYING; BarPlayerSetVolume (player); retry = play (player) == AVERROR_INVALIDDATA && !player->interrupted; } else { /* filter missing or audio device busy */ pret = PLAYER_RET_HARDFAIL; } } else { /* stream not found */ pret = PLAYER_RET_SOFTFAIL; } player->mode = PLAYER_WAITING; finish (player); } while (retry); player->mode = PLAYER_FINISHED; return (void *) pret; }
const QString RarArchEngine::createFilter() { return openFilter(); }
MainWindow::MainWindow(AmViewerState *state) : _state(state) { _state->recon_tree = NULL; _state->amEvent = NULL; _state->show_dBm = false; _state->filtered = true; _state->sumpols = false; _state->resetSearch(); // couldn't hurt? setWindowTitle("AmViewer"); // creat dialogs _searchWindow = new SearchWindow(this,_state); _visWindow = new VisWindow(this,_state); _fovWindow = new FovWindow(this,_state); _filterWindow = NULL; _infoWindow = NULL; QWidget *centralWidget = new QWidget(); setCentralWidget(centralWidget); QVBoxLayout *bigLayout = new QVBoxLayout(centralWidget); // File menu QAction *quitMenu = new QAction("&Exit",this); quitMenu->setShortcut(tr("Ctrl+Q")); connect(quitMenu,SIGNAL(triggered()),qApp,SLOT(quit())); QAction *openMenu = new QAction("&Open ROOT file...",this); openMenu->setShortcut(tr("Ctrl+O")); connect(openMenu,SIGNAL(triggered()),this,SLOT(openFile())); _saveMenu = new QAction("&Save event candidates...",this); connect(_saveMenu,SIGNAL(triggered()),this,SLOT(saveFile())); QMenu *fileDrop; fileDrop = menuBar()->addMenu("&File"); fileDrop->addAction(openMenu); fileDrop->addAction(_saveMenu); fileDrop->addAction(quitMenu); _saveMenu->setEnabled(false); // View menu _unitsMenu = new QAction("&Display dBm",this); _unitsMenu->setCheckable(true); _unitsMenu->setChecked(false); connect(_unitsMenu,SIGNAL(triggered()),this,SLOT(applyUnits())); // Filter dialog _filterMenu = new QAction("&Filter Settings",this); connect(_filterMenu,SIGNAL(triggered()),this,SLOT(openFilter())); // Polarization checkbox _polMenu = new QAction("&Sum Polarizations",this); _polMenu->setCheckable(true); _polMenu->setChecked(false); _polMenu->setEnabled(false); connect(_polMenu,SIGNAL(triggered()),this,SLOT(applySumPol())); QMenu *viewDrop; viewDrop = menuBar()->addMenu("&View"); viewDrop->addAction(_unitsMenu); viewDrop->addAction(_polMenu); viewDrop->addAction(_filterMenu); _filterMenu->setEnabled(false); // Analysis menu QAction *infoMenu = new QAction("&Event Info",this); connect(infoMenu,SIGNAL(triggered()),this,SLOT(openInfo())); _analysisDrop = menuBar()->addMenu("&Analysis"); _analysisDrop->addAction(infoMenu); QAction *searchMenu = new QAction("&Search Parameters",this); connect(searchMenu,SIGNAL(triggered()),this,SLOT(openSearch())); _analysisDrop->addAction(searchMenu); _analysisDrop->setEnabled(false); QAction *visMenu = new QAction("&Event Visualization",this); connect(visMenu,SIGNAL(triggered()),this,SLOT(openVis())); _analysisDrop->addAction(visMenu); QAction*fovMenu = new QAction("&AMBER Field of View",this); connect(fovMenu,SIGNAL(triggered()),this,SLOT(openFov())); _analysisDrop->addAction(fovMenu); // Set up layout for event browser, pixel windows, graphs QHBoxLayout *hbox = new QHBoxLayout(); bigLayout->addLayout(hbox); // Event list stuff _eventList = new QTreeWidget(this); _eventList->setColumnCount(2); _eventList->setColumnHidden(1,true); //'true' valid in C++? QTreeWidgetItem *_source0 = new QTreeWidgetItem(_eventList); _source0->setText(0,"Source:0 (LTRIG)"); QTreeWidgetItem *_source1 = new QTreeWidgetItem(_eventList); _source1->setText(0,"Source:1 (PPS)"); QTreeWidgetItem *_source2 = new QTreeWidgetItem(_eventList); _source2->setText(0,"Source:2 (Auger)"); _eventList->setHeaderLabel("Events"); hbox->addWidget(_eventList); // Some gross stuff concerning the clickable horns _hornDisplay = new HornDisplay(this,1); CenterHorns *centerLegend = new CenterHorns("center",true); QGraphicsProxyWidget *centerLegendProxy = new QGraphicsProxyWidget(); centerLegendProxy->setWidget(centerLegend->widget); _hornDisplay->hornScene->addItem(centerLegendProxy); centerLegendProxy->rotate(45); centerLegendProxy->setPos(0,-50); centerLegendProxy->setZValue(0.0); AmHorn *ppsHorn[4]; int i; stringstream out; QToolButton *b; for(i=0; i<4; i++) { b = new QToolButton(); b->setFixedSize(25,25); out.str(""); out << (i+1); ppsHorn[i] = new AmHorn(b,"PPS" + out.str()); ppsHorn[i]->proxyWidget = new QGraphicsProxyWidget(); ppsHorn[i]->proxyWidget->setWidget(ppsHorn[i]->_button); _hornDisplay->hornScene->addItem(ppsHorn[i]->proxyWidget); ppsHorn[i]->proxyWidget->setPos(25*i-145,375); // probably stupid, delete //ppsHorn[i]->trigger_color = "blue"; //ppsHorn[i]->updateStyle(); //delete b; } QGraphicsSimpleTextItem *item; for(i=0; i<4; i++) { item = new QGraphicsSimpleTextItem(); _hornDisplay->hornScene->addItem(item); if(i==0) { item->setText("CH"); item->setPos(-7,-31); item->setZValue(1.0); } if(i==1) { item->setText("CV"); item->setPos(-7,5); item->setZValue(1.0); } if(i==2) { item->setText("KH"); item->setPos(-24,-15); item->setZValue(1.0); } if(i==3) { item->setText("KV"); item->setPos(12,-15); item->setZValue(1.0); } //delete item; } // CRUFT ALERT // THIS WHOLE NEXT LOOP IS HIGHLY SUSPECT, I DOUBT IT DOES ANYTHING QString qstr; for(i=0; i<16; i++) { out.str(""); out << (i+1); qstr = QString::fromStdString(out.str()); item = new QGraphicsSimpleTextItem(qstr); _hornDisplay->hornScene->addItem(item); if(i==0) item->setPos(-2.5,75.0); else if(i==1) item->setPos(-105.0,177.5); else if(i==2) item->setPos(-2.5,280.0); else if(i==3) item->setPos(102.5,177.5); else if(i==4) item->setPos(-70.0,55.0); else if(i==5) item->setPos(-95.0,80.0); else if(i==6) item->setPos(-120.0,105.0); else if(i==7) item->setPos(-125.0,250.0); else if(i==8) item->setPos(-100.0,275.5); else if(i==9) item->setPos(-75.0,300.0); else if(i==10) item->setPos(60.0,300.0); else if(i==11) item->setPos(85.0,275.0); else if(i==12) item->setPos(110.0,250.0); else if(i==13) item->setPos(120.0,110.0); else if(i==14) item->setPos(95.0,85.0); else if(i==15) item->setPos(70.0,60.0); } QVBoxLayout *evVbox = new QVBoxLayout(); hbox->addLayout(evVbox); QGridLayout *evInfoGrid = new QGridLayout(); evVbox->addLayout(evInfoGrid); _evIdLabel = new QLabel(""); _evSourceLabel = new QLabel(""); _evSecLabel = new QLabel(""); _evNsLabel = new QLabel(""); _evInfoLabel = new QLabel(""); evInfoGrid->addWidget(_evIdLabel,0,0); evInfoGrid->addWidget(_evSourceLabel,0,1); evInfoGrid->addWidget(_evSecLabel,1,0); evInfoGrid->addWidget(_evNsLabel,1,1); evInfoGrid->addWidget(_evInfoLabel,2,0); evVbox->addWidget(_hornDisplay); QVBoxLayout *pixelVbox = new QVBoxLayout(); hbox->addLayout(pixelVbox); for(i=0; i<4; i++) { pixelWindow[i] = new PixelWindow(this,i); pixelWindow[i]->setMinimumHeight(100); pixelWindow[i]->setMinimumWidth(300); pixelVbox->addWidget(pixelWindow[i]); } for(i=0; i<28; i++) { _hornDisplay->channel[i]->setHornClickFunction(this); connect(_hornDisplay->channel[i]->_button,SIGNAL(clicked()),_hornDisplay->channel[i],SLOT(hornClick())); } for(i=0; i<4; i++) { //ppsHorn[i]->setHornClickFunction(clickHornSetPixel); ppsHorn[i]->setHornClickFunction(this); connect(ppsHorn[i]->_button,SIGNAL(clicked()),ppsHorn[i],SLOT(hornClick())); } }
void ServiceMain(int argc, char** argv) { ServiceStatus.dwServiceType = SERVICE_WIN32; ServiceStatus.dwCurrentState = SERVICE_START_PENDING; ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN; ServiceStatus.dwWin32ExitCode = 0; ServiceStatus.dwServiceSpecificExitCode = 0; ServiceStatus.dwCheckPoint = 0; ServiceStatus.dwWaitHint = 0; if (isService) { hStatus = RegisterServiceCtrlHandler(HSP_SERVICE_NAME, (LPHANDLER_FUNCTION)ControlHandler); if (hStatus == 0) { return; } } // Test for only one instance is running HANDLE mutex = CreateMutex(NULL, TRUE, instanceMutexName); DWORD err = GetLastError(); if (mutex != NULL && err == ERROR_ALREADY_EXISTS || mutex == NULL && err == ERROR_ACCESS_DENIED) { // Mutex found, so another instance is running if (hStatus != 0) { ServiceStatus.dwCurrentState = SERVICE_STOPPED; ServiceStatus.dwWin32ExitCode = ERROR_SINGLE_INSTANCE_APP; SetServiceStatus(hStatus, &ServiceStatus); } else { myLog(LOG_ERR, "%s.ServiceMain: only one instance can run, existing instance found", HSP_SERVICE_NAME); } return; } else { ServiceStatus.dwCurrentState = SERVICE_RUNNING; if (hStatus != 0) { // We are the first instance, report the running status to SCM. SetServiceStatus (hStatus, &ServiceStatus); } } wchar_t programDataDir[MAX_PATH]; if (!initialiseProgramDataDir(programDataDir, MAX_PATH)) { *programDataDir = NULL; } char mbcLogFilename[MAX_PATH]; if (isService && *programDataDir != NULL) { //set the log file name to the default. size_t dirLen = 0; if (0 == wcstombs_s(&dirLen, mbcLogFilename, MAX_PATH, programDataDir, wcslen(programDataDir))) { PathAppend(mbcLogFilename, HSP_DEFAULT_LOGFILE); logFilename = mbcLogFilename; } else { logFilename = NULL; } } if (logFilename != NULL) { // Logging on errno_t error = fopen_s(&logFile, logFilename, "wt"); if (error != 0) { logFile = stderr; myLog(LOG_ERR, "%s.ServiceMain: could not open log file %s: error %d\n", HSP_SERVICE_NAME, logFilename, error); } logFilename = NULL; } myLog(debug, "-------------Starting %s %s--------------", HSP_SERVICE_NAME, HSP_VERSION); fflush(logFile); HSP sp = { 0 }; // look up host-id fields at startup only (hostname // may change dynamically so will have to revisit this $$$) sp.host_hid.hostname.str = (char *)my_calloc(SFL_MAX_HOSTNAME_CHARS+1); sp.host_hid.os_release.str = (char *)my_calloc(SFL_MAX_OSRELEASE_CHARS+1); readHidCounters(&sp, &sp.host_hid); sp.nio_polling_secs = HSP_NIO_POLLING_SECS_32BIT; readInterfaces(&sp, TRUE); if (!readConfig(&sp)) { myLog(LOG_ERR, "%s.ServiceMain: invalid configuration", HSP_SERVICE_NAME); if (hStatus != 0) { ServiceStatus.dwCurrentState = SERVICE_STOPPED; ServiceStatus.dwWin32ExitCode = ERROR_INVALID_PARAMETER; SetServiceStatus(hStatus, &ServiceStatus); } return; } sp.hyperV = testForHyperv(); if (sp.hyperV) { myLog(debug, "%s.ServiceMain Hyper-V services are running", HSP_SERVICE_NAME); if (programDataDir == NULL || !initialiseProgramDataFiles(&sp, programDataDir)) { myLog(LOG_ERR, "%s.ServiceMain: cannot initialise switch port and VM state files", HSP_SERVICE_NAME); if (hStatus != 0) { ServiceStatus.dwCurrentState = SERVICE_STOPPED; ServiceStatus.dwWin32ExitCode = ERROR_FILE_NOT_FOUND; SetServiceStatus(hStatus, &ServiceStatus); } return; } readGuidStore(sp.f_vmStore, sp.vmStoreFile, &sp.vmStore, &sp.maxDsIndex); readGuidStore(sp.f_portStore, sp.portStoreFile, &sp.portStore, &sp.maxIfIndex); } openFilter(&sp); //try to initialise the sFlow filter for sampling initAgent(&sp); // initialize the clock so we can detect second boundaries sp.clk = time(NULL); // main loop BOOL dataAvailable = true; uint32_t currReadNum = 0; while (ServiceStatus.dwCurrentState == SERVICE_RUNNING && dataAvailable) { // check for second boundaries and generate ticks for the sFlow library time_t now = time(NULL); if ((now < sp.clk) || (now - sp.clk) > HSP_MAX_TICKS) { // avoid a busy-loop of ticks if time jumps myLog(LOG_INFO, "%s.ServiceMain: time jump detected", HSP_SERVICE_NAME); sp.clk = now - 1; } while (sp.clk < now) { //only happens on second boundary //start critical if (sp.sFlow->sFlowSettings) { // update polling interval here if config has changed. tick(&sp); } //end critical sp.clk++; } DWORD result; //process a queued counter poller processQueuedPoller(&sp); //timeout is set so that we loop around checking for ticks and samples //several times/s. //calculate timeout 200 if the counter poller queue is empty, 0 otherwise DWORD timeout = sp.pollerQHead == NULL ? HSP_TIMEOUT : 0; if (HSP_FILTER_ACTIVE(sp.filter)) { result = WaitForSingleObject(sp.filter.overlaps[currReadNum].hEvent, timeout); if (result == WAIT_OBJECT_0) { dataAvailable = sp.filter.overlaps[currReadNum].Internal == ERROR_SUCCESS; if (dataAvailable && sp.filter.overlaps[currReadNum].InternalHigh > 0) { //process the sample info in sp.filter.buffers[currReadNum] readPackets(&sp, sp.filter.buffers[currReadNum]); } // Re-queue this read queueRead(sp.filter.dev, sp.filter.buffers[currReadNum], sizeof(sp.filter.buffers[currReadNum]), &sp.filter.overlaps[currReadNum]); //set the next buffer to read currReadNum = (currReadNum+1)%numConcurrentReads; } } else { Sleep(timeout); } } return; }