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.

fellow.h 2.1 kB

8 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #ifndef FELLOW_H
  2. #define FELLOW_H
  3. #include <string>
  4. #include <memory>
  5. #include <sstream>
  6. using namespace std;
  7. class Fellow
  8. {
  9. public:
  10. string getIp() const{return mIp;}
  11. string getName() const{return mName.empty() ? mPcName : mName;}
  12. string getHost() const{return mHost;}
  13. string getMac() const{return mMac;}
  14. bool isOnLine() const{return mOnLine;}
  15. string version() const{return mVersion;}
  16. void setIp(const string& value){
  17. mIp = value;
  18. }
  19. void setName(const string& value){
  20. mName = value;
  21. }
  22. void setHost(const string& value){
  23. mHost = value;
  24. }
  25. void setMac(const string& value){
  26. mMac = value;
  27. }
  28. void setOnLine(bool value){
  29. mOnLine = value;
  30. }
  31. void setVersion(const string& value){
  32. mVersion = value;
  33. }
  34. void setPcName(const string& value){
  35. mPcName = value;
  36. }
  37. bool update(const Fellow& fellow)
  38. {
  39. bool changed = false;
  40. if (!fellow.mName.empty() && mName != fellow.mName){
  41. mName = fellow.mName;
  42. changed=true;
  43. }
  44. if (!fellow.mMac.empty() && mMac != fellow.mMac){
  45. mMac = fellow.mMac;
  46. changed=true;
  47. }
  48. if (mOnLine != fellow.mOnLine){
  49. mOnLine = fellow.mOnLine;
  50. changed=true;
  51. }
  52. return changed;
  53. }
  54. bool operator == (const Fellow& fellow)
  55. {
  56. return isSame(fellow);
  57. }
  58. bool isSame(const Fellow& fellow)
  59. {
  60. return mIp == fellow.mIp || (!mMac.empty() && mMac == fellow.mMac);
  61. }
  62. string toString() const
  63. {
  64. ostringstream os;
  65. os<<"["
  66. <<"ip="<<mIp
  67. <<",name="<<mName
  68. <<",host="<<mHost
  69. <<",pcname="<<mPcName
  70. <<",mac="<<mMac
  71. <<",online="<<mOnLine
  72. <<",version="<<mVersion
  73. <<"]";
  74. return os.str();
  75. }
  76. private:
  77. string mIp;
  78. string mPcName;
  79. string mName;
  80. string mHost;
  81. string mMac;
  82. bool mOnLine;
  83. string mVersion;
  84. };
  85. #endif // FELLOW_H

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

Contributors (1)