54 lines
2.0 KiB
C
54 lines
2.0 KiB
C
|
|
#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;
|
||
|
|
inline static int DaemonTime = 1; // Seconds
|
||
|
|
inline static bool DaemonFlag = false;
|
||
|
|
inline static Process process;
|
||
|
|
inline static CCQueue<Function<void()>> M_SignalQueues;
|
||
|
|
inline static Function<void()> func_Close;
|
||
|
|
inline static CCMutex M_Mutex;
|
||
|
|
inline static bool SingleInstance_t = false;
|
||
|
|
#ifdef _WIN32
|
||
|
|
inline static HANDLE mutex_handle{0};
|
||
|
|
inline static const String mutex_name = "Global\\" + CTL::System::GetAppName();
|
||
|
|
#else
|
||
|
|
inline static int lock_fd = -1;
|
||
|
|
inline static const String lock_file_path = String("/tmp/") + System::GetAppName() + ".lock";
|
||
|
|
inline static bool SetFileReadPermission(const std::string &filePath);
|
||
|
|
#endif
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
#endif
|