RTEMS
objectgetnameasstring.c
Go to the documentation of this file.
1 
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 /*
25  * Do not use isprint() from <ctypes.h> since this depends on the heavy weight
26  * C locale support of Newlib.
27  */
28 static bool _Objects_Name_char_is_printable( char c )
29 {
30  unsigned char uc;
31 
32  uc = (unsigned char) c;
33  return uc >= ' ' && uc <= '~';
34 }
35 
37  Objects_Name name,
38  bool is_string,
39  char *buffer,
40  size_t buffer_size
41 )
42 {
43  char lname[ 5 ];
44  const char *s;
45  char *d;
46  size_t i;
47 
48  if ( is_string ) {
49  s = name.name_p;
50  } else {
51  lname[ 0 ] = (name.name_u32 >> 24) & 0xff;
52  lname[ 1 ] = (name.name_u32 >> 16) & 0xff;
53  lname[ 2 ] = (name.name_u32 >> 8) & 0xff;
54  lname[ 3 ] = (name.name_u32 >> 0) & 0xff;
55  lname[ 4 ] = '\0';
56  s = lname;
57  }
58 
59  d = buffer;
60  i = 1;
61 
62  if ( s != NULL ) {
63  while ( *s != '\0' ) {
64  if ( i < buffer_size ) {
65  *d = _Objects_Name_char_is_printable(*s) ? *s : '*';
66  ++d;
67  }
68 
69  ++s;
70  ++i;
71  }
72  }
73 
74  if ( buffer_size > 0 ) {
75  *d = '\0';
76  }
77 
78  return i - 1;
79 }
80 
81 /*
82  * This method objects the name of an object and returns its name
83  * in the form of a C string. It attempts to be careful about
84  * overflowing the user's string and about returning unprintable characters.
85  */
86 
88  Objects_Id id,
89  size_t length,
90  char *name
91 )
92 {
93  const Objects_Information *information;
94  const Objects_Control *the_object;
95  ISR_lock_Context lock_context;
96  Objects_Id tmpId;
97 
98  if ( length == 0 )
99  return NULL;
100 
101  if ( name == NULL )
102  return NULL;
103 
104  tmpId = (id == OBJECTS_ID_OF_SELF) ? _Thread_Get_executing()->Object.id : id;
105 
106  information = _Objects_Get_information_id( tmpId );
107  if ( !information )
108  return NULL;
109 
110  the_object = _Objects_Get( tmpId, &lock_context, information );
111  if ( the_object == NULL ) {
112  return NULL;
113  }
114 
116  the_object->name,
117  _Objects_Has_string_name( information ),
118  name,
119  length
120  );
121 
122  _ISR_lock_ISR_enable( &lock_context );
123  return name;
124 }
uint32_t name_u32
Definition: object.h:68
Objects_Information * _Objects_Get_information_id(Objects_Id id)
Gets information of an object from an ID.
#define OBJECTS_ID_OF_SELF
Definition: object.h:194
size_t _Objects_Name_to_string(Objects_Name name, bool is_string, char *buffer, size_t buffer_size)
Converts the specified object name to a text representation.
#define _ISR_lock_ISR_enable(_context)
Restores the saved interrupt state of the ISR lock context.
Definition: isrlock.h:416
char * _Objects_Get_name_as_string(Objects_Id id, size_t length, char *name)
Gets object name in the form of a C string.
static __inline__ struct _Thread_Control * _Thread_Get_executing(void)
Returns the thread control block of the executing thread.
Definition: percpu.h:878
static __inline__ bool _Objects_Has_string_name(const Objects_Information *information)
Returns if the object has a string name.
Definition: objectimpl.h:411
Objects_Control Object
Definition: thread.h:727
The information structure used to manage each API class of objects.
Definition: objectdata.h:176
const char * name_p
Definition: object.h:66
Inlined Routines from the Thread Handler.
uint32_t Objects_Id
Definition: object.h:80
Objects_Control * _Objects_Get(Objects_Id id, ISR_lock_Context *lock_context, const Objects_Information *information)
Maps the specified object identifier to the associated local object control block.
Local ISR lock context for acquire and release pairs.
Definition: isrlock.h:65
Objects_Name name
Definition: objectdata.h:45
Objects_Id id
Definition: objectdata.h:43