Init Commit
This commit is contained in:
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();
|
||||
}
|
||||
Reference in New Issue
Block a user