mirror of
https://github.com/lubosz/overte.git
synced 2025-04-26 22:56:02 +02:00
Current status of my code for json
This commit is contained in:
parent
b89121a7ad
commit
dc32d5ae8d
10 changed files with 111 additions and 8 deletions
libraries
controllers/src/controllers
input-plugins/src/input-plugins
tests/controllers/src
|
@ -1,5 +1,11 @@
|
|||
//
|
||||
// Created by Bradley Austin Davis 2015/10/09
|
||||
// Copyright 2015 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
#include "Mapping.h"
|
||||
|
||||
namespace controller {
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -28,9 +28,9 @@ namespace controller {
|
|||
using Pointer = std::shared_ptr<Mapping>;
|
||||
|
||||
Map _channelMappings;
|
||||
QString _name;
|
||||
|
||||
void parse(const QString& json);
|
||||
QString serialize();
|
||||
protected:
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -301,6 +301,10 @@ namespace controller {
|
|||
return Endpoint::Pointer();
|
||||
}
|
||||
|
||||
UserInputMapper::Input NewControllerScriptingInterface::inputFor(const QString& inputName) {
|
||||
return DependencyManager::get<UserInputMapper>()->findDeviceInput(inputName);
|
||||
}
|
||||
|
||||
Endpoint::Pointer NewControllerScriptingInterface::endpointFor(const UserInputMapper::Input& inputId) {
|
||||
auto iterator = _endpoints.find(inputId);
|
||||
if (_endpoints.end() == iterator) {
|
||||
|
|
|
@ -68,6 +68,8 @@ namespace controller {
|
|||
Endpoint::Pointer endpointFor(const UserInputMapper::Input& endpoint);
|
||||
Endpoint::Pointer compositeEndpointFor(Endpoint::Pointer first, Endpoint::Pointer second);
|
||||
|
||||
UserInputMapper::Input inputFor(const QString& inputName);
|
||||
|
||||
friend class MappingBuilderProxy;
|
||||
friend class RouteBuilderProxy;
|
||||
private:
|
||||
|
|
|
@ -11,11 +11,14 @@
|
|||
#include <QtCore/QHash>
|
||||
#include <QtCore/QDebug>
|
||||
|
||||
#include <QJSONObject>
|
||||
#include <qjsonarray.h>
|
||||
|
||||
#include "RouteBuilderProxy.h"
|
||||
#include "../NewControllerScriptingInterface.h"
|
||||
#include "../Logging.h"
|
||||
|
||||
namespace controller {
|
||||
using namespace controller;
|
||||
|
||||
QObject* MappingBuilderProxy::from(const QJSValue& source) {
|
||||
qCDebug(controllers) << "Creating new Route builder proxy from " << source.toString();
|
||||
|
@ -41,4 +44,49 @@ QObject* MappingBuilderProxy::join(const QJSValue& source1, const QJSValue& sour
|
|||
return from(_parent.compositeEndpointFor(source1Endpoint, source2Endpoint));
|
||||
}
|
||||
|
||||
|
||||
const QString JSON_NAME = QStringLiteral("name");
|
||||
const QString JSON_CHANNELS = QStringLiteral("channels");
|
||||
const QString JSON_CHANNEL_FROM = QStringLiteral("from");
|
||||
const QString JSON_CHANNEL_TO = QStringLiteral("to");
|
||||
const QString JSON_CHANNEL_FILTERS = QStringLiteral("filters");
|
||||
|
||||
|
||||
void MappingBuilderProxy::parse(const QJsonObject& json) {
|
||||
_mapping->_name = json[JSON_NAME].toString();
|
||||
|
||||
_mapping->_channelMappings.clear();
|
||||
const auto& jsonChannels = json[JSON_CHANNELS].toArray();
|
||||
for (const auto& channelIt : jsonChannels) {
|
||||
parseRoute(channelIt);
|
||||
}
|
||||
}
|
||||
|
||||
void MappingBuilderProxy::parseRoute(const QJsonValue& json) {
|
||||
if (json.isObject()) {
|
||||
const auto& jsonChannel = json.toObject();
|
||||
|
||||
auto newRoute = from(jsonChannel[JSON_CHANNEL_FROM]);
|
||||
if (newRoute) {
|
||||
auto route = dynamic_cast<RouteBuilderProxy*>(newRoute);
|
||||
route->filters(jsonChannel[JSON_CHANNEL_FILTERS]);
|
||||
route->to(jsonChannel[JSON_CHANNEL_TO]);
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QObject* MappingBuilderProxy::from(const QJsonValue& json) {
|
||||
if (json.isString()) {
|
||||
return from(_parent.endpointFor(_parent.inputFor(json.toString())));
|
||||
} else if (json.isObject()) {
|
||||
// Endpoint is defined as an object, we expect a js function then
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Filter::List MappingBuilderProxy::parseFilters(const QJsonValue& json) const {
|
||||
return Filter::List();
|
||||
}
|
||||
|
|
|
@ -32,12 +32,24 @@ public:
|
|||
Q_INVOKABLE QObject* from(const QScriptValue& source);
|
||||
|
||||
Q_INVOKABLE QObject* join(const QJSValue& source1, const QJSValue& source2);
|
||||
|
||||
// JSON route creation point
|
||||
Q_INVOKABLE QObject* from(const QJsonValue& json);
|
||||
|
||||
|
||||
void parse(const QJsonObject& json);
|
||||
// void serialize(QJsonObject& json);
|
||||
|
||||
protected:
|
||||
QObject* from(const Endpoint::Pointer& source);
|
||||
|
||||
friend class RouteBuilderProxy;
|
||||
NewControllerScriptingInterface& _parent;
|
||||
Mapping::Pointer _mapping;
|
||||
|
||||
|
||||
void parseRoute(const QJsonValue& json);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -40,6 +40,10 @@ class RouteBuilderProxy : public QObject {
|
|||
Q_INVOKABLE QObject* constrainToInteger();
|
||||
Q_INVOKABLE QObject* constrainToPositiveInteger();
|
||||
|
||||
// JSON route creation point
|
||||
Q_INVOKABLE QObject* filters(const QJsonValue& json);
|
||||
Q_INVOKABLE void to(const QJsonValue& json);
|
||||
|
||||
private:
|
||||
void to(const Endpoint::Pointer& destination);
|
||||
void addFilter(Filter::Lambda lambda);
|
||||
|
|
|
@ -64,7 +64,7 @@ void UserInputMapper::resetDevice(uint16 deviceID) {
|
|||
}
|
||||
}
|
||||
|
||||
int UserInputMapper::findDevice(QString name) {
|
||||
int UserInputMapper::findDevice(QString name) const {
|
||||
for (auto device : _registeredDevices) {
|
||||
if (device.second->_name.split(" (")[0] == name) {
|
||||
return device.first;
|
||||
|
@ -82,6 +82,28 @@ QVector<QString> UserInputMapper::getDeviceNames() {
|
|||
return result;
|
||||
}
|
||||
|
||||
UserInputMapper::Input UserInputMapper::findDeviceInput(const QString& inputName) const {
|
||||
|
||||
// Split the full input name as such: deviceName.inputName
|
||||
auto names = inputName.split('.');
|
||||
|
||||
if (names.size() >= 2) {
|
||||
// Get the device name:
|
||||
auto deviceName = names[0];
|
||||
auto inputName = names[1];
|
||||
|
||||
int deviceID = findDevice(deviceName);
|
||||
if (deviceID != Input::INVALID_DEVICE) {
|
||||
// getAllInputsForDevice(deviceID);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
return Input();
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool UserInputMapper::addInputChannel(Action action, const Input& input, float scale) {
|
||||
return addInputChannel(action, input, Input(), scale);
|
||||
|
|
|
@ -140,9 +140,12 @@ public:
|
|||
QVector<InputPair> getAvailableInputs(uint16 deviceID) { return _registeredDevices[deviceID]->getAvailabeInputs(); }
|
||||
void resetAllDeviceBindings();
|
||||
void resetDevice(uint16 deviceID);
|
||||
int findDevice(QString name);
|
||||
int findDevice(QString name) const;
|
||||
QVector<QString> getDeviceNames();
|
||||
|
||||
Input findDeviceInput(const QString& inputName) const;
|
||||
|
||||
|
||||
// Actions are the output channels of the Mapper, that's what the InputChannel map to
|
||||
// For now the Actions are hardcoded, this is bad, but we will fix that in the near future
|
||||
enum Action {
|
||||
|
|
|
@ -83,7 +83,9 @@ int main(int argc, char** argv) {
|
|||
QGuiApplication app(argc, argv);
|
||||
QQmlApplicationEngine engine;
|
||||
|
||||
|
||||
for (auto path : qApp->libraryPaths()) {
|
||||
qDebug() << path;
|
||||
}
|
||||
{
|
||||
DependencyManager::set<UserInputMapper>();
|
||||
foreach(auto inputPlugin, PluginManager::getInstance()->getInputPlugins()) {
|
||||
|
|
Loading…
Reference in a new issue