| 1 |
/* |
| 2 |
* BlueALSA - cmd-info.c |
| 3 |
* Copyright (c) 2016-2024 Arkadiusz Bokowy |
| 4 |
* |
| 5 |
* This file is a part of bluez-alsa. |
| 6 |
* |
| 7 |
* This project is licensed under the terms of the MIT license. |
| 8 |
* |
| 9 |
*/ |
| 10 |
|
| 11 |
#include <getopt.h> |
| 12 |
#include <stdio.h> |
| 13 |
#include <stdlib.h> |
| 14 |
|
| 15 |
#include <dbus/dbus.h> |
| 16 |
|
| 17 |
#include "cli.h" |
| 18 |
#include "shared/dbus-client-pcm.h" |
| 19 |
#include "shared/log.h" |
| 20 |
|
| 21 |
static void usage(const char *command) { |
| 22 |
printf("Show PCM properties.\n\n"); |
| 23 |
cli_print_usage("%s [OPTION]... PCM-PATH", command); |
| 24 |
printf("\nOptions:\n" |
| 25 |
" -h, --help\t\tShow this message and exit\n" |
| 26 |
"\nPositional arguments:\n" |
| 27 |
" PCM-PATH\tBlueALSA PCM D-Bus object path\n" |
| 28 |
); |
| 29 |
} |
| 30 |
|
| 31 |
static int cmd_info_func(int argc, char *argv[]) { |
| 32 |
|
| 33 |
int opt; |
| 34 |
const char *opts = "hqv"; |
| 35 |
const struct option longopts[] = { |
| 36 |
{ "help", no_argument, NULL, 'h' }, |
| 37 |
{ "quiet", no_argument, NULL, 'q' }, |
| 38 |
{ "verbose", no_argument, NULL, 'v' }, |
| 39 |
{ 0 }, |
| 40 |
}; |
| 41 |
|
| 42 |
opterr = 0; |
| 43 |
while ((opt = getopt_long(argc, argv, opts, longopts, NULL)) != -1) { |
| 44 |
if (cli_parse_common_options(opt)) |
| 45 |
continue; |
| 46 |
switch (opt) { |
| 47 |
case 'h' /* --help */ : |
| 48 |
usage(argv[0]); |
| 49 |
return EXIT_SUCCESS; |
| 50 |
default: |
| 51 |
cmd_print_error("Invalid argument '%s'", argv[optind - 1]); |
| 52 |
return EXIT_FAILURE; |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
if (argc - optind < 1) { |
| 57 |
cmd_print_error("Missing BlueALSA PCM path argument"); |
| 58 |
return EXIT_FAILURE; |
| 59 |
} |
| 60 |
if (argc - optind > 1) { |
| 61 |
cmd_print_error("Invalid number of arguments"); |
| 62 |
return EXIT_FAILURE; |
| 63 |
} |
| 64 |
|
| 65 |
DBusError err = DBUS_ERROR_INIT; |
| 66 |
const char *path = argv[optind]; |
| 67 |
|
| 68 |
struct ba_pcm pcm; |
| 69 |
if (!cli_get_ba_pcm(path, &pcm, &err)) { |
| 70 |
cmd_print_error("Couldn't get BlueALSA PCM: %s", err.message); |
| 71 |
return EXIT_FAILURE; |
| 72 |
} |
| 73 |
|
| 74 |
cli_print_pcm_properties(&pcm, &err); |
| 75 |
if (dbus_error_is_set(&err)) |
| 76 |
warn("Unable to read available codecs: %s", err.message); |
| 77 |
|
| 78 |
return EXIT_SUCCESS; |
| 79 |
} |
| 80 |
|
| 81 |
const struct cli_command cmd_info = { |
| 82 |
"info", |
| 83 |
"Show PCM properties", |
| 84 |
cmd_info_func, |
| 85 |
}; |