-
Notifications
You must be signed in to change notification settings - Fork 0
/
CmdStatsInfo.cpp
162 lines (149 loc) · 4.12 KB
/
CmdStatsInfo.cpp
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "CmdStatsInfo.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
//---------------------------------------------------------------------------
__fastcall TCmdStatsInfo::TCmdStatsInfo()
{
Commands = new TStringList();
}
//---------------------------------------------------------------------------
__fastcall TCmdStatsInfo::~TCmdStatsInfo()
{
Clear();
delete Commands;
}
//---------------------------------------------------------------------------
void __fastcall TCmdStatsInfo::AddCommand(AnsiString Cmd)
{
int i = GetCmdIndex(Cmd);
if (i == -1) {
TCmdInfo *ptr = (TCmdInfo *)malloc(sizeof(TCmdInfo));
if (ptr != NULL)
Commands->AddObject(Cmd, (TObject *)ptr);
else
throw Exception("Couldn\'t allocate memory!");
} else
ResetStats(i);
}
//---------------------------------------------------------------------------
void __fastcall TCmdStatsInfo::RemoveCommand(AnsiString Cmd)
{
int i = GetCmdIndex(Cmd);
if (i > -1) {
TCmdInfo *ptr = (TCmdInfo *)Commands->Objects[i];
if (ptr != NULL) {
free(ptr);
Commands->Objects[i] = NULL;
}
Commands->Delete(i);
} else
throw Exception("Command not in list!");
}
//---------------------------------------------------------------------------
void __fastcall TCmdStatsInfo::Update(AnsiString Cmd, long CmdBytes, long RepBytes)
{
int i = Commands->IndexOf(Cmd);
if (i > -1) {
TCmdInfo *ptr = (TCmdInfo *)Commands->Objects[i];
if (ptr != NULL) {
ptr->Count++;
ptr->CommandBytes += CmdBytes;
ptr->ReplyBytes += RepBytes;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TCmdStatsInfo::ResetStats()
{
TCmdInfo *ptr;
for (int i = 0; i < Commands->Count; i++) {
ptr = (TCmdInfo *)Commands->Objects[i];
if (ptr != NULL) {
ptr->Count = 0;
ptr->CommandBytes = 0;
ptr->ReplyBytes = 0;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TCmdStatsInfo::ResetStats(int i)
{
if (i < Commands->Count) {
TCmdInfo *ptr = (TCmdInfo *)Commands->Objects[i];
if (ptr != NULL) {
ptr->Count = 0;
ptr->CommandBytes = 0;
ptr->ReplyBytes = 0;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TCmdStatsInfo::ResetStats(AnsiString Cmd)
{
ResetStats(GetCmdIndex(Cmd));
}
//---------------------------------------------------------------------------
void __fastcall TCmdStatsInfo::Clear()
{
TCmdInfo *ptr;
for (int i = 0; i < Commands->Count; i++) {
ptr = (TCmdInfo *)Commands->Objects[i];
if (ptr != NULL)
free(ptr);
}
Commands->Clear();
}
//---------------------------------------------------------------------------
int __fastcall TCmdStatsInfo::GetCmdIndex(AnsiString Cmd)
{
return Commands->IndexOf(Cmd);
}
//---------------------------------------------------------------------------
long __fastcall TCmdStatsInfo::GetCount(AnsiString Cmd)
{
long rc;
int i = GetCmdIndex(Cmd);
if (i > -1) {
TCmdInfo *ptr = (TCmdInfo *)Commands->Objects[i];
if (ptr != NULL)
rc = ptr->Count;
else
rc = -1;
} else
rc = -1;
return rc;
}
//---------------------------------------------------------------------------
long __fastcall TCmdStatsInfo::GetCmdSize(AnsiString Cmd)
{
long rc;
int i = GetCmdIndex(Cmd);
if (i > -1) {
TCmdInfo *ptr = (TCmdInfo *)Commands->Objects[i];
if (ptr != NULL)
rc = ptr->CommandBytes;
else
rc = -1;
} else
rc = -1;
return rc;
}
//---------------------------------------------------------------------------
long __fastcall TCmdStatsInfo::GetReplySize(AnsiString Cmd)
{
long rc;
int i = GetCmdIndex(Cmd);
if (i > -1) {
TCmdInfo *ptr = (TCmdInfo *)Commands->Objects[i];
if (ptr != NULL)
rc = ptr->ReplyBytes;
else
rc = -1;
} else
rc = -1;
return rc;
}
//---------------------------------------------------------------------------