Skip to content

Commit

Permalink
Json2proto (#15)
Browse files Browse the repository at this point in the history
* clan-tidy 11

* refactoring proto options

* first implementaion json2proto

* lazy initialization protobuf converters in producer
  • Loading branch information
RPG-18 authored Dec 4, 2021
1 parent 635a3b9 commit 352213a
Show file tree
Hide file tree
Showing 42 changed files with 1,107 additions and 230 deletions.
8 changes: 7 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Checks: "*,\
-llvm-header-guard,\
-llvm-namespace-comment,\
-llvmlibc-callee-namespace,\
-llvmlibc-restrict-system-libc-headers,\
-llvmlibc-implementation-in-namespace,\
-fuchsia-*,\
-google-default-arguments,\
-google-readability-namespace-comments,\
Expand Down Expand Up @@ -31,12 +34,15 @@ Checks: "*,\
-cppcoreguidelines-no-malloc,\
-cppcoreguidelines-non-private-member-variables-in-classes,\
-cppcoreguidelines-pro-bounds-constant-array-index,\
-cppcoreguidelines-avoid-non-const-global-variables,\
-misc-non-private-member-variables-in-classes,\
-readability-magic-numbers,\
-readability-implicit-bool-conversion,\
-readability-braces-around-statements,\
-readability-isolate-declaration,\
-bugprone-macro-parentheses,\
-bugprone-unused-return-value,\
-bugprone-suspicious-include,\
-cert-err58-cpp,\
-cert-err60-cpp"
-cert-err60-cpp,\
-readability-use-anyofallof"
17 changes: 2 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,14 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)

include(cmake/tools.cmake)
if ((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") OR (CMAKE_CXX_COMPILER_ID STREQUAL "GNU"))
add_compile_options("-Wall" "-Werror" "-Wextra" "-Wshadow" "-Wno-unused-result")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif ()

option(BUILD_OPTION_CLANG_TIDY "Build with clang-tidy enabled" OFF)
if (BUILD_OPTION_CLANG_TIDY)
find_program(CLANG_TIDY_EXE NAMES "clang-tidy")

if (CLANG_TIDY_EXE)
message(STATUS "Use clang-tidy: ${CLANG_TIDY_EXE}")
set(CMAKE_CXX_CLANG_TIDY clang-tidy -warnings-as-errors=* -header-filter='src/.*')
else ()
message(FATAL_ERROR "The clang-tidy executable not found!")
endif ()

else ()
message(STATUS "With NO clang-tidy build option")
endif ()

clang_tidy(-warnings-as-errors=* -header-filter='${CMAKE_SOURCE_DIR}/*')
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)

include_directories(3rdparty/modern-cpp-kafka/include
Expand Down
115 changes: 115 additions & 0 deletions cmake/tools.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#
# Copyright (C) 2018-2020 by George Cave - gcave@stablecoder.ca
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
# https://github.com/StableCoder/cmake-scripts

option(CLANG_TIDY "Turns on clang-tidy processing if it is found." OFF)
option(IWYU "Turns on include-what-you-use processing if it is found." OFF)
option(CPPCHECK "Turns on cppcheck processing if it is found." OFF)

# Adds clang-tidy checks to the compilation, with the given arguments being used
# as the options set.
macro(clang_tidy)
if(CLANG_TIDY AND CLANG_TIDY_EXE)
set(CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY_EXE} ${ARGN})
endif()
endmacro()

# Adds include_what_you_use to the compilation, with the given arguments being
# used as the options set.
macro(include_what_you_use)
if(IWYU AND IWYU_EXE)
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE ${IWYU_EXE} ${ARGN})
endif()
endmacro()

# Adds cppcheck to the compilation, with the given arguments being used as the
# options set.
macro(cppcheck)
if(CPPCHECK AND CPPCHECK_EXE)
set(CMAKE_CXX_CPPCHECK ${CPPCHECK_EXE} ${ARGN})
endif()
endmacro()

find_program(CLANG_TIDY_EXE NAMES "clang-tidy")
mark_as_advanced(FORCE CLANG_TIDY_EXE)
if(CLANG_TIDY_EXE)
message(STATUS "clang-tidy found: ${CLANG_TIDY_EXE}")
if(NOT CLANG_TIDY)
message(STATUS "clang-tidy NOT ENABLED via 'CLANG_TIDY' variable!")
set(CMAKE_CXX_CLANG_TIDY
""
CACHE STRING "" FORCE) # delete it
endif()
elseif(CLANG_TIDY)
message(SEND_ERROR "Cannot enable clang-tidy, as executable not found!")
set(CMAKE_CXX_CLANG_TIDY
""
CACHE STRING "" FORCE) # delete it
else()
message(STATUS "clang-tidy not found!")
set(CMAKE_CXX_CLANG_TIDY
""
CACHE STRING "" FORCE) # delete it
endif()

find_program(IWYU_EXE NAMES "include-what-you-use")
mark_as_advanced(FORCE IWYU_EXE)
if(IWYU_EXE)
message(STATUS "include-what-you-use found: ${IWYU_EXE}")
if(NOT IWYU)
message(STATUS "include-what-you-use NOT ENABLED via 'IWYU' variable!")
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE
""
CACHE STRING "" FORCE) # delete it
endif()
elseif(IWYU)
message(
SEND_ERROR "Cannot enable include-what-you-use, as executable not found!")
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE
""
CACHE STRING "" FORCE) # delete it
else()
message(STATUS "include-what-you-use not found!")
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE
""
CACHE STRING "" FORCE) # delete it
endif()

find_program(CPPCHECK_EXE NAMES "cppcheck")
mark_as_advanced(FORCE CPPCHECK_EXE)
if(CPPCHECK_EXE)
message(STATUS "cppcheck found: ${CPPCHECK_EXE}")
if(CPPECHECK)
set(CMAKE_CXX_CPPCHECK
"${CPPCHECK_EXE};--enable=warning,performance,portability,missingInclude;--template=\"[{severity}][{id}] {message} {callstack} \(On {file}:{line}\)\";--suppress=missingIncludeSystem;--quiet;--verbose;--force"
)
endif()
if(NOT CPPCHECK)
message(STATUS "cppcheck NOT ENABLED via 'CPPCHECK' variable!")
set(CMAKE_CXX_CPPCHECK
""
CACHE STRING "" FORCE) # delete it
endif()
elseif(CPPCHECK)
message(SEND_ERROR "Cannot enable cppcheck, as executable not found!")
set(CMAKE_CXX_CPPCHECK
""
CACHE STRING "" FORCE) # delete it
else()
message(STATUS "cppcheck not found!")
set(CMAKE_CXX_CPPCHECK
""
CACHE STRING "" FORCE) # delete it
endif()
5 changes: 4 additions & 1 deletion src/components/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ add_library(components
Types.h Types.cpp
Message.cpp Message.h
TopicCreator.cpp TopicCreator.h
ErrorWrap.cpp ErrorWrap.h Producer.cpp Producer.h)
ErrorWrap.cpp ErrorWrap.h
Producer.cpp Producer.h
ProtoOption.cpp ProtoOption.h
Helpers.cpp Helpers.h)

target_compile_definitions(components
PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
Expand Down
67 changes: 23 additions & 44 deletions src/components/Consumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,23 +363,20 @@ ErrorWrap Consumer::setConverter()
return ErrorWrap{};
}

if (m_typeSelector->valueType() == Protobuf) {
if (!m_typeSelector->valueProtoFile().isValid()) {
return ErrorWrap("converter", "path to proto not set");
}

if (m_typeSelector->valueProtoMessage().isEmpty()) {
return ErrorWrap("converter", "proto message not select");
m_consumer->setKeyConverter(nullptr);
m_consumer->setValueConverter(nullptr);
if (m_typeSelector->keyType() == Protobuf) {
auto [converter, err] = m_typeSelector->protoKey()->converter();
if (converter == nullptr) {
return err;
}
m_consumer->setKeyConverter(std::move(converter));
}

QStringList errors;
auto converter
= formats::protobuf::ProtobufConverter::fabric(m_typeSelector->valueProtoFile(),
m_typeSelector->valueProtoMessage(),
errors);
if (m_typeSelector->valueType() == Protobuf) {
auto [converter, err] = m_typeSelector->protoValue()->converter();
if (converter == nullptr) {
spdlog::error("failed create protobuf converter");
return ErrorWrap("consumer", errors.join('\n'));
return err;
}
m_consumer->setValueConverter(std::move(converter));
}
Expand All @@ -391,6 +388,8 @@ ConsumerTypeSelector::ConsumerTypeSelector(QObject *parent)
: QObject(parent)
, m_keyType(Types::String)
, m_valueType(Types::String)
, m_keyProto(nullptr)
, m_valueProto(nullptr)
{}

Types ConsumerTypeSelector::keyType() const
Expand All @@ -415,48 +414,28 @@ void ConsumerTypeSelector::setValueType(Types type)
emit typesChanged();
}

const QUrl &ConsumerTypeSelector::keyProtoFile()
{
return m_keyProtoFile;
}

void ConsumerTypeSelector::setKeyProtoFile(const QUrl &path)
{
m_keyProtoFile = path;
emit typesChanged();
}

const QString &ConsumerTypeSelector::keyProtoMessage()
{
return m_keyProtoMessage;
}

void ConsumerTypeSelector::setKeyProtoMessage(const QString &msg)
{
m_keyProtoMessage = msg;
emit typesChanged();
}

const QUrl &ConsumerTypeSelector::valueProtoFile()
ProtoOption *ConsumerTypeSelector::protoKey()
{
return m_valueProtoFile;
return m_keyProto;
}

void ConsumerTypeSelector::setValueProtoFile(const QUrl &path)
void ConsumerTypeSelector::setProtoKey(ProtoOption *option)
{
m_valueProtoFile = path;
m_keyProto = option;
emit typesChanged();
connect(m_keyProto, &ProtoOption::changed, this, &ConsumerTypeSelector::typesChanged);
}

const QString &ConsumerTypeSelector::valueProtoMessage()
ProtoOption *ConsumerTypeSelector::protoValue()
{
return m_valueProtoMessage;
return m_valueProto;
}

void ConsumerTypeSelector::setValueProtoMessage(const QString &msg)
void ConsumerTypeSelector::setProtoValue(ProtoOption *option)
{
m_valueProtoMessage = msg;
m_valueProto = option;
emit typesChanged();
connect(m_valueProto, &ProtoOption::changed, this, &ConsumerTypeSelector::typesChanged);
}

ConsumerLimiterSelector::ConsumerLimiterSelector(QObject *parent)
Expand Down
29 changes: 9 additions & 20 deletions src/components/Consumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "ClusterConfig.h"
#include "ErrorWrap.h"
#include "MessageModel.h"
#include "ProtoOption.h"
#include "Types.h"

namespace core {
Expand All @@ -28,11 +29,8 @@ class ConsumerTypeSelector : public QObject
Q_PROPERTY(Types keyType READ keyType WRITE setKeyType)
Q_PROPERTY(Types valueType READ valueType WRITE setValueType)

Q_PROPERTY(QUrl keyProtoFile READ keyProtoFile WRITE setKeyProtoFile)
Q_PROPERTY(QString keyProtoMessage READ keyProtoMessage WRITE setKeyProtoMessage)

Q_PROPERTY(QUrl valueProtoFile READ valueProtoFile WRITE setValueProtoFile)
Q_PROPERTY(QString valueProtoMessage READ valueProtoMessage WRITE setValueProtoMessage)
Q_PROPERTY(ProtoOption *protoKey READ protoKey WRITE setProtoKey)
Q_PROPERTY(ProtoOption *protoValue READ protoValue WRITE setProtoValue)

explicit ConsumerTypeSelector(QObject *parent = nullptr);

Expand All @@ -42,17 +40,11 @@ class ConsumerTypeSelector : public QObject
Types valueType() const;
void setValueType(Types type);

const QUrl &keyProtoFile();
void setKeyProtoFile(const QUrl &path);

const QString &keyProtoMessage();
void setKeyProtoMessage(const QString &msg);
ProtoOption *protoKey();
void setProtoKey(ProtoOption *option);

const QUrl &valueProtoFile();
void setValueProtoFile(const QUrl &path);

const QString &valueProtoMessage();
void setValueProtoMessage(const QString &msg);
ProtoOption *protoValue();
void setProtoValue(ProtoOption *option);

signals:

Expand All @@ -62,11 +54,8 @@ class ConsumerTypeSelector : public QObject
Types m_keyType;
Types m_valueType;

QUrl m_keyProtoFile;
QString m_keyProtoMessage;

QUrl m_valueProtoFile;
QString m_valueProtoMessage;
ProtoOption *m_keyProto;
ProtoOption *m_valueProto;
};

class ConsumerLimiterSelector;
Expand Down
42 changes: 42 additions & 0 deletions src/components/Helpers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <QtQml/QQmlEngine>

#include "Helpers.h"

#include "Cluster.h"
#include "ConfigModel.h"
#include "Consumer.h"
#include "ConsumerHelperModels.h"
#include "KafkaConnectivityTester.h"
#include "Producer.h"
#include "ProtoOption.h"
#include "TopicCreator.h"

void registerTypes()
{
qmlRegisterType<KafkaConnectivityTester>("plumber", 1, 0, "ConnectivityTester");
qmlRegisterType<ConfigModel>("plumber", 1, 0, "ConfigModel");
qmlRegisterType<Cluster>("plumber", 1, 0, "Cluster");
qmlRegisterType<TopicFilterModel>("plumber", 1, 0, "TopicFilterModel");
qmlRegisterType<Consumer>("plumber", 1, 0, "Consumer");
qmlRegisterType<ConsumerTypeSelector>("plumber", 1, 0, "ConsumerTypeSelector");
qmlRegisterType<ConsumerLimiterSelector>("plumber", 1, 0, "ConsumerLimiterSelector");
qmlRegisterType<ConsumerFilterSelector>("plumber", 1, 0, "ConsumerFilterSelector");
qmlRegisterType<ConsumerBeginningSelector>("plumber", 1, 0, "ConsumerBeginningSelector");
qmlRegisterType<TopicCreator>("plumber", 1, 0, "TopicCreator");

qmlRegisterType<Producer>("plumber", 1, 0, "Producer");
qmlRegisterType<ProducerOptions>("plumber", 1, 0, "ProducerOptions");
qmlRegisterType<ProtoOption>("plumber", 1, 0, "ProtoOption");

qmlRegisterType<ConsumerTypesModel>("plumber", 1, 0, "ConsumerTypesModel");
qmlRegisterType<CustomTypesModel>("plumber", 1, 0, "CustomTypesModel");
qmlRegisterType<StartFromTimeBasedModel>("plumber", 1, 0, "StartFromTimeBasedModel");
qmlRegisterType<FiltersModel>("plumber", 1, 0, "FiltersModel");
qmlRegisterType<LimitModel>("plumber", 1, 0, "LimitModel");
qmlRegisterType<MessageWrapper>("plumber", 1, 0, "MessageWrapper");
qmlRegisterType<HeaderTableModel>("plumber", 1, 0, "HeaderTableModel");

qmlRegisterAnonymousType<BrokerModel>("plumber", 1);
qmlRegisterAnonymousType<TopicModel>("plumber", 1);
qmlRegisterAnonymousType<MessageModel>("plumber", 1);
}
3 changes: 3 additions & 0 deletions src/components/Helpers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

void registerTypes();
Loading

0 comments on commit 352213a

Please sign in to comment.