Debian Codegraph @

gobi-api/Gobi_2012-06-18-1054/Core/ProtocolLog.cpp

raw
1 /*===========================================================================
2 FILE:
3 ProtocolLog.h
4
5 DESCRIPTION:
6 Simple protocol 'log' class definition
7
8 PUBLIC CLASSES AND METHODS:
9 cProtocolLog
10 This class stores protocol buffers in to a flat array (actually a
11 double-ended queue) so that they can be accessed by other objects
12 during the flow of normal processing. Note that the storage is
13 in-memory and therefore finite
14
15 Copyright (c) 2012, Code Aurora Forum. All rights reserved.
16
17 Redistribution and use in source and binary forms, with or without
18 modification, are permitted provided that the following conditions are met:
19 * Redistributions of source code must retain the above copyright
20 notice, this list of conditions and the following disclaimer.
21 * Redistributions in binary form must reproduce the above copyright
22 notice, this list of conditions and the following disclaimer in the
23 documentation and/or other materials provided with the distribution.
24 * Neither the name of Code Aurora Forum nor
25 the names of its contributors may be used to endorse or promote
26 products derived from this software without specific prior written
27 permission.
28
29
30 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
31 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
34 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
35 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
36 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
37 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
38 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
39 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
40 POSSIBILITY OF SUCH DAMAGE.
41 ===========================================================================*/
42
43 //---------------------------------------------------------------------------
44 // Include Files
45 //---------------------------------------------------------------------------
46 #include "StdAfx.h"
47 #include "ProtocolLog.h"
48
49 //---------------------------------------------------------------------------
50 // Definitions
51 //---------------------------------------------------------------------------
52
53 // The maximum number of in-memory buffers we allow
54 const ULONG MAX_PROTOCOL_BUFFERS = 1024 * 16;
55
56 /*=========================================================================*/
57 // cProtocolLog Methods
58 /*=========================================================================*/
59
60 /*===========================================================================
61 METHOD:
62 cProtocolLog (Public Method)
63
64 DESCRIPTION:
65 Constructor
66
67 PARAMETERS:
68 maxBuffers [ I ] - Maximum number of buffers to store in the log
69
70 RETURN VALUE:
71 None
72 ===========================================================================*/
73 cProtocolLog::cProtocolLog( ULONG maxBuffers )
74 : mLog( maxBuffers > MAX_PROTOCOL_BUFFERS ? MAX_PROTOCOL_BUFFERS : maxBuffers,
75 true )
76 {
77 // Nothing to do
78 }
79
80 /*===========================================================================
81 METHOD:
82 ~cProtocolLog (Public Method)
83
84 DESCRIPTION:
85 Destructor
86
87 RETURN VALUE:
88 None
89 ===========================================================================*/
90 cProtocolLog::~cProtocolLog()
91 {
92 // Empty out the log
93 Clear();
94 }
95
96 /*===========================================================================
97 METHOD:
98 AddBuffer (Public Method)
99
100 DESCRIPTION:
101 Add an protocol buffer to the end of the log
102
103 PARAMETERS:
104 buff [ I ] - Protocol buffer to add
105
106 RETURN VALUE:
107 ULONG - Index of newly added buffer (INVALID_LOG_INDEX upon failure)
108 ===========================================================================*/
109 ULONG cProtocolLog::AddBuffer( sProtocolBuffer & buf )
110 {
111 ULONG idx = INVALID_LOG_INDEX;
112 if (buf.IsValid() == false)
113 {
114 return idx;
115 }
116
117 bool bRC = mLog.AddElement( buf, idx );
118 if (bRC == false)
119 {
120 idx = INVALID_LOG_INDEX;
121 }
122
123 return idx;
124 }
125
126 /*===========================================================================
127 METHOD:
128 GetBuffer (Public Method)
129
130 DESCRIPTION:
131 Return the protocol buffer at the given index from the log
132
133 PARAMETERS:
134 idx [ I ] - Index of protocol buffer to obtain
135
136 RETURN VALUE:
137 sProtocolBuffer - Protocol buffer
138 ===========================================================================*/
139 sProtocolBuffer cProtocolLog::GetBuffer( ULONG idx ) const
140 {
141 sProtocolBuffer buf;
142 mLog.GetElement( idx, buf );
143 return buf;
144 }
145
146 /*===========================================================================
147 METHOD:
148 GetSignalEvent (Public Method)
149
150 DESCRIPTION:
151 Return the underlying signal event, which will be set when
152 the log is updated.
153
154 RETURN VALUE:
155 cEvent - Signal event
156 ===========================================================================*/
157 cEvent & cProtocolLog::GetSignalEvent() const
158 {
159 return mLog.GetSignalEvent();
160 }
161
162 /*===========================================================================
163 METHOD:
164 GetCount (Public Method)
165
166 DESCRIPTION:
167 Return the total number of buffers added to the log
168
169 RETURN VALUE:
170 ULONG
171 ===========================================================================*/
172 ULONG cProtocolLog::GetCount() const
173 {
174 return mLog.GetTotalCount();
175 }
176
177 /*===========================================================================
178 METHOD:
179 Clear (Public Method)
180
181 DESCRIPTION:
182 Clear the log
183
184 RETURN VALUE:
185 None
186 ===========================================================================*/
187 void cProtocolLog::Clear()
188 {
189 mLog.EmptyQueue();
190 }