[d4d7899] | 1 | /** |
---|
| 2 | * @file |
---|
| 3 | * |
---|
| 4 | * @brief Extracts a Node from a Chain |
---|
| 5 | * |
---|
| 6 | * @ingroup Score |
---|
| 7 | */ |
---|
| 8 | |
---|
[e1bce86] | 9 | /* |
---|
[6c06288] | 10 | * COPYRIGHT (c) 1989-2008. |
---|
[e1bce86] | 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.com/license/LICENSE. |
---|
| 16 | */ |
---|
| 17 | |
---|
| 18 | #ifdef HAVE_CONFIG_H |
---|
| 19 | #include "config.h" |
---|
| 20 | #endif |
---|
| 21 | |
---|
| 22 | #include <rtems/system.h> |
---|
| 23 | #include <rtems/score/object.h> |
---|
| 24 | #include <rtems/score/thread.h> |
---|
| 25 | #include <stdlib.h> |
---|
| 26 | #include <ctype.h> |
---|
| 27 | #include <inttypes.h> |
---|
| 28 | |
---|
| 29 | /* |
---|
| 30 | * This method objects the name of an object and returns its name |
---|
| 31 | * in the form of a C string. It attempts to be careful about |
---|
| 32 | * overflowing the user's string and about returning unprintable characters. |
---|
| 33 | */ |
---|
| 34 | |
---|
| 35 | char *_Objects_Get_name_as_string( |
---|
| 36 | Objects_Id id, |
---|
| 37 | size_t length, |
---|
| 38 | char *name |
---|
| 39 | ) |
---|
| 40 | { |
---|
[74d0cb44] | 41 | Objects_Information *information; |
---|
[ce19f1fa] | 42 | const char *s; |
---|
[e1bce86] | 43 | char *d; |
---|
| 44 | uint32_t i; |
---|
| 45 | char lname[5]; |
---|
| 46 | Objects_Control *the_object; |
---|
| 47 | Objects_Locations location; |
---|
[8932955] | 48 | Objects_Id tmpId; |
---|
[e1bce86] | 49 | |
---|
| 50 | if ( length == 0 ) |
---|
| 51 | return NULL; |
---|
| 52 | |
---|
| 53 | if ( name == NULL ) |
---|
| 54 | return NULL; |
---|
| 55 | |
---|
[8932955] | 56 | tmpId = (id == OBJECTS_ID_OF_SELF) ? _Thread_Executing->Object.id : id; |
---|
| 57 | |
---|
| 58 | information = _Objects_Get_information_id( tmpId ); |
---|
[e1bce86] | 59 | if ( !information ) |
---|
| 60 | return NULL; |
---|
| 61 | |
---|
[8932955] | 62 | the_object = _Objects_Get( information, tmpId, &location ); |
---|
[e1bce86] | 63 | switch ( location ) { |
---|
| 64 | |
---|
[0e87deaa] | 65 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[e1bce86] | 66 | case OBJECTS_REMOTE: |
---|
| 67 | /* not supported */ |
---|
[0e87deaa] | 68 | #endif |
---|
[e1bce86] | 69 | case OBJECTS_ERROR: |
---|
| 70 | return NULL; |
---|
| 71 | |
---|
| 72 | case OBJECTS_LOCAL: |
---|
| 73 | |
---|
[47988fb] | 74 | #if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES) |
---|
| 75 | if ( information->is_string ) { |
---|
| 76 | s = the_object->name.name_p; |
---|
| 77 | } else |
---|
| 78 | #endif |
---|
| 79 | { |
---|
[ce19f1fa] | 80 | uint32_t u32_name = (uint32_t) the_object->name.name_u32; |
---|
[e1bce86] | 81 | |
---|
[b9f07823] | 82 | lname[ 0 ] = (u32_name >> 24) & 0xff; |
---|
| 83 | lname[ 1 ] = (u32_name >> 16) & 0xff; |
---|
| 84 | lname[ 2 ] = (u32_name >> 8) & 0xff; |
---|
| 85 | lname[ 3 ] = (u32_name >> 0) & 0xff; |
---|
| 86 | lname[ 4 ] = '\0'; |
---|
| 87 | s = lname; |
---|
[e1bce86] | 88 | } |
---|
| 89 | |
---|
[74d0cb44] | 90 | d = name; |
---|
| 91 | if ( s ) { |
---|
| 92 | for ( i=0 ; i<(length-1) && *s ; i++, s++, d++ ) { |
---|
[bab5c5fa] | 93 | *d = (isprint((unsigned char)*s)) ? *s : '*'; |
---|
[74d0cb44] | 94 | } |
---|
[e1bce86] | 95 | } |
---|
| 96 | *d = '\0'; |
---|
| 97 | |
---|
[2d2352b] | 98 | _Objects_Put( the_object ); |
---|
[e1bce86] | 99 | return name; |
---|
| 100 | } |
---|
| 101 | return NULL; /* unreachable path */ |
---|
| 102 | } |
---|