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.
29
//***************************************************************************
33
// This file contains the function definitions for the dptCoreCon_C
36
//Author: Doug Anderson
44
//***************************************************************************
45
#include "allfiles.hpp"
47
//Function - dptCoreCon_C::dptCoreCon_C() - start
48
//===========================================================================
52
// This function is the constructor for the dptCoreCon_C class.
58
//Global Variables Affected:
60
//Remarks: (Side effects, Assumptions, Warnings...)
63
//---------------------------------------------------------------------------
65
dptCoreCon_C::dptCoreCon_C()
71
//dptCoreCon_C::dptCoreCon_C() - end
74
//Function - dptCoreCon_C::enterSuppressed() - start
75
//===========================================================================
79
// This function is called to enter an object in the connection's
80
//suppressed devices list.
86
// 1 = The device was successfully flagged as suppressed.
87
// 0 = The device could not be entered into the suppressList probably
88
// due to a memory allocation error.
90
//Global Variables Affected:
92
//Remarks: (Side effects, Assumptions, Warnings...)
95
//---------------------------------------------------------------------------
97
uSHORT dptCoreCon_C::enterSuppressed(dptCoreDev_C *dev_P)
102
// If the device is not already in the suppressed device list...
103
if (!suppressList.exists(dev_P)) {
105
// Perform pre-suppression operations
106
preAddSuppress(dev_P);
107
// Attempt to add the device to the suppressed device list
108
if (suppressList.add(dev_P)) {
110
// Flag the device as suppressed
111
dev_P->coreFlags |= FLG_ENG_SUPPRESSED;
118
//dptCoreCon_C::enterSuppressed() - end
121
//Function - dptCoreCon_C::suppress() - start
122
//===========================================================================
126
// This function suppresses an object to its origin and enters it
127
//in the suppressed device list.
133
//Global Variables Affected:
135
//Remarks: (Side effects, Assumptions, Warnings...)
138
//---------------------------------------------------------------------------
140
uSHORT dptCoreCon_C::suppress(dptCoreDev_C *dev_P,uSHORT desired)
145
// Add the specified device to the suppressed device list
146
if (enterSuppressed(dev_P)) {
148
// If suppression is desired...
150
// Indicate that the device was deliberately suppressed
151
dev_P->coreFlags |= FLG_ENG_SUP_DESIRED;
152
// Remove from logical device lists
153
if (dev_P->isLogical()) {
154
if (dev_P->myMgr_P()->myMgr_P()!=NULL)
155
// If logical, remove from all higher level managers
156
dev_P->myMgr_P()->myMgr_P()->remLogical(dev_P);
159
// If physical origin, remove from parent manager's logical
160
// device list and all higher logical device lists.
161
if (dev_P->myMgr_P() != NULL)
162
dev_P->myMgr_P()->remLogical(dev_P);
168
//dptCoreCon_C::suppress() - end
171
//Function - dptCoreCon_C::unSuppress() - start
172
//===========================================================================
176
// This function attempts to unsuppress all devices that weren't
177
//intentionally suppressed.
183
//Global Variables Affected:
185
//Remarks: (Side effects, Assumptions, Warnings...)
188
//---------------------------------------------------------------------------
190
void dptCoreCon_C::unSuppress()
193
dptCoreDev_C *dev_P = (dptCoreDev_C *) suppressList.reset();
194
while (dev_P!=NULL) {
195
// Only attempt to unsuppress devices that were not
196
// deliberately suppressed
197
if (!(dev_P->isSupDesired())) {
198
// Attempt to add the device to all logical device lists
199
if (dev_P->myMgr_P()->bubble(dev_P)==1) {
200
// Clear all suppression flags
201
dev_P->coreFlags &= ~FLG_ENG_SUPPRESSED;
202
dev_P->coreFlags &= ~FLG_ENG_SUP_DESIRED;
203
// Remove the device from the suppressed list
204
dev_P = (dptCoreDev_C *) suppressList.remove();
207
// Get the next device
208
dev_P = (dptCoreDev_C *) suppressList.next();
211
// Get the next device
212
dev_P = (dptCoreDev_C *) suppressList.next();
216
//dptCoreCon_C::unSuppress() - end
219
//Function - dptCoreCon_C::createMgrZero() - start
220
//===========================================================================
224
// This function creates and initializes the connections zero level
231
//Global Variables Affected:
233
//Remarks: (Side effects, Assumptions, Warnings...)
236
//---------------------------------------------------------------------------
238
uSHORT dptCoreCon_C::createMgrZero()
241
// Allocate the new zero level manager
242
mgrZero_P = newMgrZero();
244
// Set the manager's connection
245
mgrZero_P->conn_P = this;
247
return (mgrZero_P!=NULL);
250
//dptCoreCon_C::createMgrZero() - end
253
//Function - dptCoreCon_C::handleMessage() - start
254
//===========================================================================
258
// This function processes messages for an engine connection.
259
//If the event is not intercepted by the connection, it is
260
//passed on to the appropriate connection object.
266
//Global Variables Affected:
268
//Remarks: (Side effects, Assumptions, Warnings...)
271
//---------------------------------------------------------------------------
273
#if (!defined(UNREFERENCED_PARAMETER))
274
# if defined(__UNIX__)
275
# define UNREFERENCED_PARAMETER(x)
277
# define UNREFERENCED_PARAMETER(x) (x)
281
DPT_RTN_T dptCoreCon_C::handleMessage(DPT_MSG_T message,
283
dptBuffer_S *fromEng_P,
284
dptBuffer_S *toEng_P,
289
DPT_RTN_T retVal = MSG_RTN_FAILED | ERR_INVALID_TGT_TAG;
290
UNREFERENCED_PARAMETER(timeout);
292
if (message == MSG_DELETE)
293
// Attempt to delete the object from the engine
294
retVal = delMsgHandler(tgtTag);
296
// If targeted for object 0 or this connection...
297
if ((tgtTag==0) || (tgtTag==tag()))
298
// Event is for the zero level manager
299
retVal = mgrZero_P->handleMessage(message,fromEng_P,toEng_P);
301
// Get a pointer to the target object
302
dptCoreObj_C *obj_P = (dptCoreObj_C *) objectList.getObject(tgtTag);
304
// Pass the event on to the target object
305
retVal = obj_P->handleMessage(message,fromEng_P,toEng_P);
312
//dptCoreCon_C::handleMessage() - end
315
//Function - dptCoreCon_C::remFromCon() - start
316
//===========================================================================
320
// This function removes the specified object from the connection's
327
//Global Variables Affected:
329
//Remarks: (Side effects, Assumptions, Warnings...)
332
//---------------------------------------------------------------------------
334
void dptCoreCon_C::remFromCon(dptCoreObj_C *obj_P)
337
// Remove from the master object list
338
objectList.remove(obj_P);
339
// Remove from the suppressed device list
340
suppressList.remove(obj_P);
343
//dptCoreCon_C::remFromCon() - end
346
//Function - dptCoreCon_C::remFromCore() - start
347
//===========================================================================
351
// This function removes the specified object from existence within
352
//the core of the engine. Prior to removing the object the virtual
353
//pre-delete function is called. The following action is taken based
354
//upon the return status of the pre-delete function:
356
// 0 = Take no action
357
// 1 = Remove from engine core and free from memory
358
// 2 = Remove from engine core but do not free from memory
359
// (The object must be maintained at a higher level)
365
//Global Variables Affected:
367
//Remarks: (Side effects, Assumptions, Warnings...)
369
//---------------------------------------------------------------------------
371
uSHORT dptCoreCon_C::remFromCore(dptCoreObj_C *obj_P)
374
// Call the object's pre-delete handler
375
uSHORT action = obj_P->preDelete();
377
// Remove the object from its manager
378
obj_P->myMgr_P()->remFromMgr(obj_P);
379
// Remove the object from the connection's lists
381
// Allow the manager to perform post delete operations
382
obj_P->myMgr_P()->postDelete(obj_P);
383
// If the object is to be deleted from memory...
385
// Free the object from memory
392
//dptCoreCon_C::remFromCore() - end
395
//Function - dptCoreCon_C::delMsgHandler() - start
396
//===========================================================================
400
// This function handles an external delete object message.
406
//Global Variables Affected:
408
//Remarks: (Side effects, Assumptions, Warnings...)
411
//---------------------------------------------------------------------------
413
DPT_RTN_T dptCoreCon_C::delMsgHandler(DPT_TAG_T tgtTag)
416
DPT_RTN_T retVal = MSG_RTN_FAILED | ERR_INVALID_TGT_TAG;
418
// Get a pointer to the specified object
419
dptCoreObj_C *obj_P = (dptCoreObj_C *) objectList.getObject(tgtTag);
421
if (remFromCore(obj_P)==0)
422
retVal = MSG_RTN_FAILED | ERR_CANNOT_DELETE;
424
retVal = MSG_RTN_COMPLETED;
425
// Delete any missing objects that were freed by the deletion
427
// Attempt to un-suppress any devices that may have been freed
436
//dptCoreCon_C::delMsgHandler() - end
439
//Function - dptCoreCon_C::delMissing() - start
440
//===========================================================================
444
// This function deletes any unused missing objects.
450
//Global Variables Affected:
452
//Remarks: (Side effects, Assumptions, Warnings...)
455
//---------------------------------------------------------------------------
457
void dptCoreCon_C::delMissing()
460
uSHORT isMissingMgr = 0;
462
// Delete all missing devices
463
dptObject_C *obj_P = (dptObject_C *) objectList.reset();
464
while (obj_P!=NULL) {
465
// If the object is missing...
466
if (obj_P->isMissing()) {
467
// If the object is a missing device...
468
if (obj_P->isDevice())
469
// Attempt to delete the device
474
// Get the next object
475
obj_P = (dptObject_C *) objectList.next();
479
// Delete all missing managers
480
obj_P = (dptObject_C *) objectList.reset();
481
while (obj_P!=NULL) {
482
// If the object is a missing manager...
483
if (obj_P->isManager() && obj_P->isMissing())
484
// Attempt to delete the manager
486
// Get the next object
487
obj_P = (dptObject_C *) objectList.next();
492
//dptCoreCon_C::delMissing() - end
495
//Function - dptCoreCon_C::~dptCoreCon_C() - start
496
//===========================================================================
500
// This function is the destructor for the dptCoreCon_C class.
506
//Global Variables Affected:
508
//Remarks: (Side effects, Assumptions, Warnings...)
511
//---------------------------------------------------------------------------
513
dptCoreCon_C::~dptCoreCon_C()
516
// Delete manager zero
517
if (mgrZero_P!=NULL) {
518
// Delete all of manager zero's objects
519
mgrZero_P->delAllObjects();
525
//dptCoreCon_C::~dptCoreCon_C() - end