2020-07-13 11:17:14 +08:00

97 lines
2.3 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:
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 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);
bool HasFlag(int flag);
long long NewUUID();
long long NewSeqId();
time_t BetweenDays(time_t time1, time_t time2);
bool IsTimeToReset(int time);
void PreProcAvatarUrl(int self_channel, int target_channel, std::string& target_avatar_url);
private:
void QuickExecute();
void SlowerExecute();
void Schedule();
bool HasTask();
void DispatchMsg();
void ProcessIMMsg();
void ProcessWSProxyMsg(f8::MsgHdr& hdr);
void ProcessIMServerMsg(f8::MsgHdr& hdr);
void ProcessIMConnMsg(f8::MsgHdr& hdr);
void ProcessMSConnMsg(f8::MsgHdr& hdr);
void InitLog();
void UnInitLog();
bool ParseOpt();
void FreeSocketMsgQueue();
void FreeIMMsgQueue();
public:
int argc = 0;
char** argv = nullptr;
volatile bool terminated = false;
volatile bool shutdowned = false;
std::set<int> flags;
a8::uuid::SnowFlake uuid;
public:
int instance_id = 0;
int nowtime = 0;
bool servicing = true;
private:
long long seq_id_ = 1000;
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;
};