File: resource.cpp

package info (click to toggle)
openhpi 3.8.0-2.3
  • links: PTS
  • area: main
  • in suites: sid, trixie
  • size: 31,888 kB
  • sloc: ansic: 225,326; cpp: 63,687; java: 16,472; cs: 15,161; python: 11,884; sh: 11,508; makefile: 4,945; perl: 1,529; xml: 36; asm: 13
file content (721 lines) | stat: -rw-r--r-- 19,372 bytes parent folder | download | duplicates (4)
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
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
/*      -*- c++ -*-
 *
 * (C) Copyright Pigeon Point Systems. 2011
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTRESOURCELITY or FITNESS FOR A PARTICULAR PURPOSE.  This
 * file and program are licensed under a BSD style license.  See
 * the Copying file included with the OpenHPI distribution for
 * full licensing terms.
 *
 * Author(s):
 *        Anton Pak <anton.pak@pigeonpoint.com>
 */

#include <string.h>

#include <SaHpi.h>

#include "codec.h"
#include "handler.h"
#include "log.h"
#include "resource.h"
#include "structs.h"
#include "timers.h"
#include "utils.h"
#include "vars.h"


#include <oh_error.h>
namespace TA {


/**************************************************************
 * Helper functions
 *************************************************************/
static void MakeDefaultRptEntry( const SaHpiEntityPathT& ep,
                                 SaHpiRptEntryT& rpte )
{
    static const SaHpiGuidT guid = { 0xFB, 0x2B, 0x5D, 0xD5, 0x4E, 0x7D, 0x49, 0xF5,
                                     0x93, 0x97, 0xC2, 0xFE, 0xC2, 0x1B, 0x40, 0x10 };
    SaHpiEntityPathT ep2 = ep;
    SaHpiResourceIdT rid = oh_uid_from_entity_path( &ep2 );

    //rpte.EntryId                = SAHPI_ENTRY_UNSPECIFIED;
    rpte.EntryId                = rid; // NB! This is OpenHPI-specific
    rpte.ResourceId             = rid;

    SaHpiResourceInfoT& ri = rpte.ResourceInfo;
    ri.ResourceRev              = 0;
    ri.SpecificVer              = 0;
    ri.DeviceSupport            = 0;
    ri.ManufacturerId           = 0;
    ri.ProductId                = 0;
    ri.FirmwareMajorRev         = 42;
    ri.FirmwareMinorRev         = 43;
    ri.AuxFirmwareRev           = 44;

    memcpy( &ri.Guid, &guid, sizeof(guid) );
    // just a trick to make unique GUID
    memcpy( &ri.Guid, &rid, sizeof(rid) );

    rpte.ResourceEntity         = ep;
    rpte.ResourceCapabilities   = SAHPI_CAPABILITY_RESOURCE |
                                  SAHPI_CAPABILITY_FRU |
                                  SAHPI_CAPABILITY_MANAGED_HOTSWAP |
                                  SAHPI_CAPABILITY_POWER |
                                  SAHPI_CAPABILITY_RESET |
                                  SAHPI_CAPABILITY_RDR;
    rpte.HotSwapCapabilities    = SAHPI_HS_CAPABILITY_INDICATOR_SUPPORTED;
    rpte.ResourceSeverity       = SAHPI_INFORMATIONAL;
    rpte.ResourceFailed         = SAHPI_FALSE;
    FormatHpiTextBuffer( rpte.ResourceTag, "res-%u", (unsigned int)(rid) );
}


/**************************************************************
 * class cResource
 *************************************************************/
cResource::cResource( cHandler& handler,
                      const SaHpiEntityPathT& ep )

    : cObject( AssembleResourceObjectName( ep ), SAHPI_FALSE ),
      cInstruments( handler, *this ),
      m_handler( handler ),
      m_log( 0 )
{
    MakeDefaultRptEntry( ep, m_rpte );
    m_failed             = m_rpte.ResourceFailed;
    m_new_failed         = m_rpte.ResourceFailed;
    m_ae_timeout         = SAHPI_TIMEOUT_IMMEDIATE;
    m_prev_hs_state      = SAHPI_HS_STATE_NOT_PRESENT;
    m_hs_state           = SAHPI_HS_STATE_INACTIVE;
    m_new_hs_state       = SAHPI_HS_STATE_INACTIVE;
    m_hs_ind_state       = SAHPI_HS_INDICATOR_OFF;
    m_load_id.LoadNumber = SAHPI_LOAD_ID_DEFAULT;
    m_rst_state          = SAHPI_RESET_DEASSERT;
    m_pwr_state          = SAHPI_POWER_OFF;

    m_pwr_cycle_cnt      = 0;
}

cResource::~cResource()
{
    delete m_log;
    m_log = 0;
    m_handler.CancelTimer( this );
    SetVisible( false );
}

const SaHpiRptEntryT& cResource::GetRptEntry() const
{
    return m_rpte;
}

SaHpiResourceIdT cResource::GetResourceId() const
{
    return m_rpte.ResourceId;
}

const SaHpiEntityPathT& cResource::GetEntityPath() const
{
    return m_rpte.ResourceEntity;
}

bool cResource::IsFailed() const
{
    return m_failed != SAHPI_FALSE;
}

void cResource::UpdateCaps( SaHpiCapabilitiesT caps )
{
    m_rpte.ResourceCapabilities |= caps;
}

cLog * cResource::GetLog() const
{
    return m_log;
}

// HPI interface
SaErrorT cResource::SetTag( const SaHpiTextBufferT& tag )
{
    m_rpte.ResourceTag = tag;

    return SA_OK;
}

SaErrorT cResource::SetSeverity( SaHpiSeverityT sev )
{
    m_rpte.ResourceSeverity = sev;

    return SA_OK;
}

SaErrorT cResource::CancelHsPolicy( const SaHpiTimeoutT& timeout )
{
    const SaHpiCapabilitiesT caps = m_rpte.ResourceCapabilities;
    if ( ( caps & SAHPI_CAPABILITY_MANAGED_HOTSWAP ) == 0 ) {
        return SA_ERR_HPI_CAPABILITY;
    }
    switch ( m_hs_state ) {
        case SAHPI_HS_STATE_INSERTION_PENDING:
        case SAHPI_HS_STATE_EXTRACTION_PENDING:
            break;
        default:
            return SA_ERR_HPI_INVALID_REQUEST;
    }

    m_handler.CancelTimer( this );

    return SA_OK;
}

SaErrorT cResource::GetAutoExtractTimeout( SaHpiTimeoutT& timeout ) const
{
    const SaHpiCapabilitiesT caps = m_rpte.ResourceCapabilities;
    if ( ( caps & SAHPI_CAPABILITY_MANAGED_HOTSWAP ) == 0 ) {
        return SA_ERR_HPI_CAPABILITY;
    }

    timeout = m_ae_timeout;

    return SA_OK;
}

SaErrorT cResource::SetAutoExtractTimeout( const SaHpiTimeoutT& timeout )
{
    const SaHpiCapabilitiesT caps = m_rpte.ResourceCapabilities;
    const SaHpiHsCapabilitiesT hs_caps = m_rpte.HotSwapCapabilities;
    if ( ( caps & SAHPI_CAPABILITY_MANAGED_HOTSWAP ) == 0 ) {
        return SA_ERR_HPI_CAPABILITY;
    }
    if ( ( hs_caps & SAHPI_HS_CAPABILITY_AUTOEXTRACT_READ_ONLY ) != 0 ) {
        return SA_ERR_HPI_READ_ONLY;
    }

    m_ae_timeout = timeout;

    return SA_OK;
}

SaErrorT cResource::GetHsState( SaHpiHsStateT& state ) const
{
    const SaHpiCapabilitiesT caps = m_rpte.ResourceCapabilities;
    if ( ( caps & SAHPI_CAPABILITY_FRU ) == 0 ) {
        return SA_ERR_HPI_CAPABILITY;
    }

    state = m_hs_state;

    return SA_OK;
}

SaErrorT cResource::SetHsState( SaHpiHsStateT state )
{
    const SaHpiCapabilitiesT caps = m_rpte.ResourceCapabilities;
    if ( ( caps & SAHPI_CAPABILITY_MANAGED_HOTSWAP ) == 0 ) {
        return SA_ERR_HPI_CAPABILITY;
    }

    switch ( m_hs_state ) {
        case SAHPI_HS_STATE_INSERTION_PENDING:
        case SAHPI_HS_STATE_EXTRACTION_PENDING:
            break;
        default:
            return SA_ERR_HPI_INVALID_REQUEST;
    }

    m_handler.CancelTimer( this );
    m_new_hs_state = state;
    CommitChanges();

    return SA_OK;
}

SaErrorT cResource::RequestHsAction( SaHpiHsActionT action )
{
    const SaHpiCapabilitiesT caps = m_rpte.ResourceCapabilities;
    if ( ( caps & SAHPI_CAPABILITY_MANAGED_HOTSWAP ) == 0 ) {
        return SA_ERR_HPI_CAPABILITY;
    }


    SaHpiTimeoutT ait, aet, t;
    GetTimeouts( ait, aet );

    if ( m_hs_state == SAHPI_HS_STATE_INACTIVE ) {
        if ( action != SAHPI_HS_ACTION_INSERTION ) {
            return SA_ERR_HPI_INVALID_REQUEST;
        }
        m_new_hs_state = SAHPI_HS_STATE_INSERTION_PENDING;
        t = ait;
    } else if ( m_hs_state == SAHPI_HS_STATE_ACTIVE ) {
        if ( action != SAHPI_HS_ACTION_EXTRACTION ) {
            return SA_ERR_HPI_INVALID_REQUEST;
        }
        m_new_hs_state = SAHPI_HS_STATE_EXTRACTION_PENDING;
        t = aet;
    } else {
        return SA_ERR_HPI_INVALID_REQUEST;
    }

    CommitChanges();
    m_handler.SetTimer( this, t );

    return SA_OK;
}

SaErrorT cResource::GetHsIndicatorState( SaHpiHsIndicatorStateT& state ) const
{
    const SaHpiCapabilitiesT caps = m_rpte.ResourceCapabilities;
    const SaHpiHsCapabilitiesT hs_caps = m_rpte.HotSwapCapabilities;
    if ( ( caps & SAHPI_CAPABILITY_MANAGED_HOTSWAP ) == 0 ) {
        return SA_ERR_HPI_CAPABILITY;
    }
    if ( ( hs_caps & SAHPI_HS_CAPABILITY_INDICATOR_SUPPORTED ) == 0 ) {
        return SA_ERR_HPI_CAPABILITY;
    }

    state = m_hs_ind_state;

    return SA_OK;
}

SaErrorT cResource::SetHsIndicatorState( const SaHpiHsIndicatorStateT& state )
{
    const SaHpiCapabilitiesT caps = m_rpte.ResourceCapabilities;
    const SaHpiHsCapabilitiesT hs_caps = m_rpte.HotSwapCapabilities;
    if ( ( caps & SAHPI_CAPABILITY_MANAGED_HOTSWAP ) == 0 ) {
        return SA_ERR_HPI_CAPABILITY;
    }
    if ( ( hs_caps & SAHPI_HS_CAPABILITY_INDICATOR_SUPPORTED ) == 0 ) {
        return SA_ERR_HPI_CAPABILITY;
    }

    m_hs_ind_state = state;

    return SA_OK;
}

SaErrorT cResource::GetPowerState( SaHpiPowerStateT& state )
{
    const SaHpiCapabilitiesT caps = m_rpte.ResourceCapabilities;
    if ( ( caps & SAHPI_CAPABILITY_POWER ) == 0 ) {
        return SA_ERR_HPI_CAPABILITY;
    }

    if ( m_pwr_cycle_cnt > 0 ) {
        --m_pwr_cycle_cnt;
        if ( m_pwr_cycle_cnt == 0 ) {
            if ( m_pwr_state == SAHPI_POWER_ON ) {
                m_pwr_state = SAHPI_POWER_OFF;
            } else if ( m_pwr_state == SAHPI_POWER_OFF ) {
                m_pwr_state = SAHPI_POWER_ON;
            }
        }
    }

    state = m_pwr_state;

    return SA_OK;
}

SaErrorT cResource::SetPowerState( const SaHpiPowerStateT& state )
{
    const SaHpiCapabilitiesT caps = m_rpte.ResourceCapabilities;
    if ( ( caps & SAHPI_CAPABILITY_POWER ) == 0 ) {
        return SA_ERR_HPI_CAPABILITY;
    }
    if ( state == SAHPI_POWER_CYCLE ) {
        if ( m_pwr_state == SAHPI_POWER_ON ) {
            m_pwr_state = SAHPI_POWER_OFF;
        } else if ( m_pwr_state == SAHPI_POWER_OFF ) {
            m_pwr_state = SAHPI_POWER_ON;
        }
        m_pwr_cycle_cnt = PwrCycleDuration;
    } else {
        m_pwr_state     = state;
        m_pwr_cycle_cnt = 0;
    }

    return SA_OK;
}

SaErrorT cResource::ControlParm( SaHpiParmActionT action )
{
    const SaHpiCapabilitiesT caps = m_rpte.ResourceCapabilities;
    if ( ( caps & SAHPI_CAPABILITY_CONFIGURATION ) == 0 ) {
        return SA_ERR_HPI_CAPABILITY;
    }

    return SA_OK;
}

SaErrorT cResource::GetLoadId( SaHpiLoadIdT& load_id ) const
{
    const SaHpiCapabilitiesT caps = m_rpte.ResourceCapabilities;
    if ( ( caps & SAHPI_CAPABILITY_LOAD_ID ) == 0 ) {
        return SA_ERR_HPI_CAPABILITY;
    }

    load_id = m_load_id;

    return SA_OK;
}

SaErrorT cResource::SetLoadId( const SaHpiLoadIdT& load_id )
{
    const SaHpiCapabilitiesT caps = m_rpte.ResourceCapabilities;
    if ( ( caps & SAHPI_CAPABILITY_LOAD_ID ) == 0 ) {
        return SA_ERR_HPI_CAPABILITY;
    }

    m_load_id = load_id;

    return SA_OK;
}

SaErrorT cResource::GetResetState( SaHpiResetActionT& action ) const
{
    const SaHpiCapabilitiesT caps = m_rpte.ResourceCapabilities;
    if ( ( caps & SAHPI_CAPABILITY_RESET ) == 0 ) {
        return SA_ERR_HPI_CAPABILITY;
    }

    action = m_rst_state;

    return SA_OK;
}

SaErrorT cResource::SetResetState( const SaHpiResetActionT& action )
{
    const SaHpiCapabilitiesT caps = m_rpte.ResourceCapabilities;
    if ( ( caps & SAHPI_CAPABILITY_RESET ) == 0 ) {
        return SA_ERR_HPI_CAPABILITY;
    }

    if ( ( action == SAHPI_COLD_RESET ) || ( action == SAHPI_WARM_RESET ) ) {
        if ( m_rst_state == SAHPI_RESET_ASSERT ) {
            return SA_ERR_HPI_INVALID_REQUEST;
        }
        m_rst_state = SAHPI_RESET_DEASSERT;
    } else {
        m_rst_state = action;
    }

    return SA_OK;
}


// Event generation
void cResource::PostEvent( SaHpiEventTypeT type,
                           const SaHpiEventUnionT& data,
                           SaHpiSeverityT severity,
                           const InstrumentList& updates,
                           const InstrumentList& removals ) const
{
    if ( m_log ) {
        const cInstrument * instr = 0;
        if ( !updates.empty() ) {
            instr = updates.front();
        } else if ( !removals.empty() ) {
            instr = removals.front();
        }
        if ( instr ) {
            const SaHpiRdrT& rdr = instr->GetRdr();
            m_log->AddEntry( type, data, severity, &rdr, &m_rpte );
        } else {
            m_log->AddEntry( type, data, severity, 0, &m_rpte );
        }
    }
    if ( !IsVisible() ) {
        return;
    }
    m_handler.PostEvent( type, data, severity, this, updates, removals );
}

void cResource::PostResourceEvent( SaHpiResourceEventTypeT type ) const
{
    SaHpiEventUnionT data;
    data.ResourceEvent.ResourceEventType = type;

    // attach all instruments
    InstrumentList updates;
    if ( type == SAHPI_RESE_RESOURCE_ADDED ) {
        GetAllInstruments( updates );
    }

    SaHpiSeverityT severity;
    switch ( type ) {
        case SAHPI_RESE_RESOURCE_FAILURE:
        case SAHPI_RESE_RESOURCE_RESTORED:
        case SAHPI_RESE_RESOURCE_REMOVED:
            severity = m_rpte.ResourceSeverity;
            break;
        default:
            severity = SAHPI_INFORMATIONAL;
    }

    PostEvent( SAHPI_ET_RESOURCE, data, severity, updates );
}

void cResource::PostHsEvent( SaHpiHsStateT current, SaHpiHsStateT prev ) const
{
    SaHpiEventUnionT data;
    SaHpiHotSwapEventT& hse = data.HotSwapEvent;
    hse.HotSwapState         = current;
    hse.PreviousHotSwapState = prev;
    hse.CauseOfStateChange   = SAHPI_HS_CAUSE_AUTO_POLICY; // TODO

    // attach all instruments
    InstrumentList updates;
    if ( prev == SAHPI_HS_STATE_NOT_PRESENT ) {
        if ( current != SAHPI_HS_STATE_NOT_PRESENT ) {
            GetAllInstruments( updates );
        }
    }

    // TODO severity
    PostEvent( SAHPI_ET_HOTSWAP, data, SAHPI_INFORMATIONAL, updates );
}


// cObject virtual functions
void cResource::BeforeVisibilityChange()
{
    cObject::BeforeVisibilityChange();

    if ( IsVisible() ) {
        // Resource disappears
        if ( m_rpte.ResourceCapabilities & SAHPI_CAPABILITY_FRU ) {
            PostHsEvent( SAHPI_HS_STATE_NOT_PRESENT, m_hs_state );
        } else {
            PostResourceEvent( SAHPI_RESE_RESOURCE_REMOVED );
        }
    }
}

void cResource::AfterVisibilityChange()
{
    if ( IsVisible() ) {
        // Resource appears
        if ( m_rpte.ResourceCapabilities & SAHPI_CAPABILITY_FRU ) {
            PostHsEvent( m_hs_state, SAHPI_HS_STATE_NOT_PRESENT );
        } else {
            PostResourceEvent( SAHPI_RESE_RESOURCE_ADDED );
        }
    }

    cObject::AfterVisibilityChange();
}

void cResource::GetNewNames( cObject::NewNames& names ) const
{
    cObject::GetNewNames( names );
    names.push_back( "log" );

    cInstruments::GetNewNames( names );
}

bool cResource::CreateChild( const std::string& name )
{
    bool rc;

    rc = cObject::CreateChild( name );
    if ( rc ) {
        return true;
    }
    if ( name == cLog::classname ) {
        CreateLog();
        return true;
    }
    rc = CreateInstrument( name );
    if ( rc ) {
        return true;
    }

    return false;
}

bool cResource::RemoveChild( const std::string& name )
{
    bool rc;

    rc = cObject::RemoveChild( name );
    if ( rc ) {
        return true;
    }
    if ( name == cLog::classname ) {
        RemoveLog();
        return true;
    }
    rc = RemoveInstrument( name );
    if ( rc ) {
        return true;
    }

    return false;
}

void cResource::GetChildren( Children& children ) const
{
    cObject::GetChildren( children );
    if ( m_log ) {
        children.push_back( m_log );
    }
    cInstruments::GetChildren( children );
}

void cResource::GetVars( cVars& vars )
{
    cObject::GetVars( vars );

    SaHpiCapabilitiesT caps = m_rpte.ResourceCapabilities;
    SaHpiHsCapabilitiesT hs_caps = m_rpte.HotSwapCapabilities;
    bool fru  = ( caps & SAHPI_CAPABILITY_FRU );
    bool hs   = fru && ( caps & SAHPI_CAPABILITY_MANAGED_HOTSWAP );
    bool ind  = hs && ( hs_caps & SAHPI_HS_CAPABILITY_INDICATOR_SUPPORTED );
    bool load = ( caps & SAHPI_CAPABILITY_LOAD_ID );
    bool rst  = ( caps & SAHPI_CAPABILITY_RESET );
    bool pwr  = ( caps & SAHPI_CAPABILITY_POWER );

    Structs::GetVars( m_rpte, vars );
    vars << "ResourceFailed"
         << dtSaHpiBoolT
         << DATA( m_failed, m_new_failed )
         << VAR_END();
    vars << IF( hs )
         << "AutoExtractTimeout"
         << dtSaHpiTimeoutT
         << DATA( m_ae_timeout )
         << VAR_END();
    vars << IF( fru )
         << "PreviousHotSwapState"
         << dtSaHpiHsStateT
         << DATA( m_prev_hs_state )
         << READONLY()
         << VAR_END();
    vars << IF( fru )
         << "HotSwapState"
         << dtSaHpiHsStateT
         << DATA( m_hs_state, m_new_hs_state )
         << VAR_END();
    vars << IF( ind )
         << "HotSwapIndicatorState"
         << dtSaHpiHsIndicatorStateT
         << DATA( m_hs_ind_state )
         << VAR_END();
    if ( load ) {
        Structs::GetVars( m_load_id, vars );
    }
    vars << IF( rst )
         << "ResetState"
         << dtSaHpiResetActionT
         << DATA( m_rst_state )
         << VAR_END();
    vars << IF( pwr )
         << "PowerState"
         << dtSaHpiPowerStateT
         << DATA( m_pwr_state )
         << VAR_END();
}

void cResource::BeforeVarSet( const std::string& var_name )
{
    cObject::BeforeVarSet( var_name );

    m_new_failed   = m_failed;
    m_new_hs_state = m_hs_state;
}

void cResource::AfterVarSet( const std::string& var_name )
{
    cObject::AfterVarSet( var_name );

    if ( var_name.find( "RptEntry." ) == 0 ) {
        // RPT Entry was changed
        PostResourceEvent( SAHPI_RESE_RESOURCE_UPDATED );
    }
    if ( var_name == "PowerState" ) {
        m_pwr_cycle_cnt = 0;
    }

    CommitChanges();
}

void cResource::CreateLog()
{
    if ( m_log == 0 ) {
        m_log = new cLog();
        m_rpte.ResourceCapabilities |= cLog::RequiredResourceCap();
        PostResourceEvent( SAHPI_RESE_RESOURCE_UPDATED );
    }
}

void cResource::RemoveLog()
{
    if ( m_log ) {
        delete m_log;
        m_log = 0;
        m_rpte.ResourceCapabilities &= ~cLog::RequiredResourceCap();
        PostResourceEvent( SAHPI_RESE_RESOURCE_UPDATED );
    }
}

void cResource::TimerEvent()
{
    if ( m_hs_state == SAHPI_HS_STATE_INSERTION_PENDING ) {
        m_new_hs_state = SAHPI_HS_STATE_ACTIVE;
    } else if ( m_hs_state == SAHPI_HS_STATE_EXTRACTION_PENDING ) {
        m_new_hs_state = SAHPI_HS_STATE_INACTIVE;
    }

    CommitChanges();
}


void cResource::GetTimeouts( SaHpiTimeoutT& ai_timeout,
                             SaHpiTimeoutT& ae_timeout ) const
{
    SaHpiHsCapabilitiesT hs_caps = m_rpte.HotSwapCapabilities;
    if ( hs_caps & SAHPI_HS_CAPABILITY_AUTOINSERT_IMMEDIATE ) {
        ai_timeout = SAHPI_TIMEOUT_IMMEDIATE;
    } else {
        ai_timeout = m_handler.GetAutoInsertTimeout();
    }
    ae_timeout = m_ae_timeout;
}

void cResource::CommitChanges()
{
    if ( m_failed != m_new_failed ) {
        m_failed              = m_new_failed;
        m_rpte.ResourceFailed = m_failed;

        PostResourceEvent( ( m_failed == SAHPI_FALSE ) ?
                           SAHPI_RESE_RESOURCE_RESTORED :
                           SAHPI_RESE_RESOURCE_FAILURE );
    }

    if ( m_hs_state != m_new_hs_state ) {
        m_prev_hs_state = m_hs_state;
        m_hs_state      = m_new_hs_state;

        PostHsEvent( m_hs_state, m_prev_hs_state );
    }

    SaHpiTimeoutT ait, aet, t;
    if ( m_hs_state == SAHPI_HS_STATE_INSERTION_PENDING ) {
        GetTimeouts( t, aet );
        m_handler.SetTimer( this, t );
    } else if ( m_hs_state == SAHPI_HS_STATE_EXTRACTION_PENDING ) {
        GetTimeouts( ait, t );
        m_handler.SetTimer( this, t );
    }
}


}; // namespace TA