source: rtems/cpukit/score/src/objectgetnameasstring.c @ 25f5730f

4.115
Last change on this file since 25f5730f was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 2.3 KB
Line 
1/**
2 * @file
3 *
4 * @brief Extracts a Node from a Chain
5 *
6 * @ingroup Score
7 */
8
9/*
10 *  COPYRIGHT (c) 1989-2008.
11 *  On-Line Applications Research Corporation (OAR).
12 *
13 *  The license and distribution terms for this file may be
14 *  found in the file LICENSE in this distribution or at
15 *  http://www.rtems.org/license/LICENSE.
16 */
17
18#ifdef HAVE_CONFIG_H
19#include "config.h"
20#endif
21
22#include <rtems/score/threadimpl.h>
23
24#include <ctype.h>
25
26/*
27 *  This method objects the name of an object and returns its name
28 *  in the form of a C string.  It attempts to be careful about
29 *  overflowing the user's string and about returning unprintable characters.
30 */
31
32char *_Objects_Get_name_as_string(
33  Objects_Id        id,
34  size_t            length,
35  char             *name
36)
37{
38  Objects_Information   *information;
39  const char            *s;
40  char                  *d;
41  uint32_t               i;
42  char                   lname[5];
43  Objects_Control       *the_object;
44  Objects_Locations      location;
45  Objects_Id             tmpId;
46
47  if ( length == 0 )
48    return NULL;
49
50  if ( name == NULL )
51    return NULL;
52
53  tmpId = (id == OBJECTS_ID_OF_SELF) ? _Thread_Get_executing()->Object.id : id;
54
55  information = _Objects_Get_information_id( tmpId );
56  if ( !information )
57    return NULL;
58
59  the_object = _Objects_Get( information, tmpId, &location );
60  switch ( location ) {
61
62#if defined(RTEMS_MULTIPROCESSING)
63    case OBJECTS_REMOTE:
64      /* not supported */
65#endif
66    case OBJECTS_ERROR:
67      return NULL;
68
69    case OBJECTS_LOCAL:
70
71      #if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES)
72        if ( information->is_string ) {
73          s = the_object->name.name_p;
74        } else
75      #endif
76      {
77        uint32_t  u32_name = (uint32_t) the_object->name.name_u32;
78
79        lname[ 0 ] = (u32_name >> 24) & 0xff;
80        lname[ 1 ] = (u32_name >> 16) & 0xff;
81        lname[ 2 ] = (u32_name >>  8) & 0xff;
82        lname[ 3 ] = (u32_name >>  0) & 0xff;
83        lname[ 4 ] = '\0';
84        s = lname;
85      }
86
87      d = name;
88      if ( s ) {
89        for ( i=0 ; i<(length-1) && *s ; i++, s++, d++ ) {
90          *d = (isprint((unsigned char)*s)) ? *s : '*';
91        }
92      }
93      *d = '\0';
94
95      _Objects_Put( the_object );
96      return name;
97  }
98  return NULL;                  /* unreachable path */
99}
Note: See TracBrowser for help on using the repository browser.