Ejemplo n.º 1
0
/**
 *  \brief Initializes signal lock and signal values.
 *
 *   Start() must be called to actually begin continuous
 *   signal monitoring. The timeout is set to 3 seconds,
 *   and the signal threshold is initialized to 0%.
 *
 *  \param db_cardnum Recorder number to monitor,
 *                    if this is less than 0, SIGNAL events will not be
 *                    sent to the frontend even if SetNotifyFrontend(true)
 *                    is called.
 *  \param _channel ExternalChannel for card
 *  \param _flags   Flags to start with
 */
ExternalSignalMonitor::ExternalSignalMonitor(
    int db_cardnum, ExternalChannel *_channel, uint64_t _flags) :
    DTVSignalMonitor(db_cardnum, _channel, _flags),
    m_stream_handler(NULL), m_stream_handler_started(false)
{
    QString result;

    LOG(VB_CHANNEL, LOG_INFO, LOC + "ctor");
    m_stream_handler = ExternalStreamHandler::Get(_channel->GetDevice());
    if (!m_stream_handler || m_stream_handler->HasError())
        LOG(VB_GENERAL, LOG_ERR, LOC + "Open failed");
    else
        m_lock_timeout = GetLockTimeout() * 1000;
}
Ejemplo n.º 2
0
void	DotLock::Lock(const char *lockfile)
{
	Unlock();

unsigned nseconds=GetLockSleep();
unsigned timeout=GetLockTimeout();
const char *q, *r;

	refresh_interval=GetLockRefresh();

	for (q=r=lockfile; *q; q++)
		if (*q == '/')	r=q+1;

	q= TempName( r-lockfile ? lockfile:"", r-lockfile);

struct	stat	last_stat;
int	has_last_stat=0;
AlarmTimer	stat_timer;

	memset(&last_stat, 0, sizeof(last_stat));
	while (attemptlock(q, lockfile))
	{
	struct	stat	current_stat;

		if (stat(lockfile, &current_stat) == 0)
		{
			if (!has_last_stat ||
				current_stat.st_ino != last_stat.st_ino ||
				current_stat.st_ctime != last_stat.st_ctime ||
				current_stat.st_atime != last_stat.st_atime)
			{
				has_last_stat=1;
				last_stat=current_stat;
				stat_timer.Set(timeout);
			}
			else if (stat_timer.Expired())
			{
				unlink(lockfile);
			}
		}

	AlarmSleep sleep(nseconds);
	}
	if (refresh_interval >= 10)
		refresh.Set(refresh_interval);
}