1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup RTEMSImplClassicObject |
---|
5 | * |
---|
6 | * @brief This source file contains the implementation of |
---|
7 | * rtems_object_set_name(). |
---|
8 | */ |
---|
9 | |
---|
10 | /* |
---|
11 | * COPYRIGHT (c) 1989-2008. |
---|
12 | * On-Line Applications Research Corporation (OAR). |
---|
13 | * |
---|
14 | * The license and distribution terms for this file may be |
---|
15 | * found in the file LICENSE in this distribution or at |
---|
16 | * http://www.rtems.org/license/LICENSE. |
---|
17 | */ |
---|
18 | |
---|
19 | #ifdef HAVE_CONFIG_H |
---|
20 | #include "config.h" |
---|
21 | #endif |
---|
22 | |
---|
23 | #include <rtems/rtems/object.h> |
---|
24 | #include <rtems/rtems/statusimpl.h> |
---|
25 | #include <rtems/rtems/tasks.h> |
---|
26 | #include <rtems/score/objectimpl.h> |
---|
27 | |
---|
28 | /* |
---|
29 | * This method will set the object name based upon the user string. |
---|
30 | * If the object class uses 32-bit names, then only the first 4 bytes |
---|
31 | * of the string will be used. |
---|
32 | */ |
---|
33 | rtems_status_code rtems_object_set_name( |
---|
34 | rtems_id id, |
---|
35 | const char *name |
---|
36 | ) |
---|
37 | { |
---|
38 | Objects_Information *information; |
---|
39 | Objects_Control *the_object; |
---|
40 | Objects_Id tmpId; |
---|
41 | Status_Control status; |
---|
42 | |
---|
43 | if ( !name ) |
---|
44 | return RTEMS_INVALID_ADDRESS; |
---|
45 | |
---|
46 | tmpId = (id == OBJECTS_ID_OF_SELF) ? rtems_task_self() : id; |
---|
47 | |
---|
48 | information = _Objects_Get_information_id( tmpId ); |
---|
49 | if ( !information ) |
---|
50 | return RTEMS_INVALID_ID; |
---|
51 | |
---|
52 | _Objects_Allocator_lock(); |
---|
53 | the_object = _Objects_Get_no_protection( tmpId, information ); |
---|
54 | |
---|
55 | if ( the_object == NULL ) { |
---|
56 | _Objects_Allocator_unlock(); |
---|
57 | return RTEMS_INVALID_ID; |
---|
58 | } |
---|
59 | |
---|
60 | status = _Objects_Set_name( information, the_object, name ); |
---|
61 | _Objects_Allocator_unlock(); |
---|
62 | return _Status_Get( status ); |
---|
63 | } |
---|