diff options
-rw-r--r-- | .travis.yml | 46 | ||||
-rw-r--r-- | CMakeLists.txt | 17 | ||||
-rw-r--r-- | jobs/basejob.cpp | 1 | ||||
-rw-r--r-- | jobs/gtad.yaml | 59 | ||||
-rw-r--r-- | jobs/preamble.mustache | 3 | ||||
-rw-r--r-- | jobs/{{base}}.cpp.mustache | 75 | ||||
-rw-r--r-- | jobs/{{base}}.h.mustache | 47 |
7 files changed, 234 insertions, 14 deletions
diff --git a/.travis.yml b/.travis.yml index 24a182cf..2abf0e2b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,20 +1,40 @@ language: cpp + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-precise-3.8 + packages: + - g++-5 + - clang-3.8 + - qt5-default + matrix: include: - - os: linux - dist: trusty - compiler: gcc - - os: linux - dist: trusty - compiler: clang - - os: osx + - os: linux + env: [ ENV_EVAL="CC=gcc-5 && CXX=g++-5" ] + - os: linux + env: [ ENV_EVAL="CC=clang-3.8 && CXX=clang++-3.8" ] + - os: osx + env: [ ENV_EVAL="brew update && brew install qt5 && CMAKE_PREFIX_PATH=/usr/local/opt/qt" ] + install: - - if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew update; else sudo apt-get update -qq; fi - - if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew install qt5; export PATH="$PATH:/usr/local/opt/qt/bin"; else sudo apt-get install -y qt5-default; fi - - mkdir build && cd build - - cmake .. -script: - - cmake --build . --target all +- eval "${ENV_EVAL}" +- git clone https://github.com/QMatrixClient/matrix-doc.git +- git clone --recursive https://github.com/KitsuneRal/gtad.git +- pushd gtad +- cmake -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH} . +- cmake --build . +- popd + +before_script: +- mkdir build && cd build +- cmake -DMATRIX_DOC_PATH="matrix-doc" -DGTAD_PATH="gtad/gtad" -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH} .. +- cmake --build . --target update-api + +script: cmake --build . + notifications: webhooks: urls: diff --git a/CMakeLists.txt b/CMakeLists.txt index 2abf7e69..b1d72131 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,6 +50,11 @@ if (CMAKE_BUILD_TYPE) endif(CMAKE_BUILD_TYPE) message( STATUS "Using compiler: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}" ) message( STATUS "Using Qt ${Qt5_VERSION} at ${Qt5_Prefix}" ) +if (MATRIX_DOC_PATH AND GTAD_PATH) + message( STATUS "Generating API stubs enabled" ) + message( STATUS " Using GTAD at ${GTAD_PATH}" ) + message( STATUS " Using CS API files at ${MATRIX_DOC_PATH}/api/client-server" ) +endif () message( STATUS "=============================================================================" ) message( STATUS ) @@ -83,6 +88,18 @@ set(libqmatrixclient_SRCS jobs/mediathumbnailjob.cpp ) +if (MATRIX_DOC_PATH AND GTAD_PATH) + add_custom_target(update-api + ${GTAD_PATH} --config jobs/gtad.yaml --out jobs/generated + ${MATRIX_DOC_PATH}/api/client-server + content-repo.yaml- cas_login_redirect.yaml- cas_login_ticket.yaml- + old_sync.yaml- room_initial_sync.yaml- + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + SOURCES jobs/gtad.yaml jobs/{{base}}.h.mustache jobs/{{base}}.cpp.mustache + VERBATIM + ) +endif() + aux_source_directory(jobs/generated libqmatrixclient_job_SRCS) set(example_SRCS examples/qmc-example.cpp) diff --git a/jobs/basejob.cpp b/jobs/basejob.cpp index eb78dec8..7794337e 100644 --- a/jobs/basejob.cpp +++ b/jobs/basejob.cpp @@ -25,7 +25,6 @@ #include <QtNetwork/QNetworkReply> #include <QtCore/QTimer> #include <QtCore/QRegularExpression> -//#include <QtCore/QStringBuilder> #include <array> diff --git a/jobs/gtad.yaml b/jobs/gtad.yaml new file mode 100644 index 00000000..d09de66c --- /dev/null +++ b/jobs/gtad.yaml @@ -0,0 +1,59 @@ +preprocess: + "%CLIENT_RELEASE_LABEL%": r0 + "%CLIENT_MAJOR_VERSION%": r0 + "unsigned:": "unsigned_:" + "default:": "default_:" + +# Structure: +# swaggerType: <targetTypeSpec> +# OR +# swaggerType: +# - swaggerFormat: <targetTypeSpec> +# - /swaggerFormatRegEx/: <targetTypeSpec> +# - //: <targetTypeSpec> # default, if the format doesn't mach anything above +# WHERE +# targetTypeSpec = targetType OR +# { type: targetType, imports: <filename OR [ filenames... ]>, <other attributes...> } +types: + integer: + - int64: qint64 + - int32: qint32 + - //: int + number: + - float: float + - //: double + boolean: bool + string: + - byte: &QByteArray { type: QByteArray, imports: <QtCore/QByteArray> } + - binary: *QByteArray + - date: + type: QDate + avoidCopy?: true + imports: <QtCore/QDate> + - dateTime: + type: QDateTime + avoidCopy?: true + imports: <QtCore/QDateTime> + - //: { type: QString, imports: <QtCore/QString> } + file: + type: QByteArray + imports: <QtCore/QByteArray> + "returnFile?": true + object: { type: QJsonObject, "avoidCopy?": true, imports: <QtCore/QJsonObject> } + array: { type: "QVector<{{1}}>", "avoidCopy?": true, imports: <QtCore/QVector> } + +#operations: + +env: +# preamble: preamble.mustache + copyrightName: Kitsune Ral + copyrightEmail: <kitsune-ral@users.sf.net> +# imports: { set: } +# returnFile?: { bool: false } + +templates: +- "{{base}}.h.mustache" +- "{{base}}.cpp.mustache" + +#outFilesList: apifiles.txt + diff --git a/jobs/preamble.mustache b/jobs/preamble.mustache new file mode 100644 index 00000000..3ba87d61 --- /dev/null +++ b/jobs/preamble.mustache @@ -0,0 +1,3 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ diff --git a/jobs/{{base}}.cpp.mustache b/jobs/{{base}}.cpp.mustache new file mode 100644 index 00000000..45668d4c --- /dev/null +++ b/jobs/{{base}}.cpp.mustache @@ -0,0 +1,75 @@ +{{#@filePartial}}preamble{{/@filePartial}} + +#include "{{filenameBase}}.h" + +{{^models}}#include "jobs/converters.h"{{/models}} +{{#operations}}#include <QtCore/QStringBuilder>{{/operations}} + +using namespace QMatrixClient; +{{#models}}{{#model}} +{{classname}}::operator QJsonValue() const +{ + QJsonObject o; + {{#vars}}o.insert("{{name}}", toJson({{name}})); + {{/vars}} + return o; +} + +{{classname}} FromJson<{{classname}}>::operator()(QJsonValue jv) +{ + QJsonObject o = jv.toObject(); + {{classname}} result; + {{#vars}}result.{{name}} = fromJson<{{datatype}}>(o.value("{{name}}")); + {{/vars}} + return result; +} +{{/model}}{{/models}}{{#operations}} +static const auto basePath = QStringLiteral("{{basePathWithoutHost}}"); +{{# operation}}{{#responses}}{{#normalResponse?}}{{#properties?}} +class {{camelCaseOperationId}}Job::Private +{ + public: + {{#properties}}{{dataType}} {{paramName}}; + {{/properties}} +}; +{{/ properties?}}{{/normalResponse?}}{{/responses}} +{{camelCaseOperationId}}Job::{{camelCaseOperationId}}Job({{#allParams}}{{#avoidCopy?}}const {{dataType}}&{{/avoidCopy?}}{{^avoidCopy?}}{{dataType}}{{/avoidCopy?}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) + : BaseJob(HttpVerb::{{#@cap}}{{#@tolower}}{{httpMethod}}{{/@tolower}}{{/@cap}}, "{{camelCaseOperationId}}Job", + basePath{{#pathParts}} % {{part}}{{/pathParts}}, + Query {{^queryParams}}{ }{{/queryParams}}{{#queryParams?}}{ + {{#queryParams}}{ "{{baseName}}", toJson({{paramName}}).toString() }{{#hasMore}}, + {{/hasMore}}{{/queryParams}} + }{{/queryParams?}}, + Data {{^bodyParams}}{ }{{/bodyParams}}{{#bodyParams?}}{ + {{#bodyParams}}{ "{{baseName}}", toJson({{paramName}}) }{{#hasMore}}, + {{/hasMore}}{{/bodyParams}} + }{{/bodyParams?}}{{#skipAuth}}, false{{/skipAuth}} + ){{#responses}}{{#normalResponse?}}{{#properties?}}, d(new Private){{/properties?}}{{/normalResponse?}}{{/responses}} +{ } +{{# responses}}{{#normalResponse?}}{{#properties?}} +{{camelCaseOperationId}}Job::~{{camelCaseOperationId}}Job() +{ + delete d; +} +{{# properties}} +const {{dataType}}& {{camelCaseOperationId}}Job::{{paramName}}() const +{ + return d->{{paramName}}; +} +{{/ properties}}{{#returnFile?}} +BaseJob::Status {{camelCaseOperationId}}Job::parseReply(QByteArray data) +{ + {{#properties}}{{paramName}}{{/properties}} = data; + return Success; +}{{/ returnFile?}}{{^returnFile?}} +BaseJob::Status {{camelCaseOperationId}}Job::parseJson(const QJsonDocument& data) +{ + auto json = data.object(); + {{# properties}}{{#required?}}if (!json.contains("{{paramName}}")) + return { JsonParseError, + "The key '{{paramName}}' not found in the response" };{{/required?}} + d->{{paramName}} = fromJson<{{dataType}}>(json.value("{{paramName}}")); +{{/ properties}} + return Success; +}{{/ returnFile?}} +{{/properties?}}{{/normalResponse?}}{{/responses}}{{/operation}}{{/operations}} diff --git a/jobs/{{base}}.h.mustache b/jobs/{{base}}.h.mustache new file mode 100644 index 00000000..ad8a2f1f --- /dev/null +++ b/jobs/{{base}}.h.mustache @@ -0,0 +1,47 @@ +{{#@filePartial}}preamble{{/@filePartial}} + +#pragma once + +{{#operations}}#include "../basejob.h" +{{/operations}} +{{#imports}}#include {{.}} +{{/imports}} +{{#models}}#include "jobs/converters.h" +{{/models}} +namespace QMatrixClient +{ +{{#models}} // Data structures +{{# model}} + struct {{classname}} + { + {{#vars}}{{datatype}} {{name}}; + {{/vars}} + operator QJsonValue() const; + }; + + template <> struct FromJson<{{classname}}> + { + {{classname}} operator()(QJsonValue jv); + }; +{{/ model}} +{{/models}} +{{#operations}} // Operations +{{# operation}} + class {{camelCaseOperationId}}Job : public BaseJob + { + public: + explicit {{camelCaseOperationId}}Job({{#allParams}}{{#avoidCopy?}}const {{dataType}}&{{/avoidCopy?}}{{^avoidCopy?}}{{dataType}}{{/avoidCopy?}} {{paramName}}{{^required?}} = {{defaultValue}}{{^defaultValue}}{}{{/defaultValue}}{{/required?}}{{#hasMore}}, {{/hasMore}}{{/allParams}}); +{{# responses}}{{#normalResponse?}}{{#properties?}} + ~{{camelCaseOperationId}}Job() override; + + {{#properties}}const {{dataType}}& {{paramName}}() const; + {{/properties}} + protected: + {{^returnFile}}Status parseJson(const QJsonDocument& data) override;{{/returnFile}} + {{#returnFile?}}Status parseReply(QByteArray data) override;{{/returnFile?}} + private: + class Private; + Private* d;{{/properties?}}{{/normalResponse?}}{{/responses}} + };{{/operation}} +{{/operations}} +} // namespace QMatrixClient |