Changeset b8bcebe in rtems


Ignore:
Timestamp:
Jan 12, 2017, 7:28:57 AM (3 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
2b72162
Parents:
1772a04
git-author:
Sebastian Huber <sebastian.huber@…> (01/12/17 07:28:57)
git-committer:
Sebastian Huber <sebastian.huber@…> (01/13/17 06:19:21)
Message:

score: Add and use _Objects_Name_to_string()

Update #2858.

Location:
cpukit/score
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpukit/score/include/rtems/score/objectimpl.h

    r1772a04 rb8bcebe  
    656656
    657657/**
     658 * @brief Converts the specified object name to a text representation.
     659 *
     660 * Non-printable characters according to isprint() are converted to '*'.
     661 *
     662 * @param[in] name The object name.
     663 * @param[in] is_string Indicates if the object name is a string or a four
     664 *   character array (32-bit unsigned integer).
     665 * @param[in] buffer The string buffer for the text representation.
     666 * @param[in] buffer_size The buffer size in characters.
     667 *
     668 * @retval The length of the text representation.  May be greater than or equal
     669 * to the buffer size if truncation occurred.
     670 */
     671size_t _Objects_Name_to_string(
     672  Objects_Name  name,
     673  bool          is_string,
     674  char         *buffer,
     675  size_t        buffer_size
     676);
     677
     678/**
    658679 *  @brief Set objects name.
    659680 *
  • cpukit/score/src/objectgetnameasstring.c

    r1772a04 rb8bcebe  
    2424#include <ctype.h>
    2525
     26size_t _Objects_Name_to_string(
     27  Objects_Name  name,
     28  bool          is_string,
     29  char         *buffer,
     30  size_t        buffer_size
     31)
     32{
     33  char        lname[ 5 ];
     34  const char *s;
     35  char       *d;
     36  size_t      i;
     37
     38#if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES)
     39  if ( is_string ) {
     40    s = name.name_p;
     41  } else
     42#endif
     43  {
     44    lname[ 0 ] = (name.name_u32 >> 24) & 0xff;
     45    lname[ 1 ] = (name.name_u32 >> 16) & 0xff;
     46    lname[ 2 ] = (name.name_u32 >>  8) & 0xff;
     47    lname[ 3 ] = (name.name_u32 >>  0) & 0xff;
     48    lname[ 4 ] = '\0';
     49    s = lname;
     50  }
     51
     52  d = buffer;
     53  i = 1;
     54
     55  if ( s != NULL ) {
     56    while ( *s != '\0' ) {
     57      if ( i < buffer_size ) {
     58        *d = isprint((unsigned char) *s) ? *s : '*';
     59        ++d;
     60      }
     61
     62      ++s;
     63      ++i;
     64    }
     65  }
     66
     67  if ( buffer_size > 0 ) {
     68    *d = '\0';
     69  }
     70
     71  return i - 1;
     72}
     73
    2674/*
    2775 *  This method objects the name of an object and returns its name
     
    3785{
    3886  Objects_Information   *information;
    39   const char            *s;
    40   char                  *d;
    41   uint32_t               i;
    42   char                   lname[5];
    4387  Objects_Control       *the_object;
    4488  ISR_lock_Context       lock_context;
     
    62106  }
    63107
    64   #if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES)
    65     if ( information->is_string ) {
    66       s = the_object->name.name_p;
    67     } else
    68   #endif
    69   {
    70     uint32_t  u32_name = (uint32_t) the_object->name.name_u32;
    71 
    72     lname[ 0 ] = (u32_name >> 24) & 0xff;
    73     lname[ 1 ] = (u32_name >> 16) & 0xff;
    74     lname[ 2 ] = (u32_name >>  8) & 0xff;
    75     lname[ 3 ] = (u32_name >>  0) & 0xff;
    76     lname[ 4 ] = '\0';
    77     s = lname;
    78   }
    79 
    80   d = name;
    81   if ( s ) {
    82     for ( i=0 ; i<(length-1) && *s ; i++, s++, d++ ) {
    83       *d = (isprint((unsigned char)*s)) ? *s : '*';
    84     }
    85   }
    86   *d = '\0';
     108  _Objects_Name_to_string(
     109    the_object->name,
     110#if defined(RTEMS_SCORE_OBJECT_ENABLE_STRING_NAMES)
     111    information->is_string,
     112#else
     113    false,
     114#endif
     115    name,
     116    length
     117  );
    87118
    88119  _ISR_lock_ISR_enable( &lock_context );
Note: See TracChangeset for help on using the changeset viewer.