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

ListConnInfo.h 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /* Copyright (C) 2002-2003 RealVNC Ltd. All Rights Reserved.
  2. *
  3. * This is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This software is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this software; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  16. * USA.
  17. */
  18. #ifndef __RFB_LISTCONNINFO_INCLUDED__
  19. #define __RFB_LISTCONNINFO_INCLUDED__
  20. #include <list>
  21. #include <rfb/util.h>
  22. namespace rfb {
  23. struct ListConnInfo {
  24. ListConnInfo() : disableClients(false) {}
  25. void Clear() {
  26. conn.clear();
  27. IP_address.clear();
  28. time_conn.clear();
  29. status.clear();
  30. }
  31. bool Empty() { return conn.empty();}
  32. void iBegin() {
  33. ci = conn.begin();
  34. Ii = IP_address.begin();
  35. ti = time_conn.begin();
  36. si = status.begin();
  37. }
  38. bool iEnd() { return ci == conn.end();}
  39. void iNext() {
  40. ci++;
  41. Ii++;
  42. ti++;
  43. si++;
  44. }
  45. void addInfo(void* Conn, char* IP, char* Time, int Status) {
  46. conn.push_back(Conn);
  47. IP_address.push_back(strDup(IP));
  48. time_conn.push_back(strDup(Time));
  49. status.push_back(Status);
  50. }
  51. void iGetCharInfo(char* buf[3]) {
  52. buf[0] = *Ii;
  53. buf[1] = *ti;
  54. switch (*si) {
  55. case 0:
  56. buf[2] = strDup("Full control");
  57. break;
  58. case 1:
  59. buf[2] = strDup("View only");
  60. break;
  61. case 2:
  62. buf[2] = strDup("Stop updating");
  63. break;
  64. default:
  65. buf[2] = strDup("Unknown");
  66. }
  67. }
  68. void* iGetConn() { return *ci;}
  69. int iGetStatus() { return *si;}
  70. void iSetStatus(int istatus) { *si = istatus;}
  71. void Copy(ListConnInfo* InputList) {
  72. Clear();
  73. if (InputList->Empty()) return;
  74. for (InputList->iBegin(); !InputList->iEnd(); InputList->iNext()) {
  75. iAdd(InputList);
  76. }
  77. setDisable(InputList->getDisable());
  78. }
  79. void iAdd (ListConnInfo* InputList) {
  80. char* buf[3];
  81. InputList->iGetCharInfo(buf);
  82. addInfo(InputList->iGetConn(), buf[0], buf[1], InputList->iGetStatus());
  83. }
  84. void setDisable(bool disable) {disableClients = disable;}
  85. bool getDisable() {return disableClients;}
  86. void setAllStatus(int stat) {
  87. std::list<int>::iterator st;
  88. for (st = status.begin(); st != status.end(); st++)
  89. *st = stat;
  90. }
  91. private:
  92. std::list<void*> conn;
  93. std::list<char*> IP_address;
  94. std::list<char*> time_conn;
  95. std::list<int> status;
  96. std::list<void*>::iterator ci;
  97. std::list<char*>::iterator Ii;
  98. std::list<char*>::iterator ti;
  99. std::list<int>::iterator si;
  100. bool disableClients;
  101. };
  102. };
  103. #endif