Changeset a90fc0c in mainline


Ignore:
Timestamp:
2011-03-21T15:53:51Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d7186cd
Parents:
aaff605
Message:

Refactoring of "enum to string" functions

Location:
uspace/lib/usb
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usb/include/usb/usb.h

    raaff605 ra90fc0c  
    6161
    6262const char * usb_str_transfer_type(usb_transfer_type_t t);
     63const char * usb_str_transfer_type_short(usb_transfer_type_t t);
    6364
    6465/** USB data transfer direction. */
  • uspace/lib/usb/src/usb.c

    raaff605 ra90fc0c  
    3636#include <errno.h>
    3737
     38#define ARR_SIZE(arr) (sizeof(arr)/sizeof(arr[0]))
     39
    3840static const char *str_speed[] = {
    3941        "low",
     
    4143        "high"
    4244};
    43 static size_t str_speed_size = sizeof(str_speed)/sizeof(str_speed[0]);
     45
     46static const char *str_transfer_type[] = {
     47        "control",
     48        "isochronous",
     49        "bulk",
     50        "interrupt"
     51};
     52
     53static const char *str_transfer_type_short[] = {
     54        "ctrl",
     55        "iso",
     56        "bulk",
     57        "intr"
     58};
    4459
    4560/** String representation for USB transfer type.
     
    4863 * @return Transfer type as a string (in English).
    4964 */
    50 const char * usb_str_transfer_type(usb_transfer_type_t t)
     65const char *usb_str_transfer_type(usb_transfer_type_t t)
    5166{
    52         switch (t) {
    53                 case USB_TRANSFER_ISOCHRONOUS:
    54                         return "isochronous";
    55                 case USB_TRANSFER_INTERRUPT:
    56                         return "interrupt";
    57                 case USB_TRANSFER_CONTROL:
    58                         return "control";
    59                 case USB_TRANSFER_BULK:
    60                         return "bulk";
    61                 default:
    62                         return "unknown";
     67        if (t >= ARR_SIZE(str_transfer_type)) {
     68                return "invalid";
    6369        }
     70        return str_transfer_type[t];
     71}
     72
     73/** String representation for USB transfer type (short version).
     74 *
     75 * @param t Transfer type.
     76 * @return Transfer type as a short string for debugging messages.
     77 */
     78const char *usb_str_transfer_type_short(usb_transfer_type_t t)
     79{
     80        if (t >= ARR_SIZE(str_transfer_type_short)) {
     81                return "invl";
     82        }
     83        return str_transfer_type_short[t];
    6484}
    6585
     
    7191const char *usb_str_speed(usb_speed_t s)
    7292{
    73         if (s >= str_speed_size) {
     93        if (s >= ARR_SIZE(str_speed)) {
    7494                return "invalid";
    7595        }
Note: See TracChangeset for help on using the changeset viewer.