You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

feiqengine.h 2.7 kB

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

mac下的“飞秋”大多数只是飞鸽传书协议,而且未发现令人满意的开源项目,所以基于c++与qt实现了基础的飞秋协议。

Contributors (1)