#ifndef FEIQENGINE_H #define FEIQENGINE_H #include "content.h" #include "feiqcommu.h" #include #include #include #include #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 send(shared_ptr fellow, shared_ptr content); pair sendFiles(shared_ptr fellow, list > &files); bool downloadFile(FileTask* task); public: pair 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); void onBrEntry(shared_ptr post); void onBrExit(shared_ptr post); void onMsg(shared_ptr post); void onSendCheck(shared_ptr post); void onReadCheck(shared_ptr post); void onSendTimeo(IdType packetId, const string &ip, shared_ptr content); void onReadMessage(shared_ptr post); private: void fileServerHandler(unique_ptr client, int packetNo, int fileId, int offset); private: shared_ptr addOrUpdateFellow(shared_ptr fellow); void dispatchMsg(shared_ptr msg); void broadcastToCurstomGroup(SendProtocol& protocol); private: FeiqCommu mCommu; vector> mRecvProtocols; FeiqModel mModel; string mHost; string mName; MsgQueueThread mMsgThd; IFeiqView* mView; vector mBroadcast; bool mStarted=false; AsynWait mAsyncWait;//异步等待对方回包 struct EnumClassHash { template std::size_t operator()(T t) const { return static_cast(t); } }; //可以用unique_ptr,但是unique_ptr要求知道具体定义 unordered_map, EnumClassHash> mContentSender; }; #endif // FEIQENGINE_H