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

5
Last change on this file since c65aeed was 3384994, checked in by Chris Johns <chrisj@…>, on 11/13/17 at 02:25:18

Clean up sphinx warnings.

  • Fix minor formatting issues.
  • Fix reference the gloassary TLS using ':term:'.
  • Make sure nothing is between an anchor and the heading where ':ref:' references the anchor. This meant moving all the recently added '.. index::' entries.

Update #3232.
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.. index:: build object name
184.. index:: rtems_build_name
185
186.. _rtems_build_name:
187
188BUILD_NAME - Build object name from characters
189----------------------------------------------
190
191CALLING SEQUENCE:
192    .. code-block:: c
193
194        rtems_name rtems_build_name(
195            uint8_t c1,
196            uint8_t c2,
197            uint8_t c3,
198            uint8_t c4
199        );
200
201DIRECTIVE STATUS CODES:
202    Returns a name constructed from the four characters.
203
204DESCRIPTION:
205    This service takes the four characters provided as arguments and constructs
206    a thirty-two bit object name with ``c1`` in the most significant byte and
207    ``c4`` in the least significant byte.
208
209NOTES:
210    This directive is strictly local and does not impact task scheduling.
211
212.. raw:: latex
213
214   \clearpage
215
216.. index:: get name from id
217.. index:: obtain name from id
218.. index:: rtems_object_get_classic_name
219
220.. _rtems_object_get_classic_name:
221
222OBJECT_GET_CLASSIC_NAME - Lookup name from id
223---------------------------------------------
224
225CALLING SEQUENCE:
226    .. code-block:: c
227
228        rtems_status_code rtems_object_get_classic_name(
229            rtems_id      id,
230            rtems_name   *name
231        );
232
233DIRECTIVE STATUS CODES:
234    .. list-table::
235     :class: rtems-table
236
237     * - ``RTEMS_SUCCESSFUL``
238       - name looked up successfully
239     * - ``RTEMS_INVALID_ADDRESS``
240       - invalid name pointer
241     * - ``RTEMS_INVALID_ID``
242       - invalid object id
243
244DESCRIPTION:
245    This service looks up the name for the object ``id`` specified and, if
246    found, places the result in ``*name``.
247
248NOTES:
249    This directive is strictly local and does not impact task scheduling.
250
251.. raw:: latex
252
253   \clearpage
254
255.. index:: get object name as string
256.. index:: obtain object name as string
257.. index:: rtems_object_get_name
258
259.. _rtems_object_get_name:
260
261OBJECT_GET_NAME - Obtain object name as string
262----------------------------------------------
263
264CALLING SEQUENCE:
265    .. code-block:: c
266
267        char* rtems_object_get_name(
268            rtems_id       id,
269            size_t         length,
270            char          *name
271        );
272
273DIRECTIVE STATUS CODES:
274    Returns a pointer to the name if successful or ``NULL`` otherwise.
275
276DESCRIPTION:
277    This service looks up the name of the object specified by ``id`` and places
278    it in the memory pointed to by ``name``.  Every attempt is made to return
279    name as a printable string even if the object has the Classic API
280    thirty-two bit style name.
281
282NOTES:
283    This directive is strictly local and does not impact task scheduling.
284
285.. raw:: latex
286
287   \clearpage
288
289.. index:: set object name
290.. index:: rtems_object_set_name
291
292.. _rtems_object_set_name:
293
294OBJECT_SET_NAME - Set object name
295---------------------------------
296
297CALLING SEQUENCE:
298    .. code-block:: c
299
300        rtems_status_code rtems_object_set_name(
301            rtems_id       id,
302            const char    *name
303        );
304
305DIRECTIVE STATUS CODES:
306    .. list-table::
307     :class: rtems-table
308
309     * - ``RTEMS_SUCCESSFUL``
310       - name looked up successfully
311     * - ``RTEMS_INVALID_ADDRESS``
312       - invalid name pointer
313     * - ``RTEMS_INVALID_ID``
314       - invalid object id
315
316DESCRIPTION:
317    This service sets the name of ``id`` to that specified by the string
318    located at ``name``.
319
320NOTES:
321    This directive is strictly local and does not impact task scheduling.
322
323    If the object specified by ``id`` is of a class that has a string name,
324    this method will free the existing name to the RTEMS Workspace and allocate
325    enough memory from the RTEMS Workspace to make a copy of the string located
326    at ``name``.
327
328    If the object specified by ``id`` is of a class that has a thirty-two bit
329    integer style name, then the first four characters in ``*name`` will be
330    used to construct the name.  name to the RTEMS Workspace and allocate
331    enough memory from the RTEMS Workspace to make a copy of the string
332
333.. raw:: latex
334
335   \clearpage
336
337.. index:: obtain API from id
338.. index:: rtems_object_id_get_api
339
340.. _rtems_object_id_get_api:
341
342OBJECT_ID_GET_API - Obtain API from Id
343--------------------------------------
344
345CALLING SEQUENCE:
346    .. code-block:: c
347
348        int rtems_object_id_get_api(
349            rtems_id id
350        );
351
352DIRECTIVE STATUS CODES:
353    Returns the API portion of the object Id.
354
355DESCRIPTION:
356    This directive returns the API portion of the provided object ``id``.
357
358NOTES:
359    This directive is strictly local and does not impact task scheduling.
360
361    This directive does NOT validate the ``id`` provided.
362
363.. raw:: latex
364
365   \clearpage
366
367.. index:: obtain class from object id
368.. index:: rtems_object_id_get_class
369
370.. _rtems_object_id_get_class:
371
372OBJECT_ID_GET_CLASS - Obtain Class from Id
373------------------------------------------
374
375CALLING SEQUENCE:
376    .. code-block:: c
377
378        int rtems_object_id_get_class(
379            rtems_id id
380        );
381
382DIRECTIVE STATUS CODES:
383    Returns the class portion of the object Id.
384
385DESCRIPTION:
386    This directive returns the class portion of the provided object ``id``.
387
388NOTES:
389    This directive is strictly local and does not impact task scheduling.
390
391    This directive does NOT validate the ``id`` provided.
392
393.. raw:: latex
394
395   \clearpage
396
397.. index:: obtain node from object id
398.. index:: rtems_object_id_get_node
399
400.. _rtems_object_id_get_node:
401
402OBJECT_ID_GET_NODE - Obtain Node from Id
403----------------------------------------
404
405CALLING SEQUENCE:
406    .. code-block:: c
407
408        int rtems_object_id_get_node(
409            rtems_id id
410        );
411
412DIRECTIVE STATUS CODES:
413    Returns the node portion of the object Id.
414
415DESCRIPTION:
416    This directive returns the node portion of the provided object ``id``.
417
418NOTES:
419    This directive is strictly local and does not impact task scheduling.
420
421    This directive does NOT validate the ``id`` provided.
422
423.. raw:: latex
424
425   \clearpage
426
427.. index:: obtain index from object id
428.. index:: rtems_object_id_get_index
429
430.. _rtems_object_id_get_index:
431
432OBJECT_ID_GET_INDEX - Obtain Index from Id
433------------------------------------------
434
435CALLING SEQUENCE:
436    .. code-block:: c
437
438        int rtems_object_id_get_index(
439            rtems_id id
440        );
441
442DIRECTIVE STATUS CODES:
443    Returns the index portion of the object Id.
444
445DESCRIPTION:
446    This directive returns the index portion of the provided object ``id``.
447
448NOTES:
449    This directive is strictly local and does not impact task scheduling.
450
451    This directive does NOT validate the ``id`` provided.
452
453.. raw:: latex
454
455   \clearpage
456
457.. index:: build object id from components
458.. index:: rtems_build_id
459
460.. _rtems_build_id:
461
462BUILD_ID - Build Object Id From Components
463------------------------------------------
464
465CALLING SEQUENCE:
466    .. code-block:: c
467
468        rtems_id rtems_build_id(
469            int the_api,
470            int the_class,
471            int the_node,
472            int the_index
473        );
474
475DIRECTIVE STATUS CODES:
476    Returns an object Id constructed from the provided arguments.
477
478DESCRIPTION:
479    This service constructs an object Id from the provided ``the_api``,
480    ``the_class``, ``the_node``, and ``the_index``.
481
482NOTES:
483    This directive is strictly local and does not impact task scheduling.
484
485    This directive does NOT validate the arguments provided or the Object id
486    returned.
487
488.. raw:: latex
489
490   \clearpage
491
492.. index:: obtain minimum API value
493.. index:: rtems_object_id_api_minimum
494
495.. _rtems_object_id_api_minimum:
496
497OBJECT_ID_API_MINIMUM - Obtain Minimum API Value
498------------------------------------------------
499
500CALLING SEQUENCE:
501    .. code-block:: c
502
503        int rtems_object_id_api_minimum(void);
504
505DIRECTIVE STATUS CODES:
506    Returns the minimum valid for the API portion of an object Id.
507
508DESCRIPTION:
509    This service returns the minimum valid for the API portion of an object Id.
510
511NOTES:
512    This directive is strictly local and does not impact task scheduling.
513
514.. raw:: latex
515
516   \clearpage
517
518.. index:: obtain maximum API value
519.. index:: rtems_object_id_api_maximum
520
521.. _rtems_object_id_api_maximum:
522
523OBJECT_ID_API_MAXIMUM - Obtain Maximum API Value
524------------------------------------------------
525
526CALLING SEQUENCE:
527    .. code-block:: c
528
529        int rtems_object_id_api_maximum(void);
530
531DIRECTIVE STATUS CODES:
532    Returns the maximum valid for the API portion of an object Id.
533
534DESCRIPTION:
535    This service returns the maximum valid for the API portion of an object Id.
536
537NOTES:
538    This directive is strictly local and does not impact task scheduling.
539
540.. raw:: latex
541
542   \clearpage
543
544.. index:: obtain minimum class value
545.. index:: rtems_object_api_minimum_class
546
547.. _rtems_object_api_minimum_class:
548
549OBJECT_API_MINIMUM_CLASS - Obtain Minimum Class Value
550-----------------------------------------------------
551
552CALLING SEQUENCE:
553    .. code-block:: c
554
555        int rtems_object_api_minimum_class(
556            int api
557        );
558
559DIRECTIVE STATUS CODES:
560    If ``api`` is not valid, -1 is returned.
561
562    If successful, this service returns the minimum valid for the class portion
563    of an object Id for the specified ``api``.
564
565DESCRIPTION:
566    This service returns the minimum valid for the class portion of an object
567    Id for the specified ``api``.
568
569NOTES:
570    This directive is strictly local and does not impact task scheduling.
571
572.. raw:: latex
573
574   \clearpage
575
576.. index:: obtain maximum class value
577.. index:: rtems_object_api_maximum_class
578
579.. _rtems_object_api_maximum_class:
580
581OBJECT_API_MAXIMUM_CLASS - Obtain Maximum Class Value
582-----------------------------------------------------
583
584CALLING SEQUENCE:
585    .. code-block:: c
586
587        int rtems_object_api_maximum_class(
588            int api
589        );
590
591DIRECTIVE STATUS CODES:
592    If ``api`` is not valid, -1 is returned.
593
594    If successful, this service returns the maximum valid for the class portion
595    of an object Id for the specified ``api``.
596
597DESCRIPTION:
598    This service returns the maximum valid for the class portion of an object
599    Id for the specified ``api``.
600
601NOTES:
602    This directive is strictly local and does not impact task scheduling.
603
604.. raw:: latex
605
606   \clearpage
607
608.. index:: obtain minimum class value for an API
609.. index:: rtems_object_id_api_minimum_class
610
611.. _rtems_object_id_api_minimum_class:
612
613OBJECT_ID_API_MINIMUM_CLASS - Obtain Minimum Class Value for an API
614-------------------------------------------------------------------
615
616CALLING SEQUENCE:
617    .. code-block:: c
618
619        int rtems_object_get_id_api_minimum_class(
620            int api
621        );
622
623DIRECTIVE STATUS CODES:
624    If ``api`` is not valid, -1 is returned.
625
626    If successful, this service returns the index corresponding to the first
627    object class of the specified ``api``.
628
629DESCRIPTION:
630    This service returns the index for the first object class associated with
631    the specified ``api``.
632
633NOTES:
634    This directive is strictly local and does not impact task scheduling.
635
636.. raw:: latex
637
638   \clearpage
639
640.. index:: obtain maximum class value for an API
641.. index:: rtems_object_id_api_maximum_class
642
643.. _rtems_object_id_api_maximum_class:
644
645OBJECT_ID_API_MAXIMUM_CLASS - Obtain Maximum Class Value for an API
646-------------------------------------------------------------------
647
648CALLING SEQUENCE:
649    .. code-block:: c
650
651        int rtems_object_get_api_maximum_class(
652            int api
653        );
654
655DIRECTIVE STATUS CODES:
656    If ``api`` is not valid, -1 is returned.
657
658    If successful, this service returns the index corresponding to the last
659    object class of the specified ``api``.
660
661DESCRIPTION:
662    This service returns the index for the last object class associated with
663    the specified ``api``.
664
665NOTES:
666    This directive is strictly local and does not impact task scheduling.
667
668.. raw:: latex
669
670   \clearpage
671
672.. index:: obtain API name
673.. index:: rtems_object_get_api_name
674
675.. _rtems_object_get_api_name:
676
677OBJECT_GET_API_NAME - Obtain API Name
678-------------------------------------
679
680CALLING SEQUENCE:
681    .. code-block:: c
682
683        const char* rtems_object_get_api_name(
684            int api
685        );
686
687DIRECTIVE STATUS CODES:
688    If ``api`` is not valid, the string ``"BAD API"`` is returned.
689
690    If successful, this service returns a pointer to a string containing the
691    name of the specified ``api``.
692
693DESCRIPTION:
694    This service returns the name of the specified ``api``.
695
696NOTES:
697    This directive is strictly local and does not impact task scheduling.
698
699    The string returned is from constant space.  Do not modify or free it.
700
701.. raw:: latex
702
703   \clearpage
704
705.. index:: obtain class name
706.. index:: rtems_object_get_api_class_name
707
708.. _rtems_object_get_api_class_name:
709
710OBJECT_GET_API_CLASS_NAME - Obtain Class Name
711---------------------------------------------
712
713CALLING SEQUENCE:
714    .. code-block:: c
715
716        const char *rtems_object_get_api_class_name(
717            int the_api,
718            int the_class
719        );
720
721DIRECTIVE STATUS CODES:
722    If ``the_api`` is not valid, the string ``"BAD API"`` is returned.
723
724    If ``the_class`` is not valid, the string ``"BAD CLASS"`` is returned.
725
726    If successful, this service returns a pointer to a string containing the
727    name of the specified ``the_api`` / ``the_class`` pair.
728
729DESCRIPTION:
730    This service returns the name of the object class indicated by the
731    specified ``the_api`` and ``the_class``.
732
733NOTES:
734    This directive is strictly local and does not impact task scheduling.
735
736    The string returned is from constant space.  Do not modify or free it.
737
738.. raw:: latex
739
740   \clearpage
741
742.. index:: obtain class information
743.. index:: rtems_object_get_class_information
744
745.. _rtems_object_get_class_information:
746
747OBJECT_GET_CLASS_INFORMATION - Obtain Class Information
748-------------------------------------------------------
749
750CALLING SEQUENCE:
751    .. code-block:: c
752
753        rtems_status_code rtems_object_get_class_information(
754            int                                 the_api,
755            int                                 the_class,
756            rtems_object_api_class_information *info
757        );
758
759DIRECTIVE STATUS CODES:
760    .. list-table::
761     :class: rtems-table
762
763     * - ``RTEMS_SUCCESSFUL``
764       - information obtained successfully
765     * - ``RTEMS_INVALID_ADDRESS``
766       - ``info`` is NULL
767     * - ``RTEMS_INVALID_NUMBER``
768       - invalid ``api`` or ``the_class``
769
770    If successful, the structure located at ``info`` will be filled in with
771    information about the specified ``api`` / ``the_class`` pairing.
772
773DESCRIPTION:
774    This service returns information about the object class indicated by the
775    specified ``api`` and ``the_class``. This structure is defined as follows:
776
777    .. code-block:: c
778
779        typedef struct {
780            rtems_id  minimum_id;
781            rtems_id  maximum_id;
782            int       maximum;
783            bool      auto_extend;
784            int       unallocated;
785        } rtems_object_api_class_information;
786
787NOTES:
788    This directive is strictly local and does not impact task scheduling.
Note: See TracBrowser for help on using the repository browser.