summaryrefslogtreecommitdiffstats
path: root/cpukit/score
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2016-03-18 07:25:23 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2016-03-18 15:36:58 +0100
commitc904df573396d95957dc79b242b3a76911063089 (patch)
treebe6406676689018e8af8a929b6a4ef5284f94c70 /cpukit/score
parentsptests/sptls02: Use GNU++11 (diff)
downloadrtems-c904df573396d95957dc79b242b3a76911063089.tar.bz2
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.
Diffstat (limited to 'cpukit/score')
-rw-r--r--cpukit/score/include/rtems/score/objectimpl.h39
-rw-r--r--cpukit/score/src/objectnametoidstring.c59
2 files changed, 61 insertions, 37 deletions
diff --git a/cpukit/score/include/rtems/score/objectimpl.h b/cpukit/score/include/rtems/score/objectimpl.h
index fb2aca8408..f75ae59c0f 100644
--- a/cpukit/score/include/rtems/score/objectimpl.h
+++ b/cpukit/score/include/rtems/score/objectimpl.h
@@ -448,25 +448,31 @@ Objects_Name_or_id_lookup_errors _Objects_Name_to_id_u32(
);
#if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES)
+typedef enum {
+ OBJECTS_GET_BY_NAME_INVALID_NAME,
+ OBJECTS_GET_BY_NAME_NAME_TOO_LONG,
+ OBJECTS_GET_BY_NAME_NO_OBJECT
+} Objects_Get_by_name_error;
+
/**
- * @brief Converts an object name to an Id.
+ * @brief Gets an object control block identified by its name.
*
- * This method converts an object name to an Id. It performs a look up
- * using the object information block for this object class.
+ * The object information must use string names.
*
- * @param[in] information points to an object class information block.
- * @param[in] name is the name of the object to find.
- * @param[in] id will contain the Id if the search is successful.
+ * @param information The object information. Must not be NULL.
+ * @param name The object name.
+ * @param name_length_p Optional parameter to return the name length.
+ * @param error The error indication in case of failure. Must not be NULL.
*
- * @retval This method returns one of the values from the
- * @ref Objects_Name_or_id_lookup_errors enumeration to indicate
- * successful or failure. On success @a id will contain the Id of
- * the requested object.
+ * @retval NULL No object exists for this name or invalid parameters.
+ * @retval other The first object according to object index associated with
+ * this name.
*/
-Objects_Name_or_id_lookup_errors _Objects_Name_to_id_string(
- Objects_Information *information,
- const char *name,
- Objects_Id *id
+Objects_Control *_Objects_Get_by_name(
+ const Objects_Information *information,
+ const char *name,
+ size_t *name_length_p,
+ Objects_Get_by_name_error *error
);
#endif
@@ -1054,6 +1060,11 @@ RTEMS_INLINE_ROUTINE void _Objects_Allocator_unlock( void )
_RTEMS_Unlock_allocator();
}
+RTEMS_INLINE_ROUTINE bool _Objects_Allocator_is_owner( void )
+{
+ return _RTEMS_Allocator_is_owner();
+}
+
/** @} */
#ifdef __cplusplus
diff --git a/cpukit/score/src/objectnametoidstring.c b/cpukit/score/src/objectnametoidstring.c
index 00c84f04d3..bd4b4a9ead 100644
--- a/cpukit/score/src/objectnametoidstring.c
+++ b/cpukit/score/src/objectnametoidstring.c
@@ -23,40 +23,53 @@
#include <string.h>
#if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES)
-Objects_Name_or_id_lookup_errors _Objects_Name_to_id_string(
- Objects_Information *information,
- const char *name,
- Objects_Id *id
+Objects_Control *_Objects_Get_by_name(
+ const Objects_Information *information,
+ const char *name,
+ size_t *name_length_p,
+ Objects_Get_by_name_error *error
)
{
- Objects_Control *the_object;
- uint32_t index;
+ size_t name_length;
+ size_t max_name_length;
+ uint32_t index;
- /* ASSERT: information->is_string == true */
+ _Assert( information->is_string );
+ _Assert( _Objects_Allocator_is_owner() );
- if ( !id )
- return OBJECTS_INVALID_ADDRESS;
+ if ( name == NULL ) {
+ *error = OBJECTS_GET_BY_NAME_INVALID_NAME;
+ return NULL;
+ }
+
+ name_length = strnlen( name, information->name_length + 1 );
+ max_name_length = information->name_length;
+ if ( name_length > max_name_length ) {
+ *error = OBJECTS_GET_BY_NAME_NAME_TOO_LONG;
+ return NULL;
+ }
+
+ if ( name_length_p != NULL ) {
+ *name_length_p = name_length;
+ }
- if ( !name )
- return OBJECTS_INVALID_NAME;
+ for ( index = 1; index <= information->maximum; index++ ) {
+ Objects_Control *the_object;
- if ( information->maximum != 0 ) {
+ the_object = information->local_table[ index ];
- for ( index = 1; index <= information->maximum; index++ ) {
- the_object = information->local_table[ index ];
- if ( !the_object )
- continue;
+ if ( the_object == NULL )
+ continue;
- if ( !the_object->name.name_p )
- continue;
+ if ( the_object->name.name_p == NULL )
+ continue;
- if (!strncmp( name, the_object->name.name_p, information->name_length)) {
- *id = the_object->id;
- return OBJECTS_NAME_OR_ID_LOOKUP_SUCCESSFUL;
- }
+ if ( strncmp( name, the_object->name.name_p, max_name_length ) == 0 ) {
+ return the_object;
}
}
- return OBJECTS_INVALID_NAME;
+ *error = OBJECTS_GET_BY_NAME_NO_OBJECT;
+ return NULL;
}
#endif