msgintf.pp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. unit msgintf;
  15. interface
  16. uses Classes;
  17. Const
  18. DebugServerID : String = 'fpcdebugserver';
  19. lctStop = -1;
  20. lctInformation = 0;
  21. lctWarning = 1;
  22. lctError = 2;
  23. lctIdentify = 3;
  24. Type
  25. TDebugMessage = Record
  26. MsgType : Integer;
  27. MsgTimeStamp : TDateTime;
  28. Msg : String;
  29. end;
  30. Procedure ReadDebugMessageFromStream(AStream : TStream; Var Msg : TDebugMessage);
  31. Procedure WriteDebugMessageToStream(AStream : TStream; Const Msg : TDebugMessage);
  32. Function DebugMessageName(msgType : Integer) : String;
  33. implementation
  34. resourcestring
  35. SStop = 'Stop';
  36. SInformation = 'Information';
  37. SWarning = 'Warning';
  38. SError = 'Error';
  39. SIdentify = 'Identify';
  40. SUnknown = 'Unknown';
  41. procedure ReadDebugMessageFromStream(AStream : TStream; Var Msg : TDebugMessage);
  42. Var
  43. MsgSize : Integer;
  44. begin
  45. With AStream do
  46. begin
  47. ReadBuffer(Msg.MsgType,SizeOf(Integer));
  48. ReadBuffer(Msg.MsgTimeStamp,SizeOf(TDateTime));
  49. ReadBuffer(MsgSize,SizeOf(Integer));
  50. SetLength(Msg.Msg,MsgSize);
  51. If (MsgSize<>0) then
  52. ReadBuffer(Msg.msg[1],MsgSize);
  53. end;
  54. end;
  55. procedure WriteDebugMessageToStream(AStream : TStream; Const Msg : TDebugMessage);
  56. Var
  57. MsgSize : Integer;
  58. begin
  59. With AStream do
  60. begin
  61. WriteBuffer(Msg.MsgType,SizeOf(Integer));
  62. WriteBuffer(Msg.MsgTimeStamp,SizeOf(TDateTime));
  63. MsgSize:=Length(Msg.Msg);
  64. WriteBuffer(MsgSize,SizeOf(Integer));
  65. WriteBuffer(Msg.msg[1],MsgSize);
  66. end;
  67. end;
  68. Function DebugMessageName(msgType : Integer) : String;
  69. begin
  70. Case MsgType of
  71. lctStop : Result:=SStop;
  72. lctInformation : Result:=SInformation;
  73. lctWarning : Result:=SWarning;
  74. lctError : Result:=SError;
  75. lctIdentify : Result:=SIdentify;
  76. else
  77. Result:=SUnknown;
  78. end;
  79. end;
  80. end.