2023-04-17 03:05:53 +00:00

93 lines
1.9 KiB
C++

#pragma once
#include <a8/uuid.h>
#include <a8/singleton.h>
namespace a8
{
struct UdpPacket;
}
struct MsgNode;
struct UdpMsgNode;
class App : public a8::Singleton<App>
{
private:
App() {};
friend class a8::Singleton<App>;
public:
bool Init(int argc, char* argv[]);
void UnInit();
int Run();
void AddSocketMsg(SocketFrom_e sockfrom,
int sockhandle,
long ip_saddr,
unsigned short msgid,
unsigned int seqid,
const char *msgbody,
int bodylen);
void AddUdpMsg(a8::UdpPacket* pkt);
void NotifyLoopCond();
bool HasFlag(int flag);
private:
void QuickExecute();
void SlowerExecute();
void Schedule();
bool HasTask();
void DispatchMsg();
void DispatchUdpMsg();
void ProcessClientMsg(f8::MsgHdr& hdr);
void ProcessMasterServerMsg(f8::MsgHdr& hdr);
void ProcessTargetServerMsg(f8::MsgHdr& hdr);
void InitLog();
void UnInitLog();
bool ParseOpt();
void FreeSocketMsgQueue();
void FreeUdpMsgQueue();
public:
int argc = 0;
char** argv = nullptr;
volatile bool terminated = false;
volatile bool shutdowned = false;
std::set<int> flags;
PerfMonitor perf;
a8::uuid::SnowFlake uuid;
public:
int node_id = 0;
int instance_id = 0;
private:
std::mutex *loop_mutex_ = nullptr;
std::condition_variable *loop_cond_ = nullptr;
std::mutex* msg_mutex_ = nullptr;
MsgNode* top_node_ = nullptr;
MsgNode* bot_node_ = nullptr;
MsgNode* work_node_ = nullptr;
std::mutex* udp_msg_mutex_ = nullptr;
UdpMsgNode* udp_top_node_ = nullptr;
UdpMsgNode* udp_bot_node_ = nullptr;
UdpMsgNode* udp_work_node_ = nullptr;
public:
int msgnode_size_ = 0 ;
int udp_msgnode_size_ = 0 ;
int working_msgnode_size_ = 0;
int udp_working_msgnode_size_ = 0;
};