source: rtems-docs/c-user/object_services.rst @ 6c56401

5
Last change on this file since 6c56401 was 6c56401, checked in by Chris Johns <chrisj@…>, on 11/12/17 at 03:34:48

c-user: Fix index locations.

Update #3229.

  • Property mode set to 100644
File size: 19.8 KB
Line 
1.. comment SPDX-License-Identifier: CC-BY-SA-4.0
2
3.. COMMENT: COPYRIGHT (c) 1988-2008.
4.. COMMENT: On-Line Applications Research Corporation (OAR).
5.. COMMENT: All rights reserved.
6
7.. index:: object manipulation
8
9Object Services
10***************
11
12Introduction
13============
14
15RTEMS provides a collection of services to assist in the management and usage
16of the objects created and utilized via other managers.  These services assist
17in the manipulation of RTEMS objects independent of the API used to create
18them.  The object related services provided by RTEMS are:
19
20- build_id
21
22- rtems_build_name_ - build object name from characters
23
24- rtems_object_get_classic_name_ - lookup name from Id
25
26- rtems_object_get_name_ - obtain object name as string
27
28- rtems_object_set_name_ - set object name
29
30- rtems_object_id_get_api_ - obtain API from Id
31
32- rtems_object_id_get_class_ - obtain class from Id
33
34- rtems_object_id_get_node_ - obtain node from Id
35
36- rtems_object_id_get_index_ - obtain index from Id
37
38- rtems_build_id_ - build object id from components
39
40- rtems_object_id_api_minimum_ - obtain minimum API value
41
42- rtems_object_id_api_maximum_ - obtain maximum API value
43
44- rtems_object_id_api_minimum_class_ - obtain minimum class value
45
46- rtems_object_id_api_maximum_class_ - obtain maximum class value
47
48- rtems_object_get_api_name_ - obtain API name
49
50- rtems_object_get_api_class_name_ - obtain class name
51
52- rtems_object_get_class_information_ - obtain class information
53
54Background
55==========
56
57APIs
58----
59
60RTEMS implements multiple APIs including an Internal API, the Classic API, and
61the POSIX API.  These APIs share the common foundation of SuperCore objects and
62thus share object management code. This includes a common scheme for object Ids
63and for managing object names whether those names be in the thirty-two bit form
64used by the Classic API or C strings.
65
66The object Id contains a field indicating the API that an object instance is
67associated with.  This field holds a numerically small non-zero integer.
68
69Object Classes
70--------------
71
72Each API consists of a collection of managers.  Each manager is responsible for
73instances of a particular object class.  Classic API Tasks and POSIX Mutexes
74example classes.
75
76The object Id contains a field indicating the class that an object instance is
77associated with.  This field holds a numerically small non-zero integer.  In
78all APIs, a class value of one is reserved for tasks or threads.
79
80Object Names
81------------
82
83Every RTEMS object which has an Id may also have a name associated with it.
84Depending on the API, names may be either thirty-two bit integers as in the
85Classic API or strings as in the POSIX API.
86
87Some objects have Ids but do not have a defined way to associate a name with
88them.  For example, POSIX threads have Ids but per POSIX do not have names. In
89RTEMS, objects not defined to have thirty-two bit names may have string names
90assigned to them via the ``rtems_object_set_name`` service.  The original
91impetus in providing this service was so the normally anonymous POSIX threads
92could have a user defined name in CPU Usage Reports.
93
94Operations
95==========
96
97Decomposing and Recomposing an Object Id
98----------------------------------------
99
100Services are provided to decompose an object Id into its subordinate
101components. The following services are used to do this:
102
103- ``rtems_object_id_get_api``
104
105- ``rtems_object_id_get_class``
106
107- ``rtems_object_id_get_node``
108
109- ``rtems_object_id_get_index``
110
111The following C language example illustrates the decomposition of an Id and
112printing the values.
113
114.. code-block:: c
115
116    void printObjectId(rtems_id id)
117    {
118        printf(
119            "API=%d Class=%d Node=%d Index=%d\n",
120            rtems_object_id_get_api(id),
121            rtems_object_id_get_class(id),
122            rtems_object_id_get_node(id),
123            rtems_object_id_get_index(id)
124        );
125    }
126
127This prints the components of the Ids as integers.
128
129It is also possible to construct an arbitrary Id using the ``rtems_build_id``
130service.  The following C language example illustrates how to construct the
131"next Id."
132
133.. code-block:: c
134
135    rtems_id nextObjectId(rtems_id id)
136    {
137        return rtems_build_id(
138                    rtems_object_id_get_api(id),
139                    rtems_object_id_get_class(id),
140                    rtems_object_id_get_node(id),
141                    rtems_object_id_get_index(id) + 1
142               );
143    }
144
145Note that this Id may not be valid in this
146system or associated with an allocated object.
147
148Printing an Object Id
149---------------------
150
151RTEMS also provides services to associate the API and Class portions of an
152Object Id with strings.  This allows the application developer to provide more
153information about an object in diagnostic messages.
154
155In the following C language example, an Id is decomposed into its constituent
156parts and "pretty-printed."
157
158.. code-block:: c
159
160    void prettyPrintObjectId(rtems_id id)
161    {
162        int tmpAPI, tmpClass;
163
164        tmpAPI   = rtems_object_id_get_api(id),
165        tmpClass = rtems_object_id_get_class(id),
166
167        printf(
168            "API=%s Class=%s Node=%d Index=%d\n",
169            rtems_object_get_api_name(tmpAPI),
170            rtems_object_get_api_class_name(tmpAPI, tmpClass),
171            rtems_object_id_get_node(id),
172            rtems_object_id_get_index(id)
173        );
174    }
175
176Directives
177==========
178
179.. raw:: latex
180
181   \clearpage
182
183.. _rtems_build_name:
184.. index:: build object name
185.. index:: rtems_build_name
186
187BUILD_NAME - Build object name from characters
188----------------------------------------------
189
190CALLING SEQUENCE:
191    .. code-block:: c
192
193        rtems_name rtems_build_name(
194            uint8_t c1,
195            uint8_t c2,
196            uint8_t c3,
197            uint8_t c4
198        );
199
200DIRECTIVE STATUS CODES:
201    Returns a name constructed from the four characters.
202
203DESCRIPTION:
204    This service takes the four characters provided as arguments and constructs
205    a thirty-two bit object name with ``c1`` in the most significant byte and
206    ``c4`` in the least significant byte.
207
208NOTES:
209    This directive is strictly local and does not impact task scheduling.
210
211.. raw:: latex
212
213   \clearpage
214
215.. _rtems_object_get_classic_name:
216.. index:: get name from id
217.. index:: obtain name from id
218.. index:: rtems_object_get_classic_name
219
220OBJECT_GET_CLASSIC_NAME - Lookup name from id
221---------------------------------------------
222
223CALLING SEQUENCE:
224    .. code-block:: c
225
226        rtems_status_code rtems_object_get_classic_name(
227            rtems_id      id,
228            rtems_name   *name
229        );
230
231DIRECTIVE STATUS CODES:
232    .. list-table::
233     :class: rtems-table
234
235     * - ``RTEMS_SUCCESSFUL``
236       - name looked up successfully
237     * - ``RTEMS_INVALID_ADDRESS``
238       - invalid name pointer
239     * - ``RTEMS_INVALID_ID``
240       - invalid object id
241
242DESCRIPTION:
243    This service looks up the name for the object ``id`` specified and, if
244    found, places the result in ``*name``.
245
246NOTES:
247    This directive is strictly local and does not impact task scheduling.
248
249.. raw:: latex
250
251   \clearpage
252
253.. _rtems_object_get_name:
254.. index:: get object name as string
255.. index:: obtain object name as string
256.. index:: rtems_object_get_name
257
258OBJECT_GET_NAME - Obtain object name as string
259----------------------------------------------
260
261CALLING SEQUENCE:
262    .. code-block:: c
263
264        char* rtems_object_get_name(
265            rtems_id       id,
266            size_t         length,
267            char          *name
268        );
269
270DIRECTIVE STATUS CODES:
271    Returns a pointer to the name if successful or ``NULL`` otherwise.
272
273DESCRIPTION:
274    This service looks up the name of the object specified by ``id`` and places
275    it in the memory pointed to by ``name``.  Every attempt is made to return
276    name as a printable string even if the object has the Classic API
277    thirty-two bit style name.
278
279NOTES:
280    This directive is strictly local and does not impact task scheduling.
281
282.. raw:: latex
283
284   \clearpage
285
286.. _rtems_object_set_name:
287.. index:: set object name
288.. index:: rtems_object_set_name
289
290OBJECT_SET_NAME - Set object name
291---------------------------------
292
293CALLING SEQUENCE:
294    .. code-block:: c
295
296        rtems_status_code rtems_object_set_name(
297            rtems_id       id,
298            const char    *name
299        );
300
301DIRECTIVE STATUS CODES:
302    .. list-table::
303     :class: rtems-table
304
305     * - ``RTEMS_SUCCESSFUL``
306       - name looked up successfully
307     * - ``RTEMS_INVALID_ADDRESS``
308       - invalid name pointer
309     * - ``RTEMS_INVALID_ID``
310       - invalid object id
311
312DESCRIPTION:
313    This service sets the name of ``id`` to that specified by the string
314    located at ``name``.
315
316NOTES:
317    This directive is strictly local and does not impact task scheduling.
318
319    If the object specified by ``id`` is of a class that has a string name,
320    this method will free the existing name to the RTEMS Workspace and allocate
321    enough memory from the RTEMS Workspace to make a copy of the string located
322    at ``name``.
323
324    If the object specified by ``id`` is of a class that has a thirty-two bit
325    integer style name, then the first four characters in ``*name`` will be
326    used to construct the name.  name to the RTEMS Workspace and allocate
327    enough memory from the RTEMS Workspace to make a copy of the string
328
329.. raw:: latex
330
331   \clearpage
332
333.. _rtems_object_id_get_api:
334.. index:: obtain API from id
335.. index:: rtems_object_id_get_api
336
337OBJECT_ID_GET_API - Obtain API from Id
338--------------------------------------
339
340CALLING SEQUENCE:
341    .. code-block:: c
342
343        int rtems_object_id_get_api(
344            rtems_id id
345        );
346
347DIRECTIVE STATUS CODES:
348    Returns the API portion of the object Id.
349
350DESCRIPTION:
351    This directive returns the API portion of the provided object ``id``.
352
353NOTES:
354    This directive is strictly local and does not impact task scheduling.
355
356    This directive does NOT validate the ``id`` provided.
357
358.. raw:: latex
359
360   \clearpage
361
362.. _rtems_object_id_get_class:
363.. index:: obtain class from object id
364.. index:: rtems_object_id_get_class
365
366OBJECT_ID_GET_CLASS - Obtain Class from Id
367------------------------------------------
368
369CALLING SEQUENCE:
370    .. code-block:: c
371
372        int rtems_object_id_get_class(
373            rtems_id id
374        );
375
376DIRECTIVE STATUS CODES:
377    Returns the class portion of the object Id.
378
379DESCRIPTION:
380    This directive returns the class portion of the provided object ``id``.
381
382NOTES:
383    This directive is strictly local and does not impact task scheduling.
384
385    This directive does NOT validate the ``id`` provided.
386
387.. raw:: latex
388
389   \clearpage
390
391.. _rtems_object_id_get_node:
392.. index:: obtain node from object id
393.. index:: rtems_object_id_get_node
394
395OBJECT_ID_GET_NODE - Obtain Node from Id
396----------------------------------------
397
398CALLING SEQUENCE:
399    .. code-block:: c
400
401        int rtems_object_id_get_node(
402            rtems_id id
403        );
404
405DIRECTIVE STATUS CODES:
406    Returns the node portion of the object Id.
407
408DESCRIPTION:
409    This directive returns the node portion of the provided object ``id``.
410
411NOTES:
412    This directive is strictly local and does not impact task scheduling.
413
414    This directive does NOT validate the ``id`` provided.
415
416.. raw:: latex
417
418   \clearpage
419
420.. _rtems_object_id_get_index:
421.. index:: obtain index from object id
422.. index:: rtems_object_id_get_index
423
424OBJECT_ID_GET_INDEX - Obtain Index from Id
425------------------------------------------
426
427CALLING SEQUENCE:
428    .. code-block:: c
429
430        int rtems_object_id_get_index(
431            rtems_id id
432        );
433
434DIRECTIVE STATUS CODES:
435    Returns the index portion of the object Id.
436
437DESCRIPTION:
438    This directive returns the index portion of the provided object ``id``.
439
440NOTES:
441    This directive is strictly local and does not impact task scheduling.
442
443    This directive does NOT validate the ``id`` provided.
444
445.. raw:: latex
446
447   \clearpage
448
449.. _rtems_build_id:
450.. index:: build object id from components
451.. index:: rtems_build_id
452
453BUILD_ID - Build Object Id From Components
454------------------------------------------
455
456CALLING SEQUENCE:
457    .. code-block:: c
458
459        rtems_id rtems_build_id(
460            int the_api,
461            int the_class,
462            int the_node,
463            int the_index
464        );
465
466DIRECTIVE STATUS CODES:
467    Returns an object Id constructed from the provided arguments.
468
469DESCRIPTION:
470    This service constructs an object Id from the provided ``the_api``,
471    ``the_class``, ``the_node``, and ``the_index``.
472
473NOTES:
474    This directive is strictly local and does not impact task scheduling.
475
476    This directive does NOT validate the arguments provided or the Object id
477    returned.
478
479.. raw:: latex
480
481   \clearpage
482
483.. _rtems_object_id_api_minimum:
484.. index:: obtain minimum API value
485.. index:: rtems_object_id_api_minimum
486
487OBJECT_ID_API_MINIMUM - Obtain Minimum API Value
488------------------------------------------------
489
490CALLING SEQUENCE:
491    .. code-block:: c
492
493        int rtems_object_id_api_minimum(void);
494
495DIRECTIVE STATUS CODES:
496    Returns the minimum valid for the API portion of an object Id.
497
498DESCRIPTION:
499    This service returns the minimum valid for the API portion of an object Id.
500
501NOTES:
502    This directive is strictly local and does not impact task scheduling.
503
504.. raw:: latex
505
506   \clearpage
507
508.. _rtems_object_id_api_maximum:
509.. index:: obtain maximum API value
510.. index:: rtems_object_id_api_maximum
511
512OBJECT_ID_API_MAXIMUM - Obtain Maximum API Value
513------------------------------------------------
514
515CALLING SEQUENCE:
516    .. code-block:: c
517
518        int rtems_object_id_api_maximum(void);
519
520DIRECTIVE STATUS CODES:
521    Returns the maximum valid for the API portion of an object Id.
522
523DESCRIPTION:
524    This service returns the maximum valid for the API portion of an object Id.
525
526NOTES:
527    This directive is strictly local and does not impact task scheduling.
528
529.. raw:: latex
530
531   \clearpage
532
533.. _rtems_object_api_minimum_class:
534.. index:: obtain minimum class value
535.. index:: rtems_object_api_minimum_class
536
537OBJECT_API_MINIMUM_CLASS - Obtain Minimum Class Value
538-----------------------------------------------------
539
540CALLING SEQUENCE:
541    .. code-block:: c
542
543        int rtems_object_api_minimum_class(
544            int api
545        );
546
547DIRECTIVE STATUS CODES:
548    If ``api`` is not valid, -1 is returned.
549
550    If successful, this service returns the minimum valid for the class portion
551    of an object Id for the specified ``api``.
552
553DESCRIPTION:
554    This service returns the minimum valid for the class portion of an object
555    Id for the specified ``api``.
556
557NOTES:
558    This directive is strictly local and does not impact task scheduling.
559
560.. raw:: latex
561
562   \clearpage
563
564.. _rtems_object_api_maximum_class:
565.. index:: obtain maximum class value
566.. index:: rtems_object_api_maximum_class
567
568OBJECT_API_MAXIMUM_CLASS - Obtain Maximum Class Value
569-----------------------------------------------------
570
571CALLING SEQUENCE:
572    .. code-block:: c
573
574        int rtems_object_api_maximum_class(
575            int api
576        );
577
578DIRECTIVE STATUS CODES:
579    If ``api`` is not valid, -1 is returned.
580
581    If successful, this service returns the maximum valid for the class portion
582    of an object Id for the specified ``api``.
583
584DESCRIPTION:
585    This service returns the maximum valid for the class portion of an object
586    Id for the specified ``api``.
587
588NOTES:
589    This directive is strictly local and does not impact task scheduling.
590
591.. raw:: latex
592
593   \clearpage
594
595.. _rtems_object_id_api_minimum_class:
596.. index:: obtain minimum class value for an API
597.. index:: rtems_object_id_api_minimum_class
598
599OBJECT_ID_API_MINIMUM_CLASS - Obtain Minimum Class Value for an API
600-------------------------------------------------------------------
601
602CALLING SEQUENCE:
603    .. code-block:: c
604
605        int rtems_object_get_id_api_minimum_class(
606            int api
607        );
608
609DIRECTIVE STATUS CODES:
610    If ``api`` is not valid, -1 is returned.
611
612    If successful, this service returns the index corresponding to the first
613    object class of the specified ``api``.
614
615DESCRIPTION:
616    This service returns the index for the first object class associated with
617    the specified ``api``.
618
619NOTES:
620    This directive is strictly local and does not impact task scheduling.
621
622.. raw:: latex
623
624   \clearpage
625
626.. _rtems_object_id_api_maximum_class:
627.. index:: obtain maximum class value for an API
628.. index:: rtems_object_id_api_maximum_class
629
630OBJECT_ID_API_MAXIMUM_CLASS - Obtain Maximum Class Value for an API
631-------------------------------------------------------------------
632
633CALLING SEQUENCE:
634    .. code-block:: c
635
636        int rtems_object_get_api_maximum_class(
637            int api
638        );
639
640DIRECTIVE STATUS CODES:
641    If ``api`` is not valid, -1 is returned.
642
643    If successful, this service returns the index corresponding to the last
644    object class of the specified ``api``.
645
646DESCRIPTION:
647    This service returns the index for the last object class associated with
648    the specified ``api``.
649
650NOTES:
651    This directive is strictly local and does not impact task scheduling.
652
653.. raw:: latex
654
655   \clearpage
656
657.. _rtems_object_get_api_name:
658.. index:: obtain API name
659.. index:: rtems_object_get_api_name
660
661OBJECT_GET_API_NAME - Obtain API Name
662-------------------------------------
663
664CALLING SEQUENCE:
665    .. code-block:: c
666
667        const char* rtems_object_get_api_name(
668            int api
669        );
670
671DIRECTIVE STATUS CODES:
672    If ``api`` is not valid, the string ``"BAD API"`` is returned.
673
674    If successful, this service returns a pointer to a string containing the
675    name of the specified ``api``.
676
677DESCRIPTION:
678    This service returns the name of the specified ``api``.
679
680NOTES:
681    This directive is strictly local and does not impact task scheduling.
682
683    The string returned is from constant space.  Do not modify or free it.
684
685.. raw:: latex
686
687   \clearpage
688
689.. _rtems_object_get_api_class_name:
690.. index:: obtain class name
691.. index:: rtems_object_get_api_class_name
692
693OBJECT_GET_API_CLASS_NAME - Obtain Class Name
694---------------------------------------------
695
696CALLING SEQUENCE:
697    .. code-block:: c
698
699        const char *rtems_object_get_api_class_name(
700            int the_api,
701            int the_class
702        );
703
704DIRECTIVE STATUS CODES:
705    If ``the_api`` is not valid, the string ``"BAD API"`` is returned.
706
707    If ``the_class`` is not valid, the string ``"BAD CLASS"`` is returned.
708
709    If successful, this service returns a pointer to a string containing the
710    name of the specified ``the_api`` / ``the_class`` pair.
711
712DESCRIPTION:
713    This service returns the name of the object class indicated by the
714    specified ``the_api`` and ``the_class``.
715
716NOTES:
717    This directive is strictly local and does not impact task scheduling.
718
719    The string returned is from constant space.  Do not modify or free it.
720
721.. raw:: latex
722
723   \clearpage
724
725.. _rtems_object_get_class_information:
726.. index:: obtain class information
727.. index:: rtems_object_get_class_information
728
729OBJECT_GET_CLASS_INFORMATION - Obtain Class Information
730-------------------------------------------------------
731
732CALLING SEQUENCE:
733    .. code-block:: c
734
735        rtems_status_code rtems_object_get_class_information(
736            int                                 the_api,
737            int                                 the_class,
738            rtems_object_api_class_information *info
739        );
740
741DIRECTIVE STATUS CODES:
742    .. list-table::
743     :class: rtems-table
744
745     * - ``RTEMS_SUCCESSFUL``
746       - information obtained successfully
747     * - ``RTEMS_INVALID_ADDRESS``
748       - ``info`` is NULL
749     * - ``RTEMS_INVALID_NUMBER``
750       - invalid ``api`` or ``the_class``
751
752    If successful, the structure located at ``info`` will be filled in with
753    information about the specified ``api`` / ``the_class`` pairing.
754
755DESCRIPTION:
756    This service returns information about the object class indicated by the
757    specified ``api`` and ``the_class``. This structure is defined as follows:
758
759    .. code-block:: c
760
761        typedef struct {
762            rtems_id  minimum_id;
763            rtems_id  maximum_id;
764            int       maximum;
765            bool      auto_extend;
766            int       unallocated;
767        } rtems_object_api_class_information;
768
769NOTES:
770    This directive is strictly local and does not impact task scheduling.
Note: See TracBrowser for help on using the repository browser.