Debian Codegraph @

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

raw
1 /*===========================================================================
2 FILE:
3 ProtocolNotification.cpp
4
5 DESCRIPTION:
6 Implementation 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) 2012, 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 // Include Files
50 //---------------------------------------------------------------------------
51 #include "StdAfx.h"
52 #include "ProtocolNotification.h"
53
54 //---------------------------------------------------------------------------
55 // Definitions
56 //---------------------------------------------------------------------------
57
58 /*=========================================================================*/
59 // cProtocolQueueNotification Methods
60 /*=========================================================================*/
61
62 /*===========================================================================
63 METHOD:
64 cProtocolQueueNotification (Public Method)
65
66 DESCRIPTION:
67 Constructor
68
69 PARAMETERS:
70 pSQ [ I ] - Sync queue to utilize
71
72 RETURN VALUE:
73 None
74 ===========================================================================*/
75 cProtocolQueueNotification::cProtocolQueueNotification(
76 cSyncQueue <sProtocolNotificationEvent> * pSQ )
77 : mpSQ( pSQ )
78 {
79 // Nothing to do
80 }
81
82 /*===========================================================================
83 METHOD:
84 cProtocolQueueNotification (Public Method)
85
86 DESCRIPTION:
87 Copy constructor
88
89 PARAMETERS:
90 notifier [ I ] - Notifier to base the new one on
91
92 RETURN VALUE:
93 None
94 ===========================================================================*/
95 cProtocolQueueNotification::cProtocolQueueNotification(
96 const cProtocolQueueNotification & notifier )
97 : mpSQ( notifier.mpSQ )
98 {
99 // Nothing to do
100 }
101
102 /*===========================================================================
103 METHOD:
104 ~cProtocolQueueNotification (Public Method)
105
106 DESCRIPTION:
107 Destructor
108
109 RETURN VALUE:
110 None
111 ===========================================================================*/
112 cProtocolQueueNotification::~cProtocolQueueNotification()
113 {
114 mpSQ = 0;
115 }
116
117 /*===========================================================================
118 METHOD:
119 Clone (Public Method)
120
121 DESCRIPTION:
122 Return an allocated copy of this object downcasted to our base class
123
124 RETURN VALUE:
125 cProtocolNotification * : Cloned object (0 on error)
126 ===========================================================================*/
127 cProtocolNotification * cProtocolQueueNotification::Clone() const
128 {
129 cProtocolQueueNotification * pCopy = 0;
130
131 try
132 {
133 pCopy = new cProtocolQueueNotification( *this );
134 }
135 catch (...)
136 {
137 // Simply return 0
138 }
139
140 return ((cProtocolNotification *)pCopy);
141 }
142
143 /*===========================================================================
144 METHOD:
145 Notify (Public Method)
146
147 DESCRIPTION:
148 Notify view of a protocol event by adding notification structure to
149 the underlying sync queue (which will provide the notification
150 by signalling an event)
151
152 PARAMETERS:
153 eventType [ I ] - Protocol event type
154 param1 [ I ] - Event type specific argument (see header description)
155 param2 [ I ] - Event type specific argument (see header description)
156
157 RETURN VALUE:
158 None
159 ===========================================================================*/
160 void cProtocolQueueNotification::Notify(
161 eProtocolEventType eventType,
162 DWORD param1,
163 DWORD param2 ) const
164 {
165 sProtocolNotificationEvent evt( eventType, param1, param2 );
166 if (evt.IsValid() == true && mpSQ != 0 && mpSQ->IsValid() == true)
167 {
168 sProtocolNotificationEvent elem( eventType, param1, param2 );
169 mpSQ->AddElement( elem );
170 }
171 }