source: rtems/cpukit/score/src/objectnametoidstring.c @ 2548d14

5
Last change on this file since 2548d14 was c904df5, checked in by Sebastian Huber <sebastian.huber@…>, on 03/18/16 at 06:25:23

score: Add _Objects_Get_by_name()

Replace _Objects_Name_to_id_string() with _Objects_Get_by_name() since
all users of this function are interested in the object itself and not
the identifier.

Use the object allocator lock to protect the search.

Update #2555.

  • Property mode set to 100644
File size: 1.6 KB
Line 
1/**
2 * @file
3 *
4 * @brief Object ID to Name
5 * @ingroup ScoreObject
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2010.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.org/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <rtems/score/objectimpl.h>
22
23#include <string.h>
24
25#if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES)
26Objects_Control *_Objects_Get_by_name(
27  const Objects_Information *information,
28  const char                *name,
29  size_t                    *name_length_p,
30  Objects_Get_by_name_error *error
31)
32{
33  size_t   name_length;
34  size_t   max_name_length;
35  uint32_t index;
36
37  _Assert( information->is_string );
38  _Assert( _Objects_Allocator_is_owner() );
39
40  if ( name == NULL ) {
41    *error = OBJECTS_GET_BY_NAME_INVALID_NAME;
42    return NULL;
43  }
44
45  name_length = strnlen( name, information->name_length + 1 );
46  max_name_length = information->name_length;
47  if ( name_length > max_name_length ) {
48    *error = OBJECTS_GET_BY_NAME_NAME_TOO_LONG;
49    return NULL;
50  }
51
52  if ( name_length_p != NULL ) {
53    *name_length_p = name_length;
54  }
55
56  for ( index = 1; index <= information->maximum; index++ ) {
57    Objects_Control *the_object;
58
59    the_object = information->local_table[ index ];
60
61    if ( the_object == NULL )
62      continue;
63
64    if ( the_object->name.name_p == NULL )
65      continue;
66
67    if ( strncmp( name, the_object->name.name_p, max_name_length ) == 0 ) {
68      return the_object;
69    }
70  }
71
72  *error = OBJECTS_GET_BY_NAME_NO_OBJECT;
73  return NULL;
74}
75#endif
Note: See TracBrowser for help on using the repository browser.