summaryrefslogtreecommitdiffstats
path: root/src/usr/targeting/common/targetservice.C
blob: ab534100a4094af2f783789ae9217e9dd50adb08 (plain)
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
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/targeting/common/targetservice.C $                    */
/*                                                                        */
/* IBM CONFIDENTIAL                                                       */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2011,2012              */
/*                                                                        */
/* p1                                                                     */
/*                                                                        */
/* Object Code Only (OCO) source materials                                */
/* Licensed Internal Code Source Materials                                */
/* IBM HostBoot Licensed Internal Code                                    */
/*                                                                        */
/* The source code for this program is not published or otherwise         */
/* divested of its trade secrets, irrespective of what has been           */
/* deposited with the U.S. Copyright Office.                              */
/*                                                                        */
/* Origin: 30                                                             */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
/**
 *  @file targeting/common/targetservice.C
 *
 *  @brief Implementation of the TargetService which manages the pool of
 *      available targets, provides iteration support, and otherwise makes
 *      target available and usable.
 */

//******************************************************************************
// Includes
//******************************************************************************

// STD
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// This component
#include <targeting/common/targetservice.H>
#include <targeting/common/predicates/predicates.H>
#include <pnortargeting.H>
#include <targeting/attrrp.H>
#include <targeting/common/trace.H>
#include <targeting/adapters/types.H>

//******************************************************************************
// targetService
//******************************************************************************

namespace TARGETING
{

#define TARG_NAMESPACE "TARGETING::"

#define TARG_CLASS "targetService"

//******************************************************************************
// targetService
//******************************************************************************

TARGETING::TargetService& targetService()
{
    #define TARG_FN "targetService()"

    return TARG_GET_SINGLETON(TARGETING::theTargetService);

    #undef TARG_FN
}

//******************************************************************************
// Component trace buffer
//******************************************************************************

TARG_TD_t g_trac_targeting = {0};
TRAC_INIT(&g_trac_targeting, "TARG", 4096);

#undef TARG_CLASS
#define TARG_CLASS "TargetService::"

//******************************************************************************
// TargetService::TargetService
//******************************************************************************

TargetService::TargetService() :
    iv_initialized(false), iv_maxTargets(0), iv_pPnor(NULL)
{
    #define TARG_FN "TargetService()"

    #undef TARG_FN
}

//******************************************************************************
// TargetService::~TargetService
//******************************************************************************

TargetService::~TargetService()
{
    #define TARG_FN "~TargetService()"

    // Nothing to do; Target[] memory not owned by this object

    #undef TARG_FN
}

//******************************************************************************
// TargetService::init
//******************************************************************************

void TargetService::init()
{
    #define TARG_FN "init()"

    TARG_ENTER();

    // Build the association mappings
    AssociationAttrMap a1 = {PARENT, INWARDS, ATTR_PHYS_PATH};
    AssociationAttrMap a2 = {CHILD, OUTWARDS, ATTR_PHYS_PATH};
    AssociationAttrMap a3 = {PARENT_BY_AFFINITY, INWARDS, ATTR_AFFINITY_PATH};
    AssociationAttrMap a4 = {CHILD_BY_AFFINITY, OUTWARDS, ATTR_AFFINITY_PATH};
    AssociationAttrMap a5 = {VOLTAGE_SUPPLIER, INWARDS, ATTR_POWER_PATH};
    AssociationAttrMap a6 = {VOLTAGE_CONSUMER, OUTWARDS, ATTR_POWER_PATH};
    iv_associationMappings.push_back(a1);
    iv_associationMappings.push_back(a2);
    iv_associationMappings.push_back(a3);
    iv_associationMappings.push_back(a4);
    iv_associationMappings.push_back(a5);
    iv_associationMappings.push_back(a6);

    // Cache location of RO section containing all the attribute metadata
    TargetingHeader* l_pHdr = reinterpret_cast<TargetingHeader*>(
            TARG_GET_SINGLETON(TARGETING::theAttrRP).getBaseAddress());

    TARG_ASSERT((l_pHdr != NULL), TARG_ERR_LOC
                "FATAL: Targeting header is NULL!")
    TARG_ASSERT((l_pHdr->eyeCatcher == PNOR_TARG_EYE_CATCHER), TARG_ERR_LOC
                "FATAL: Targeting eyecatcher not found; "
                "expected 0x%08X but got 0x%08X",
                PNOR_TARG_EYE_CATCHER,l_pHdr->eyeCatcher);

    iv_pPnor = reinterpret_cast<uint32_t*>(
        (reinterpret_cast<char*>(l_pHdr) + l_pHdr->headerSize));

    (void)_configureTargetPool();

    iv_initialized = true;

    TARG_EXIT();

    #undef TARG_FN
}

//******************************************************************************
// TargetService::begin (non-const version)
//******************************************************************************

TargetService::iterator TargetService::begin()
{
    #define TARG_FN "begin()"

    TARG_ASSERT(iv_initialized, TARG_ERR_LOC
               "USAGE: TargetService not initialized");

    Target* l_pFirstTarget = (iv_maxTargets == 0) ? NULL : &(*iv_targets)[0];
    TARG_ASSERT(l_pFirstTarget != NULL, TARG_ERR_LOC
               "FATAL: Could not find any targets");

    return iterator(l_pFirstTarget);

    #undef TARG_FN
}

//******************************************************************************
// TargetService::begin (const version)
//******************************************************************************

//TargetService::const_iterator
_TargetIterator<const Target*> TargetService::begin() const
{
    #define TARG_FN "begin() const"

    TARG_ASSERT(iv_initialized, TARG_ERR_LOC
               "USAGE: TargetService not initialized");

    const Target* l_pFirstTarget =
        (iv_maxTargets == 0) ? NULL : &(*iv_targets)[0];
    TARG_ASSERT(l_pFirstTarget != NULL, TARG_ERR_LOC
               "FATAL: Could not find any targets");

    return const_iterator(l_pFirstTarget);

    #undef TARG_FN
}

//******************************************************************************
// TargetService::end (non-const version)
//******************************************************************************

TargetService::iterator TargetService::end()
{
    #define TARG_FN "end()"

    TARG_ASSERT(iv_initialized, TARG_ERR_LOC
               "USAGE: TargetService not initialized");

    return iterator(NULL);

    #undef TARG_FN
}

//******************************************************************************
// TargetService::end (const version)
//******************************************************************************

TargetService::const_iterator TargetService::end() const
{
    #define TARG_FN "end() const"

    TARG_ASSERT(iv_initialized, TARG_ERR_LOC
               "USAGE: TargetService not initialized");

    return const_iterator(NULL);

    #undef TARG_FN
}

//******************************************************************************
// TargetService::getTopLevelTarget
//******************************************************************************

void TargetService::getTopLevelTarget(
    Target*& o_targetHandle) const
{
    #define TARG_FN "getTopLevelTarget(...)"

    TARG_ASSERT(iv_initialized, TARG_ERR_LOC
               "USAGE: TargetService not initialized");

    EntityPath l_topLevelPhysicalPath(EntityPath::PATH_PHYSICAL);
    l_topLevelPhysicalPath.addLast(TYPE_SYS, 0);
    o_targetHandle = toTarget(l_topLevelPhysicalPath);

    #undef TARG_FN
}

//******************************************************************************
// TargetService::exists
//******************************************************************************

void TargetService::exists(
    const EntityPath& i_entityPath,
          bool&       o_exists) const
{
    #define TARG_FN "exists(...)"

    bool l_found = false;

    TARG_ASSERT(iv_initialized, TARG_ERR_LOC
                "USAGE: TargetService not initialized");

    for (uint32_t i = 0; i < iv_maxTargets; ++i)
    {
        if (i_entityPath == (*iv_targets)[i].getAttr<ATTR_PHYS_PATH> ())
        {
            l_found = true;
        }
    }

    o_exists = l_found;

    #undef TARG_FN
}

//******************************************************************************
// TargetService::toTarget
//******************************************************************************

Target* TargetService::toTarget(
    const EntityPath& i_entityPath) const
{
    #define TARG_FN "toTarget(...)"

    // Used by -> operator on EntityPath for convenience (can be dangerous
    // though!)
    Target* l_pTarget = NULL;

    TARG_ASSERT(iv_initialized, TARG_ERR_LOC
                "USAGE: TargetService not initialized");

    for (uint32_t i = 0; i < iv_maxTargets; ++i)
    {
        bool found = false;
        switch(i_entityPath.type())
        {
            case EntityPath::PATH_PHYSICAL: 
                found = (   (i_entityPath)
                         == (*iv_targets)[i].getAttr<ATTR_PHYS_PATH>());
                break;
            case EntityPath::PATH_AFFINITY: 
                found = (   (i_entityPath)
                         == (*iv_targets)[i].getAttr<ATTR_AFFINITY_PATH>());
                break;
            default:
                break;
        }

        if (found)
        {
            l_pTarget = &(*iv_targets)[i];
            break;
        }
    }

    return l_pTarget;

    #undef TARG_FN
}

//******************************************************************************
// TargetService::masterProcChipTargetHandle
//******************************************************************************

void TargetService::masterProcChipTargetHandle(
    Target*& o_masterProcChipTargetHandle,
    const uint8_t i_node) const
{
    #define TARG_FN "masterProcChipTargetHandle(...)"

    Target* l_pTarget = NULL;

    TARG_ASSERT(iv_initialized, TARG_ERR_LOC
                "USAGE: TargetService not initialized");

    //@TODO Need to query the actual hardware and cross check it with
    // PNOR to determine the master chip
    // target; for now, just always report sys0.n0.proc0
    EntityPath l_masterProcChipEntityPath(EntityPath::PATH_PHYSICAL);
    l_masterProcChipEntityPath.addLast(TYPE_SYS, 0).addLast(TYPE_NODE, i_node)
        .addLast(TYPE_PROC, 0);

    l_pTarget = l_masterProcChipEntityPath.operator->();

    o_masterProcChipTargetHandle = l_pTarget;

    #undef TARG_FN
}

//******************************************************************************
// TargetService::tryGetPath
//******************************************************************************

bool TargetService::tryGetPath(
    const ATTRIBUTE_ID  i_attr,
    const Target* const i_pTarget,
          EntityPath&   o_entityPath) const
{
    #define TARG_FN "tryGetPath(...)"

    bool l_exist = false;

    TARG_ASSERT(iv_initialized, TARG_ERR_LOC
                "USAGE: TargetService not initialized");

    switch (i_attr)
    {
        case ATTR_PHYS_PATH:
            l_exist = i_pTarget->tryGetAttr<ATTR_PHYS_PATH> (o_entityPath);
            break;
        case ATTR_AFFINITY_PATH:
            l_exist = i_pTarget->tryGetAttr<ATTR_AFFINITY_PATH> (
                o_entityPath);
            break;
        case ATTR_POWER_PATH:
            l_exist = i_pTarget->tryGetAttr<ATTR_POWER_PATH> (o_entityPath);
            break;
        default:
            TARG_ASSERT(0, TARG_ERR_LOC
                        "i_attr = 0x%08X does not map to an entity path",
                        i_attr);
            break;
    }

    return l_exist;

    #undef TARG_FN
}

//******************************************************************************
// TargetService::getAssociated
//******************************************************************************

void TargetService::getAssociated(
          TargetHandleList&    o_list,
    const Target* const        i_pTarget,
    const ASSOCIATION_TYPE     i_type,
    const RECURSION_LEVEL      i_recursionLevel,
    const PredicateBase* const i_pPredicate) const
{
    #define TARG_FN "getAssociated(...)"

    do {

    TARG_ASSERT(iv_initialized, TARG_ERR_LOC
                "USAGE: TargetService not initialized");

    TARG_ASSERT(   (i_pTarget != NULL)
                && (i_pTarget != MASTER_PROCESSOR_CHIP_TARGET_SENTINEL),
                TARG_ERR_LOC "Caller tried to get association using a NULL "
                "target handle or the master processor chip target handle "
                "sentinel. i_pTarget = %p",i_pTarget);

    // Start with no elements
    o_list.clear();

    // Figure out which attribute to look up
    for (uint32_t i = 0; i < iv_associationMappings.size(); ++i)
    {
        if (i_type == iv_associationMappings[i].associationType)
        {
            EntityPath l_entityPath;

            bool l_exist = tryGetPath(iv_associationMappings[i].attr,
                i_pTarget, l_entityPath);

            if (l_exist)
            {
                if (iv_associationMappings[i].associationDir == INWARDS)
                {
                    (void) _getInwards(iv_associationMappings[i].attr,
                        i_recursionLevel, l_entityPath, i_pPredicate, o_list);
                }
                else if (iv_associationMappings[i].associationDir
                    == OUTWARDS)
                {
                    (void) _getOutwards(iv_associationMappings[i].attr,
                        i_recursionLevel, l_entityPath, i_pPredicate, o_list);
                }
                else
                {
                    TARG_ASSERT(0, TARG_LOC
                           "iv_associationMappings[i].associationDir "
                           "= 0x%X not supported",
                           iv_associationMappings[i].associationDir);
                }
            }
            break;
        }
    }

    } while (0);

    #undef TARG_FN
}

//******************************************************************************
// TargetService::dump()
//******************************************************************************

void TargetService::dump() const
{
    #define TARG_FN "dump(...)"

    TARG_ASSERT(iv_initialized, TARG_ERR_LOC
               "USAGE: TargetService not initialized");

    TARG_INF("Targets (size=%d):",
             sizeof(Target)*iv_maxTargets);

    for (uint32_t i = 0; i < iv_maxTargets; ++i)
    {
        TARG_INF(
            "[Target %d] "
            "Class = 0x%X, "
            "Type = 0x%X, "
            "Model = 0x%X",
            i,
            (*iv_targets)[i].getAttr<ATTR_CLASS>(),
            (*iv_targets)[i].getAttr<ATTR_TYPE>(),
            (*iv_targets)[i].getAttr<ATTR_MODEL>());
        TARG_INF("Physical");
        (*iv_targets)[i].getAttr<ATTR_PHYS_PATH>().dump();

        EntityPath l_entityPath;
        if( (*iv_targets)[i].tryGetAttr<ATTR_AFFINITY_PATH>(l_entityPath) )
        {
            TARG_INF("Affinity");
            l_entityPath.dump();
        }

        if( (*iv_targets)[i].tryGetAttr<ATTR_POWER_PATH>(l_entityPath) )
        {
            TARG_INF("Power");
            l_entityPath.dump();
        }

        DUMMY_RW_ATTR l_dummyRw;
        memset(l_dummyRw,0x00,sizeof(l_dummyRw));
        if ((*iv_targets)[i].tryGetAttr<ATTR_DUMMY_RW> (l_dummyRw))
        {
            TARG_INF("Dummy = 0x%X",
                l_dummyRw[0][0][0]);
        }

        TARG_INF("Supports FSI SCOM = %d",
        (*iv_targets)[i].getAttr<ATTR_PRIMARY_CAPABILITIES>()
            .supportsFsiScom);
        TARG_INF("Supports XSCOM SCOM = %d",
        (*iv_targets)[i].getAttr<ATTR_PRIMARY_CAPABILITIES>()
            .supportsXscom);
        TARG_INF("Supports Inband SCOM = %d",
        (*iv_targets)[i].getAttr<ATTR_PRIMARY_CAPABILITIES>()
            .supportsInbandScom);

        ScomSwitches l_switches = {0};
        if ( (*iv_targets)[i].tryGetAttr<ATTR_SCOM_SWITCHES>(l_switches) )
        {
            TARG_INF("Use FSI SCOM = %d",l_switches.useFsiScom);
            TARG_INF("Use XSCOM = %d",l_switches.useXscom);
            TARG_INF("Use inband SCOM = %d",l_switches.useInbandScom);
        }

        uint64_t l_xscomBaseAddr = 0;
        if ( (*iv_targets)[i].tryGetAttr<ATTR_XSCOM_BASE_ADDRESS>(
            l_xscomBaseAddr) )
        {
            TARG_INF("XSCOM Base Address = 0x%016llX",l_xscomBaseAddr);
        }

        uint8_t l_Node_Id = 0;
        if ( (*iv_targets)[i].tryGetAttr<ATTR_FABRIC_NODE_ID>(l_Node_Id))
        {
            TARG_INF("XSCOM Node ID = 0x%X",l_Node_Id);
        }

        uint8_t l_Chip_Id = 0;
        if ( (*iv_targets)[i].tryGetAttr<ATTR_FABRIC_CHIP_ID>(l_Chip_Id))
        {
            TARG_INF("XSCOM Chip ID = 0x%X",l_Chip_Id);
        }

    }

    return;

    #undef TARG_FN
}


//******************************************************************************
// TargetService::writeSectionData
//******************************************************************************
bool TargetService::writeSectionData(
    const std::vector<sectionRefData>& i_pages)
{
    #define TARG_FN "writeSectionData(...)"
    TARG_ENTER();
    bool l_response = false;
    if(i_pages.size() != 0)
    {
        TARG_GET_SINGLETON(TARGETING::theAttrRP).writeSectionData(i_pages);
        l_response = true;
    }
    TARG_EXIT();

    return l_response;
    #undef TARG_FN
}

//******************************************************************************
// TargetService::readSectionData
//******************************************************************************
void TargetService::readSectionData(
    std::vector <sectionRefData>& o_pages,
    const SECTION_TYPE i_sectionId)
{
    #define TARG_FN "readSectionData(...)"
    TARG_ENTER();

    TARG_GET_SINGLETON(TARGETING::theAttrRP).readSectionData(
                                                     o_pages, i_sectionId);

    TARG_EXIT();

    #undef TARG_FN
}

//******************************************************************************
// TargetService::_configureTargetPool
//******************************************************************************

void TargetService::_configureTargetPool()
{
#define TARG_FN "_configureTargetPool(...)"

    TARG_ENTER();

    _maxTargets();

    // iv_pPnor--> points to uint32_t* --> points to --> uint32_t, targets[]
    //                   (uint32_t*)+1 --> points to ------------> targets[]
    const AbstractPointer<uint32_t>* ppNumTargets 
        = static_cast<const AbstractPointer<uint32_t>*>(iv_pPnor);
    iv_targets =
           reinterpret_cast< Target(*)[] > (
               (TARG_TO_PLAT_PTR_AND_INC(*ppNumTargets,1)));
    TARG_ASSERT(iv_targets, TARG_ERR_LOC
                "FATAL: Could not determine location of targets");
    TARG_INF("iv_targets = %p", iv_targets);

    // Only translate addresses on platforms where addresses are 4 bytes wide
    // (FSP). The compiler should perform dead code elimination of this path on
    // platforms with 8 byte wide addresses (Hostboot), since the "if" check
    // can be statically computed at compile time.
    if(TARG_ADDR_TRANSLATION_REQUIRED)
    {
        iv_targets = static_cast<Target(*)[]>(
                TARG_GET_SINGLETON(TARGETING::theAttrRP).translateAddr(
                        iv_targets));
        TARG_ASSERT(iv_targets, TARG_ERR_LOC
                    "FATAL: Could not determine location of targets after "
                    "address translation");
        TARG_INF("iv_targets after translation = %p", iv_targets);
    }

    TARG_EXIT();

    #undef TARG_FN
}

//******************************************************************************
// TargetService::_maxTargets
//******************************************************************************

uint32_t TargetService::_maxTargets()
{
    #define TARG_FN "_maxTargets(...)"

    // Target count found by following the pointer pointed to by the iv_pPnor
    // pointer.
    const AbstractPointer<uint32_t>* pNumTargetsPtr 
        = static_cast<const AbstractPointer<uint32_t>*>(iv_pPnor);
    uint32_t* pNumTargets = TARG_TO_PLAT_PTR(*pNumTargetsPtr);

    // Only translate addresses on platforms where addresses are 4 bytes wide
    // (FSP). The compiler should perform dead code elimination of this path on
    // platforms with 8 byte wide addresses (Hostboot), since the "if" check
    // can be statically computed at compile time.
    if(TARG_ADDR_TRANSLATION_REQUIRED)
    {
        pNumTargets = static_cast<uint32_t*>(
                TARG_GET_SINGLETON(TARGETING::theAttrRP).translateAddr(
                        pNumTargets));
    }

    iv_maxTargets = *pNumTargets;

    TARG_INF("Max targets = %d",iv_maxTargets);

    return iv_maxTargets;

    #undef TARG_FN
}

//******************************************************************************
// TargetService::_getInwards
//******************************************************************************

void TargetService::_getInwards(
    const ATTRIBUTE_ID         i_attr,
    const RECURSION_LEVEL      i_recursionLevel,
          EntityPath           i_entityPath,
    const PredicateBase* const i_pPredicate,
          TargetHandleList&    o_list) const
{
    #define TARG_FN "_getInwards(...)"

    while (i_entityPath.size() > 1)
    {
        i_entityPath.removeLast();
        for (uint32_t i = 0; i < iv_maxTargets; ++i)
        {
            EntityPath l_candidatePath;
            bool l_candidateFound = tryGetPath(i_attr, &(*iv_targets)[i],
                l_candidatePath);
            if (   l_candidateFound
                && (l_candidatePath == i_entityPath)
                && (   (i_pPredicate == NULL)
                    || (*i_pPredicate)( &(*iv_targets)[i]) ) )
            {
                o_list.push_back(&(*iv_targets)[i]);
                break;
            }
        }

        if (i_recursionLevel == IMMEDIATE)
        {
            break;
        }
    }

    #undef TARG_FN
}

//******************************************************************************
// TargetService::_getOutwards
//******************************************************************************

void TargetService::_getOutwards(
    const ATTRIBUTE_ID         i_attr,
    const RECURSION_LEVEL      i_recursionLevel,
          EntityPath           i_entityPath,
    const PredicateBase* const i_pPredicate,
          TargetHandleList&    o_list) const
{
    #define TARG_FN "_getOutwards()...)"

    do {

    // If at max depth (a leaf path element), no children possible
    if (i_entityPath.size() >= EntityPath::MAX_PATH_ELEMENTS)
    {
        break;
    }

    // Find the children (immediate, or all), depending on recursion level
    for (uint32_t i = 0; i < iv_maxTargets; ++i)
    {
        EntityPath l_candidatePath;
        bool l_candidateFound = tryGetPath(i_attr, &(*iv_targets)[i],
            l_candidatePath);
        if (l_candidateFound)
        {
            if (   (   (i_recursionLevel == IMMEDIATE)
                    && (l_candidatePath.size() == i_entityPath.size() + 1))
                || (   (i_recursionLevel == ALL)
                    && (l_candidatePath.size() > i_entityPath.size())))
            {
                if (   i_entityPath.equals(l_candidatePath,i_entityPath.size())
                    && (   (i_pPredicate == NULL)
                        || (*i_pPredicate)( &(*iv_targets)[i]) ) )
                {
                    o_list.push_back(&(*iv_targets)[i]);
                }
            }
        }
    }

    } while (0);

    #undef TARG_FN
}

#undef TARG_CLASS

#undef TARG_NAMESPACE

} // End namespace TARGETING

OpenPOWER on IntegriCloud