Beispiel #1
0
void EventManager::setTransport(EventTransport *transport)
{
    eventTransport_ = transport;

    if (eventTransport_) {
        bool needSync = false;
        {
            KAA_MUTEX_LOCKING("pendingEventsGuard_");
            KAA_MUTEX_UNIQUE_DECLARE(eventsLock, pendingEventsGuard_);
            KAA_MUTEX_LOCKED("pendingEventsGuard_");
            needSync = !pendingEvents_.empty();
            KAA_MUTEX_UNLOCKED("pendingEventsGuard_");
        }

        if (!needSync) {
            KAA_MUTEX_LOCKING("eventListenersGuard_");
            KAA_MUTEX_UNIQUE_DECLARE(eventListenersLock, eventListenersGuard_);
            KAA_MUTEX_LOCKED("eventListenersGuard_");
            needSync = !eventListenersRequests_.empty();
            KAA_MUTEX_UNLOCKED("eventListenersGuard_");
        }

        if (needSync) {
            doSync();
        }
    }
}
Beispiel #2
0
bool MFileDataStore::createValue(const QString &key, const QVariant &value)
{
    Q_D(MFileDataStore);
    bool returnValue = false;
    // QSettings has some kind of a cache so we'll prevent any temporary writes
    // by checking if the data can be actually stored before doing anything
    if (isWritable()) {
        bool originalValueSet = d->settings.contains(key);
        QVariant originalValue = d->settings.value(key);
        d->settings.setValue(key, value);
        bool syncOk = doSync(d->settings, d->watcher);
        if (syncOk) {
            returnValue = true;
            // Emit valueChanged signal when value is changed or a new key is added
            if ((originalValueSet && originalValue != value)
                    || !originalValueSet) {
                d->settingsSnapshot[key] = value;
                emit valueChanged(key, value);
            }
        } else if (originalValueSet) {
            // if sync fails, make sure the value in memory is the original
            d->settings.setValue(key, originalValue);
        } else {
            d->settings.remove(key);
        }

    }
    return returnValue;
}
Beispiel #3
0
std::int32_t EventManager::findEventListeners(const std::list<std::string>& eventFQNs, IFetchEventListenersPtr listener)
{
    if (eventFQNs.empty() || !listener) {
        KAA_LOG_WARN("Failed to add event listeners request: bad input data");
        throw KaaException("Bad event listeners data");
    }

    std::int32_t requestId = UuidGenerator::generateRandomInt();

    std::shared_ptr<EventListenersInfo> info(new EventListenersInfo);
    info->eventFQNs_ = eventFQNs;
    info->listener_ = listener;

    {
        KAA_MUTEX_LOCKING("eventListenersGuard_");
        KAA_MUTEX_UNIQUE_DECLARE(eventListenersLock, eventListenersGuard_);
        KAA_MUTEX_LOCKED("eventListenersGuard_");

        eventListenersRequests_.insert(std::make_pair(requestId, info));
        KAA_MUTEX_UNLOCKED("eventListenersGuard_");
    }

    KAA_LOG_TRACE("Added event listeners resolving request");

    doSync();

    return requestId;
}
			int sync()
			{
				// write any data in the put buffer
				doSync();
				// flush file
				doFlush();
				return 0; // no error, -1 for error
			}			
			void checkWriteBuffer()
			{
				// if write buffer is not empty, then flush it
				if ( pptr() != pbase() )
				{
					doSync();
										
					// get write position
					assert ( static_cast<off_t>(writepos) == doSeek(0,SEEK_CUR) );
				}			
			}
			int_type overflow(int_type c = traits_type::eof())
			{
				if ( c != traits_type::eof() )
				{
					*pptr() = c;
					pbump(1);
					doSync();
				}

				return c;
			}
Beispiel #7
0
void LogCollector::processLogUploadDecision(LogUploadStrategyDecision decision)
{
    switch (decision) {
    case LogUploadStrategyDecision::UPLOAD: {
        KAA_LOG_DEBUG("Going to upload logs");
        doSync();
        break;
    }
    case LogUploadStrategyDecision::NOOP:
        KAA_LOG_TRACE("Nothing to do now");
        if (storage_->getStatus().getRecordsCount() > 0) {
            startLogUploadCheckTimer();
        }
        break;
    default:
        KAA_LOG_WARN("Unknown log upload decision");
        break;
    }
}
Beispiel #8
0
void EventManager::commit(TransactionIdPtr trxId, IKaaClientContext &context_)
{
    auto it = transactions_.find(trxId);
    if (it != transactions_.end()) {
        KAA_MUTEX_LOCKING("pendingEventsGuard_");
        KAA_MUTEX_UNIQUE_DECLARE(eventsLock, pendingEventsGuard_);
        KAA_MUTEX_LOCKED("pendingEventsGuard_");

        std::list<Event> & events = it->second;
        for (Event &e : events) {
            pendingEvents_.insert(std::make_pair(currentEventIndex_++, std::move(e)));
        }
        transactions_.erase(it);

        KAA_MUTEX_UNLOCKING("pendingEventsGuard_");
        KAA_UNLOCK(eventsLock);
        KAA_MUTEX_UNLOCKED("pendingEventsGuard_");

        doSync();
    }
}
Beispiel #9
0
void EventManager::produceEvent(const std::string& fqn, const std::vector<std::uint8_t>& data,
                                const std::string& target, TransactionIdPtr trxId)
{
    if (fqn.empty()) {
        KAA_LOG_WARN("Failed to process outgoing event: bad input data");
        return;
    }

    KAA_LOG_DEBUG(boost::format("Going to produce Event [FQN: %1%, target: %2%, data_size = %3%]") % fqn
                  % (target.empty() ? "broadcast" : target) % data.size());

    Event event;
    event.eventClassFQN = fqn;
    event.eventData.assign(data.begin(), data.end());

    if (target.empty()) {
        event.target.set_null();
    } else {
        event.target.set_string(target);
    }

    if (trxId) {
        getContainerByTrxId(trxId, context_).push_back(event);
        return;
    }

    KAA_LOG_TRACE(boost::format("New event %1% is produced for %2%") % fqn % target);

    {
        KAA_MUTEX_LOCKING("pendingEventsGuard_");
        KAA_MUTEX_UNIQUE_DECLARE(eventsLock, pendingEventsGuard_);
        KAA_MUTEX_LOCKED("pendingEventsGuard_");
        pendingEvents_.insert(std::make_pair(currentEventIndex_++, event));
        KAA_MUTEX_UNLOCKED("pendingEventsGuard_");
    }

    doSync();
}
Beispiel #10
0
void MFileDataStore::remove(const QString &key)
{
    Q_D(MFileDataStore);
    // QSettings has some kind of a cache so we'll prevent any temporary writes
    // by checking if the data can be actually stored before doing anything
    if (isWritable()) {
        bool originalValueSet = d->settings.contains(key);
        if (!originalValueSet) {
            return;
        }
        QVariant originalValue = d->settings.value(key);
        d->settings.remove(key);
        bool syncOk = doSync(d->settings, d->watcher);
        if (!syncOk) {
            if (originalValueSet) {
                // if sync fails, make sure the value in memory is the original
                d->settings.setValue(key, originalValue);
            }
        } else {
            d->settingsSnapshot.remove(key);
            emit valueChanged(key, QVariant());
        }
    }
}
Beispiel #11
0
void LogCollector::retryLogUpload(std::size_t delay)
{
    KAA_LOG_INFO(boost::format("Schedule log upload with %u second(s) delay ...") % delay);
    scheduledUploadTimer_.stop();
    scheduledUploadTimer_.start(delay, [&] { doSync(); });
}
Beispiel #12
0
void LogCollector::retryLogUpload()
{
    KAA_LOG_INFO("Going to retry log upload...");
    doSync();
}
void Call::tryToWrite(bool flush) {
	//debug(QString("Situation: %3, %4").arg(bufferLocal.size()).arg(bufferRemote.size()));

	long samples; // number of samples to write

	if (flush) {
		// when flushing, we pad the shorter buffer, so that all
		// available data is written.  this shouldn't usually be a
		// significant amount, but it might be if there was an audio
		// I/O error in Skype.
		samples = padBuffers();
	} else {
		long l = bufferLocal.size() / 2;
		long r = bufferRemote.size() / 2;

		sync.add(r - l);

		long syncAmount = sync.getSync();
		syncAmount = (syncAmount / 160) * 160;

		if (syncAmount) {
			doSync(syncAmount);
			sync.reset();
			l = bufferLocal.size() / 2;
			r = bufferRemote.size() / 2;
		}

		if (syncFile.isOpen())
			syncFile.write(QString("%1 %2 %3\n").arg(syncTime.elapsed()).arg(r - l).arg(syncAmount).toAscii().constData());

		if (std::labs(r - l) > skypeSamplingRate * 20) {
			// more than 20 seconds out of sync, something went
			// wrong.  avoid eating memory by accumulating data
			long s = (r - l) / skypeSamplingRate;
			debug(QString("Call %1: WARNING: seriously out of sync by %2s; padding").arg(id).arg(s));
			samples = padBuffers();
			sync.reset();
		} else {
			samples = l < r ? l : r;

			// skype usually sends new PCM data every 10ms (160
			// samples at 16kHz).  let's accumulate at least 100ms
			// of data before bothering to write it to disk
			if (samples < skypeSamplingRate / 10)
				return;
		}
	}

	// got new samples to write to file, or have to flush.  note that we
	// have to flush even if samples == 0

	bool success;

	if (!stereo) {
		// mono
		mixToMono(samples);
		QByteArray dummy;
		success = writer->write(bufferLocal, dummy, samples, flush);
		bufferRemote.remove(0, samples * 2);
	} else if (stereoMix == 0) {
		// local left, remote right
		success = writer->write(bufferLocal, bufferRemote, samples, flush);
	} else if (stereoMix == 100) {
		// local right, remote left
		success = writer->write(bufferRemote, bufferLocal, samples, flush);
	} else {
		mixToStereo(samples, stereoMix);
		success = writer->write(bufferLocal, bufferRemote, samples, flush);
	}

	if (!success) {
		QMessageBox *box = new QMessageBox(QMessageBox::Critical, PROGRAM_NAME " - Error",
			QString(PROGRAM_NAME " encountered an error while writing this call to disk.  Recording terminated."));
		box->setWindowModality(Qt::NonModal);
		box->setAttribute(Qt::WA_DeleteOnClose);
		box->show();
		stopRecording(false);
		return;
	}

	// the writer will remove the samples from the buffers
	//debug(QString("Call %1: wrote %2 samples").arg(id).arg(samples));

	// TODO: handle the case where the two streams get out of sync (buffers
	// not equally fulled by a significant amount).  does skype document
	// whether we always get two nice, equal, in-sync streams, even if
	// there have been transmission errors?  perl-script behavior: if out
	// of sync by more than 6.4ms, then remove 1ms from the stream that's
	// ahead.
}
void ClusterServer::render(RenderActionBase *action)
{
    doSync  (false );
    doRender(action);
    doSwap  (      );
}
bool PodSync::OnDriveInserted( char drive )
{
    rInfo( "Media detected %c", drive );
    return doSync();
}
Beispiel #16
0
Sync::Sync(QObject *parent) : QObject(parent)
{
    syncTimer = new QTimer(this);
    connect(syncTimer, SIGNAL(timeout()), this, SLOT(doSync()));
}
			int sync()
			{
				doSync();
				doFlush();
				return 0; // no error, -1 for error
			}			
Beispiel #18
0
			int sync()
			{
				doSync();
				BgzfDeflateWrapper<std::ostream>::object.flush();
				return 0; // no error, -1 for error
			}