summaryrefslogtreecommitdiff
path: root/fpcsrc/packages/fcl-process/src/dbugmsg.pp
blob: 2cb575824a8eea3f9ae267f5816e2e9050da7a37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
{
    This file is part of the Free Component library.
    Copyright (c) 2005 by Michael Van Canneyt, member of
    the Free Pascal development team

    Debugserver Client/Server common code.

    See the file COPYING.FPC, included in this distribution,
    for details about the copyright.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 **********************************************************************}
{$mode objfpc}
{$h+}
unit dbugmsg;

interface

uses Classes;

Const
  DebugServerID  : String = 'fpcdebugserver';

  lctStop        = -1;
  lctInformation = 0;
  lctWarning     = 1;
  lctError       = 2;
  lctIdentify    = 3;

Type
  TDebugMessage = Record
    MsgType      : Integer;
    MsgTimeStamp : TDateTime;
    Msg          : String;
  end;

Procedure ReadDebugMessageFromStream(AStream : TStream; Var Msg : TDebugMessage);
Procedure WriteDebugMessageToStream(AStream : TStream; Const Msg : TDebugMessage);
Function DebugMessageName(msgType : Integer) : String;


implementation

resourcestring
  SStop        = 'Stop';
  SInformation = 'Information';
  SWarning     = 'Warning';
  SError       = 'Error';
  SIdentify    = 'Identify';
  SUnknown     = 'Unknown';

procedure ReadDebugMessageFromStream(AStream : TStream; Var Msg : TDebugMessage);

Var
  MsgSize : Integer;

begin
  With AStream do
    begin
    ReadBuffer(Msg.MsgType,SizeOf(Integer));
    ReadBuffer(Msg.MsgTimeStamp,SizeOf(TDateTime));
    ReadBuffer(MsgSize,SizeOf(Integer));
    SetLength(Msg.Msg,MsgSize);
    If (MsgSize<>0) then
      ReadBuffer(Msg.msg[1],MsgSize);
    end;
end;

procedure WriteDebugMessageToStream(AStream : TStream; Const Msg : TDebugMessage);

Var
  MsgSize : Integer;

begin
  With AStream do
    begin
    WriteBuffer(Msg.MsgType,SizeOf(Integer));
    WriteBuffer(Msg.MsgTimeStamp,SizeOf(TDateTime));
    MsgSize:=Length(Msg.Msg);
    WriteBuffer(MsgSize,SizeOf(Integer));
    WriteBuffer(Msg.msg[1],MsgSize);
    end;
end;

Function DebugMessageName(msgType : Integer) : String;

begin
  Case MsgType of
    lctStop        : Result:=SStop;
    lctInformation : Result:=SInformation;
    lctWarning     : Result:=SWarning;
    lctError       : Result:=SError;
    lctIdentify    : Result:=SIdentify;
  else
    Result:=SUnknown;
  end;
end;

end.