Changeset 0499235 in mainline for uspace/app/sysinfo/sysinfo.c


Ignore:
Timestamp:
2012-03-02T17:20:23Z (12 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5608deba, 98cb0495, c30a015
Parents:
3113d47
Message:

add basic support for encoding name/value properties in sysinfo

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/sysinfo/sysinfo.c

    r3113d47 r0499235  
    9292}
    9393
     94static int print_item_property(char *ipath, char *iprop)
     95{
     96        size_t size;
     97        void *data = sysinfo_get_property(ipath, iprop, &size);
     98        if (data == NULL) {
     99                printf("Error reading property '%s' of item '%s'.\n", iprop,
     100                    ipath);
     101                return -1;
     102        }
     103       
     104        printf("%s property %s -> ", ipath, iprop);
     105        dump_bytes_hex(data, size);
     106        fputs(" ('", stdout);
     107        dump_bytes_text(data, size);
     108        fputs("')\n", stdout);
     109       
     110        return EOK;
     111}
     112
    94113static void print_spaces(size_t spaces)
    95114{
     
    143162int main(int argc, char *argv[])
    144163{
    145         if (argc != 2) {
     164        int rc = 0;
     165       
     166        if (argc < 2) {
    146167                /* Print keys */
    147168                print_keys("", 0);
    148                 return 0;
     169                return rc;
    149170        }
    150171       
    151172        char *ipath = argv[1];
    152         sysinfo_item_val_type_t tag = sysinfo_get_val_type(ipath);
    153        
    154         /* Silence warning */
    155         int rc = 0;
    156        
    157         switch (tag) {
    158         case SYSINFO_VAL_UNDEFINED:
    159                 printf("Error: Sysinfo item '%s' not defined.\n", ipath);
    160                 rc = 2;
    161                 break;
    162         case SYSINFO_VAL_VAL:
    163                 rc = print_item_val(ipath);
    164                 break;
    165         case SYSINFO_VAL_DATA:
    166                 rc = print_item_data(ipath);
    167                 break;
    168         default:
    169                 printf("Error: Sysinfo item '%s' with unknown value type.\n",
    170                     ipath);
    171                 rc = 2;
    172                 break;
    173         }
    174        
     173       
     174        if (argc < 3) {
     175                sysinfo_item_val_type_t tag = sysinfo_get_val_type(ipath);
     176               
     177                switch (tag) {
     178                case SYSINFO_VAL_UNDEFINED:
     179                        printf("Error: Sysinfo item '%s' not defined.\n", ipath);
     180                        rc = 2;
     181                        break;
     182                case SYSINFO_VAL_VAL:
     183                        rc = print_item_val(ipath);
     184                        break;
     185                case SYSINFO_VAL_DATA:
     186                        rc = print_item_data(ipath);
     187                        break;
     188                default:
     189                        printf("Error: Sysinfo item '%s' with unknown value type.\n",
     190                            ipath);
     191                        rc = 2;
     192                        break;
     193                }
     194               
     195                return rc;
     196        }
     197       
     198        char *iprop = argv[2];
     199        rc = print_item_property(ipath, iprop);
    175200        return rc;
    176201}
Note: See TracChangeset for help on using the changeset viewer.