| 1 |
/*=========================================================================== |
| 2 |
FILE: |
| 3 |
ProtocolNotification.h |
| 4 |
|
| 5 |
DESCRIPTION: |
| 6 |
Declaration of cProtocolNotification base class and derivations |
| 7 |
|
| 8 |
PUBLIC CLASSES AND METHODS: |
| 9 |
sProtocolNotificationEvent |
| 10 |
Generic protocol event notification structure |
| 11 |
|
| 12 |
cProtocolNotification |
| 13 |
This abstract base class provides notification of protocol server |
| 14 |
events sent from the protocol server to protocol server clients |
| 15 |
|
| 16 |
cProtocolQueueNotification |
| 17 |
This class provides notification via a cSyncQueue object |
| 18 |
populated with sProtocolNotificationEvent objects |
| 19 |
|
| 20 |
Copyright (c) 2011, Code Aurora Forum. All rights reserved. |
| 21 |
|
| 22 |
Redistribution and use in source and binary forms, with or without |
| 23 |
modification, are permitted provided that the following conditions are met: |
| 24 |
* Redistributions of source code must retain the above copyright |
| 25 |
notice, this list of conditions and the following disclaimer. |
| 26 |
* Redistributions in binary form must reproduce the above copyright |
| 27 |
notice, this list of conditions and the following disclaimer in the |
| 28 |
documentation and/or other materials provided with the distribution. |
| 29 |
* Neither the name of Code Aurora Forum nor |
| 30 |
the names of its contributors may be used to endorse or promote |
| 31 |
products derived from this software without specific prior written |
| 32 |
permission. |
| 33 |
|
| 34 |
|
| 35 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 36 |
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 37 |
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 38 |
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 39 |
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 40 |
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 41 |
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 42 |
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 43 |
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 44 |
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 45 |
POSSIBILITY OF SUCH DAMAGE. |
| 46 |
===========================================================================*/ |
| 47 |
|
| 48 |
//--------------------------------------------------------------------------- |
| 49 |
// Pragmas |
| 50 |
//--------------------------------------------------------------------------- |
| 51 |
#pragma once |
| 52 |
|
| 53 |
//--------------------------------------------------------------------------- |
| 54 |
// Include Files |
| 55 |
//--------------------------------------------------------------------------- |
| 56 |
#include "SyncQueue.h" |
| 57 |
|
| 58 |
//--------------------------------------------------------------------------- |
| 59 |
// Definitions |
| 60 |
//--------------------------------------------------------------------------- |
| 61 |
enum eProtocolEventType |
| 62 |
{ |
| 63 |
ePROTOCOL_EVT_BEGIN = -1, |
| 64 |
|
| 65 |
ePROTOCOL_EVT_REQ_ERR, // There was an error sending the request |
| 66 |
ePROTOCOL_EVT_REQ_SENT, // The request has been sent |
| 67 |
|
| 68 |
ePROTOCOL_EVT_RSP_ERR, // There was an error receiving the response |
| 69 |
ePROTOCOL_EVT_RSP_RECV, // The response has been received |
| 70 |
|
| 71 |
ePROTOCOL_EVT_AUX_TU_SENT, // Auxiliary data transmission unit sent |
| 72 |
|
| 73 |
ePROTOCOL_EVT_END |
| 74 |
}; |
| 75 |
|
| 76 |
// NOTE: The arguments for each event are currently as follows: |
| 77 |
// |
| 78 |
// ePROTOCOL_EVT_REQ_ERR |
| 79 |
// param1: Request ID |
| 80 |
// param2: Error code |
| 81 |
// |
| 82 |
// ePROTOCOL_EVT_REQ_SENT |
| 83 |
// param1: Request ID |
| 84 |
// param2: Index of request buffer in associated protocol log |
| 85 |
|
| 86 |
// ePROTOCOL_EVT_RSP_ERR |
| 87 |
// param1: Request ID |
| 88 |
// param2: Error code |
| 89 |
// |
| 90 |
// ePROTOCOL_EVT_RSP_RECV |
| 91 |
// param1: Request ID |
| 92 |
// param2: Index of response buffer in associated protocol log |
| 93 |
// |
| 94 |
// ePROTOCOL_EVT_AUX_TU_SENT |
| 95 |
// param1: Request ID |
| 96 |
// param2: Size of transmission unit |
| 97 |
|
| 98 |
// NOTE: To handle protoocl events using the Windows notifier add the following |
| 99 |
// prototype to your Window class header file: |
| 100 |
// |
| 101 |
// afx_msg LRESULT OnProtocolEvent( |
| 102 |
// WPARAM wParam, |
| 103 |
// LPARAM lParam ); |
| 104 |
// |
| 105 |
// Then add an entry to the message map in your Window class source file: |
| 106 |
// |
| 107 |
// BEGIN_MESSAGE_MAP( CView, CChildView ) |
| 108 |
// ON_MESSAGE( PROTOCOL_WM_BASE + (ULONG)ePROTOCOL_EVT_XXX, OnProtocolEvent ) |
| 109 |
// END_MESSAGE_MAP() |
| 110 |
// |
| 111 |
// Finally write the handler itself: |
| 112 |
// |
| 113 |
// LRESULT CView::OnProtocolEvent( |
| 114 |
// WPARAM wParam, |
| 115 |
// LPARAM lParam ) |
| 116 |
// { |
| 117 |
// Do something |
| 118 |
// return 0; |
| 119 |
// } |
| 120 |
|
| 121 |
/*=========================================================================== |
| 122 |
METHOD: |
| 123 |
IsValid (Inline Method) |
| 124 |
|
| 125 |
DESCRIPTION: |
| 126 |
eProtocolEventType validity check |
| 127 |
|
| 128 |
PARAMETERS: |
| 129 |
evtType [ I ] - Enum value being verified |
| 130 |
|
| 131 |
RETURN VALUE: |
| 132 |
bool |
| 133 |
===========================================================================*/ |
| 134 |
inline bool IsValid( eProtocolEventType evtType ) |
| 135 |
{ |
| 136 |
bool bRC = false; |
| 137 |
if (evtType > ePROTOCOL_EVT_BEGIN && evtType < ePROTOCOL_EVT_END) |
| 138 |
{ |
| 139 |
bRC = true; |
| 140 |
} |
| 141 |
|
| 142 |
return bRC; |
| 143 |
}; |
| 144 |
|
| 145 |
/*=========================================================================*/ |
| 146 |
// Struct sProtocolNotificationEvent |
| 147 |
/*=========================================================================*/ |
| 148 |
struct sProtocolNotificationEvent |
| 149 |
{ |
| 150 |
public: |
| 151 |
// (Inline) Default constructor (results in invalid object) |
| 152 |
sProtocolNotificationEvent() |
| 153 |
: mEventType( ePROTOCOL_EVT_BEGIN ), |
| 154 |
mParam1( 0 ), |
| 155 |
mParam2( 0 ) |
| 156 |
{ |
| 157 |
// Nothing to do |
| 158 |
}; |
| 159 |
|
| 160 |
// (Inline) Parameter constructor |
| 161 |
sProtocolNotificationEvent( |
| 162 |
eProtocolEventType eventType, |
| 163 |
DWORD param1, |
| 164 |
DWORD param2 ) |
| 165 |
: mEventType( eventType ), |
| 166 |
mParam1( param1 ), |
| 167 |
mParam2( param2 ) |
| 168 |
{ |
| 169 |
// Nothing to do |
| 170 |
}; |
| 171 |
|
| 172 |
// (Inline) Is this object valid? |
| 173 |
bool IsValid() |
| 174 |
{ |
| 175 |
return ::IsValid( mEventType ); |
| 176 |
} |
| 177 |
|
| 178 |
/* Event type */ |
| 179 |
eProtocolEventType mEventType; |
| 180 |
|
| 181 |
/* First parameter (see above) */ |
| 182 |
DWORD mParam1; |
| 183 |
|
| 184 |
/* Second parameter (see above) */ |
| 185 |
DWORD mParam2; |
| 186 |
}; |
| 187 |
|
| 188 |
/*=========================================================================*/ |
| 189 |
// Class cProtocolNotification |
| 190 |
// |
| 191 |
// This abstract base class provides notification of protocol server |
| 192 |
// events sent from the protocol server to protocol server clients |
| 193 |
/*=========================================================================*/ |
| 194 |
class cProtocolNotification |
| 195 |
{ |
| 196 |
public: |
| 197 |
// Return an allocated copy of this object |
| 198 |
virtual cProtocolNotification * Clone() const = 0; |
| 199 |
|
| 200 |
// Notify view of a protocol event |
| 201 |
virtual void Notify( |
| 202 |
eProtocolEventType eventType, |
| 203 |
DWORD param1, |
| 204 |
DWORD param2 ) const = 0; |
| 205 |
}; |
| 206 |
|
| 207 |
/*=========================================================================*/ |
| 208 |
// Class cProtocolQueueNotification |
| 209 |
// |
| 210 |
// This class provides notification via a cSyncQueue object |
| 211 |
// populated with sProtocolNotificationEvent objects |
| 212 |
/*=========================================================================*/ |
| 213 |
class cProtocolQueueNotification : public cProtocolNotification |
| 214 |
{ |
| 215 |
public: |
| 216 |
// Constructor |
| 217 |
cProtocolQueueNotification( cSyncQueue <sProtocolNotificationEvent> * pSQ ); |
| 218 |
|
| 219 |
// Copy constructor |
| 220 |
cProtocolQueueNotification( const cProtocolQueueNotification & notifier ); |
| 221 |
|
| 222 |
// Destructor |
| 223 |
virtual ~cProtocolQueueNotification(); |
| 224 |
|
| 225 |
// Return a copy of this object |
| 226 |
virtual cProtocolNotification * Clone() const; |
| 227 |
|
| 228 |
// Notify view of a MIS event |
| 229 |
virtual void Notify( |
| 230 |
eProtocolEventType eventType, |
| 231 |
DWORD param1, |
| 232 |
DWORD param2 ) const; |
| 233 |
|
| 234 |
protected: |
| 235 |
/* Event notification queue */ |
| 236 |
mutable cSyncQueue <sProtocolNotificationEvent> * mpSQ; |
| 237 |
}; |