Changeset 9d1488d in mainline


Ignore:
Timestamp:
2011-11-25T22:29:54Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
be51d73
Parents:
10f2b34
Message:

mixerctl: Move channel print to separate function, fix memory leaks.

File:
1 edited

Legend:

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

    r10f2b34 r9d1488d  
    3333 */
    3434
     35#include <assert.h>
    3536#include <errno.h>
    3637#include <str_error.h>
     
    4142#define DEFAULT_DEVICE "/hw/pci0/00:01.0/sb16/mixer"
    4243
    43 int main(int argc, char *argv[])
     44static void print_levels(async_exch_t *exch)
    4445{
    45         devman_handle_t mixer_handle;
    46         int ret = devman_fun_get_handle(DEFAULT_DEVICE, &mixer_handle, 0);
    47         if (ret != EOK) {
    48                 printf("Failed to get device(%s) handle: %s.\n",
    49                     DEFAULT_DEVICE, str_error(ret));
    50                 return 1;
    51         }
    52 
    53         async_sess_t *session = devman_device_connect(
    54             EXCHANGE_ATOMIC, mixer_handle, IPC_FLAG_BLOCKING);
    55         if (!session) {
    56                 printf("Failed to connect to device.\n");
    57                 return 1;
    58         }
    59 
    60         async_exch_t *exch = async_exchange_begin(session);
    61         if (!exch) {
    62                 printf("Failed to start session exchange.\n");
    63                 async_hangup(session);
    64                 return 1;
    65         }
    66 
    6746        const char* name = NULL;
    6847        unsigned count = 0;
    69         ret = audio_mixer_get_info(exch, &name, &count);
     48        int ret = audio_mixer_get_info(exch, &name, &count);
    7049        if (ret != EOK) {
    7150                printf("Failed to get mixer info: %s.\n", str_error(ret));
    72                 return 1;
     51                return;
    7352        }
    74         printf("MIXER: %s.\n", name);
     53        printf("MIXER %s:\n", name);
    7554
    7655        for (unsigned i = 0; i < count; ++i) {
     
    10887                        }
    10988
    110                         printf("Channel(%u/%u) %s %s volume: %u/%u%s.\n",
     89                        printf("\tChannel(%u/%u) %s %s volume: %u/%u%s.\n",
    11190                            i, j, name, chan, level, max, mute ? " (M)":"");
     91                        free(chan);
    11292                }
     93                free(name);
    11394
    11495        }
     96}
    11597
     98int main(int argc, char *argv[])
     99{
     100
     101        const char *device = DEFAULT_DEVICE;
     102        if (argc == 2)
     103                device = argv[1];
     104
     105
     106        devman_handle_t mixer_handle;
     107        int ret = devman_fun_get_handle(device, &mixer_handle, 0);
     108        if (ret != EOK) {
     109                printf("Failed to get device(%s) handle: %s.\n",
     110                    DEFAULT_DEVICE, str_error(ret));
     111                return 1;
     112        }
     113
     114        async_sess_t *session = devman_device_connect(
     115            EXCHANGE_ATOMIC, mixer_handle, IPC_FLAG_BLOCKING);
     116        if (!session) {
     117                printf("Failed to connect to device.\n");
     118                return 1;
     119        }
     120
     121        async_exch_t *exch = async_exchange_begin(session);
     122        if (!exch) {
     123                printf("Failed to start session exchange.\n");
     124                async_hangup(session);
     125                return 1;
     126        }
     127
     128        print_levels(exch);
    116129
    117130        async_exchange_end(exch);
Note: See TracChangeset for help on using the changeset viewer.