From acfb9a3daed086c86d3b23e76d9c5adb81e3586d Mon Sep 17 00:00:00 2001 From: zynfly Date: Sat, 18 Dec 2021 11:27:44 +0800 Subject: [PATCH] Init Commit --- .gitignore | 2 ++ CMakeLists.txt | 26 ++++++++++++++++ Example/CMakeLists.txt | 0 QtRO/CMakeLists.txt | 21 +++++++++++++ QtRO/Options.rep | 8 +++++ QtRO/ServiceStatus.rep | 3 ++ Server/CMakeLists.txt | 46 +++++++++++++++++++++++++++ Server/Service/CMakeLists.txt | 11 +++++++ Server/Service/Options.cpp | 30 ++++++++++++++++++ Server/Service/Options.h | 33 ++++++++++++++++++++ Server/Service/ServiceStatus.cpp | 18 +++++++++++ Server/Service/ServiceStatus.h | 22 +++++++++++++ Server/main.cpp | 53 ++++++++++++++++++++++++++++++++ conf/registry.ini | 2 ++ 14 files changed, 275 insertions(+) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 Example/CMakeLists.txt create mode 100644 QtRO/CMakeLists.txt create mode 100644 QtRO/Options.rep create mode 100644 QtRO/ServiceStatus.rep create mode 100644 Server/CMakeLists.txt create mode 100644 Server/Service/CMakeLists.txt create mode 100644 Server/Service/Options.cpp create mode 100644 Server/Service/Options.h create mode 100644 Server/Service/ServiceStatus.cpp create mode 100644 Server/Service/ServiceStatus.h create mode 100644 Server/main.cpp create mode 100644 conf/registry.ini diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e3fcfb5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +cmake-build-*/ +.idea/ \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..bd9cce3 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,26 @@ +cmake_minimum_required(VERSION 3.21) +project(RegistryCenter) + +set(CMAKE_CXX_STANDARD 17) + + +if (NOT CMAKE_PREFIX_PATH) + set(CMAKE_PREFIX_PATH "Z:\\Qt\\5.15.2\\msvc2019_64") +endif () + +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) +set(CMAKE_AUTOUIC ON) + + +set(QT_LIBS Core RemoteObjects Network Sql) + +find_package(Qt5 COMPONENTS + ${QT_LIBS} + REQUIRED) + +add_subdirectory(QtRO) +if (NOT ONLY_REGISTRY_CENTER_CLIENT) + add_subdirectory(Server) + add_subdirectory(Example) +endif () diff --git a/Example/CMakeLists.txt b/Example/CMakeLists.txt new file mode 100644 index 0000000..e69de29 diff --git a/QtRO/CMakeLists.txt b/QtRO/CMakeLists.txt new file mode 100644 index 0000000..dd9a26d --- /dev/null +++ b/QtRO/CMakeLists.txt @@ -0,0 +1,21 @@ +# ServiceStatus Source and Replica +qt_generate_repc(ServiceStatusRepSourceSrc ServiceStatus.rep SOURCE) +add_library(ServiceStatusSource STATIC ${ServiceStatusRepSourceSrc}) +target_link_libraries(ServiceStatusSource PUBLIC Qt5::RemoteObjects) +target_include_directories(ServiceStatusSource PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) + +qt_generate_repc(ServiceStatusRepReplicaSrc ServiceStatus.rep REPLICA) +add_library(ServiceStatusReplica STATIC ${ServiceStatusRepReplicaSrc}) +target_link_libraries(ServiceStatusReplica PUBLIC Qt5::RemoteObjects) +target_include_directories(ServiceStatusReplica PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) + +# Option Source and Replica +qt_generate_repc(OptionRepSourceSrc Options.rep SOURCE) +add_library(OptionSource STATIC ${OptionRepSourceSrc}) +target_link_libraries(OptionSource PUBLIC Qt5::RemoteObjects) +target_include_directories(OptionSource PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) + +qt_generate_repc(OptionRepReplicaSrc Options.rep REPLICA) +add_library(OptionReplica STATIC ${OptionRepReplicaSrc}) +target_link_libraries(OptionReplica PUBLIC Qt5::RemoteObjects) +target_include_directories(OptionReplica PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) \ No newline at end of file diff --git a/QtRO/Options.rep b/QtRO/Options.rep new file mode 100644 index 0000000..1e1d689 --- /dev/null +++ b/QtRO/Options.rep @@ -0,0 +1,8 @@ +class Options{ + ENUM OptionType{READONLY, TYPE_LINE_EDIT, TYPE_COMBO_BOX} + SLOT(void registerOption(QString optionId, QString optionName, QVariant defaultValue, OptionType type, bool autoLoad = false, QString editConfig = "", QString description = "")) + SLOT(QVariant getOption(QString optionId)) + SLOT(void setOption(QString optionId, QVariant value)) + + SIGNAL(optionChanged(QString optionId, QVariant value)) +} \ No newline at end of file diff --git a/QtRO/ServiceStatus.rep b/QtRO/ServiceStatus.rep new file mode 100644 index 0000000..32b4285 --- /dev/null +++ b/QtRO/ServiceStatus.rep @@ -0,0 +1,3 @@ +class ServiceStatus{ + SLOT(void reportStatus(QString appId,QString appName)) +} \ No newline at end of file diff --git a/Server/CMakeLists.txt b/Server/CMakeLists.txt new file mode 100644 index 0000000..c0eefd0 --- /dev/null +++ b/Server/CMakeLists.txt @@ -0,0 +1,46 @@ +project(RegistryCenterServer) + + +add_subdirectory(Service) +set( + RegistryCenterServer_SRCS + main.cpp +) + +add_executable(${PROJECT_NAME} ${RegistryCenterServer_SRCS}) +target_link_libraries( + ${PROJECT_NAME} + Qt5::Core + Qt5::RemoteObjects +) +target_link_libraries(${PROJECT_NAME} ServerService) + + +if (WIN32) + set(DEBUG_SUFFIX) + if (MSVC AND (CMAKE_BUILD_TYPE MATCHES "Debug")) + set(DEBUG_SUFFIX "d") + endif () + set(QT_INSTALL_PATH "${CMAKE_PREFIX_PATH}") + if (NOT EXISTS "${QT_INSTALL_PATH}/bin") + set(QT_INSTALL_PATH "${QT_INSTALL_PATH}/..") + if (NOT EXISTS "${QT_INSTALL_PATH}/bin") + set(QT_INSTALL_PATH "${QT_INSTALL_PATH}/..") + endif () + endif () + if (EXISTS "${QT_INSTALL_PATH}/plugins/platforms/qwindows${DEBUG_SUFFIX}.dll") + add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E make_directory + "$/plugins/platforms/") + add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + "${QT_INSTALL_PATH}/plugins/platforms/qwindows${DEBUG_SUFFIX}.dll" + "$/plugins/platforms/") + endif () + foreach (QT_LIB ${QT_LIBS}) + add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + "${QT_INSTALL_PATH}/bin/Qt5${QT_LIB}${DEBUG_SUFFIX}.dll" + "$") + endforeach (QT_LIB) +endif () diff --git a/Server/Service/CMakeLists.txt b/Server/Service/CMakeLists.txt new file mode 100644 index 0000000..e6d7f0f --- /dev/null +++ b/Server/Service/CMakeLists.txt @@ -0,0 +1,11 @@ +set( + ServerServiceSrcs + ServiceStatus.cpp + ServiceStatus.h + Options.cpp + Options.h +) + +add_library(ServerService STATIC ${ServerServiceSrcs}) +target_link_libraries(ServerService ServiceStatusSource) +target_link_libraries(ServerService OptionSource) \ No newline at end of file diff --git a/Server/Service/Options.cpp b/Server/Service/Options.cpp new file mode 100644 index 0000000..053a6aa --- /dev/null +++ b/Server/Service/Options.cpp @@ -0,0 +1,30 @@ +// +// Created by fly on 2021/12/17. +// + +#include "Options.h" + + +Options::Options(QObject *parent) : OptionsSource(parent) { + +} + +void Options::registerOption( + QString optionId, + QString optionName, + QVariant defaultValue, + OptionsSource::OptionType type, + bool autoLoad, + QString editConfig, + QString description +) { + +} + +QVariant Options::getOption(QString optionId) { + return {}; +} + +void Options::setOption(QString optionId, QVariant value) { + +} diff --git a/Server/Service/Options.h b/Server/Service/Options.h new file mode 100644 index 0000000..5cf7319 --- /dev/null +++ b/Server/Service/Options.h @@ -0,0 +1,33 @@ +// +// Created by fly on 2021/12/17. +// + +#ifndef REGISTRYCENTER_OPTIONS_H +#define REGISTRYCENTER_OPTIONS_H + +#include + +class Options : public OptionsSource { +Q_OBJECT +public: + explicit Options(QObject *parent = nullptr); + + ~Options() override = default; + + void registerOption( + QString optionId, + QString optionName, + QVariant defaultValue, + OptionsSource::OptionType type, + bool autoLoad, + QString editConfig, + QString description + ) override; + + QVariant getOption(QString optionId) override; + + void setOption(QString optionId, QVariant value) override; +}; + + +#endif //REGISTRYCENTER_OPTIONS_H diff --git a/Server/Service/ServiceStatus.cpp b/Server/Service/ServiceStatus.cpp new file mode 100644 index 0000000..789a8c9 --- /dev/null +++ b/Server/Service/ServiceStatus.cpp @@ -0,0 +1,18 @@ +// +// Created by fly on 2021/12/17. +// + +#include "ServiceStatus.h" + + +ServiceStatus::ServiceStatus(QObject *parent) : ServiceStatusSource(parent) { + +} + +ServiceStatus::~ServiceStatus() { + +} + +void ServiceStatus::reportStatus(QString appId, QString appName) { + +} diff --git a/Server/Service/ServiceStatus.h b/Server/Service/ServiceStatus.h new file mode 100644 index 0000000..18fec2d --- /dev/null +++ b/Server/Service/ServiceStatus.h @@ -0,0 +1,22 @@ +// +// Created by fly on 2021/12/17. +// + +#ifndef REGISTRYCENTER_SERVICESTATUS_H +#define REGISTRYCENTER_SERVICESTATUS_H + +#include + + +class ServiceStatus : public ServiceStatusSource { +Q_OBJECT +public: + explicit ServiceStatus(QObject *parent = nullptr); + + ~ServiceStatus() override; + + void reportStatus(QString appId, QString appName) override; +}; + + +#endif //REGISTRYCENTER_SERVICESTATUS_H diff --git a/Server/main.cpp b/Server/main.cpp new file mode 100644 index 0000000..8cb097f --- /dev/null +++ b/Server/main.cpp @@ -0,0 +1,53 @@ +#include +#include +#include +#include +#include +#include +#include + + +#include "Service/ServiceStatus.h" + +int main(int argc, char *argv[]) { + QCoreApplication a(argc, argv); + + QScopedPointer settings(new QSettings); + + do { + auto arguments = QCoreApplication::arguments(); + //没有传入配置文件路径 + if (arguments.size() < 2) { + break; + } + const auto &configFile = arguments.at(1); + //传入的路径文件不存在 + if (!QFile::exists(configFile)) { + break; + } + + settings.reset( + new QSettings( + configFile, + QSettings::IniFormat + ) + ); + } while (false); + + //启动注册中心服务 + QRemoteObjectRegistryHost registryHost( + QUrl( + settings->value( + "registry/url", + "tcp://*:7478" + ).toString() + ) + ); + + //服务状态监控服务 + auto *serviceStatus = new ServiceStatus; + registryHost.enableRemoting(serviceStatus); + + + return QCoreApplication::exec(); +} diff --git a/conf/registry.ini b/conf/registry.ini new file mode 100644 index 0000000..18c2b81 --- /dev/null +++ b/conf/registry.ini @@ -0,0 +1,2 @@ +[registry] +url=tcp://*:7478 \ No newline at end of file