1
/* Copyright (c) 1996-2004, Adaptec Corporation
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions are met:
7
* - Redistributions of source code must retain the above copyright notice, this
8
* list of conditions and the following disclaimer.
9
* - Redistributions in binary form must reproduce the above copyright notice,
10
* this list of conditions and the following disclaimer in the documentation
11
* and/or other materials provided with the distribution.
12
* - Neither the name of the Adaptec Corporation nor the names of its
13
* contributors may be used to endorse or promote products derived from this
14
* software without specific prior written permission.
16
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
* POSSIBILITY OF SUCH DAMAGE.
30
//***************************************************************************
34
// This file contains the function definitions for the dptCoreMgr_C
37
//Author: Doug Anderson
45
//***************************************************************************
46
#include "allfiles.hpp"
48
//Function - dptCoreMgr_C::dptCoreMgr_C() - start
49
//===========================================================================
53
// This function is the constructor for the dptCoreMgr_C class.
59
//Global Variables Affected:
61
//Remarks: (Side effects, Assumptions, Warnings...)
64
//---------------------------------------------------------------------------
66
dptCoreMgr_C::dptCoreMgr_C()
71
// Initialize this manager's level of operation
73
// Indicate that this object is a manager object
77
//dptCoreMgr_C::dptCoreMgr_C() - end
80
//Function - dptCoreMgr_C::enterLog() - start
81
//===========================================================================
85
// This function adds an object to this manager's logical devices list.
91
// 1 = The device was successfully entered into the engine core.
92
// 0 = The device was not entered into the engine core and was deleted.
94
//Global Variables Affected:
96
//Remarks: (Side effects, Assumptions, Warnings...)
99
//---------------------------------------------------------------------------
101
DPT_RTN_T dptCoreMgr_C::enterLog(dptCoreDev_C *inDev_P)
107
// Determine if it is OK to add this device
108
if ((retVal = preEnterLog(inDev_P)) == MSG_RTN_COMPLETED) {
109
// The device originates in a logical device list
110
inDev_P->coreFlags |= FLG_ENG_LIST;
111
// The object is attached to this manager.
112
inDev_P->attachedTo_P = this;
113
// Set the object's connection pointer
114
inDev_P->conn_P = myConn_P();
115
// Add the object to the connection's master object list
116
if (myConn_P()->objectList.addEnd(inDev_P)) {
117
// Attempt to add the new device to this manager's logical device
118
// list and all higher level managers' logical device lists
119
_status = bubble(inDev_P);
121
// Call the handler for an incomplete bubble
122
_status = myConn_P()->enterSuppressed(inDev_P);
124
// Remove from the connection's master device list
125
myConn_P()->objectList.remove(inDev_P);
126
} // end if (objectList.addEnd())
128
retVal = MSG_RTN_FAILED | ERR_MEM_ALLOC;
129
} // end if (preEnterLog())
132
// Call the handler for an invalid add to engine core
133
notAddedToCore(inDev_P);
138
//dptCoreMgr_C::enterLog() - end
141
//Function - dptCoreMgr_C::enterPhy() - start
142
//===========================================================================
146
// This function adds an object to the physical device list.
152
//Global Variables Affected:
154
//Remarks: (Side effects, Assumptions, Warnings...)
157
//---------------------------------------------------------------------------
159
DPT_RTN_T dptCoreMgr_C::enterPhy(dptCoreObj_C *inObj_P)
167
// Determine if it is OK to enter this object
168
if ((retVal = preEnterPhy(inObj_P))==MSG_RTN_COMPLETED) {
169
retVal = MSG_RTN_FAILED | ERR_MEM_ALLOC;
170
// Add the object to the connection's master object list
171
if (myConn_P()->objectList.addEnd(inObj_P)) {
172
if (preAddPhy(inObj_P)) {
173
if (phyList.add(inObj_P)) {
174
// The object is attached to this manager.
175
inObj_P->attachedTo_P = this;
176
// Set the object's connection pointer
177
inObj_P->conn_P = myConn_P();
178
// If the object is a device...
179
if (inObj_P->isDevice()) {
180
// Cast the object as a device
181
dev_P = (dptCoreDev_C *) inObj_P;
182
// Set the object's highest visible level
183
dev_P->visibleLevel = level + 1;
184
// If this manager bubbles physical devices...
186
// Bubble the object up the logical device chain
187
_status = bubble(dev_P);
188
if ((_status==2) || (_status==0))
189
// Enter in the connection's suppressed device list
190
myConn_P()->enterSuppressed(dev_P);
191
} // end if (isBubbler())
193
// Intentionally suppress the device
194
myConn_P()->suppress(dev_P);
196
} // end if (isDevice())
198
// Cast the object as a manager
199
mgr_P = (dptCoreMgr_C *) inObj_P;
200
// Set the sub-manager's level
201
mgr_P->level = level + 1;
203
// Call the post add physical handler
205
// The object was added to the engine core
208
retVal = MSG_RTN_COMPLETED;
209
} // end if (phyList.add())
210
} // end if (preAddPhy())
211
} // end if (objectList.addEnd())
212
} // end if (preEnterPhy())
215
// Remove from the connection's master device list
216
myConn_P()->objectList.remove(inObj_P);
217
// Call the handler for an invalid add to engine core
218
notAddedToCore(inObj_P);
224
//dptCoreMgr_C::enterPhy() - end
227
//Function - dptCoreMgr_C::bubble() - start
228
//===========================================================================
232
// This function attempts to add a device to the logical device list.
233
//If the object is successfully added to this manager's logical device
234
//list, the logical addition is passed to the next manager.
240
// 2 = The device was added to this manager's logical device list
241
// but could not be added to a higher level manager's logical
242
// device list (An incomplete bubble).
243
// 1 = The device was added to or already existed in this manager's
244
// logical device list and all higher level manager's logical
246
// 0 = The device could not be added to this manager's logical device
249
//Global Variables Affected:
251
//Remarks: (Side effects, Assumptions, Warnings...)
254
//---------------------------------------------------------------------------
256
uSHORT dptCoreMgr_C::bubble(dptCoreDev_C *inDev_P)
261
// Check if the device already exists
262
if (logList.exists(inDev_P))
265
// If the pre-add logical functions were performed OK...
266
if (preAddLog(inDev_P)) {
267
// Attempt to add the device to the logical device list
268
if (logList.add(inDev_P)) {
269
// Set the object's highest visible level
270
inDev_P->visibleLevel = level;
271
// Call the post enter logical handler
279
if (myMgr_P()!=NULL) {
280
// Pass the addition up the attachment chain
281
retVal = ((dptCoreMgr_C *)myMgr_P())->bubble(inDev_P);
282
// If the next level failed, indicate an incomplete bubble
283
if (retVal==0) retVal = 2;
290
//dptCoreMgr_C::bubble() - end
293
//Function - dptCoreMgr_C::remLogical() - start
294
//===========================================================================
298
// This function removes the specified device from this manager's
299
//logical device list and passes the removal request up the attachment
306
//Global Variables Affected:
308
//Remarks: (Side effects, Assumptions, Warnings...)
311
//---------------------------------------------------------------------------
313
void dptCoreMgr_C::remLogical(dptCoreDev_C *dev_P)
316
// Remove the device from this manager's logical device list
317
logList.remove(dev_P);
319
if (attachedTo_P!=NULL)
320
// Pass the logical removal up the attachment chain
321
attachedTo_P->remLogical(dev_P);
324
//dptCoreMgr_C::remLogical() - end
327
//Function - dptCoreMgr_C::remFromMgr() - start
328
//===========================================================================
332
// This function removes the specified object from this manager's lists.
338
//Global Variables Affected:
340
//Remarks: (Side effects, Assumptions, Warnings...)
343
//---------------------------------------------------------------------------
345
void dptCoreMgr_C::remFromMgr(dptCoreObj_C *obj_P)
348
// If the object is a manager...
349
if (obj_P->isManager())
350
// Delete all the manager's objects
351
((dptCoreMgr_C *)obj_P)->delAllObjects();
353
// Remove from this manager's logical device list & all
354
// higher level manager's logical device lists
355
remLogical((dptCoreDev_C *)obj_P);
357
// Remove the object from this manager's physical device list
358
phyList.remove(obj_P);
361
//dptCoreMgr_C::remFromMgr() - end
364
//Function - dptCoreMgr_C::delAllObjects() - start
365
//===========================================================================
369
// This function deletes all objects attached directly to this manager.
375
//Global Variables Affected:
377
//Remarks: (Side effects, Assumptions, Warnings...)
380
//---------------------------------------------------------------------------
382
void dptCoreMgr_C::delAllObjects()
388
// Delete all logical devices attached directly to this manager
389
dev_P = (dptCoreDev_C *) logList.reset();
390
while (dev_P!=NULL) {
391
if (dev_P->isMyObject(this) && dev_P->isLogical()) {
392
// Remove the device from any higher level manager's log lists
393
if (attachedTo_P!=NULL)
394
// Pass the logical removal up the attachment chain
395
attachedTo_P->remLogical(dev_P);
397
// Remove the device from the connection's lists
398
myConn_P()->remFromCon(dev_P);
401
// Remove the device from this manager's logical device list
402
dev_P = (dptCoreDev_C *) logList.remove();
405
// Get the next logical device
406
dev_P = (dptCoreDev_C *) logList.next();
409
// Delete all physical objects attached directly to this manager
410
obj_P = (dptCoreObj_C *) phyList.reset();
411
while (obj_P!=NULL) {
412
// If the object is a manager...
413
if (obj_P->isManager())
414
// Delete all of the sub-manager's objects
415
((dptCoreMgr_C *)obj_P)->delAllObjects();
417
// Remove from this manager's logical device list & all
418
// higher level manager's logical device lists
419
remLogical((dptCoreDev_C *)obj_P);
421
// Remove the object from the connection's lists
422
myConn_P()->remFromCon(obj_P);
425
// Remove the object from this manager's physical object list
426
obj_P = (dptCoreObj_C *) phyList.remove();
430
//dptCoreMgr_C::delAllObjects() - end
433
//Function - dptCoreMgr_C::getDevLevel() - start
434
//===========================================================================
438
// This function determines the logical level of the attached device.
444
//Global Variables Affected:
446
//Remarks: (Side effects, Assumptions, Warnings...)
449
//---------------------------------------------------------------------------
451
uSHORT dptCoreMgr_C::getDevLevel(dptCoreDev_C *dev_P)
454
uSHORT retVal = level;
456
if (dev_P->isPhysical())
462
//dptCoreMgr_C::getDevLevel() - end