TypeUnit.pas 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. unit TypeUnit;
  2. interface
  3. uses Windows, Messages, Forms, IdTcpServer, TypeConfig;
  4. const
  5. SM_BASE = WM_USER + 200;
  6. SM_ClientCount = SM_BASE + 1;
  7. SM_Status = SM_BASE + 2;
  8. type
  9. TOperType = (otAdd, otDelete, otModify);
  10. {客户信息记录}
  11. TInfoRecd = record
  12. IP: string;
  13. User: Integer;
  14. Action: Integer; {0: Add 1: Delete -1: check}
  15. end;
  16. PInfoRecd = ^TInfoRecd;
  17. {线程信息记录}
  18. TThrdsRecd = record
  19. Thread: TIdPeerThread;
  20. IP : string;
  21. User : Integer;
  22. end;
  23. PThrdsRecd = ^TThrdsRecd;
  24. TLinkControl = class
  25. private
  26. FV0Count: Integer;
  27. FV1Count: Integer;
  28. FV2Count: Integer;
  29. FV0MaxLinks: Integer;
  30. FV1MaxLinks: Integer;
  31. FV2MaxLinks: Integer;
  32. procedure RefreshAppCount;
  33. public
  34. procedure AddCount(AType: Integer);
  35. procedure DeleteCount(AType: Integer);
  36. function CheckIsFull(AType: Integer): Boolean;
  37. procedure InitCount;
  38. property V0MaxLinks: Integer read FV0MaxLinks write FV0MaxLinks;
  39. property V1MaxLinks: Integer read FV1MaxLinks write FV1MaxLinks;
  40. property V2MaxLinks: Integer read FV2MaxLinks write FV2MaxLinks;
  41. end;
  42. implementation
  43. { TLinkControl }
  44. procedure TLinkControl.AddCount(AType: Integer);
  45. begin
  46. case AType of
  47. Flag_Version_0: InterlockedIncrement(FV0Count);
  48. end;
  49. RefreshAppCount;
  50. end;
  51. function TLinkControl.CheckIsFull(AType: Integer): Boolean;
  52. begin
  53. Result := True;
  54. case AType of
  55. Flag_Version_0: if FV0Count < FV0MaxLinks then Result := False;
  56. end;
  57. end;
  58. procedure TLinkControl.DeleteCount(AType: Integer);
  59. begin
  60. case AType of
  61. Flag_Version_0: if FV0Count > 0 then InterlockedDecrement(FV0Count);
  62. end;
  63. RefreshAppCount;
  64. end;
  65. procedure TLinkControl.InitCount;
  66. begin
  67. FV0Count := 0;
  68. RefreshAppCount;
  69. end;
  70. procedure TLinkControl.RefreshAppCount;
  71. var
  72. wpValue, lpValue: Integer;
  73. begin
  74. wpValue := FV0Count;
  75. wpValue := wpValue shl 16;
  76. wpValue := wpValue + FV1Count;
  77. lpValue := FV2Count;
  78. SendMessage(Application.MainForm.Handle, SM_ClientCount, wpValue, lpValue);
  79. end;
  80. end.