diff options
Diffstat (limited to 'daemon/jskitobjects.cpp')
| -rw-r--r-- | daemon/jskitobjects.cpp | 125 |
1 files changed, 63 insertions, 62 deletions
diff --git a/daemon/jskitobjects.cpp b/daemon/jskitobjects.cpp index fe924e8..2aca027 100644 --- a/daemon/jskitobjects.cpp +++ b/daemon/jskitobjects.cpp @@ -11,7 +11,7 @@ static const char *token_salt = "0feeb7416d3c4546a19b04bccd8419b1"; JSKitPebble::JSKitPebble(const AppInfo &info, JSKitManager *mgr) - : QObject(mgr), _appInfo(info), _mgr(mgr) + : QObject(mgr), l(metaObject()->className()), _appInfo(info), _mgr(mgr) { } @@ -44,35 +44,35 @@ uint JSKitPebble::sendAppMessage(QJSValue message, QJSValue callbackForAck, QJSV QPointer<JSKitPebble> pebbObj = this; uint transactionId = _mgr->_appmsg->nextTransactionId(); - logger()->debug() << "sendAppMessage" << data; + qCDebug(l) << "sendAppMessage" << data; _mgr->_appmsg->send(_appInfo.uuid(), data, [pebbObj, transactionId, callbackForAck]() mutable { if (pebbObj.isNull()) return; if (callbackForAck.isCallable()) { - pebbObj->logger()->debug() << "Invoking ack callback"; + qCDebug(pebbObj->l) << "Invoking ack callback"; QJSValue event = pebbObj->buildAckEventObject(transactionId); QJSValue result = callbackForAck.call(QJSValueList({event})); if (result.isError()) { - pebbObj->logger()->warn() << "error while invoking ACK callback" << callbackForAck.toString() << ":" + qCWarning(pebbObj->l) << "error while invoking ACK callback" << callbackForAck.toString() << ":" << JSKitManager::describeError(result); } } else { - pebbObj->logger()->debug() << "Ack callback not callable"; + qCDebug(pebbObj->l) << "Ack callback not callable"; } }, [pebbObj, transactionId, callbackForNack]() mutable { if (pebbObj.isNull()) return; if (callbackForNack.isCallable()) { - pebbObj->logger()->debug() << "Invoking nack callback"; + qCDebug(pebbObj->l) << "Invoking nack callback"; QJSValue event = pebbObj->buildAckEventObject(transactionId, "NACK from watch"); QJSValue result = callbackForNack.call(QJSValueList({event})); if (result.isError()) { - pebbObj->logger()->warn() << "error while invoking NACK callback" << callbackForNack.toString() << ":" + qCWarning(pebbObj->l) << "error while invoking NACK callback" << callbackForNack.toString() << ":" << JSKitManager::describeError(result); } } else { - pebbObj->logger()->debug() << "Nack callback not callable"; + qCDebug(pebbObj->l) << "Nack callback not callable"; } }); @@ -81,13 +81,13 @@ uint JSKitPebble::sendAppMessage(QJSValue message, QJSValue callbackForAck, QJSV void JSKitPebble::showSimpleNotificationOnPebble(const QString &title, const QString &body) { - logger()->debug() << "showSimpleNotificationOnPebble" << title << body; + qCDebug(l) << "showSimpleNotificationOnPebble" << title << body; emit _mgr->appNotification(_appInfo.uuid(), title, body); } void JSKitPebble::openURL(const QUrl &url) { - logger()->debug() << "opening url" << url.toString(); + qCDebug(l) << "opening url" << url.toString(); emit _mgr->appOpenUrl(url); } @@ -102,13 +102,13 @@ QString JSKitPebble::getAccountToken() const QString token = _mgr->_settings->property("accountToken").toString(); if (token.isEmpty()) { token = QUuid::createUuid().toString(); - logger()->debug() << "created new account token" << token; + qCDebug(l) << "created new account token" << token; _mgr->_settings->setProperty("accountToken", token); } hasher.addData(token.toLatin1()); QString hash = hasher.result().toHex(); - logger()->debug() << "returning account token" << hash; + qCDebug(l) << "returning account token" << hash; return hash; } @@ -122,7 +122,7 @@ QString JSKitPebble::getWatchToken() const hasher.addData(_mgr->_watch->serialNumber().toLatin1()); QString hash = hasher.result().toHex(); - logger()->debug() << "returning watch token" << hash; + qCDebug(l) << "returning watch token" << hash; return hash; } @@ -158,23 +158,23 @@ void JSKitPebble::invokeCallbacks(const QString &type, const QJSValueList &args) QList<QJSValue> &callbacks = _callbacks[type]; for (QList<QJSValue>::iterator it = callbacks.begin(); it != callbacks.end(); ++it) { - logger()->debug() << "invoking callback" << type << it->toString(); + qCDebug(l) << "invoking callback" << type << it->toString(); QJSValue result = it->call(args); if (result.isError()) { - logger()->warn() << "error while invoking callback" << type << it->toString() << ":" + qCWarning(l) << "error while invoking callback" << type << it->toString() << ":" << JSKitManager::describeError(result); } } } JSKitConsole::JSKitConsole(JSKitManager *mgr) - : QObject(mgr) + : QObject(mgr), l(metaObject()->className()) { } void JSKitConsole::log(const QString &msg) { - logger()->info() << msg; + qCDebug(l) << msg; } JSKitLocalStorage::JSKitLocalStorage(const QUuid &uuid, JSKitManager *mgr) @@ -237,17 +237,17 @@ QString JSKitLocalStorage::getStorageFileFor(const QUuid &uuid) } JSKitXMLHttpRequest::JSKitXMLHttpRequest(JSKitManager *mgr, QObject *parent) - : QObject(parent), _mgr(mgr), + : QObject(parent), l(metaObject()->className()), _mgr(mgr), _net(new QNetworkAccessManager(this)), _timeout(0), _reply(0) { - logger()->debug() << "constructed"; + qCDebug(l) << "constructed"; connect(_net, &QNetworkAccessManager::authenticationRequired, this, &JSKitXMLHttpRequest::handleAuthenticationRequired); } JSKitXMLHttpRequest::~JSKitXMLHttpRequest() { - logger()->debug() << "destructed"; + qCDebug(l) << "destructed"; } void JSKitXMLHttpRequest::open(const QString &method, const QString &url, bool async, const QString &username, const QString &password) @@ -263,12 +263,12 @@ void JSKitXMLHttpRequest::open(const QString &method, const QString &url, bool a _verb = method; Q_UNUSED(async); - logger()->debug() << "opened to URL" << _request.url().toString(); + qCDebug(l) << "opened to URL" << _request.url().toString(); } void JSKitXMLHttpRequest::setRequestHeader(const QString &header, const QString &value) { - logger()->debug() << "setRequestHeader" << header << value; + qCDebug(l) << "setRequestHeader" << header << value; _request.setRawHeader(header.toLatin1(), value.toLatin1()); } @@ -299,12 +299,12 @@ void JSKitXMLHttpRequest::send(const QJSValue &data) byteData.append(array.property(i).toInt()); } - logger()->debug() << "passed an ArrayBufferView of" << byteData.length() << "bytes"; + qCDebug(l) << "passed an ArrayBufferView of" << byteData.length() << "bytes"; } else { - logger()->warn() << "passed an unknown/invalid ArrayBuffer" << data.toString(); + qCWarning(l) << "passed an unknown/invalid ArrayBuffer" << data.toString(); } } else { - logger()->warn() << "passed an unknown object" << data.toString(); + qCWarning(l) << "passed an unknown object" << data.toString(); } } @@ -317,7 +317,7 @@ void JSKitXMLHttpRequest::send(const QJSValue &data) buffer = 0; } - logger()->debug() << "sending" << _verb << "to" << _request.url() << "with" << QString::fromUtf8(byteData); + qCDebug(l) << "sending" << _verb << "to" << _request.url() << "with" << QString::fromUtf8(byteData); _reply = _net->sendCustomRequest(_request, _verb.toLatin1(), buffer); connect(_reply, &QNetworkReply::finished, @@ -416,7 +416,7 @@ QString JSKitXMLHttpRequest::responseType() const void JSKitXMLHttpRequest::setResponseType(const QString &type) { - logger()->debug() << "response type set to" << type; + qCDebug(l) << "response type set to" << type; _responseType = type; } @@ -436,13 +436,13 @@ QJSValue JSKitXMLHttpRequest::response() const array.setProperty(i, engine->toScriptValue<int>(_response[i])); } arrayBuf.setProperty("_bytes", array); - logger()->debug() << "returning ArrayBuffer of" << _response.size() << "bytes"; + qCDebug(l) << "returning ArrayBuffer of" << _response.size() << "bytes"; } else { - logger()->warn() << "Cannot find proto of ArrayBuffer"; + qCWarning(l) << "Cannot find proto of ArrayBuffer"; } return arrayBuf; } else { - logger()->warn() << "unsupported responseType:" << _responseType; + qCWarning(l) << "unsupported responseType:" << _responseType; return engine->toScriptValue<void*>(0); } } @@ -455,12 +455,12 @@ QString JSKitXMLHttpRequest::responseText() const void JSKitXMLHttpRequest::handleReplyFinished() { if (!_reply) { - logger()->info() << "reply finished too late"; + qCDebug(l) << "reply finished too late"; return; } _response = _reply->readAll(); - logger()->debug() << "reply finished, reply text:" << QString::fromUtf8(_response); + qCDebug(l) << "reply finished, reply text:" << QString::fromUtf8(_response); emit readyStateChanged(); emit statusChanged(); @@ -469,34 +469,34 @@ void JSKitXMLHttpRequest::handleReplyFinished() emit responseTextChanged(); if (_onload.isCallable()) { - logger()->debug() << "going to call onload handler:" << _onload.toString(); + qCDebug(l) << "going to call onload handler:" << _onload.toString(); QJSValue result = _onload.callWithInstance(_mgr->engine()->newQObject(this)); if (result.isError()) { - logger()->warn() << "JS error on onload handler:" << JSKitManager::describeError(result); + qCWarning(l) << "JS error on onload handler:" << JSKitManager::describeError(result); } } else { - logger()->debug() << "No onload set"; + qCDebug(l) << "No onload set"; } } void JSKitXMLHttpRequest::handleReplyError(QNetworkReply::NetworkError code) { if (!_reply) { - logger()->info() << "reply error too late"; + qCDebug(l) << "reply error too late"; return; } - logger()->info() << "reply error" << code; + qCDebug(l) << "reply error" << code; emit readyStateChanged(); emit statusChanged(); emit statusTextChanged(); if (_onerror.isCallable()) { - logger()->debug() << "going to call onerror handler:" << _onload.toString(); + qCDebug(l) << "going to call onerror handler:" << _onload.toString(); QJSValue result = _onerror.callWithInstance(_mgr->engine()->newQObject(this)); if (result.isError()) { - logger()->warn() << "JS error on onerror handler:" << JSKitManager::describeError(result); + qCWarning(l) << "JS error on onerror handler:" << JSKitManager::describeError(result); } } } @@ -504,21 +504,22 @@ void JSKitXMLHttpRequest::handleReplyError(QNetworkReply::NetworkError code) void JSKitXMLHttpRequest::handleAuthenticationRequired(QNetworkReply *reply, QAuthenticator *auth) { if (_reply == reply) { - logger()->debug() << "authentication required"; + qCDebug(l) << "authentication required"; if (!_username.isEmpty() || !_password.isEmpty()) { - logger()->debug() << "using provided authorization:" << _username; + qCDebug(l) << "using provided authorization:" << _username; auth->setUser(_username); auth->setPassword(_password); } else { - logger()->debug() << "no username or password provided"; + qCDebug(l) << "no username or password provided"; } } } JSKitGeolocation::JSKitGeolocation(JSKitManager *mgr) - : QObject(mgr), _mgr(mgr), _source(0), _lastWatchId(0) + : QObject(mgr), l(metaObject()->className()), + _mgr(mgr), _source(0), _lastWatchId(0) { } @@ -539,16 +540,16 @@ void JSKitGeolocation::clearWatch(int watchId) void JSKitGeolocation::handleError(QGeoPositionInfoSource::Error error) { - logger()->warn() << "positioning error: " << error; + qCWarning(l) << "positioning error: " << error; // TODO } void JSKitGeolocation::handlePosition(const QGeoPositionInfo &pos) { - logger()->debug() << "got position at" << pos.timestamp() << "type" << pos.coordinate().type(); + qCDebug(l) << "got position at" << pos.timestamp() << "type" << pos.coordinate().type(); if (_watches.empty()) { - logger()->warn() << "got position update but no one is watching"; + qCWarning(l) << "got position update but no one is watching"; _source->stopUpdates(); // Just in case. return; } @@ -569,10 +570,10 @@ void JSKitGeolocation::handlePosition(const QGeoPositionInfo &pos) void JSKitGeolocation::handleTimeout() { - logger()->info() << "positioning timeout"; + qCDebug(l) << "positioning timeout"; if (_watches.empty()) { - logger()->warn() << "got position timeout but no one is watching"; + qCWarning(l) << "got position timeout but no one is watching"; _source->stopUpdates(); return; } @@ -581,7 +582,7 @@ void JSKitGeolocation::handleTimeout() for (auto it = _watches.begin(); it != _watches.end(); /*no adv*/) { if (it->timer.hasExpired(it->timeout)) { - logger()->info() << "positioning timeout for watch" << it->watchId + qCDebug(l) << "positioning timeout for watch" << it->watchId << ", watch is" << it->timer.elapsed() << "ms old, timeout is" << it->timeout; invokeCallback(it->errorCallback, obj); @@ -603,11 +604,11 @@ void JSKitGeolocation::updateTimeouts() { int once_timeout = -1, updates_timeout = -1; - logger()->debug() << Q_FUNC_INFO; + qCDebug(l) << Q_FUNC_INFO; Q_FOREACH(const Watcher &watcher, _watches) { qint64 rem_timeout = watcher.timeout - watcher.timer.elapsed(); - logger()->debug() << "watch" << watcher.watchId << "rem timeout" << rem_timeout; + qCDebug(l) << "watch" << watcher.watchId << "rem timeout" << rem_timeout; if (rem_timeout >= 0) { // In case it is too large... rem_timeout = qMin<qint64>(rem_timeout, std::numeric_limits<int>::max()); @@ -620,16 +621,16 @@ void JSKitGeolocation::updateTimeouts() } if (updates_timeout >= 0) { - logger()->debug() << "setting location update interval to" << updates_timeout; + qCDebug(l) << "setting location update interval to" << updates_timeout; _source->setUpdateInterval(updates_timeout); _source->startUpdates(); } else { - logger()->debug() << "stopping updates"; + qCDebug(l) << "stopping updates"; _source->stopUpdates(); } if (once_timeout >= 0) { - logger()->debug() << "requesting single location update with timeout" << once_timeout; + qCDebug(l) << "requesting single location update with timeout" << once_timeout; _source->requestUpdate(once_timeout); } } @@ -646,7 +647,7 @@ int JSKitGeolocation::setupWatcher(const QJSValue &successCallback, const QJSVal qlonglong maximumAge = options.value("maximumAge", 0).toLongLong(); - logger()->debug() << "setting up watcher, gps=" << watcher.highAccuracy << "timeout=" << watcher.timeout << "maximumAge=" << maximumAge << "once=" << once; + qCDebug(l) << "setting up watcher, gps=" << watcher.highAccuracy << "timeout=" << watcher.timeout << "maximumAge=" << maximumAge << "once=" << once; if (!_source) { _source = QGeoPositionInfoSource::createDefaultSource(this); @@ -661,7 +662,7 @@ int JSKitGeolocation::setupWatcher(const QJSValue &successCallback, const QJSVal if (maximumAge > 0) { QDateTime threshold = QDateTime::currentDateTime().addMSecs(-qint64(maximumAge)); QGeoPositionInfo pos = _source->lastKnownPosition(watcher.highAccuracy); - logger()->debug() << "got pos timestamp" << pos.timestamp() << " but we want" << threshold; + qCDebug(l) << "got pos timestamp" << pos.timestamp() << " but we want" << threshold; if (pos.isValid() && pos.timestamp() >= threshold) { invokeCallback(watcher.successCallback, buildPositionObject(pos)); if (once) { @@ -678,7 +679,7 @@ int JSKitGeolocation::setupWatcher(const QJSValue &successCallback, const QJSVal watcher.timer.start(); _watches.append(watcher); - logger()->debug() << "added new watch" << watcher.watchId; + qCDebug(l) << "added new watch" << watcher.watchId; QMetaObject::invokeMethod(this, "updateTimeouts", Qt::QueuedConnection); @@ -689,7 +690,7 @@ void JSKitGeolocation::removeWatcher(int watchId) { Watcher watcher; - logger()->debug() << "removing watchId" << watcher.watchId; + qCDebug(l) << "removing watchId" << watcher.watchId; for (int i = 0; i < _watches.size(); i++) { if (_watches[i].watchId == watchId) { @@ -699,7 +700,7 @@ void JSKitGeolocation::removeWatcher(int watchId) } if (watcher.watchId != watchId) { - logger()->warn() << "watchId not found"; + qCWarning(l) << "watchId not found"; return; } @@ -761,12 +762,12 @@ QJSValue JSKitGeolocation::buildPositionErrorObject(PositionError error, const Q void JSKitGeolocation::invokeCallback(QJSValue callback, QJSValue event) { if (callback.isCallable()) { - logger()->debug() << "invoking callback" << callback.toString(); + qCDebug(l) << "invoking callback" << callback.toString(); QJSValue result = callback.call(QJSValueList({event})); if (result.isError()) { - logger()->warn() << "while invoking callback: " << JSKitManager::describeError(result); + qCWarning(l) << "while invoking callback: " << JSKitManager::describeError(result); } } else { - logger()->warn() << "callback is not callable"; + qCWarning(l) << "callback is not callable"; } } |
