Example #1
0
void eHttpStream::thread()
{
	hasStarted();
	std::string currenturl, newurl;
	currenturl = streamUrl;
	for (unsigned int i = 0; i < 5; i++)
	{
		if (openUrl(currenturl, newurl) < 0)
		{
			/* connection failed */
			eDebug("eHttpStream::Thread end NO connection");
			connectionStatus = FAILED;
			return;
		}
		if (newurl == "")
		{
			/* we have a valid stream connection */
			eDebug("eHttpStream::Thread end connection");
			connectionStatus = CONNECTED;
			return;
		}
		/* switch to new url */
		close();
		currenturl = newurl;
		newurl = "";
	}
	/* too many redirect / playlist levels */
	eDebug("eHttpStream::Thread end NO connection");
	connectionStatus = FAILED;
	return;
}
Example #2
0
void eFilePushThreadRecorder::thread()
{
	setIoPrio(IOPRIO_CLASS_RT, 7);

	eDebug("[eFilePushThreadRecorder] THREAD START");

	/* we set the signal to not restart syscalls, so we can detect our signal. */
	struct sigaction act;
	act.sa_handler = signal_handler; // no, SIG_IGN doesn't do it. we want to receive the -EINTR
	act.sa_flags = 0;
	sigaction(SIGUSR1, &act, 0);

	hasStarted();

	/* m_stop must be evaluated after each syscall. */
	while (!m_stop)
	{
		ssize_t bytes = ::read(m_fd_source, m_buffer, m_buffersize);
		if (bytes < 0)
		{
			bytes = 0;
			/* Check m_stop after interrupted syscall. */
			if (m_stop) {
				break;
			}
			if (errno == EINTR || errno == EBUSY || errno == EAGAIN)
				continue;
			if (errno == EOVERFLOW)
			{
				eWarning("[eFilePushThreadRecorder] OVERFLOW while recording");
				++m_overflow_count;
				continue;
			}
			eDebug("[eFilePushThreadRecorder] *read error* (%m) - aborting thread because i don't know what else to do.");
			sendEvent(evtReadError);
			break;
		}

#ifdef SHOW_WRITE_TIME
		struct timeval starttime;
		struct timeval now;
		gettimeofday(&starttime, NULL);
#endif
		int w = writeData(bytes);
#ifdef SHOW_WRITE_TIME
		gettimeofday(&now, NULL);
		suseconds_t diff = (1000000 * (now.tv_sec - starttime.tv_sec)) + now.tv_usec - starttime.tv_usec;
		eDebug("[eFilePushThreadRecorder] write %d bytes time: %9u us", bytes, (unsigned int)diff);
#endif
		if (w < 0)
		{
			eDebug("[eFilePushThreadRecorder] WRITE ERROR, aborting thread: %m");
			sendEvent(evtWriteError);
			break;
		}
	}
	flush();
	sendEvent(evtStopped);
	eDebug("[eFilePushThreadRecorder] THREAD STOP");
}
Example #3
0
void gSDLDC::thread()
{
	hasStarted();

	bool stop = false;
	while (!stop) {
		SDL_Event event;
		if (SDL_WaitEvent(&event)) {
			switch (event.type) {
			case SDL_KEYDOWN:
			case SDL_KEYUP:
			case SDL_QUIT:
				m_pump.send(event);
				break;
			case SDL_USEREVENT:
				switch (event.user.code) {
				case EV_SET_VIDEO_MODE:
					evSetVideoMode((unsigned long)event.user.data1, (unsigned long)event.user.data2);
					break;
				case EV_FLIP:
					evFlip();
					break;
				case EV_QUIT:
					stop = true;
					break;
				}
				break;
			}
		}
	}
}
Example #4
0
void eHttpStream::thread()
{
	hasStarted();
	ret_code = openHttpConnection();
	eDebug("eHttpStream::open: ret %d", ret_code);
	sock_mutex.unlock();
}
Example #5
0
void eErrorOutput::thread()
{
//	fprintf(stderr, "[eErrorOutput] start thread\n");
	hasStarted();
	nice(4);
	runLoop();
//	fprintf(stderr, "[eErrorOutput] behind runloop\n");
}
 virtual void stop() override
 {
     if (hasStarted())
     {
         if (global)
             putNext(NULL);
     }
     PARENT::stop();
 }
Example #7
0
void eBackgroundFileEraser::thread()
{
	hasStarted();
	nice(5);
	setIoPrio(IOPRIO_CLASS_BE, 7);
	reset();
	runLoop();
	stop_thread_timer->stop();
}
Example #8
0
QueryData genOsqueryEvents(QueryContext& context) {
  QueryData results;

  auto publishers = EventFactory::publisherTypes();
  for (const auto& publisher : publishers) {
    Row r;
    r["name"] = publisher;
    r["publisher"] = publisher;
    r["type"] = "publisher";

    auto pubref = EventFactory::getEventPublisher(publisher);
    if (pubref != nullptr) {
      r["subscriptions"] = INTEGER(pubref->numSubscriptions());
      r["events"] = INTEGER(pubref->numEvents());
      r["restarts"] = INTEGER(pubref->restartCount());
      r["active"] = (pubref->hasStarted() && !pubref->isEnding()) ? "1" : "0";
    } else {
      r["subscriptions"] = "0";
      r["events"] = "0";
      r["restarts"] = "0";
      r["active"] = "-1";
    }
    results.push_back(r);
  }

  auto subscribers = EventFactory::subscriberNames();
  for (const auto& subscriber : subscribers) {
    Row r;
    r["name"] = subscriber;
    r["type"] = "subscriber";
    // Subscribers will never 'restart'.
    r["restarts"] = "0";

    auto subref = EventFactory::getEventSubscriber(subscriber);
    if (subref != nullptr) {
      r["publisher"] = subref->getType();
      r["subscriptions"] = INTEGER(subref->numSubscriptions());
      r["events"] = INTEGER(subref->numEvents());

      // Subscribers are always active, even if their publisher is not.
      r["active"] = (subref->state() == SUBSCRIBER_RUNNING) ? "1" : "0";
    } else {
      r["subscriptions"] = "0";
      r["events"] = "0";
      r["active"] = "-1";
    }
    results.push_back(r);
  }

  return results;
}
Example #9
0
 virtual void stop() override
 {
     if (output)
     {
         output->stop();
         output.clear();
     }
     if (hasStarted())
     {
         ActPrintLog("SORT waiting barrier.2");
         barrier->wait(false);
         ActPrintLog("SORT barrier.2 raised");
         ActPrintLog("SORT waiting for merge");
         sorter->stopMerge();
     }
     PARENT::stop();
 }
Example #10
0
void AIOpponent::simulate(float dt)
{
	auto world = G_getWorld();
	if (!world->hasStarted()) return;
	if (world->isPaused() || world->isGameOver()) return;
	if (orderedOpponents == NULL) return;
	if (powerUpExecuted && pwrupType == PowerUp::PowerUpType::GHOST) return;
	if (powerUpExecuted && pwrupType == PowerUp::PowerUpType::SPEED) return;
	if (orderedOpponents->size() == 0) return;
	this->setPrzedniTylni();
	if (tylni && tylni->getVelocityX() > 1.2f*this->getVelocityX() && tylni->isJumping())
	{
		jump();
	}
	else if (przedni && przedni->getVelocityX() < 0.8f*this->getVelocityX())
	{
		jump();
	}
	else if (stykasie())
	{
		jump();
	}
	if (pwrupType != PowerUp::PowerUpType::NONE) maintainPowerUp();
}
Example #11
0
void eStreamThread::thread() {
	const int bufsize = 40000;
	unsigned char buf[bufsize];
	bool eof = false;
	fd_set rfds;
	fd_set wfds;
	struct timeval timeout;
	int rc,r,w,maxfd;
	time_t next_scantime = 0;
	bool sosSend = false;
	m_running = true;

	r = w = 0;
	hasStarted();
	eDebug("eStreamThread started");
	while (!m_stop) {
		pthread_testcancel();
		FD_ZERO(&rfds);
		FD_ZERO(&wfds);
		maxfd = 0;
		timeout.tv_sec = 1;
		timeout.tv_usec = 0;
		if (r < bufsize) {
			FD_SET(m_srcfd, &rfds);
			maxfd = MAX(maxfd, m_srcfd);
		}
		if (w < r) {
			FD_SET(m_destfd, &wfds);
			maxfd = MAX(maxfd, m_destfd);
		}
		rc = select(maxfd+1, &rfds, &wfds, NULL, &timeout);
		if (rc == 0) {
			eDebug("eStreamThread::thread: timeout!");
			continue;
		}
		if (rc < 0) {
			eDebug("eStreamThread::thread: error in select (%d)", errno);
			break;
		}
		if (FD_ISSET(m_srcfd, &rfds)) {
			rc = ::read(m_srcfd, buf+r, bufsize - r);
			if (rc < 0) {
				eDebug("eStreamThread::thread: error in read (%d)", errno);
				m_messagepump.send(evtReadError);
				break;
			} else if (rc == 0) {
				eof = true;
			} else {
				if (!sosSend) {
					sosSend = true;
					m_messagepump.send(evtSOS);
				}
				r += rc;
				if (r == bufsize) eDebug("eStreamThread::thread: buffer full");
			}
		}
		if (FD_ISSET(m_destfd, &wfds) && (w < r) && ((r > bufsize/4) || eof)) {
			rc = ::write(m_destfd, buf+w, r-w);
			if (rc < 0) {
				eDebug("eStreamThread::thread: error in write (%d)", errno);
				m_messagepump.send(evtWriteError);
				break;
			}
			w += rc;
			//eDebug("eStreamThread::thread: buffer r=%d w=%d",r,w);
			if (w == r) {
				if (time(0) >= next_scantime) {
					if (scanAudioInfo(buf, r)) {
						m_messagepump.send(evtStreamInfo);
						next_scantime = time(0) + 1;
					}
				}
				w = r = 0;
			}
		}
		if (eof && (r==w)) {
			m_messagepump.send(evtEOS);
			break;
		}
	}
	eDebug("eStreamThread end");
}
Example #12
0
void eFilePushThread::thread()
{
	ignore_but_report_signals();
	hasStarted(); /* "start()" blocks until we get here */
	setIoPrio(prio_class, prio);
	eDebug("FILEPUSH THREAD START");

	do
	{
	int eofcount = 0;
	int buf_end = 0;
	size_t bytes_read = 0;
	off_t current_span_offset = 0;
	size_t current_span_remaining = 0;

#if defined(__sh__)
// opens video device for the reverse playback workaround
// Changes in this file are cause e2 doesnt tell the player to play reverse
	int fd_video = open("/dev/dvb/adapter0/video0", O_RDONLY);
// Fix to ensure that event evtEOF is called at end of playbackl part 1/3
	bool already_empty = false;
#endif

	while (!m_stop)
	{
		if (m_sg && !current_span_remaining)
		{
#if defined (__sh__) // tells the player to play in reverse
#define VIDEO_DISCONTINUITY                   _IO('o', 84)
#define DVB_DISCONTINUITY_SKIP                0x01
#define DVB_DISCONTINUITY_CONTINUOUS_REVERSE  0x02
			if ((m_sg->getSkipMode() != 0))
			{
				// inform the player about the jump in the stream data
				// this only works if the video device allows the discontinuity ioctl in read-only mode (patched)
				int param = DVB_DISCONTINUITY_SKIP; // | DVB_DISCONTINUITY_CONTINUOUS_REVERSE;
				int rc = ioctl(fd_video, VIDEO_DISCONTINUITY, (void*)param);
			}
#endif
			m_sg->getNextSourceSpan(m_current_position, bytes_read, current_span_offset, current_span_remaining);
			ASSERT(!(current_span_remaining % m_blocksize));
			m_current_position = current_span_offset;
			bytes_read = 0;
		}

		size_t maxread = m_buffersize;

			/* if we have a source span, don't read past the end */
		if (m_sg && maxread > current_span_remaining)
			maxread = current_span_remaining;

			/* align to blocksize */
		maxread -= maxread % m_blocksize;

		if (maxread)
		{
#ifdef SHOW_WRITE_TIME
			struct timeval starttime;
			struct timeval now;
			gettimeofday(&starttime, NULL);
#endif
			buf_end = m_source->read(m_current_position, m_buffer, maxread);
#ifdef SHOW_WRITE_TIME
			gettimeofday(&now, NULL);
			suseconds_t diff = (1000000 * (now.tv_sec - starttime.tv_sec)) + now.tv_usec - starttime.tv_usec;
			eDebug("[eFilePushThread] read %d bytes time: %9u us", buf_end, (unsigned int)diff);
#endif
		}
		else
			buf_end = 0;

		if (buf_end < 0)
		{
			buf_end = 0;
			/* Check m_stop after interrupted syscall. */
			if (m_stop) {
				break;
			}
			if (errno == EINTR || errno == EBUSY || errno == EAGAIN)
				continue;
			if (errno == EOVERFLOW)
			{
				eWarning("OVERFLOW while playback?");
				continue;
			}
			eDebug("eFilePushThread *read error* (%m) - not yet handled");
		}

			/* a read might be mis-aligned in case of a short read. */
		int d = buf_end % m_blocksize;
		if (d)
			buf_end -= d;

		if (buf_end == 0)
		{
				/* on EOF, try COMMITting once. */
			if (m_send_pvr_commit)
			{
				struct pollfd pfd;
				pfd.fd = m_fd_dest;
				pfd.events = POLLIN;
				switch (poll(&pfd, 1, 250)) // wait for 250ms
				{
					case 0:
						eDebug("wait for driver eof timeout");
#if defined(__sh__) // Fix to ensure that event evtEOF is called at end of playbackl part 2/3
						if (already_empty)
						{
							break;
						}
						else
						{
							already_empty = true;
							continue;
						}
#else
						continue;
#endif
					case 1:
						eDebug("wait for driver eof ok");
						break;
					default:
						eDebug("wait for driver eof aborted by signal");
						/* Check m_stop after interrupted syscall. */
						if (m_stop)
							break;
						continue;
				}
			}

			if (m_stop)
				break;

				/* in stream_mode, we are sending EOF events
				   over and over until somebody responds.

				   in stream_mode, think of evtEOF as "buffer underrun occurred". */
			sendEvent(evtEOF);

			if (m_stream_mode)
			{
				eDebug("reached EOF, but we are in stream mode. delaying 1 second.");
				sleep(1);
				continue;
			}
			else if (++eofcount < 10)
			{
				eDebug("reached EOF, but the file may grow. delaying 1 second.");
				sleep(1);
				continue;
			}
			break;
		} else
		{
			/* Write data to mux */
			int buf_start = 0;
			filterRecordData(m_buffer, buf_end);
			while ((buf_start != buf_end) && !m_stop)
			{
				int w = write(m_fd_dest, m_buffer + buf_start, buf_end - buf_start);

				if (w <= 0)
				{
					/* Check m_stop after interrupted syscall. */
					if (m_stop) {
						w = 0;
						buf_start = 0;
						buf_end = 0;
						break;
					}
					if (w < 0 && (errno == EINTR || errno == EAGAIN || errno == EBUSY))
					{
#if HAVE_CPULOADFIX
						sleep(2);
#endif
						continue;
					}
					eDebug("eFilePushThread WRITE ERROR");
					sendEvent(evtWriteError);
					break;
				}
				buf_start += w;
			}

			eofcount = 0;
#if defined(__sh__) // Fix to ensure that event evtEOF is called at end of playbackl part 3/3
			already_empty = false;
#endif
			m_current_position += buf_end;
			bytes_read += buf_end;
			if (m_sg)
				current_span_remaining -= buf_end;
		}
	}
#if defined(__sh__) // closes video device for the reverse playback workaround
	close(fd_video);
#endif
	sendEvent(evtStopped);

	{ /* mutex lock scope */
		eSingleLocker lock(m_run_mutex);
		m_run_state = 0;
		m_run_cond.signal(); /* Tell them we're here */
		while (m_stop == 2) {
			eDebug("FILEPUSH THREAD PAUSED");
			m_run_cond.wait(m_run_mutex);
		}
		if (m_stop == 0)
			m_run_state = 1;
	}

	} while (m_stop == 0);
	eDebug("FILEPUSH THREAD STOP");
}
Example #13
0
void eLircInputDriver::thread()
{
	cTimeMs FirstTime;
	cTimeMs LastTime;
	char buf[LIRC_BUFFER_SIZE];
	char LastKeyName[54] = "";
	bool repeat = false;
	int timeout = -1;
	lircEvent event;

	hasStarted();
	thread_stop = false;

	while (!thread_stop && f>=0) {
		bool ready = fileReady(f, timeout);
		int ret = ready ? safe_read(f, buf, sizeof(buf)) : -1;

		if (ready && ret <= 0 ) {
			eDebug("ERROR: lircd connection broken, trying to reconnect every %.1f seconds", float(RECONNECTDELAY) / 1000);
			close(f);
			f = -1;
			while (!thread_stop && f < 0) {
				cCondWait::SleepMs(RECONNECTDELAY);
				if (Connect()) {
					eDebug("reconnected to lircd");
					break;
				}
			}
		}

		if (ready && ret > 21) {
			unsigned int count;
			char countstring[2] = "";
			char substr[3] = "";
			char rawcode[17] = "";
			char KeyName[54] = "";
			char RemoteName[54] = "";
			if (sscanf(buf, "%17s %2s %53s %53s", rawcode, countstring, KeyName, RemoteName) != 4) { // 128buffer size = 17 + 2 + 2x53 + 3 spaces!!
				eDebug("ERROR: unparseable lirc command: %s", buf);
				continue;
			}
			else {
				xtoi(countstring, &count);
				sscanf(RemoteName, "%3s %*s", substr);
			}
			if (strcmp(substr, "E2_") != 0) {
				eDebug("Ignored event from remote : %s", RemoteName);
				continue;
			}
			if (count == 0) {
				if (strcmp(KeyName, LastKeyName) == 0 && FirstTime.Elapsed() < REPEATDELAY)
					continue; // skip keys coming in too fast
				if (repeat) {
					event.name = LastKeyName;
					event.repeat = false;
					event.release = true;
					m_pump.send(event);
				}
				strcpy(LastKeyName, KeyName);
				repeat = false;
				FirstTime.Set();
				timeout = -1;
			}
			else {
				if (LastTime.Elapsed() < REPEATFREQ)
					continue; // repeat function kicks in after a short delay (after last key instead of first key)
				if (FirstTime.Elapsed() < REPEATDELAY)
					continue; // skip keys coming in too fast (for count != 0 as well)
				repeat = true;
			}
			//eDebug("Count : %2d", count);
			if (((count != 1) || (IGNOREFIRSTREPEAT == false)) && ((count + REPEATCOUNT) % REPEATCOUNT) == 0) {
				LastTime.Set();
				event.name = KeyName;
				event.repeat = repeat;
				event.release = false;
				m_pump.send(event);
			}
		}
		else if (repeat) { // the last one was a repeat, so let's generate a release
			if (LastTime.Elapsed() >= REPEATTIMEOUT) {
				event.name = LastKeyName;
				event.repeat = false;
				event.release = true;
				m_pump.send(event);
				repeat = false;
				*LastKeyName = 0;
				timeout = -1;
			}
		}
	}
}
 void ensureSendCount()
 {
     if (hasStarted() && !isLookAheadActive(0))
         sendOnce(getDataLinkCount() + skipped);
 }
Example #15
0
void eFilePushThread::thread()
{
	setIoPrio(prio_class, prio);

	off_t dest_pos = 0, source_pos = 0;
	size_t bytes_read = 0;
	
	off_t current_span_offset = 0;
	size_t current_span_remaining = 0;
	
	size_t written_since_last_sync = 0;

	eDebug("FILEPUSH THREAD START");
	
		/* we set the signal to not restart syscalls, so we can detect our signal. */
	struct sigaction act;
	act.sa_handler = signal_handler; // no, SIG_IGN doesn't do it. we want to receive the -EINTR
	act.sa_flags = 0;
	sigaction(SIGUSR1, &act, 0);
	
	hasStarted();
	
	source_pos = m_raw_source.lseek(0, SEEK_CUR);
	
		/* m_stop must be evaluated after each syscall. */
	while (!m_stop)
	{
			/* first try flushing the bufptr */
		if (m_buf_start != m_buf_end)
		{
				/* filterRecordData wants to work on multiples of blocksize.
				   if it returns a negative result, it means that this many bytes should be skipped
				   *in front* of the buffer. Then, it will be called again. with the newer, shorter buffer.
				   if filterRecordData wants to skip more data then currently available, it must do that internally.
				   Skipped bytes will also not be output.

				   if it returns a positive result, that means that only these many bytes should be used
				   in the buffer. 
				   
				   In either case, current_span_remaining is given as a reference and can be modified. (Of course it 
				   doesn't make sense to decrement it to a non-zero value unless you return 0 because that would just
				   skip some data). This is probably a very special application for fast-forward, where the current
				   span is to be cancelled after a complete iframe has been output.

				   we always call filterRecordData with our full buffer (otherwise we couldn't easily strip from the end)
				   
				   we filter data only once, of course, but it might not get immediately written.
				   that's what m_filter_end is for - it points to the start of the unfiltered data.
				*/
			
			int filter_res;
			
			do
			{
				filter_res = filterRecordData(m_buffer + m_filter_end, m_buf_end - m_filter_end, current_span_remaining);

				if (filter_res < 0)
				{
					eDebug("[eFilePushThread] filterRecordData re-syncs and skips %d bytes", -filter_res);
					m_buf_start = m_filter_end + -filter_res;  /* this will also drop unwritten data */
					ASSERT(m_buf_start <= m_buf_end); /* otherwise filterRecordData skipped more data than available. */
					continue; /* try again */
				}
				
					/* adjust end of buffer to strip dropped tail bytes */
				m_buf_end = m_filter_end + filter_res;
					/* mark data as filtered. */
				m_filter_end = m_buf_end;
			} while (0);
			
			ASSERT(m_filter_end == m_buf_end);
			
			if (m_buf_start == m_buf_end)
				continue;

				/* now write out data. it will be 'aligned' (according to filterRecordData). 
				   absolutely forbidden is to return EINTR and consume a non-aligned number of bytes. 
				*/
			int w = write(m_fd_dest, m_buffer + m_buf_start, m_buf_end - m_buf_start);
//			fwrite(m_buffer + m_buf_start, 1, m_buf_end - m_buf_start, f);
//			eDebug("wrote %d bytes", w);
			if (w <= 0)
			{
				if (errno == EINTR || errno == EAGAIN || errno == EBUSY)
					continue;
				eDebug("eFilePushThread WRITE ERROR");
				sendEvent(evtWriteError);
				break;
				// ... we would stop the thread
			}

			written_since_last_sync += w;

			if (written_since_last_sync >= 512*1024)
			{
				int toflush = written_since_last_sync > 2*1024*1024 ?
					2*1024*1024 : written_since_last_sync &~ 4095; // write max 2MB at once
				dest_pos = lseek(m_fd_dest, 0, SEEK_CUR);
				dest_pos -= toflush;
				posix_fadvise(m_fd_dest, dest_pos, toflush, POSIX_FADV_DONTNEED);
				written_since_last_sync -= toflush;
			}

//			printf("FILEPUSH: wrote %d bytes\n", w);
			m_buf_start += w;
			continue;
		}

			/* now fill our buffer. */
			
		if (m_sg && !current_span_remaining)
		{
			m_sg->getNextSourceSpan(source_pos, bytes_read, current_span_offset, current_span_remaining);
			ASSERT(!(current_span_remaining % m_blocksize));

			if (source_pos != current_span_offset)
				source_pos = m_raw_source.lseek(current_span_offset, SEEK_SET);
			bytes_read = 0;
		}
		
		size_t maxread = sizeof(m_buffer);
		
			/* if we have a source span, don't read past the end */
		if (m_sg && maxread > current_span_remaining)
			maxread = current_span_remaining;

			/* align to blocksize */
		maxread -= maxread % m_blocksize;

		m_buf_start = 0;
		m_filter_end = 0;
		m_buf_end = 0;
		
		if (maxread)
			m_buf_end = m_raw_source.read(m_buffer, maxread);

		if (m_buf_end < 0)
		{
			m_buf_end = 0;
			if (errno == EINTR || errno == EBUSY || errno == EAGAIN)
				continue;
			if (errno == EOVERFLOW)
			{
				eWarning("OVERFLOW while recording");
				continue;
			}
			eDebug("eFilePushThread *read error* (%m) - not yet handled");
		}

			/* a read might be mis-aligned in case of a short read. */
		int d = m_buf_end % m_blocksize;
		if (d)
		{
			m_raw_source.lseek(-d, SEEK_CUR);
			m_buf_end -= d;
		}

		if (m_buf_end == 0)
		{
				/* on EOF, try COMMITting once. */
			if (m_send_pvr_commit)
			{
				struct pollfd pfd;
				pfd.fd = m_fd_dest;
				pfd.events = POLLIN;
				switch (poll(&pfd, 1, 250)) // wait for 250ms
				{
					case 0:
						eDebug("wait for driver eof timeout");
						continue;
					case 1:
						eDebug("wait for driver eof ok");
						break;
					default:
						eDebug("wait for driver eof aborted by signal");
						continue;
				}
			}
			
				/* in stream_mode, we are sending EOF events 
				   over and over until somebody responds.
				   
				   in stream_mode, think of evtEOF as "buffer underrun occured". */
			sendEvent(evtEOF);

			if (m_stream_mode)
			{
				eDebug("reached EOF, but we are in stream mode. delaying 1 second.");
				sleep(1);
				continue;
			}
#if 0
			eDebug("FILEPUSH: end-of-file! (currently unhandled)");
			if (!m_raw_source.lseek(0, SEEK_SET))
			{
				eDebug("(looping)");
				continue;
			}
#endif
			break;
		} else
		{
			source_pos += m_buf_end;
			bytes_read += m_buf_end;
			if (m_sg)
				current_span_remaining -= m_buf_end;
		}
//		printf("FILEPUSH: read %d bytes\n", m_buf_end);
	}
	fdatasync(m_fd_dest);

	eDebug("FILEPUSH THREAD STOP");
}
Example #16
0
void eFilePushThread::thread()
{
	int eofcount = 0;
	setIoPrio(prio_class, prio);
	int buf_end = 0;

	size_t bytes_read = 0;
	off_t current_span_offset = 0;
	size_t current_span_remaining = 0;
	eDebug("FILEPUSH THREAD START");
	
		/* we set the signal to not restart syscalls, so we can detect our signal. */
	struct sigaction act;
	act.sa_handler = signal_handler; // no, SIG_IGN doesn't do it. we want to receive the -EINTR
	act.sa_flags = 0;
	sigaction(SIGUSR1, &act, 0);
	
	hasStarted();

	while (!m_stop)
	{
		if (m_sg && !current_span_remaining)
		{
			m_sg->getNextSourceSpan(m_current_position, bytes_read, current_span_offset, current_span_remaining);
			ASSERT(!(current_span_remaining % m_blocksize));
			m_current_position = current_span_offset;
			bytes_read = 0;
		}
		
		size_t maxread = m_buffersize;
		
			/* if we have a source span, don't read past the end */
		if (m_sg && maxread > current_span_remaining)
			maxread = current_span_remaining;

			/* align to blocksize */
		maxread -= maxread % m_blocksize;

		if (maxread)
		{
#ifdef SHOW_WRITE_TIME
			struct timeval starttime;
			struct timeval now;
			gettimeofday(&starttime, NULL);
#endif
			buf_end = m_source->read(m_current_position, m_buffer, maxread);
#ifdef SHOW_WRITE_TIME
			gettimeofday(&now, NULL);
			suseconds_t diff = (1000000 * (now.tv_sec - starttime.tv_sec)) + now.tv_usec - starttime.tv_usec;
			eDebug("[eFilePushThread] read %d bytes time: %9u us", buf_end, (unsigned int)diff);
#endif
		}
		else
			buf_end = 0;

		if (buf_end < 0)
		{
			buf_end = 0;
			/* Check m_stop after interrupted syscall. */
			if (m_stop) {
				break;
			}
			if (errno == EINTR || errno == EBUSY || errno == EAGAIN)
				continue;
			if (errno == EOVERFLOW)
			{
				eWarning("OVERFLOW while playback?");
				continue;
			}
			eDebug("eFilePushThread *read error* (%m) - not yet handled");
		}

			/* a read might be mis-aligned in case of a short read. */
		int d = buf_end % m_blocksize;
		if (d)
			buf_end -= d;

		if (buf_end == 0)
		{
				/* on EOF, try COMMITting once. */
			if (m_send_pvr_commit)
			{
				struct pollfd pfd;
				pfd.fd = m_fd_dest;
				pfd.events = POLLIN;
				switch (poll(&pfd, 1, 250)) // wait for 250ms
				{
					case 0:
						eDebug("wait for driver eof timeout");
						continue;
					case 1:
						eDebug("wait for driver eof ok");
						break;
					default:
						eDebug("wait for driver eof aborted by signal");
						/* Check m_stop after interrupted syscall. */
						if (m_stop)
							break;
						continue;
				}
			}

			if (m_stop)
				break;

				/* in stream_mode, we are sending EOF events 
				   over and over until somebody responds.
				   
				   in stream_mode, think of evtEOF as "buffer underrun occurred". */
			sendEvent(evtEOF);

			if (m_stream_mode)
			{
				eDebug("reached EOF, but we are in stream mode. delaying 1 second.");
				sleep(1);
				continue;
			}
			else if (++eofcount < 10)
			{
				eDebug("reached EOF, but the file may grow. delaying 1 second.");
				sleep(1);
				continue;
			}
			break;
		} else
		{
			/* Write data to mux */
			int buf_start = 0;
			filterRecordData(m_buffer, buf_end);
			while ((buf_start != buf_end) && !m_stop)
			{
				int w = write(m_fd_dest, m_buffer + buf_start, buf_end - buf_start);

				if (w <= 0)
				{
					/* Check m_stop after interrupted syscall. */
					if (m_stop) {
						w = 0;
						buf_start = 0;
						buf_end = 0;
						break;
					}
					if (w < 0 && (errno == EINTR || errno == EAGAIN || errno == EBUSY))
						continue;
					eDebug("eFilePushThread WRITE ERROR");
					sendEvent(evtWriteError);
					break;
				}
				buf_start += w;
			}

			eofcount = 0;
			m_current_position += buf_end;
			bytes_read += buf_end;
			if (m_sg)
				current_span_remaining -= buf_end;
		}
	}
	sendEvent(evtStopped);
	eDebug("FILEPUSH THREAD STOP");
}
Example #17
0
void eServiceDVD::thread()
{
	eDebug("eServiceDVD dvd thread started");
	hasStarted();
	ddvd_run(m_ddvdconfig);
}
Example #18
0
void eFilePushThread::thread()
{
	ignore_but_report_signals();
	hasStarted(); /* "start()" blocks until we get here */
	setIoPrio(IOPRIO_CLASS_BE, 0);
	eDebug("[eFilePushThread] START thread");

	do
	{
	int eofcount = 0;
	int buf_end = 0;
	size_t bytes_read = 0;
	off_t current_span_offset = 0;
	size_t current_span_remaining = 0;

	while (!m_stop)
	{
		if (m_sg && !current_span_remaining)
		{
			m_sg->getNextSourceSpan(m_current_position, bytes_read, current_span_offset, current_span_remaining, m_blocksize);
			ASSERT(!(current_span_remaining % m_blocksize));
			m_current_position = current_span_offset;
			bytes_read = 0;
		}

		size_t maxread = m_buffersize;

			/* if we have a source span, don't read past the end */
		if (m_sg && maxread > current_span_remaining)
			maxread = current_span_remaining;

			/* align to blocksize */
		maxread -= maxread % m_blocksize;

		if (maxread)
		{
#ifdef SHOW_WRITE_TIME
			struct timeval starttime;
			struct timeval now;
			gettimeofday(&starttime, NULL);
#endif
			buf_end = m_source->read(m_current_position, m_buffer, maxread);
#ifdef SHOW_WRITE_TIME
			gettimeofday(&now, NULL);
			suseconds_t diff = (1000000 * (now.tv_sec - starttime.tv_sec)) + now.tv_usec - starttime.tv_usec;
			eDebug("[eFilePushThread] read %d bytes time: %9u us", buf_end, (unsigned int)diff);
#endif
		}
		else
			buf_end = 0;

		if (buf_end < 0)
		{
			buf_end = 0;
			/* Check m_stop after interrupted syscall. */
			if (m_stop) {
				break;
			}
			if (errno == EINTR || errno == EBUSY || errno == EAGAIN)
				continue;
			if (errno == EOVERFLOW)
			{
				eWarning("[eFilePushThread] OVERFLOW while playback?");
				continue;
			}
			eDebug("[eFilePushThread] read error: %m");
		}

			/* a read might be mis-aligned in case of a short read. */
		int d = buf_end % m_blocksize;
		if (d)
			buf_end -= d;

		if (buf_end == 0)
		{
				/* on EOF, try COMMITting once. */
			if (m_send_pvr_commit)
			{
				struct pollfd pfd;
				pfd.fd = m_fd_dest;
				pfd.events = POLLIN;
				switch (poll(&pfd, 1, 250)) // wait for 250ms
				{
					case 0:
						eDebug("[eFilePushThread] wait for driver eof timeout");
						continue;
					case 1:
						eDebug("[eFilePushThread] wait for driver eof ok");
						break;
					default:
						eDebug("[eFilePushThread] wait for driver eof aborted by signal");
						/* Check m_stop after interrupted syscall. */
						if (m_stop)
							break;
						continue;
				}
			}

			if (m_stop)
				break;

				/* in stream_mode, we are sending EOF events
				   over and over until somebody responds.

				   in stream_mode, think of evtEOF as "buffer underrun occurred". */
			sendEvent(evtEOF);

			if (m_stream_mode)
			{
				eDebug("[eFilePushThread] reached EOF, but we are in stream mode. delaying 1 second.");
				sleep(1);
				continue;
			}
			else if (++eofcount < 10)
			{
				eDebug("[eFilePushThread] reached EOF, but the file may grow. delaying 1 second.");
				sleep(1);
				continue;
			}
			break;
		} else
		{
			/* Write data to mux */
			int buf_start = 0;
			filterRecordData(m_buffer, buf_end);
			while ((buf_start != buf_end) && !m_stop)
			{
				int w = write(m_fd_dest, m_buffer + buf_start, buf_end - buf_start);

				if (w <= 0)
				{
					/* Check m_stop after interrupted syscall. */
					if (m_stop) {
						w = 0;
						buf_start = 0;
						buf_end = 0;
						break;
					}
					if (w < 0 && (errno == EINTR || errno == EAGAIN || errno == EBUSY))
						continue;
					eDebug("[eFilePushThread] write: %m");
					sendEvent(evtWriteError);
					break;
				}
				buf_start += w;
			}

			eofcount = 0;
			m_current_position += buf_end;
			bytes_read += buf_end;
			if (m_sg)
				current_span_remaining -= buf_end;
		}
	}
	sendEvent(evtStopped);

	{ /* mutex lock scope */
		eSingleLocker lock(m_run_mutex);
		m_run_state = 0;
		m_run_cond.signal(); /* Tell them we're here */
		while (m_stop == 2) {
			eDebug("[eFilePushThread] PAUSED");
			m_run_cond.wait(m_run_mutex);
		}
		if (m_stop == 0)
			m_run_state = 1;
	}

	} while (m_stop == 0);
	eDebug("[eFilePushThread] STOP");
}
Example #19
0
void eTuxtxtApp::thread()
{
    hasStarted();
    //tuxtxt_run_ui(pid, demux);
}
Example #20
0
void ComplexTetris::timeoutElapsed(){
    if(hasStarted() && !isPaused() && !isGameOver()){
        oneLineDown();
    }
}
Example #21
0
void ComplexTetris::setPaused(bool paused){
    if (!hasStarted()){
        return;
    }
    this->paused = paused;
}
Example #22
0
void eLircInputDriver::thread()
{
	cTimeMs FirstTime;
	cTimeMs LastTime;
	char buf[LIRC_BUFFER_SIZE];
	char LastKeyName[LIRC_KEY_BUF] = "";
	bool repeat = false;
	int timeout = -1;
	lircEvent event;

	hasStarted();
	thread_stop = false;

	while (!thread_stop && f>=0) {
		bool ready = fileReady(f, timeout);
		int ret = ready ? safe_read(f, buf, sizeof(buf)) : -1;

		if (ready && ret <= 0 ) {
			eDebug("ERROR: lircd connection broken, trying to reconnect every %.1f seconds", float(RECONNECTDELAY) / 1000);
			close(f);
			f = -1;
			while (!thread_stop && f < 0) {
				cCondWait::SleepMs(RECONNECTDELAY);
				if (Connect()) {
					eDebug("reconnected to lircd");
					break;
				}
			}
		}

		if (ready && ret > 21) {
			int count;
			char KeyName[LIRC_KEY_BUF];
			if (sscanf(buf, "%*x %x %29s", &count, KeyName) != 2) { // '29' in '%29s' is LIRC_KEY_BUF-1!
				eDebug("ERROR: unparseable lirc command: %s", buf);
				continue;
			}
			if (count == 0) {
				if (strcmp(KeyName, LastKeyName) == 0 && FirstTime.Elapsed() < REPEATDELAY)
					continue; // skip keys coming in too fast
				if (repeat) {
					event.name = LastKeyName;
					event.repeat = false;
					event.release = true;
					m_pump.send(event);
				}
				strcpy(LastKeyName, KeyName);
				repeat = false;
				FirstTime.Set();
				timeout = -1;
			}
			else {
				if (LastTime.Elapsed() < REPEATFREQ)
					continue; // repeat function kicks in after a short delay (after last key instead of first key)
				if (FirstTime.Elapsed() < REPEATDELAY)
					continue; // skip keys coming in too fast (for count != 0 as well)
				repeat = true;
				timeout = REPEATDELAY;
			}
			LastTime.Set();
			event.name = KeyName;
			event.repeat = repeat;
			event.release = false;
			m_pump.send(event);
		}
		else if (repeat) { // the last one was a repeat, so let's generate a release
			if (LastTime.Elapsed() >= REPEATTIMEOUT) {
				event.name = LastKeyName;
				event.repeat = false;
				event.release = true;
				m_pump.send(event);
				repeat = false;
				*LastKeyName = 0;
				timeout = -1;
			}
		}
	}
}