Exemplo n.º 1
0
void testApp::threadedFunction()
{
    while ( isThreadRunning() != 0 )
    {
        if ( lock() )
        {
            unlock();
            ofSleepMillis(1 * 1000);
        }

    }
}
Exemplo n.º 2
0
 void onStop (Journal journal)
 {
     if (isThreadRunning ())
     {
         journal.debug << "Stopping";
         stopThreadAsync ();
     }
     else
     {
         stopped ();
     }
 }
Exemplo n.º 3
0
void FaceTracker::update(ofBaseVideoDraws& video)
{
	if (!isThreadRunning())
	{
		//videoMat = Mat(h, w, CV_8UC3);
		videoMat = toCv(video).clone();
		convertColor(videoMat, grayMat, CV_RGB2GRAY);
		resize(grayMat, graySmallMat, graySmallMat.size());
		
		startThread(true, false);
	}
}
Exemplo n.º 4
0
    void callTimersSynchronously()
    {
        if (! isThreadRunning())
        {
            // (This is relied on by some plugins in cases where the MM has
            // had to restart and the async callback never started)
            cancelPendingUpdate();
            triggerAsyncUpdate();
        }

        callTimers();
    }
Exemplo n.º 5
0
void Client::start()
{
    if (!isThreadRunning())
    {
        ofLogVerbose("Client::start") << "Starting thread.";
        startThread(true);   // blocking, verbose
    }
    else
    {
        ofLogVerbose("Client::start") << "New message queued, signalling.";
    }
}
void ofxOpenNI2Grabber::threadedFunction()
{
	while (isThreadRunning()) 
	{
		int changedIndex;
		Status status = OpenNI::waitForAnyStream(&streams[0], streams.size(), &changedIndex);
		if (status != STATUS_OK)
		{
			ofLogError() << "waitForAnyStream FAIL:" << OpenNI::getExtendedError();
		}
	}
}
Exemplo n.º 7
0
string ofxSimpleHttp::getCurrentDownloadFileName(){

	string download = "";
	lock();
		int n = q.size();
		if ( isThreadRunning() && n > 0 ){
			ofxSimpleHttpResponse * r = q.front();
			download = r->fileName;
		}
	unlock();
	return download;
}
//------------------------------------------------------------
void ofOpenALSoundPlayer::threadedFunction(){
    vector<vector<short> > multibuffer;
    multibuffer.resize(channels);
    while(isThreadRunning()){
        cout << "threaded function" << endl;
        for(int i=0; i<int(sources.size())/channels; i++){
            int processed;
            alGetSourcei(sources[i*channels], AL_BUFFERS_PROCESSED, &processed);
            
            while(processed--)
            {
                stream("",buffer);
                int numFrames = buffer.size()/channels;
                if(channels>1){
                    for(int j=0;j<channels;j++){
                        multibuffer[j].resize(buffer.size()/channels);
                        for(int k=0;k<numFrames;k++){
                            multibuffer[j][k] = buffer[k*channels+j];
                        }
                        ALuint albuffer;
                        alSourceUnqueueBuffers(sources[i*channels+j], 1, &albuffer);
                        alBufferData(albuffer,AL_FORMAT_MONO16,&multibuffer[j][0],buffer.size()*2/channels,samplerate);
                        alSourceQueueBuffers(sources[i*channels+j], 1, &albuffer);
                    }
                }else{
                    ALuint albuffer;
                    alSourceUnqueueBuffers(sources[i], 1, &albuffer);
                    alBufferData(albuffer,AL_FORMAT_MONO16,&buffer[0],buffer.size()*2/channels,samplerate);
                    alSourceQueueBuffers(sources[i], 1, &albuffer);
                }
                if(stream_end){
                    break;
                }
            }
            ALint state;
            alGetSourcei(sources[i*channels],AL_SOURCE_STATE,&state);
            bool stream_running=false;
//#ifdef OF_USING_MPG123
//            stream_running = streamf || mp3streamf;
//#else
            stream_running = streamf;
//#endif
            if(state != AL_PLAYING && stream_running && !stream_end){
                alSourcePlayv(channels,&sources[i*channels]);
            }
            
            stream_end = false;
        }
        timeSet = false;
        
        ofSleepMillis(1);
    }
}
Exemplo n.º 9
0
void ofxSickPlayer::threadedFunction() {
	while(isThreadRunning()) {
		lock();
		if(recordedData.size() > 0) {
			scanBack = recordedData[position];
			position = (position + 1) % recordedData.size();
			newFrame = true;
		}
		unlock();
		ofSleepMillis(20); // ~50Hz
	}
}
Exemplo n.º 10
0
float ofxSimpleHttp::getCurrentDownloadProgress(){

	float downloadPercent = -1;
	lock();
		int n = q.size();
		if ( isThreadRunning() && n > 0){
			ofxSimpleHttpResponse * r = q.front();
			downloadPercent = r->downloadProgress;
		}
	unlock();
	return downloadPercent;
}
Exemplo n.º 11
0
void ofxPS3EyeGrabber::threadedFunction()
{
    while (isThreadRunning())
    {
        bool res = ps3eye::PS3EYECam::updateDevices();

        if (!res)
        {
            break;
        }
    }
}
//--------------------------------------------------------------
void execThread::threadedFunction(){
    if(isThreadRunning()){
        ofLogVerbose("execThread") << "starting command: " <<  execCommand;
        int result = system(execCommand.c_str());
        if (result == 0) {
            ofLogVerbose("execThread") << "command completed successfully.";
            initialized = true;
        } else {
            ofLogError("execThread") << "command failed with result: " << result;
        }
    }
}
Exemplo n.º 13
0
    void Camera::threadedFunction() {
#if defined(TARGET_WIN32)
        CoInitializeEx(NULL, 0x0); // COINIT_APARTMENTTHREADED in SDK docs
#endif
        while(isThreadRunning()) {
            captureLoop();
            ofSleepMillis(5);
        }
#if defined(TARGET_WIN32)
        CoUninitialize();
#endif
    }
void InstagramDataProvider::threadedFunction(){

	while(isThreadRunning()){
		
		float now = ofGetElapsedTimef();
		float updateTime = _lastUpdateTime + _updateIntervalSeconds;
		
		if(now >= updateTime || _lastUpdateTime < 0){
			_instagram.getUserRecentMedia("self", 10);
			_lastUpdateTime = now;
			
			InstagramDataLoadedEventArgs args;
			
			for(int i = 0; i < _instagram.getVideoURL().size(); ++i){
				InstagramPostData postData;
				basicData data;
				data = _instagram.getBasicData()[i];
				
				postData.id = data.imageID;
				postData.username = data.user;
				postData.caption = data.caption;
				postData.videoUrl = _instagram.getVideoURL()[i];
				postData.imageUrl = _instagram.getImageURL()[i];
				postData.profilePictureUrl = _instagram.getProfilePicture()[i];
				
				if(postData.videoUrl == ""){
					postData.type = "image";
				}else{
					postData.type = "video";
				}
				
				args.posts.push_back(postData);
			} // for
			
			// Compare
			bool isSameOld = false;
			for(int i = 0; i < _args.posts.size(); ++i){
				if(_args.posts[i].id != args.posts[i].id){
					isSameOld = false;
				}
			}
			
			if(!isSameOld){
				ofNotifyEvent(dataLoadedEvent, args, this);
			}
			
		} // if
		
		ofSleepMillis(50);
	}
	
}
Exemplo n.º 15
0
/* Runs a query, which sleeps for 10 seconds, and
   in the main thread parallelly also sleeps for 10 seconds. */
int main(int argc, char* argv[])
{
    int retval;
    // Points to thread descriptor
    pthread_t *sqlthread;
    // For passing parameters to new thread's sqlFunction
    SQLThreadParams *params = (SQLThreadParams *)malloc(sizeof(SQLThreadParams));
    
    // Setting parameters
    params->conn = getConnection();
    params->query = "SELECT SLEEP(10)";
    
    // Creating and starting new thread
    printf("Creating and starting SQL thread\n");
    sqlthread = createBackgroundQuery(params);
    
    // Do some important stuff...
    printf("Doing some important stuff\n");
    sleep(5);
    if (isThreadRunning(sqlthread)) {
        printf("Background query is still running\n");
    } else {
        printf("Background query finished\n");
    }
    sleep(5);
    if (isThreadRunning(sqlthread)) {
        printf("Background query is still running\n");
    } else {
        printf("Background query finished\n");
    }
    printf("Important stuff finished\n");
    
    // Wait for the sqlthread finish
    retval = finishBackgroundQuery(sqlthread);
    printf("Background query finished, return value: %d\n", retval);
    free(params);
    
    return 0;
}
Exemplo n.º 16
0
//--------------------------------------------------------------
void imgLoader::threadedFunction() {
    while (isThreadRunning() != 0)
    {
        if (!imgLoaded) {
            if( lock() ) {
                //Double calls to load two textures for the transition.
                loadNextTexture();
                unlock();
            }
        }
        ofSleepMillis(1 * 1000);
    }
}
Exemplo n.º 17
0
Thread::~Thread()
{
    /* If your thread class's destructor has been called without first stopping the thread, that
       means that this partially destructed object is still performing some work - and that's
       probably a Bad Thing!

       To avoid this type of nastiness, always make sure you call stopThread() before or during
       your subclass's destructor.
    */
    assert (! isThreadRunning());

    stopThread ();
}
Exemplo n.º 18
0
//--------------------------------------------------------------------------------
void ofxKinectV2::threadedFunction(){
    while(isThreadRunning()){
        protonect.updateKinect(rgbPixelsBack, depthPixelsBack);
        rgbPixelsFront.swap(rgbPixelsBack);
        depthPixelsFront.swap(depthPixelsBack);
        
        lock();
        bNewBuffer = true;
        unlock();
        
        ofSleepMillis(2);
    }
}
Exemplo n.º 19
0
void ofxCrazyflie::RadioThread::threadedFunction() {
  int wait_time = 0;
  int emtpy_count = 0;
  
  while (isThreadRunning() || crazyflie_->packet_out_.size()) {

    ofxCRTPPacket *packet = NULL;
    ofxCrazyradio::Ack *ack = NULL;
    
    if (crazyflie_->packet_out_.size() == 0) {
      sleep(wait_time);
      packet = &ping;
    } else {
      lock();
      packet = crazyflie_->packet_out_.front();
      crazyflie_->packet_out_.pop_front();
      unlock();
    }
    
    ack = crazyflie_->radio_.SendPacket(packet->raw_data(), packet->length() + 1);
    
    if (packet->need_response()) {
      if (ack == NULL || !ack->ack_received) {
        delete ack;
        if (packet != &ping) {
          lock();
          crazyflie_->packet_out_.push_front(packet);
          unlock();
        }
        ofLog(OF_LOG_WARNING, "retry: %d, %d, %d", packet->sequence(), packet->port(), packet->channel());
        sleep(200);
        continue;
      }
      if (packet != &ping) {
//        ofLog(OF_LOG_VERBOSE, "got response: %d, %d, %d", packet->sequence(), packet->port(), packet->channel());
        delete packet;
      }
    }
    
    if (ack->length > 0) {
      lock();
      crazyflie_->packet_in_.push_back(new ofxCRTPPacket(ack->data, MAX(0, ack->length - 1)));
      unlock();
      wait_time = 0;
      emtpy_count = 0;
    } else {
      wait_time = ++emtpy_count > 10 ? 10 : 0;
    }
    delete ack;
  }
}
Exemplo n.º 20
0
void HandJockey::threadedFunction()
{
		nite::HandTracker handTracker;		
		nite::HandTrackerFrameRef handTrackerFrame;	
		nite::Status niteRc;

		niteRc = handTracker.create();
		if (niteRc != nite::STATUS_OK)
		{
			throw ("Couldn't create user tracker\n");
		}

		handTracker.startGestureDetection(nite::GESTURE_WAVE);
		handTracker.startGestureDetection(nite::GESTURE_CLICK);


		//if using nite thread (unsupported for now)
		//handTracker.addListener(this);	


		while (isThreadRunning())
		{
			niteRc = handTracker.readFrame(&handTrackerFrame);
			if (niteRc != nite::STATUS_OK)
			{
				printf("Get next frame failed\n");
				continue;
			}

			const nite::Array<nite::GestureData>& gestures = handTrackerFrame.getGestures();
			for (int i = 0; i < gestures.getSize(); ++i)
			{
				if (gestures[i].isComplete())
				{
					nite::HandId newId;
					handTracker.startHandTracking(gestures[i].getCurrentPosition(), &newId);
				}
			}

			const nite::Array<nite::HandData>& hands = handTrackerFrame.getHands();
			for (int i = 0; i < hands.getSize(); ++i)
			{
				const nite::HandData& hand = hands[i];
				TrackedPoint p = toTrackedPoint(hand);
				p.time = handTrackerFrame.getTimestamp();
				ofNotifyEvent(getJockeyEvents().handUpdate, p); //TODO send id
			}
		}

		nite::NiTE::shutdown();
}
Exemplo n.º 21
0
void ThreadWithProgressWindow::timerCallback()
{
    if (! isThreadRunning())
    {
        // thread has finished normally..
        alertWindow->exitModalState (1);
        alertWindow->setVisible (false);
    }
    else
    {
        const ScopedLock sl (messageLock);
        alertWindow->setMessage (message);
    }
}
Exemplo n.º 22
0
//--------------------------------------------------------------
void
GeoData::destroy()
{
	if (isThreadRunning())
		stopThread();

#ifdef USE_OGR
	if (layer != NULL)
		datasource->ReleaseResultSet(layer);

	if (datasource != NULL)
		OGRDataSource::DestroyDataSource(datasource);
#endif
}
Exemplo n.º 23
0
//---------------------------------------------------------------------------
void ofxKinect::close() {
	if(isThreadRunning()) {
		stopThread();
		ofSleepMillis(10);
		waitForThread(false);
	}

	deviceId = -1;
	serial = "";
	bIsFrameNewVideo = false;
	bNeedsUpdateVideo = false;
	bIsFrameNewDepth = false;
	bNeedsUpdateDepth = false;
}
//--------------------------------------------------------------
void CloudsVHXAuth::requestToken()
{
    if (isThreadRunning()) {
        ofLogError("CloudsVHXAuth::requestToken") << "Thread is already running with mode " << mode;
        return;
    }
    if (mode != WAITING) {
        ofLogError("CloudsVHXAuth::requestToken") << "Mode " << mode << " is still active";
        return;
    }
    
    mode = REQUEST_TOKEN;
    startThread();
}
Exemplo n.º 25
0
void testApp::threadedFunction(){

	getPocoThread().setName("MyLoopingThread");

	while(isThreadRunning()){
		TS_START("task");
			ofSleepMillis(30);
			TS_START("subtask1");
			ofSleepMillis(300);
			TS_STOP("subtask1");

		TS_STOP("task");
		ofSleepMillis(100);
	}
}
Exemplo n.º 26
0
void VideoRate::threadedFunction(){
	while(isThreadRunning()){
		unsigned long long time = ofGetElapsedTimeMicros();
		if(back!=NULL){
			mutexFront.lock();
			framesToSend.push(back);
			mutexFront.unlock();
		}
		time = ofGetElapsedTimeMicros()-time;
		long long sleeptime =  1000000./fps-time;
		if(sleeptime>0){
			usleep(sleeptime);
		}
	}
}
Exemplo n.º 27
0
void
PVGLImageLoader::threadedFunction()
{
    while (isThreadRunning() != 0)
    {
        if (!imgLoaded) {
            loadPanorama("data/panoramas/operan8192.jpg");
            createPanoramaSections();
            imgLoaded = true;
        }
    }
    ofLog(OF_LOG_VERBOSE, "PVGLImageLoader - Exiting threadedFunction() in 30 seconds...");
    ofSleepMillis(30000);
    ofLog(OF_LOG_VERBOSE, "PVGLImageLoader - Exiting threadedFunction() NOW!");
}
Exemplo n.º 28
0
//--------------------------------------------------------------
void ofxGifEncoder::threadedFunction() {
	while( isThreadRunning() != 0 ) {
		if( lock() ){
            
            if(bSaving) {
                doSave();
                bSaving = false;
                ofNotifyEvent(OFX_GIF_SAVE_FINISHED, fileName, this);
            }

			unlock();
			ofSleepMillis(10);
		}
	}
}
Exemplo n.º 29
0
//--------------------------------------------------------------------------------
void ofxKinectV2::threadedFunction(){

    while(isThreadRunning()){
        protonect.updateKinect(rgbPixelsBack, depthPixelsBack, irPixelsBack, registeredPixelsBack);
        lock();

        rgbPixelsFront.swap(rgbPixelsBack);
        depthPixelsFront.swap(depthPixelsBack);
        irPixelsFront.swap(irPixelsBack);
        registeredPixelsFront.swap(registeredPixelsBack);

        bNewBuffer = true;
        unlock();
    }
}
Exemplo n.º 30
0
// thread main
void ofxScheduleEvent::threadedFunction() {
    // no times
    if (this->times.size() == 0) {
        return;
    }

    this->lastCheckAppExitMin = -1;
    while (isThreadRunning()) {
        if (lock()) {
            this->threadedUpdate();
            unlock();
            sleep(interval * 1000);
        }
    }
}