2025-11-11 17:46:19 +08:00
|
|
|
#ifndef CC_APPLICATION_H
|
|
|
|
|
#define CC_APPLICATION_H
|
|
|
|
|
|
|
|
|
|
#include "CCThread.h"
|
|
|
|
|
#include "CCSystem.h"
|
|
|
|
|
#include "CCProcess.h"
|
|
|
|
|
|
|
|
|
|
namespace CTL {
|
|
|
|
|
struct AppParameter_t{
|
|
|
|
|
int argc = 0;
|
|
|
|
|
CCVector<String> argv;
|
|
|
|
|
};
|
|
|
|
|
class Application{
|
|
|
|
|
public:
|
|
|
|
|
Application(int argc, char** argv);
|
|
|
|
|
~Application();
|
|
|
|
|
static int Running(const Application* app = nullptr);
|
|
|
|
|
//--------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void SetApp(void* app);
|
|
|
|
|
void* GetApp();
|
|
|
|
|
//--------------------------------------------------------------------------------------------------------------
|
|
|
|
|
AppParameter_t GetParameter();
|
|
|
|
|
//--------------------------------------------------------------------------------------------------------------
|
|
|
|
|
static void Signal(Function<void()>&& func);
|
|
|
|
|
static void SetCloseFun(Function<void()>&& func);
|
|
|
|
|
static bool IsSingleInstance();
|
|
|
|
|
static void ReleaseLock();
|
|
|
|
|
static void StartDaemon(int argc, char **argv);
|
|
|
|
|
static void StopDaemon();
|
|
|
|
|
static bool IsDaemon();
|
|
|
|
|
//--------------------------------------------------------------------------------------------------------------
|
|
|
|
|
private:
|
|
|
|
|
AppParameter_t Parameter{};
|
|
|
|
|
void* App = nullptr;
|
2026-03-24 14:43:26 +08:00
|
|
|
static int DaemonTime; // Seconds
|
|
|
|
|
static bool DaemonFlag;
|
|
|
|
|
static Process process;
|
|
|
|
|
static CCQueue<Function<void()>> M_SignalQueues;
|
|
|
|
|
static Function<void()> func_Close;
|
|
|
|
|
static CCMutex M_Mutex;
|
|
|
|
|
static bool SingleInstance_t;
|
2025-11-11 17:46:19 +08:00
|
|
|
#ifdef _WIN32
|
2026-03-20 09:51:56 +08:00
|
|
|
inline static HANDLE mutex_handle{nullptr};
|
2025-11-11 17:46:19 +08:00
|
|
|
inline static const String mutex_name = "Global\\" + CTL::System::GetAppName();
|
|
|
|
|
#else
|
2026-03-24 14:43:26 +08:00
|
|
|
static int lock_fd;
|
|
|
|
|
static const String lock_file_path;
|
|
|
|
|
static bool SetFileReadPermission(const std::string &filePath);
|
2025-11-11 17:46:19 +08:00
|
|
|
#endif
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|