summaryrefslogtreecommitdiffstats
path: root/src/include/usr/targeting/entitypath.H
blob: 27af7120ccf1d4167c3b59dadee3b77bd4870503 (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

#ifndef TARG_ENTITYPATH_H
#define TARG_ENTITYPATH_H

/**
 *  @file entitypath.H
 *
 *  @brief Interface for the EntityPath class
 *
 *  This header file contains the interface for the EntityPath class which
 *  supports hierarchical path representation of various flavors
 */

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

// STD
#include <stdint.h>
#include <stdlib.h>
#include <vector>

namespace TARGETING
{

class Target;

/**
 *  @brief Entity path class which represents a target's relationship(s) to
 *      other targets
 *
 *  Entity path class which represents a target's relationship(s) to other
 *  targets via hierarchical paths.  Entity paths can represent different
 *  relationships, such as logical containment (where part X contains part Y
 *  contains part Z), hardware affinity, etc.  An entity path is composed of
 *  a number of type/instance pairs that represent a given target in a given
 *  hierarchy.  In the logical containment example, part Z's logical containment
 *  path would look something like partX-0/partY-1/partZ-0.
 */
class EntityPath
{
    public:

        /**
         *  @brief Maximum number of path elements than an entity path can have
         */
        enum
        {
            MAX_PATH_ELEMENTS = 8,
        };

        /**
         *  @brief Entity Path Types
         *
         *  An entity path type indicates which specific set of relationships is
         *  modeled by a particular entity path.  For example, PATH_AFFINITY
         *  models how targets are connected to each other from a hardware
         *  affinity perspective.
         */
        enum PATH_TYPE
        {
            PATH_NA       = 0x00, ///< Not applicable
            PATH_AFFINITY = 0x01, ///< Entity path models hardware affinity
                                  ///< relationships
            PATH_PHYSICAL = 0x02, ///< Entity path models logical containment
                                  ///< relationships
            PATH_DEVICE   = 0x03, ///< Entity path models a device driver path
            PATH_POWER    = 0x04, ///< Entity path models power provider and
                                  ///< power consumer relationships
        };

        /**
         *  @brief Entity Path Element Definition
         *
         *  Any entity path models one level of an entity path hierarchy
         */
        struct PathElement
        {
           TYPE    type;     ///< Type of element at this level in the hierarchy
           uint8_t instance; ///< Instance ID for the element, relative to
                             ///< the parent

        } PACKED;

        /**
         *  @brief Creates an entity path object, based on path type
         *
         *  Creates an entity path of the specified type, but does not populate
         *  it with any path elements.
         *
         *  @param[in] i_pathType Type of entity path to create
         *
         *  @post Entity path of specified type created with no path elements
         */
        EntityPath(
            PATH_TYPE i_pathType);

        /**
         *  @brief Creates an empty entity path object
         *
         *  Creates an empty entity path of N/A type and does not populate it
         *  with any path elements. The caller must initialize the type and
         *  populate it with path elements as needed
         *
         *  @post Entity path created with default type and no path elements
         */
        EntityPath();

        /**
         *  @brief Destroys an entity path object
         *
         *  Destroys an entity path object and frees all resources it
         *  exclusively owns.
         *
         *  @post Entity path destroyed and all previously owned exclusive
         *      resources freed
         */
        ~EntityPath();

        /**
         *  @brief Removes/clears the last path element from an entity path
         *
         *  Removes/clears the last path element from an entity path.  If the
         *  caller attempts this operation and no path elements exist, the
         *  routine asserts.
         *
         *  @post Entity path element removed from path
         */
        EntityPath& removeLast();

        /**
         *  @brief Returns a copy of the entity path with the last path
         *      element removed.  The original entity path is not altered
         *
         *  Returns a copy of the entity path with the last path
         *  element removed, useful for non-destructive transformations.
         *  caller attempts this operation and no path elements exist, the
         *  routine asserts.  The original entity path is not altered.
         *  Equivalent to p1 = p2; p1.removeLast();
         *
         *  @post Copy of entity path with last element removed returned
         */
        EntityPath copyRemoveLast() const;

        /**
         *  @brief Adds a path element to the end of an existing entity path
         *      object
         *
         *  Adds a path element to the end of an existing entity path object.
         *  If the new path exceeds the maximum allowable number of path
         *  elements, the routine asserts
         *
         *  @param[in] i_type Type of path element to add
         *  @param[in] i_instance Instance # of path element to add
         *
         *  @pre N/A
         *
         *  @post Entity path will increased by one path element, as specified
         *      by the input parameters
         *
         *  @return Reference to the larger entity path
         */
        EntityPath& addLast(
            TYPE    i_type,
            uint8_t i_instance);

        /**
         *  @brief Returns a copy of the entity path with the specified
         *      path element added to the end. The original entity path is not
         *      altered
         *
         *  Returns a copy of the entity path with the specified path element
         *  added to the end. If the new path exceeds the maximum allowable
         *  number of path elements, the routine asserts.  The original entity
         *  path is not altered.  Equivalent to p1 = p2.  p1.addLast(..);
         *
         *  @param[in] i_type Type of path element to add
         *  @param[in] i_instance Instance # of path element to add
         *
         *  @pre N/A
         *
         *  @post Copy of entity path with additional path element returned to
         *      caller
         *
         *  @return Copy of the entity path with an additional path element
         */
        EntityPath copyAddLast(
            TYPE    i_type,
            uint8_t i_instance) const;

        /**
         *  @brief Returns a target handle to the target referred to by the
         *      entity path object
         *
         *  Returns a target handle to the target referred to by the
         *  entity path object if it exists (NULL otherwise)
         *
         *  @pre N/A
         *
         *  @post Target handle returned to caller or NULL (if related target
         *      doesn't exist)
         *
         *  @return Target handle
         *
         *  @retval NULL Target doesn't exist
         *  @retval !NULL Target handle to the target referred to by the entity
         *      path
         */
        Target* operator->(void);

        /**
         *  @brief Returns whether two entity paths are logically equal
         *
         *  Returns whether two entity paths are logically equal.  This
         *  determination takes into account the entity path type, the number
         *  of path elements, and the values of the path elements themselves.
         *
         *  @param[in] i_rhs Const reference to entity path to compare
         *
         *  @pre N/A
         *
         *  @post Equality returned to caller
         *
         *  @return bool indicating whether two entity paths are logically equal
         *
         *  @retval true The entity paths are logically equal
         *  @retval false The entity paths are not logically equal
         */
        bool operator==(
            const EntityPath& i_rhs) const;

        /**
         *  @brief Returns whether two entity paths are logically equal, but
         *      only for the specified number of path elements
         *
         *  Returns whether two entity paths are logically equal, but only for
         *  the specified number of path elements.  This determination takes
         *  into account the entity path type, the specified number of path
         *  elements, and the values of the subset of path elements to be
         *  compared.  For example, a device path of
         *  fsi0/cfam0/fsi0/cfam1/engine0 is equal to fsi0/cfam0 if the
         *  specified number of path elements is 1 or 2.
         *
         *  @param[in] i_rhs Const reference to entity path to compare
         *  @param[in] i_size Number of path elements to compare; must be
         *      <= this->size() (otherwise routine will assert)
         *
         *  @pre N/A
         *
         *  @post Equality (for specified number of path elements) returned to
         *      caller
         *
         *  @return bool indicating whether two entity paths are logically equal
         *        for the specified number of path elements (or assertion if
         *        specified size > this->size())
         *
         *  @retval true The entity paths are logically equal for the specified
         *      number of path elements
         *  @retval false The entity paths are not logically equal for the
         *      specified number of path elements
         */
        bool equals(
            const EntityPath& i_rhs,
                  uint32_t    i_size) const;

        /**
         *  @brief Returns the path element at the specified index
         *
         *  Returns the path element at the specified index (zero based).  The
         *  routine will assert if the index exceeds this->size()-1;
         *
         *  @param[in] i_index Path element to return (0 based indexing)
         *
         *  @pre N/A
         *
         *  @post Path element returned to caller on valid index.  Assert
         *      triggered on invalid index.
         *
         *  @return PathElement at the position in the entity path specified by
         *      index
         */
        const PathElement& operator[](
            uint32_t i_index) const;

        /**
         *  @brief Returns the number of path elements
         *
         *  Returns the number of path elements for the entity path.
         *
         *  @pre N/A
         *
         *  @post Number of path elements returned to caller
         *
         *  @return uint32_t giving the number of path elements
         */
        uint32_t size() const;

        /**
         *  @brief Sets the path type
         *
         *  Sets the path type for the entity path
         *
         *  @param[in] i_pathType Path type specifier
         *
         *  @pre N/A
         *
         *  @post Path type set to the specified value
         *
         *  @return N/A
         */
        void setType(
            PATH_TYPE i_pathType);

        /**
         *  @brief Returns the path type
         *
         *  Returns the path type for the entity path
         *
         *  @pre N/A
         *
         *  @post Path type returned to caller
         *
         *  @return PATH_TYPE indicating the entity path's path type
         */
        PATH_TYPE type() const;

        /**
         *  @brief DEBUG ONLY.  Returns the path type as a string.
         *
         *  Returns the string encoding of the path type
         *
         *  @pre N/A
         *
         *  @post Path type string returned to caller
         *
         *  @return String representation of the path type
         */
        const char* pathTypeAsString() const;

        /**
         *  @brief DEBUG ONLY.  Returns the path element type as a string.
         *
         *  Returns the string encoding of the path element type
         *
         *  @param[in] i_type Path element type to translate
         *
         *  @pre N/A
         *
         *  @post Path element type string returned to caller
         *
         *  @return String representation of the path element type
         */
        const char* pathElementTypeAsString(
            TYPE i_type) const;

        /**
         *  @brief DEBUG ONLY.  Returns the path element engine instance as a
         *      string.
         *
         *  @param[in] i_engine Path element engine instance to translate
         *
         *  Returns the string encoding of the path element engine instance
         *
         *  @pre N/A
         *
         *  @post Path element engine instance string returned to caller
         *
         *  @return String representation of the path element engine instance
         */
        const char* pathEngineInstanceAsString(
            ENGINE_TYPE i_engine) const;

        /**
         *  @brief DEBUG ONLY.  Dump the entity path
         *
         *  Dumps the entity path
         *
         *  @pre N/A
         *
         *  @post Entity path dumped
         *
         *  @return N/A
         */
        void dump() const;

    private:

        PATH_TYPE   iv_type : 4; ///< Entity path type (4 bits)
        uint8_t     iv_size : 4; ///< Number of path elements (4 bits)
        PathElement iv_pathElement[MAX_PATH_ELEMENTS]; ///< Array of path
                                                       ///< elements

        // Compiler generated copy and assignment operators explicitly
        // allowed and used

} PACKED;

} // End namespace TARGETING

#endif // TARG_ENTITYPATH_H
OpenPOWER on IntegriCloud