Init Commit
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
cmake-build-*/
|
||||
.idea/
|
||||
26
CMakeLists.txt
Normal file
26
CMakeLists.txt
Normal file
@@ -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 ()
|
||||
0
Example/CMakeLists.txt
Normal file
0
Example/CMakeLists.txt
Normal file
21
QtRO/CMakeLists.txt
Normal file
21
QtRO/CMakeLists.txt
Normal file
@@ -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})
|
||||
8
QtRO/Options.rep
Normal file
8
QtRO/Options.rep
Normal file
@@ -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))
|
||||
}
|
||||
3
QtRO/ServiceStatus.rep
Normal file
3
QtRO/ServiceStatus.rep
Normal file
@@ -0,0 +1,3 @@
|
||||
class ServiceStatus{
|
||||
SLOT(void reportStatus(QString appId,QString appName))
|
||||
}
|
||||
46
Server/CMakeLists.txt
Normal file
46
Server/CMakeLists.txt
Normal file
@@ -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
|
||||
"$<TARGET_FILE_DIR:${PROJECT_NAME}>/plugins/platforms/")
|
||||
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
"${QT_INSTALL_PATH}/plugins/platforms/qwindows${DEBUG_SUFFIX}.dll"
|
||||
"$<TARGET_FILE_DIR:${PROJECT_NAME}>/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"
|
||||
"$<TARGET_FILE_DIR:${PROJECT_NAME}>")
|
||||
endforeach (QT_LIB)
|
||||
endif ()
|
||||
11
Server/Service/CMakeLists.txt
Normal file
11
Server/Service/CMakeLists.txt
Normal file
@@ -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)
|
||||
30
Server/Service/Options.cpp
Normal file
30
Server/Service/Options.cpp
Normal file
@@ -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) {
|
||||
|
||||
}
|
||||
33
Server/Service/Options.h
Normal file
33
Server/Service/Options.h
Normal file
@@ -0,0 +1,33 @@
|
||||
//
|
||||
// Created by fly on 2021/12/17.
|
||||
//
|
||||
|
||||
#ifndef REGISTRYCENTER_OPTIONS_H
|
||||
#define REGISTRYCENTER_OPTIONS_H
|
||||
|
||||
#include <rep_Options_source.h>
|
||||
|
||||
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
|
||||
18
Server/Service/ServiceStatus.cpp
Normal file
18
Server/Service/ServiceStatus.cpp
Normal file
@@ -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) {
|
||||
|
||||
}
|
||||
22
Server/Service/ServiceStatus.h
Normal file
22
Server/Service/ServiceStatus.h
Normal file
@@ -0,0 +1,22 @@
|
||||
//
|
||||
// Created by fly on 2021/12/17.
|
||||
//
|
||||
|
||||
#ifndef REGISTRYCENTER_SERVICESTATUS_H
|
||||
#define REGISTRYCENTER_SERVICESTATUS_H
|
||||
|
||||
#include <rep_ServiceStatus_source.h>
|
||||
|
||||
|
||||
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
|
||||
53
Server/main.cpp
Normal file
53
Server/main.cpp
Normal file
@@ -0,0 +1,53 @@
|
||||
#include <QCoreApplication>
|
||||
#include <QRemoteObjectRegistryHost>
|
||||
#include <QSettings>
|
||||
#include <QFile>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QScopedPointer>
|
||||
|
||||
|
||||
#include "Service/ServiceStatus.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
QCoreApplication a(argc, argv);
|
||||
|
||||
QScopedPointer<QSettings> 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();
|
||||
}
|
||||
2
conf/registry.ini
Normal file
2
conf/registry.ini
Normal file
@@ -0,0 +1,2 @@
|
||||
[registry]
|
||||
url=tcp://*:7478
|
||||
Reference in New Issue
Block a user