V1.0
This commit is contained in:
parent
306337b765
commit
675aa1930e
@ -1,5 +1,4 @@
|
||||
#include "IO/CCProcess.h"
|
||||
|
||||
#include <CCThread.h>
|
||||
|
||||
CTL::Process::Process(Process &p) {
|
||||
|
||||
@ -12,53 +12,11 @@ set(CMAKE_AUTORCC ON)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm|ARM|Armv[0-9]+")
|
||||
set(CMAKE_PREFIX_PATH "/home/xunb/Environment/ARM-Qt5.11.3")
|
||||
message(STATUS "Building for ARM")
|
||||
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|i686") # 显式添加 x86 支持
|
||||
set(CMAKE_PREFIX_PATH "/home/xunb/Environment/5.15.2/gcc_64")
|
||||
message(STATUS "Building for x86: ${CMAKE_PREFIX_PATH}")
|
||||
else()
|
||||
message(FATAL_ERROR "Unsupported architecture: ${CMAKE_SYSTEM_PROCESSOR}")
|
||||
endif()
|
||||
|
||||
|
||||
# QtCreator supports the following variables for Android, which are identical to qmake Android variables.
|
||||
# Check http://doc.qt.io/qt-5/deployment-android.html for more information.
|
||||
# They need to be set before the find_package(Qt5 ...) call.
|
||||
|
||||
#if(ANDROID)
|
||||
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
|
||||
# if (ANDROID_ABI STREQUAL "armeabi-v7a")
|
||||
# set(ANDROID_EXTRA_LIBS
|
||||
# ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libcrypto.so
|
||||
# ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libssl.so)
|
||||
# endif()
|
||||
#endif()
|
||||
set(Qt5_DIR "${CMAKE_PREFIX_PATH}/lib/cmake/Qt5") # 关键修复
|
||||
find_package(Qt5 COMPONENTS Widgets REQUIRED)
|
||||
message(STATUS "Qt5Widgets_LIBRARIES = ${Qt5Widgets_LIBRARIES}")
|
||||
if(ANDROID)
|
||||
add_library(IPBS_NSSM SHARED
|
||||
add_executable(IPBS_NSSM
|
||||
main.cpp
|
||||
)
|
||||
else()
|
||||
add_executable(IPBS_NSSM
|
||||
# WIN32
|
||||
main.cpp
|
||||
)
|
||||
endif()
|
||||
)
|
||||
|
||||
target_include_directories(IPBS_NSSM PUBLIC ${CC_API_INC})
|
||||
|
||||
target_link_libraries(IPBS_NSSM PRIVATE Qt5::Widgets CC_API)
|
||||
|
||||
#if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm|ARM|Armv[0-9]+")
|
||||
# target_link_libraries(IPBS_NSSM PRIVATE Qt5::Widgets CC_API)
|
||||
#else ()
|
||||
# target_link_libraries(IPBS_NSSM PRIVATE
|
||||
# ${CMAKE_PREFIX_PATH}/lib/libQt5Widgets.so.5.15.2
|
||||
# ${CMAKE_PREFIX_PATH}/lib/libQt5Core.so.5.15.2
|
||||
# CC_API
|
||||
# )
|
||||
#endif ()
|
||||
target_link_libraries(IPBS_NSSM PRIVATE CC_API)
|
||||
|
||||
64
main.cpp
64
main.cpp
@ -1,14 +1,12 @@
|
||||
#include <dirent.h>
|
||||
#include <QCoreApplication>
|
||||
#include <QString>
|
||||
#include <QFuture>
|
||||
#include <iostream>
|
||||
#include "CCThread.h"
|
||||
#include "QProcess"
|
||||
#include "QSharedMemory"
|
||||
#include <fstream>
|
||||
|
||||
#include "CCSystem.h"
|
||||
#include "CCApplication.h"
|
||||
#include "CCProcess.h"
|
||||
#include "CCSocket.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
@ -82,14 +80,23 @@ bool IsProcessRunning(const std::string& processName) {
|
||||
}
|
||||
|
||||
static bool Flag = true;
|
||||
inline CTL::Socket socket_t;
|
||||
|
||||
bool CloseConnect() {
|
||||
Flag = false;
|
||||
CTL::System::Println("CloseConnect");
|
||||
// CTL::System::Exit();
|
||||
return false;
|
||||
}
|
||||
|
||||
void CloseApp(const CTL::String& exe){
|
||||
#ifdef _WIN32
|
||||
const auto str = CTL::String::format("taskkill -f -t -im {}",exe.c_str());
|
||||
#elif __linux__
|
||||
const auto str = CTL::String::format("killall -9 {}",exe.c_str());
|
||||
#endif
|
||||
CTL::System::Execute(str);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if(argc < 3){
|
||||
return -2;
|
||||
@ -98,24 +105,45 @@ int main(int argc, char *argv[]) {
|
||||
std::cout << argv[1] << std::endl;
|
||||
std::cout << argv[2] << std::endl;
|
||||
std::cout << argv[3] << std::endl;
|
||||
static auto *shareMem = new QSharedMemory(argv[1]); //创建“SingleApp”的共享内存块
|
||||
if (!shareMem->create(1)){ //创建大小1b的内存
|
||||
CTL::System::Println("创建共享内存失败");
|
||||
delete shareMem;
|
||||
return -1;
|
||||
}
|
||||
QCoreApplication a(argc, argv);
|
||||
CTL::Application app(argc, argv);
|
||||
CC::SetCloseFun(CloseConnect);
|
||||
const CTL::String Bit = argv[1];
|
||||
if(Bit != "TCP_Daemon"){
|
||||
while (Flag){
|
||||
bool F = IsProcessRunning(argv[2]);
|
||||
// CTL::System::Println("IsProcessRunning %d",F ? 1 : 0);
|
||||
if(!F){
|
||||
QProcess::startDetached(argv[3]);
|
||||
CTL::Process app_t;
|
||||
CloseApp(argv[2]);
|
||||
app_t.AddCommand(argv[3]);
|
||||
app_t.Start();
|
||||
}
|
||||
CTL::Thread::SleepMS(5 * 1000);
|
||||
}
|
||||
CloseApp(argv[2]);
|
||||
}
|
||||
else{
|
||||
socket_t.Init(CTL::IPV4,CTL::TCP);
|
||||
while (Flag){
|
||||
const int Port = CTL::String(argv[2]).to_int();
|
||||
const bool F = socket_t.Connect("127.0.0.1",Port);
|
||||
if(F){
|
||||
char buffer[1024]{};
|
||||
const auto len = socket_t.RecvData(buffer,sizeof buffer);
|
||||
socket_t.Close();
|
||||
socket_t.Init(CTL::IPV4,CTL::TCP);
|
||||
CTL::System::Println("TCP_Daemon Close {}",argv[3]);
|
||||
}
|
||||
else{
|
||||
CTL::Process app_t;
|
||||
CloseApp(argv[4]);
|
||||
app_t.AddCommand(argv[3]);
|
||||
app_t.Start();
|
||||
CTL::System::Println("Auto Start {}",argv[3]);
|
||||
}
|
||||
CTL::Thread::SleepMS(5 * 1000);
|
||||
}
|
||||
}
|
||||
CTL::Thread::Sleep(1000 * 1000 * 5);
|
||||
|
||||
}
|
||||
// shareMem->detach();
|
||||
// return QCoreApplication::exec();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user