100 lines
2.3 KiB
C++
100 lines
2.3 KiB
C++
#pragma once
|
|
|
|
#include <a8/singleton.h>
|
|
|
|
namespace a8
|
|
{
|
|
struct UdpPacket;
|
|
namespace uuid
|
|
{
|
|
class SnowFlake;
|
|
}
|
|
}
|
|
|
|
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,
|
|
int tag = ST_Tcp);
|
|
|
|
void AddUdpMsg(a8::UdpPacket* pkt);
|
|
|
|
void NotifyLoopCond();
|
|
bool HasFlag(int flag);
|
|
long long NewUuid();
|
|
int GetNodeId() { return node_id_; }
|
|
int GetInstanceId() { return instance_id_; }
|
|
PerfMonitor& GetPerf() { return perf_; }
|
|
int GetMsgNodeSize() { return msgnode_size_;}
|
|
int GetUdpMsgNodeSize() { return udp_msgnode_size_;}
|
|
|
|
private:
|
|
void QuickExecute();
|
|
void SlowerExecute();
|
|
void Schedule();
|
|
bool HasTask();
|
|
|
|
void DispatchMsg();
|
|
void DispatchUdpMsg();
|
|
|
|
void ProcessClientMsg(f8::MsgHdr& hdr, int tag);
|
|
void ProcessMasterServerMsg(f8::MsgHdr& hdr, int tag);
|
|
void ProcessTargetServerMsg(f8::MsgHdr& hdr, int tag);
|
|
|
|
void InitLog();
|
|
void UnInitLog();
|
|
|
|
bool ParseOpt();
|
|
void FreeSocketMsgQueue();
|
|
void FreeUdpMsgQueue();
|
|
|
|
private:
|
|
int argc_ = 0;
|
|
char** argv_ = nullptr;
|
|
PerfMonitor perf_;
|
|
volatile bool terminated_ = false;
|
|
volatile bool shutdowned_ = false;
|
|
|
|
int node_id_ = 0;
|
|
int instance_id_ = 0;
|
|
std::set<int> flags_;
|
|
|
|
std::shared_ptr<a8::uuid::SnowFlake> uuid_;
|
|
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;
|
|
|
|
int msgnode_size_ = 0 ;
|
|
int udp_msgnode_size_ = 0 ;
|
|
int working_msgnode_size_ = 0;
|
|
int udp_working_msgnode_size_ = 0;
|
|
|
|
};
|