1 | /* |
---|
2 | * RTEMS Object Helper -- Set Name of Object as String |
---|
3 | * |
---|
4 | * COPYRIGHT (c) 1989-2008. |
---|
5 | * On-Line Applications Research Corporation (OAR). |
---|
6 | * |
---|
7 | * The license and distribution terms for this file may be |
---|
8 | * found in the file LICENSE in this distribution or at |
---|
9 | * http://www.rtems.com/license/LICENSE. |
---|
10 | * |
---|
11 | * $Id$ |
---|
12 | */ |
---|
13 | |
---|
14 | #ifdef HAVE_CONFIG_H |
---|
15 | #include "config.h" |
---|
16 | #endif |
---|
17 | |
---|
18 | #include <rtems/system.h> |
---|
19 | #include <rtems/score/object.h> |
---|
20 | #include <rtems/score/thread.h> |
---|
21 | #include <rtems/rtems/status.h> |
---|
22 | #include <rtems/rtems/types.h> |
---|
23 | |
---|
24 | /* |
---|
25 | * This method will set the object name based upon the user string. |
---|
26 | * If the object class uses 32-bit names, then only the first 4 bytes |
---|
27 | * of the string will be used. |
---|
28 | */ |
---|
29 | rtems_status_code rtems_object_set_name( |
---|
30 | rtems_id id, |
---|
31 | const char *name |
---|
32 | ) |
---|
33 | { |
---|
34 | Objects_Information *information; |
---|
35 | Objects_Locations location; |
---|
36 | Objects_Control *the_object; |
---|
37 | Objects_Id tmpId; |
---|
38 | |
---|
39 | if ( !name ) |
---|
40 | return RTEMS_INVALID_ADDRESS; |
---|
41 | |
---|
42 | tmpId = (id == OBJECTS_ID_OF_SELF) ? _Thread_Executing->Object.id : id; |
---|
43 | |
---|
44 | information = _Objects_Get_information_id( tmpId ); |
---|
45 | if ( !information ) |
---|
46 | return RTEMS_INVALID_ID; |
---|
47 | |
---|
48 | the_object = _Objects_Get( information, tmpId, &location ); |
---|
49 | switch ( location ) { |
---|
50 | |
---|
51 | case OBJECTS_LOCAL: |
---|
52 | _Objects_Set_name( information, the_object, name ); |
---|
53 | _Thread_Enable_dispatch(); |
---|
54 | return RTEMS_SUCCESSFUL; |
---|
55 | |
---|
56 | #if defined(RTEMS_MULTIPROCESSING) |
---|
57 | case OBJECTS_REMOTE: |
---|
58 | #endif |
---|
59 | case OBJECTS_ERROR: |
---|
60 | break; |
---|
61 | } |
---|
62 | |
---|
63 | return RTEMS_INVALID_ID; |
---|
64 | } |
---|