Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add declarative properties for Cometd configuration

  • Loading branch information...
commit bfbe097339797f3f6535f4934f9d5c3bbb153329 1 parent 12010ed
@torarnv authored
Showing with 76 additions and 5 deletions.
  1. +3 −2 examples/echo.qml
  2. +73 −3 src/api/Cometd.qml
View
5 examples/echo.qml
@@ -59,6 +59,9 @@ Rectangle {
property string channel: "/service/echo"
+ url: "http://localhost:8080/cometd"
+ logLevel: "debug"
+
function echo(message) {
publish(channel, { msg: message });
}
@@ -68,8 +71,6 @@ Rectangle {
}
Component.onCompleted: {
- setLogLevel("debug");
- configure("http://localhost:8080/cometd");
handshake();
subscribe(channel, handleEcho);
}
View
76 src/api/Cometd.qml
@@ -43,13 +43,51 @@ import QtQuick 1.1
import "private"
Item {
+ id: api
+
+ property string url
+ property string logLevel
+ property int maxConnections
+ property int backoffIncrement
+ property int maxBackoff
+ property bool reverseIncomingExtensions
+ property int maxNetworkDelay
+ property variant requestHeaders
+ property bool appendMessageTypeToURL
+ property bool autoBatch
+
+ onUrlChanged: pimpl.setConfigurationProperty()
+ onLogLevelChanged: pimpl.setConfigurationProperty()
+ onMaxConnectionsChanged: pimpl.setConfigurationProperty()
+ onBackoffIncrementChanged: pimpl.setConfigurationProperty()
+ onMaxBackoffChanged: pimpl.setConfigurationProperty()
+ onReverseIncomingExtensionsChanged: pimpl.setConfigurationProperty()
+ onMaxNetworkDelayChanged: pimpl.setConfigurationProperty()
+ onRequestHeadersChanged: pimpl.setConfigurationProperty()
+ onAppendMessageTypeToURLChanged: pimpl.setConfigurationProperty()
+ onAutoBatchChanged: pimpl.setConfigurationProperty()
+
// Public API, matching the API from Cometd.js
+
+ function configure() {
+ pimpl.call();
+ pimpl.updateConfiguration();
+ }
+
+ function init() {
+ pimpl.call();
+ pimpl.updateConfiguration();
+ }
+
+ function setLogLevel() {
+ pimpl.call();
+ pimpl.updateConfiguration();
+ }
+
function registerTransport() { return pimpl.call(); }
function getTransportTypes() { return pimpl.call(); }
function unregisterTransport() { return pimpl.call(); }
function findTransport() { return pimpl.call(); }
- function configure() { return pimpl.call(); }
- function init() { return pimpl.call(); }
function handshake() { return pimpl.call(); }
function disconnect() { return pimpl.call(); }
function startBatch() { return pimpl.call(); }
@@ -67,7 +105,6 @@ Item {
function setBackoffIncrement() { return pimpl.call(); }
function getBackoffIncrement() { return pimpl.call(); }
function getBackoffPeriod() { return pimpl.call(); }
- function setLogLevel() { return pimpl.call(); }
function registerExtension() { return pimpl.call(); }
function unregisterExtension() { return pimpl.call(); }
function getExtension() { return pimpl.call(); }
@@ -78,6 +115,10 @@ Item {
function getConfiguration() { return pimpl.call(); }
function getAdvice() { return pimpl.call(); }
+ Component.onCompleted: {
+ pimpl.updateConfiguration()
+ }
+
Cometd {
id: pimpl
@@ -85,5 +126,34 @@ Item {
var caller = arguments.callee.caller;
return forward(caller.name, caller.arguments);
}
+
+ property bool updatingConfiguration: false
+
+ // Update the Cometd config based on the declarative property change
+ function setConfigurationProperty() {
+ if (updatingConfiguration)
+ return
+
+ var signalName = arguments.callee.caller.name
+ var propertyName = /^on(.+?)Changed$/.exec(signalName)[1]
+ propertyName = propertyName.charAt(0).toLowerCase() + propertyName.substr(1)
+
+ var config = {}
+ config[propertyName] = api[propertyName]
+ api.configure(config)
+ }
+
+ // Update the declarative properties based on the Cometd configuration
+ function updateConfiguration() {
+ updatingConfiguration = true
+ var config = getConfiguration()
+ for (var prop in config) {
+ if (prop == "advice")
+ continue
+
+ api[prop] = config[prop]
+ }
+ updatingConfiguration = false
+ }
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.