~ubuntu-branches/ubuntu/intrepid/raidutils/intrepid

« back to all changes in this revision

Viewing changes to raideng/core_con.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Barak Pearlmutter
  • Date: 2004-05-18 11:33:42 UTC
  • Revision ID: james.westby@ubuntu.com-20040518113342-tyqavmso5q351xi2
Tags: upstream-0.0.4
ImportĀ upstreamĀ versionĀ 0.0.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 1996-2004, Adaptec Corporation
 
2
 * All rights reserved.
 
3
 *
 
4
 * Redistribution and use in source and binary forms, with or without
 
5
 * modification, are permitted provided that the following conditions are met:
 
6
 *
 
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.
 
15
 *
 
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.
 
27
 */
 
28
 
 
29
//***************************************************************************
 
30
//
 
31
//Description:
 
32
//
 
33
//    This file contains the function definitions for the dptCoreCon_C
 
34
//class.
 
35
//
 
36
//Author:       Doug Anderson
 
37
//Date:         10/16/92
 
38
//
 
39
//Editors:
 
40
//
 
41
//Remarks:
 
42
//
 
43
//
 
44
//***************************************************************************
 
45
#include "allfiles.hpp"
 
46
 
 
47
//Function - dptCoreCon_C::dptCoreCon_C() - start
 
48
//===========================================================================
 
49
//
 
50
//Description:
 
51
//
 
52
//    This function is the constructor for the dptCoreCon_C class.
 
53
//
 
54
//Parameters:
 
55
//
 
56
//Return Value:
 
57
//
 
58
//Global Variables Affected:
 
59
//
 
60
//Remarks: (Side effects, Assumptions, Warnings...)
 
61
//
 
62
//
 
63
//---------------------------------------------------------------------------
 
64
 
 
65
dptCoreCon_C::dptCoreCon_C()
 
66
{
 
67
 
 
68
mgrZero_P = NULL;
 
69
 
 
70
}
 
71
//dptCoreCon_C::dptCoreCon_C() - end
 
72
 
 
73
 
 
74
//Function - dptCoreCon_C::enterSuppressed() - start
 
75
//===========================================================================
 
76
//
 
77
//Description:
 
78
//
 
79
//    This function is called to enter an object in the connection's
 
80
//suppressed devices list.
 
81
//
 
82
//Parameters:
 
83
//
 
84
//Return Value:
 
85
//
 
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.
 
89
//
 
90
//Global Variables Affected:
 
91
//
 
92
//Remarks: (Side effects, Assumptions, Warnings...)
 
93
//
 
94
//
 
95
//---------------------------------------------------------------------------
 
96
 
 
97
uSHORT  dptCoreCon_C::enterSuppressed(dptCoreDev_C *dev_P)
 
98
{
 
99
 
 
100
   uSHORT               retVal = 1;
 
101
 
 
102
  // If the device is not already in the suppressed device list...
 
103
if (!suppressList.exists(dev_P)) {
 
104
   retVal = 0;
 
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)) {
 
109
      retVal = 1;
 
110
        // Flag the device as suppressed
 
111
      dev_P->coreFlags |= FLG_ENG_SUPPRESSED;
 
112
  }
 
113
}
 
114
 
 
115
return (retVal);
 
116
 
 
117
}
 
118
//dptCoreCon_C::enterSuppressed() - end
 
119
 
 
120
 
 
121
//Function - dptCoreCon_C::suppress() - start
 
122
//===========================================================================
 
123
//
 
124
//Description:
 
125
//
 
126
//    This function suppresses an object to its origin and enters it
 
127
//in the suppressed device list.
 
128
//
 
129
//Parameters:
 
130
//
 
131
//Return Value:
 
132
//
 
133
//Global Variables Affected:
 
134
//
 
135
//Remarks: (Side effects, Assumptions, Warnings...)
 
136
//
 
137
//
 
138
//---------------------------------------------------------------------------
 
139
 
 
140
uSHORT  dptCoreCon_C::suppress(dptCoreDev_C *dev_P,uSHORT desired)
 
141
{
 
142
 
 
143
   uSHORT               retVal = 0;
 
144
 
 
145
  // Add the specified device to the suppressed device list
 
146
if (enterSuppressed(dev_P)) {
 
147
   retVal = 1;
 
148
     // If suppression is desired...
 
149
   if (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);
 
157
   }
 
158
   else
 
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);
 
163
}
 
164
 
 
165
return (retVal);
 
166
 
 
167
}
 
168
//dptCoreCon_C::suppress() - end
 
169
 
 
170
 
 
171
//Function - dptCoreCon_C::unSuppress() - start
 
172
//===========================================================================
 
173
//
 
174
//Description:
 
175
//
 
176
//    This function attempts to unsuppress all devices that weren't
 
177
//intentionally suppressed.
 
178
//
 
179
//Parameters:
 
180
//
 
181
//Return Value:
 
182
//
 
183
//Global Variables Affected:
 
184
//
 
185
//Remarks: (Side effects, Assumptions, Warnings...)
 
186
//
 
187
//
 
188
//---------------------------------------------------------------------------
 
189
 
 
190
void    dptCoreCon_C::unSuppress()
 
191
{
 
192
 
 
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();
 
205
      }
 
206
      else
 
207
           // Get the next device
 
208
         dev_P = (dptCoreDev_C *) suppressList.next();
 
209
   }
 
210
   else
 
211
        // Get the next device
 
212
      dev_P = (dptCoreDev_C *) suppressList.next();
 
213
}
 
214
 
 
215
}
 
216
//dptCoreCon_C::unSuppress() - end
 
217
 
 
218
 
 
219
//Function - dptCoreCon_C::createMgrZero() - start
 
220
//===========================================================================
 
221
//
 
222
//Description:
 
223
//
 
224
//    This function creates and initializes the connections zero level
 
225
//manager.
 
226
//
 
227
//Parameters:
 
228
//
 
229
//Return Value:
 
230
//
 
231
//Global Variables Affected:
 
232
//
 
233
//Remarks: (Side effects, Assumptions, Warnings...)
 
234
//
 
235
//
 
236
//---------------------------------------------------------------------------
 
237
 
 
238
uSHORT  dptCoreCon_C::createMgrZero()
 
239
{
 
240
 
 
241
  // Allocate the new zero level manager
 
242
mgrZero_P = newMgrZero();
 
243
if (mgrZero_P!=NULL)
 
244
     // Set the manager's connection
 
245
   mgrZero_P->conn_P = this;
 
246
 
 
247
return (mgrZero_P!=NULL);
 
248
 
 
249
}
 
250
//dptCoreCon_C::createMgrZero() - end
 
251
 
 
252
 
 
253
//Function - dptCoreCon_C::handleMessage() - start
 
254
//===========================================================================
 
255
//
 
256
//Description:
 
257
//
 
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.
 
261
//
 
262
//Parameters:
 
263
//
 
264
//Return Value:
 
265
//
 
266
//Global Variables Affected:
 
267
//
 
268
//Remarks: (Side effects, Assumptions, Warnings...)
 
269
//
 
270
//
 
271
//---------------------------------------------------------------------------
 
272
 
 
273
#if (!defined(UNREFERENCED_PARAMETER))
 
274
# if defined(__UNIX__)
 
275
#  define UNREFERENCED_PARAMETER(x)
 
276
# else
 
277
#  define UNREFERENCED_PARAMETER(x) (x)
 
278
# endif
 
279
#endif
 
280
 
 
281
DPT_RTN_T       dptCoreCon_C::handleMessage(DPT_MSG_T   message,
 
282
                                            DPT_TAG_T   tgtTag,
 
283
                                            dptBuffer_S *fromEng_P,
 
284
                                            dptBuffer_S *toEng_P,
 
285
                                            uLONG       timeout
 
286
                                           )
 
287
{
 
288
 
 
289
   DPT_RTN_T    retVal = MSG_RTN_FAILED | ERR_INVALID_TGT_TAG;
 
290
   UNREFERENCED_PARAMETER(timeout);
 
291
 
 
292
if (message == MSG_DELETE)
 
293
     // Attempt to delete the object from the engine
 
294
   retVal = delMsgHandler(tgtTag);
 
295
else {
 
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);
 
300
   else {
 
301
        // Get a pointer to the target object
 
302
      dptCoreObj_C *obj_P = (dptCoreObj_C *) objectList.getObject(tgtTag);
 
303
      if (obj_P!=NULL)
 
304
           // Pass the event on to the target object
 
305
         retVal = obj_P->handleMessage(message,fromEng_P,toEng_P);
 
306
   }
 
307
}
 
308
 
 
309
return(retVal);
 
310
 
 
311
}
 
312
//dptCoreCon_C::handleMessage() - end
 
313
 
 
314
 
 
315
//Function - dptCoreCon_C::remFromCon() - start
 
316
//===========================================================================
 
317
//
 
318
//Description:
 
319
//
 
320
//    This function removes the specified object from the connection's
 
321
//lists.
 
322
//
 
323
//Parameters:
 
324
//
 
325
//Return Value:
 
326
//
 
327
//Global Variables Affected:
 
328
//
 
329
//Remarks: (Side effects, Assumptions, Warnings...)
 
330
//
 
331
//
 
332
//---------------------------------------------------------------------------
 
333
 
 
334
void    dptCoreCon_C::remFromCon(dptCoreObj_C *obj_P)
 
335
{
 
336
 
 
337
  // Remove from the master object list
 
338
objectList.remove(obj_P);
 
339
  // Remove from the suppressed device list
 
340
suppressList.remove(obj_P);
 
341
 
 
342
}
 
343
//dptCoreCon_C::remFromCon() - end
 
344
 
 
345
 
 
346
//Function - dptCoreCon_C::remFromCore() - start
 
347
//===========================================================================
 
348
//
 
349
//Description:
 
350
//
 
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:
 
355
//
 
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)
 
360
//
 
361
//Parameters:
 
362
//
 
363
//Return Value:
 
364
//
 
365
//Global Variables Affected:
 
366
//
 
367
//Remarks: (Side effects, Assumptions, Warnings...)
 
368
//
 
369
//---------------------------------------------------------------------------
 
370
 
 
371
uSHORT  dptCoreCon_C::remFromCore(dptCoreObj_C *obj_P)
 
372
{
 
373
 
 
374
  // Call the object's pre-delete handler
 
375
uSHORT action = obj_P->preDelete();
 
376
if (action!=0) {
 
377
     // Remove the object from its manager
 
378
   obj_P->myMgr_P()->remFromMgr(obj_P);
 
379
     // Remove the object from the connection's lists
 
380
   remFromCon(obj_P);
 
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...
 
384
   if (action==1)
 
385
        // Free the object from memory
 
386
      delete(obj_P);
 
387
}
 
388
 
 
389
return (action);
 
390
 
 
391
}
 
392
//dptCoreCon_C::remFromCore() - end
 
393
 
 
394
 
 
395
//Function - dptCoreCon_C::delMsgHandler() - start
 
396
//===========================================================================
 
397
//
 
398
//Description:
 
399
//
 
400
//    This function handles an external delete object message.
 
401
//
 
402
//Parameters:
 
403
//
 
404
//Return Value:
 
405
//
 
406
//Global Variables Affected:
 
407
//
 
408
//Remarks: (Side effects, Assumptions, Warnings...)
 
409
//
 
410
//
 
411
//---------------------------------------------------------------------------
 
412
 
 
413
DPT_RTN_T       dptCoreCon_C::delMsgHandler(DPT_TAG_T tgtTag)
 
414
{
 
415
 
 
416
   DPT_RTN_T    retVal = MSG_RTN_FAILED | ERR_INVALID_TGT_TAG;
 
417
 
 
418
  // Get a pointer to the specified object
 
419
dptCoreObj_C *obj_P = (dptCoreObj_C *) objectList.getObject(tgtTag);
 
420
if (obj_P!=NULL) {
 
421
   if (remFromCore(obj_P)==0)
 
422
      retVal = MSG_RTN_FAILED | ERR_CANNOT_DELETE;
 
423
   else {
 
424
      retVal = MSG_RTN_COMPLETED;
 
425
        // Delete any missing objects that were freed by the deletion
 
426
      delMissing();
 
427
        // Attempt to un-suppress any devices that may have been freed
 
428
        // by the removal
 
429
      unSuppress();
 
430
   }
 
431
}
 
432
 
 
433
return (retVal);
 
434
 
 
435
}
 
436
//dptCoreCon_C::delMsgHandler() - end
 
437
 
 
438
 
 
439
//Function - dptCoreCon_C::delMissing() - start
 
440
//===========================================================================
 
441
//
 
442
//Description:
 
443
//
 
444
//    This function deletes any unused missing objects.
 
445
//
 
446
//Parameters:
 
447
//
 
448
//Return Value:
 
449
//
 
450
//Global Variables Affected:
 
451
//
 
452
//Remarks: (Side effects, Assumptions, Warnings...)
 
453
//
 
454
//
 
455
//---------------------------------------------------------------------------
 
456
 
 
457
void    dptCoreCon_C::delMissing()
 
458
{
 
459
 
 
460
   uSHORT       isMissingMgr = 0;
 
461
 
 
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
 
470
         remFromCore(obj_P);
 
471
      else
 
472
         isMissingMgr = 1;
 
473
   }
 
474
     // Get the next object
 
475
   obj_P = (dptObject_C *) objectList.next();
 
476
}
 
477
 
 
478
if (isMissingMgr) {
 
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
 
485
         remFromCore(obj_P);
 
486
        // Get the next object
 
487
      obj_P = (dptObject_C *) objectList.next();
 
488
   }
 
489
}
 
490
 
 
491
}
 
492
//dptCoreCon_C::delMissing() - end
 
493
 
 
494
 
 
495
//Function - dptCoreCon_C::~dptCoreCon_C() - start
 
496
//===========================================================================
 
497
//
 
498
//Description:
 
499
//
 
500
//    This function is the destructor for the dptCoreCon_C class.
 
501
//
 
502
//Parameters:
 
503
//
 
504
//Return Value:
 
505
//
 
506
//Global Variables Affected:
 
507
//
 
508
//Remarks: (Side effects, Assumptions, Warnings...)
 
509
//
 
510
//
 
511
//---------------------------------------------------------------------------
 
512
 
 
513
dptCoreCon_C::~dptCoreCon_C()
 
514
{
 
515
 
 
516
  // Delete manager zero
 
517
if (mgrZero_P!=NULL) {
 
518
     // Delete all of manager zero's objects
 
519
   mgrZero_P->delAllObjects();
 
520
     // Free from memory
 
521
   delete (mgrZero_P);
 
522
}
 
523
 
 
524
}
 
525
//dptCoreCon_C::~dptCoreCon_C() - end
 
526
 
 
527