-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathfeiqengine.h
More file actions
92 lines (80 loc) · 2.6 KB
/
feiqengine.h
File metadata and controls
92 lines (80 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#ifndef FEIQENGINE_H
#define FEIQENGINE_H
#include "content.h"
#include "feiqcommu.h"
#include <string>
#include <tuple>
#include <list>
#include <unordered_map>
#include "feiqmodel.h"
#include "msgqueuethread.h"
#include "ifeiqview.h"
#include "asynwait.h"
using namespace std;
class Post;
class ContentSender;
/**
* @brief The FeiqEngine class
* feiq以mvc模式架构,FeiqEngine是control部分,负责逻辑控制(以及具体协议来往)
*/
class FeiqEngine
{
public:
FeiqEngine();
public:
pair<bool, string> send(shared_ptr<Fellow> fellow, shared_ptr<Content> content);
pair<bool, string> sendFiles(shared_ptr<Fellow> fellow, list<shared_ptr<FileContent> > &files);
bool downloadFile(FileTask* task);
public:
pair<bool, string> start();
void stop();
void addToBroadcast(const string& ip);
void setMyHost(string host);
void setMyName(string name);
void setView(IFeiqView* view){mView = view;}
void sendImOnLine(const string& ip = "");
/**
* @brief enableIntervalDetect 当接入路由,被禁止发送广播包时,
* 启用间隔检测可每隔一段时间发送一次上线通知到指定网段,以实现检测。
*/
void enableIntervalDetect(int seconds);
public:
FeiqModel &getModel();
private://trigers
void onAnsEntry(shared_ptr<Post> post);
void onBrEntry(shared_ptr<Post> post);
void onBrExit(shared_ptr<Post> post);
void onMsg(shared_ptr<Post> post);
void onSendCheck(shared_ptr<Post> post);
void onReadCheck(shared_ptr<Post> post);
void onSendTimeo(IdType packetId, const string &ip, shared_ptr<Content> content);
void onReadMessage(shared_ptr<Post> post);
private:
void fileServerHandler(unique_ptr<TcpSocket> client, int packetNo, int fileId, int offset);
private:
shared_ptr<Fellow> addOrUpdateFellow(shared_ptr<Fellow> fellow);
void dispatchMsg(shared_ptr<ViewEvent> msg);
void broadcastToCurstomGroup(SendProtocol& protocol);
private:
FeiqCommu mCommu;
vector<unique_ptr<RecvProtocol>> mRecvProtocols;
FeiqModel mModel;
string mHost;
string mName;
MsgQueueThread<ViewEvent> mMsgThd;
IFeiqView* mView;
vector<string> mBroadcast;
bool mStarted=false;
AsynWait mAsyncWait;//异步等待对方回包
struct EnumClassHash
{
template <typename T>
std::size_t operator()(T t) const
{
return static_cast<std::size_t>(t);
}
};
//可以用unique_ptr,但是unique_ptr要求知道具体定义
unordered_map<ContentType, shared_ptr<ContentSender>, EnumClassHash> mContentSender;
};
#endif // FEIQENGINE_H