source: rtems-docs/c_user/object_services.rst @ fd6dc8c8

4.115
Last change on this file since fd6dc8c8 was fd6dc8c8, checked in by Amar Takhar <amar@…>, on 01/18/16 at 00:19:43

Split document into seperate files by section.

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