dbugmsg.pp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. {
  2. This file is part of the Free Component library.
  3. Copyright (c) 2005 by Michael Van Canneyt, member of
  4. the Free Pascal development team
  5. Debugserver Client/Server common code.
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program 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.
  11. **********************************************************************}
  12. {$mode objfpc}
  13. {$h+}
  14. {$IFNDEF FPC_DOTTEDUNITS}
  15. unit dbugmsg;
  16. {$ENDIF FPC_DOTTEDUNITS}
  17. interface
  18. {$IFDEF FPC_DOTTEDUNITS}
  19. uses System.Classes;
  20. {$ELSE FPC_DOTTEDUNITS}
  21. uses Classes;
  22. {$ENDIF FPC_DOTTEDUNITS}
  23. Const
  24. DebugServerID = 'fpcdebugserver'; { compiled IPC server's IDentifiant-name. Should be the same as the compiled IPC client dbugintf.DefaultDebugServer }
  25. lctStop = -1;
  26. lctInformation = 0;
  27. lctWarning = 1;
  28. lctError = 2;
  29. lctIdentify = 3;
  30. Type
  31. TDebugMessage = Record
  32. MsgType : Integer;
  33. MsgTimeStamp : TDateTime;
  34. Msg : String;
  35. end;
  36. Procedure ReadDebugMessageFromStream(AStream : TStream; Var Msg : TDebugMessage);
  37. Procedure WriteDebugMessageToStream(AStream : TStream; Const Msg : TDebugMessage);
  38. Function DebugMessageName(msgType : Integer) : String;
  39. implementation
  40. resourcestring
  41. SStop = 'Stop';
  42. SInformation = 'Information';
  43. SWarning = 'Warning';
  44. SError = 'Error';
  45. SIdentify = 'Identify';
  46. SUnknown = 'Unknown';
  47. procedure ReadDebugMessageFromStream(AStream : TStream; Var Msg : TDebugMessage);
  48. Var
  49. MsgSize : Integer;
  50. begin
  51. With AStream do
  52. begin
  53. ReadBuffer(Msg.MsgType,SizeOf(Integer));
  54. ReadBuffer(Msg.MsgTimeStamp,SizeOf(TDateTime));
  55. ReadBuffer(MsgSize,SizeOf(Integer));
  56. SetLength(Msg.Msg,MsgSize);
  57. If (MsgSize<>0) then
  58. ReadBuffer(Msg.msg[1],MsgSize);
  59. end;
  60. end;
  61. procedure WriteDebugMessageToStream(AStream : TStream; Const Msg : TDebugMessage);
  62. Var
  63. MsgSize : Integer;
  64. begin
  65. With AStream do
  66. begin
  67. WriteBuffer(Msg.MsgType,SizeOf(Integer));
  68. WriteBuffer(Msg.MsgTimeStamp,SizeOf(TDateTime));
  69. MsgSize:=Length(Msg.Msg);
  70. WriteBuffer(MsgSize,SizeOf(Integer));
  71. WriteBuffer(Msg.msg[1],MsgSize);
  72. end;
  73. end;
  74. Function DebugMessageName(msgType : Integer) : String;
  75. begin
  76. Case MsgType of
  77. lctStop : Result:=SStop;
  78. lctInformation : Result:=SInformation;
  79. lctWarning : Result:=SWarning;
  80. lctError : Result:=SError;
  81. lctIdentify : Result:=SIdentify;
  82. else
  83. Result:=SUnknown;
  84. end;
  85. end;
  86. end.