83 lines
1.8 KiB
C++
83 lines
1.8 KiB
C++
#pragma once
|
|
|
|
#include <a8/uuid.h>
|
|
|
|
struct MsgNode;
|
|
struct IMMsgNode;
|
|
class App : public a8::Singleton<App>
|
|
{
|
|
private:
|
|
App() {};
|
|
friend class a8::Singleton<App>;
|
|
|
|
public:
|
|
|
|
void 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 AddIMMsg(unsigned short imcmd, a8::XParams params);
|
|
|
|
void NotifyLoopCond();
|
|
|
|
a8::XParams* AddContext(long long context_id);
|
|
void DelContext(long long context_id);
|
|
a8::XParams* GetContext(long long context_id);
|
|
|
|
private:
|
|
void QuickExecute();
|
|
void SlowerExecute();
|
|
void Schedule();
|
|
bool HasTask();
|
|
|
|
void DispatchMsg();
|
|
void ProcessIMMsg();
|
|
|
|
void ProcessClientMsg(MsgHdr& hdr);
|
|
void ProcessTargetServerMsg(MsgHdr& hdr);
|
|
|
|
void InitLog();
|
|
void UnInitLog();
|
|
|
|
bool ParseOpt();
|
|
|
|
public:
|
|
int argc = 0;
|
|
char** argv = nullptr;
|
|
volatile bool terminated = false;
|
|
PerfMonitor perf;
|
|
a8::uuid::SnowFlake uuid;
|
|
|
|
public:
|
|
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* im_msg_mutex_ = nullptr;
|
|
IMMsgNode* im_top_node_ = nullptr;
|
|
IMMsgNode* im_bot_node_ = nullptr;
|
|
IMMsgNode* im_work_node_ = nullptr;
|
|
|
|
std::map<long long, a8::XParams> context_hash_;
|
|
|
|
public:
|
|
int msgnode_size_ = 0 ;
|
|
int working_msgnode_size_ = 0;
|
|
|
|
};
|