1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527
|
/* Copyright (c) 1996-2004, Adaptec Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* - Neither the name of the Adaptec Corporation nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
//***************************************************************************
//
//Description:
//
// This file contains the function definitions for the dptCoreCon_C
//class.
//
//Author: Doug Anderson
//Date: 10/16/92
//
//Editors:
//
//Remarks:
//
//
//***************************************************************************
#include "allfiles.hpp"
//Function - dptCoreCon_C::dptCoreCon_C() - start
//===========================================================================
//
//Description:
//
// This function is the constructor for the dptCoreCon_C class.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------
dptCoreCon_C::dptCoreCon_C()
{
mgrZero_P = NULL;
}
//dptCoreCon_C::dptCoreCon_C() - end
//Function - dptCoreCon_C::enterSuppressed() - start
//===========================================================================
//
//Description:
//
// This function is called to enter an object in the connection's
//suppressed devices list.
//
//Parameters:
//
//Return Value:
//
// 1 = The device was successfully flagged as suppressed.
// 0 = The device could not be entered into the suppressList probably
// due to a memory allocation error.
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------
uSHORT dptCoreCon_C::enterSuppressed(dptCoreDev_C *dev_P)
{
uSHORT retVal = 1;
// If the device is not already in the suppressed device list...
if (!suppressList.exists(dev_P)) {
retVal = 0;
// Perform pre-suppression operations
preAddSuppress(dev_P);
// Attempt to add the device to the suppressed device list
if (suppressList.add(dev_P)) {
retVal = 1;
// Flag the device as suppressed
dev_P->coreFlags |= FLG_ENG_SUPPRESSED;
}
}
return (retVal);
}
//dptCoreCon_C::enterSuppressed() - end
//Function - dptCoreCon_C::suppress() - start
//===========================================================================
//
//Description:
//
// This function suppresses an object to its origin and enters it
//in the suppressed device list.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------
uSHORT dptCoreCon_C::suppress(dptCoreDev_C *dev_P,uSHORT desired)
{
uSHORT retVal = 0;
// Add the specified device to the suppressed device list
if (enterSuppressed(dev_P)) {
retVal = 1;
// If suppression is desired...
if (desired)
// Indicate that the device was deliberately suppressed
dev_P->coreFlags |= FLG_ENG_SUP_DESIRED;
// Remove from logical device lists
if (dev_P->isLogical()) {
if (dev_P->myMgr_P()->myMgr_P()!=NULL)
// If logical, remove from all higher level managers
dev_P->myMgr_P()->myMgr_P()->remLogical(dev_P);
}
else
// If physical origin, remove from parent manager's logical
// device list and all higher logical device lists.
if (dev_P->myMgr_P() != NULL)
dev_P->myMgr_P()->remLogical(dev_P);
}
return (retVal);
}
//dptCoreCon_C::suppress() - end
//Function - dptCoreCon_C::unSuppress() - start
//===========================================================================
//
//Description:
//
// This function attempts to unsuppress all devices that weren't
//intentionally suppressed.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------
void dptCoreCon_C::unSuppress()
{
dptCoreDev_C *dev_P = (dptCoreDev_C *) suppressList.reset();
while (dev_P!=NULL) {
// Only attempt to unsuppress devices that were not
// deliberately suppressed
if (!(dev_P->isSupDesired())) {
// Attempt to add the device to all logical device lists
if (dev_P->myMgr_P()->bubble(dev_P)==1) {
// Clear all suppression flags
dev_P->coreFlags &= ~FLG_ENG_SUPPRESSED;
dev_P->coreFlags &= ~FLG_ENG_SUP_DESIRED;
// Remove the device from the suppressed list
dev_P = (dptCoreDev_C *) suppressList.remove();
}
else
// Get the next device
dev_P = (dptCoreDev_C *) suppressList.next();
}
else
// Get the next device
dev_P = (dptCoreDev_C *) suppressList.next();
}
}
//dptCoreCon_C::unSuppress() - end
//Function - dptCoreCon_C::createMgrZero() - start
//===========================================================================
//
//Description:
//
// This function creates and initializes the connections zero level
//manager.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------
uSHORT dptCoreCon_C::createMgrZero()
{
// Allocate the new zero level manager
mgrZero_P = newMgrZero();
if (mgrZero_P!=NULL)
// Set the manager's connection
mgrZero_P->conn_P = this;
return (mgrZero_P!=NULL);
}
//dptCoreCon_C::createMgrZero() - end
//Function - dptCoreCon_C::handleMessage() - start
//===========================================================================
//
//Description:
//
// This function processes messages for an engine connection.
//If the event is not intercepted by the connection, it is
//passed on to the appropriate connection object.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------
#if (!defined(UNREFERENCED_PARAMETER))
# if defined(__UNIX__)
# define UNREFERENCED_PARAMETER(x)
# else
# define UNREFERENCED_PARAMETER(x) (x)
# endif
#endif
DPT_RTN_T dptCoreCon_C::handleMessage(DPT_MSG_T message,
DPT_TAG_T tgtTag,
dptBuffer_S *fromEng_P,
dptBuffer_S *toEng_P,
uLONG timeout
)
{
DPT_RTN_T retVal = MSG_RTN_FAILED | ERR_INVALID_TGT_TAG;
UNREFERENCED_PARAMETER(timeout);
if (message == MSG_DELETE)
// Attempt to delete the object from the engine
retVal = delMsgHandler(tgtTag);
else {
// If targeted for object 0 or this connection...
if ((tgtTag==0) || (tgtTag==tag()))
// Event is for the zero level manager
retVal = mgrZero_P->handleMessage(message,fromEng_P,toEng_P);
else {
// Get a pointer to the target object
dptCoreObj_C *obj_P = (dptCoreObj_C *) objectList.getObject(tgtTag);
if (obj_P!=NULL)
// Pass the event on to the target object
retVal = obj_P->handleMessage(message,fromEng_P,toEng_P);
}
}
return(retVal);
}
//dptCoreCon_C::handleMessage() - end
//Function - dptCoreCon_C::remFromCon() - start
//===========================================================================
//
//Description:
//
// This function removes the specified object from the connection's
//lists.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------
void dptCoreCon_C::remFromCon(dptCoreObj_C *obj_P)
{
// Remove from the master object list
objectList.remove(obj_P);
// Remove from the suppressed device list
suppressList.remove(obj_P);
}
//dptCoreCon_C::remFromCon() - end
//Function - dptCoreCon_C::remFromCore() - start
//===========================================================================
//
//Description:
//
// This function removes the specified object from existence within
//the core of the engine. Prior to removing the object the virtual
//pre-delete function is called. The following action is taken based
//upon the return status of the pre-delete function:
//
// 0 = Take no action
// 1 = Remove from engine core and free from memory
// 2 = Remove from engine core but do not free from memory
// (The object must be maintained at a higher level)
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//---------------------------------------------------------------------------
uSHORT dptCoreCon_C::remFromCore(dptCoreObj_C *obj_P)
{
// Call the object's pre-delete handler
uSHORT action = obj_P->preDelete();
if (action!=0) {
// Remove the object from its manager
obj_P->myMgr_P()->remFromMgr(obj_P);
// Remove the object from the connection's lists
remFromCon(obj_P);
// Allow the manager to perform post delete operations
obj_P->myMgr_P()->postDelete(obj_P);
// If the object is to be deleted from memory...
if (action==1)
// Free the object from memory
delete(obj_P);
}
return (action);
}
//dptCoreCon_C::remFromCore() - end
//Function - dptCoreCon_C::delMsgHandler() - start
//===========================================================================
//
//Description:
//
// This function handles an external delete object message.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------
DPT_RTN_T dptCoreCon_C::delMsgHandler(DPT_TAG_T tgtTag)
{
DPT_RTN_T retVal = MSG_RTN_FAILED | ERR_INVALID_TGT_TAG;
// Get a pointer to the specified object
dptCoreObj_C *obj_P = (dptCoreObj_C *) objectList.getObject(tgtTag);
if (obj_P!=NULL) {
if (remFromCore(obj_P)==0)
retVal = MSG_RTN_FAILED | ERR_CANNOT_DELETE;
else {
retVal = MSG_RTN_COMPLETED;
// Delete any missing objects that were freed by the deletion
delMissing();
// Attempt to un-suppress any devices that may have been freed
// by the removal
unSuppress();
}
}
return (retVal);
}
//dptCoreCon_C::delMsgHandler() - end
//Function - dptCoreCon_C::delMissing() - start
//===========================================================================
//
//Description:
//
// This function deletes any unused missing objects.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------
void dptCoreCon_C::delMissing()
{
uSHORT isMissingMgr = 0;
// Delete all missing devices
dptObject_C *obj_P = (dptObject_C *) objectList.reset();
while (obj_P!=NULL) {
// If the object is missing...
if (obj_P->isMissing()) {
// If the object is a missing device...
if (obj_P->isDevice())
// Attempt to delete the device
remFromCore(obj_P);
else
isMissingMgr = 1;
}
// Get the next object
obj_P = (dptObject_C *) objectList.next();
}
if (isMissingMgr) {
// Delete all missing managers
obj_P = (dptObject_C *) objectList.reset();
while (obj_P!=NULL) {
// If the object is a missing manager...
if (obj_P->isManager() && obj_P->isMissing())
// Attempt to delete the manager
remFromCore(obj_P);
// Get the next object
obj_P = (dptObject_C *) objectList.next();
}
}
}
//dptCoreCon_C::delMissing() - end
//Function - dptCoreCon_C::~dptCoreCon_C() - start
//===========================================================================
//
//Description:
//
// This function is the destructor for the dptCoreCon_C class.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------
dptCoreCon_C::~dptCoreCon_C()
{
// Delete manager zero
if (mgrZero_P!=NULL) {
// Delete all of manager zero's objects
mgrZero_P->delAllObjects();
// Free from memory
delete (mgrZero_P);
}
}
//dptCoreCon_C::~dptCoreCon_C() - end
|