|
14 | 14 | #include <stdio.h> |
15 | 15 | #include <unistd.h> |
16 | 16 | #include <string.h> |
| 17 | +#include <getopt.h> |
17 | 18 |
|
18 | 19 | #ifndef ADSP_LISTENER_VERSIONED |
19 | 20 | #define ADSP_LISTENER_VERSIONED "libadsp_default_listener.so.1" |
|
34 | 35 |
|
35 | 36 | typedef int (*dsp_default_listener_start_t)(int argc, char *argv[]); |
36 | 37 |
|
| 38 | +/** |
| 39 | + * Prints help information about the daemon. |
| 40 | + * @param program_name The name of the program |
| 41 | + * @param dsp_name The DSP name (ADSP, CDSP, etc.) |
| 42 | + */ |
| 43 | +static void print_help(const char *program_name, const char *dsp_name) { |
| 44 | + printf("Usage: %s [OPTION]...\n", program_name); |
| 45 | + printf("Daemon that establishes a connection to %s.\n", dsp_name); |
| 46 | +#ifdef USE_ADSP |
| 47 | + printf("If audiopd is passed as an argument to this daemon, it will connect to audio PD on %s.\n", dsp_name); |
| 48 | +#endif |
| 49 | + printf("If no argument is provided or rootpd is passed, it will connect to root PD on %s.\n\n", dsp_name); |
| 50 | + |
| 51 | + printf("Functionality:\n"); |
| 52 | +#ifdef USE_ADSP |
| 53 | + printf(" rootpd:\n"); |
| 54 | + printf(" - Exception logging: Facilitates transfer of %s process exception logs\n", dsp_name); |
| 55 | + printf(" to the HLOS (High-Level Operating System) logging infrastructure for\n"); |
| 56 | + printf(" effective monitoring and debugging\n"); |
| 57 | + printf(" - Remote file system access\n"); |
| 58 | + printf(" audiopd:\n"); |
| 59 | + printf(" - Memory requirements for audio PD dynamic loading\n"); |
| 60 | + printf(" - Remote file system access\n\n"); |
| 61 | +#elif defined(USE_SDSP) |
| 62 | + printf(" rootpd:\n"); |
| 63 | + printf(" - Remote file system access\n\n"); |
| 64 | +#else |
| 65 | + printf(" rootpd:\n"); |
| 66 | + printf(" - Exception logging: Facilitates transfer of %s process exception logs\n", dsp_name); |
| 67 | + printf(" to the HLOS (High-Level Operating System) logging infrastructure for\n"); |
| 68 | + printf(" effective monitoring and debugging\n"); |
| 69 | + printf(" - Remote file system access\n\n"); |
| 70 | +#endif |
| 71 | + |
| 72 | + printf("Options:\n"); |
| 73 | + printf(" -h, --help display this help and exit\n"); |
| 74 | + printf(" <pd_name> <domain> start daemon for specific PD and domain\n"); |
| 75 | +#ifdef USE_ADSP |
| 76 | + printf(" example: %s rootpd adsp\n", program_name); |
| 77 | +#elif defined(USE_SDSP) |
| 78 | + printf(" example: %s rootpd sdsp\n", program_name); |
| 79 | +#elif defined(USE_CDSP) |
| 80 | + printf(" example: %s rootpd cdsp (or cdsp1)\n", program_name); |
| 81 | +#elif defined(USE_GDSP) |
| 82 | + printf(" example: %s rootpd gdsp0 (or gdsp1)\n", program_name); |
| 83 | +#endif |
| 84 | +#ifndef USE_GDSP |
| 85 | + printf(" <pd_name> start daemon for specific PD\n"); |
| 86 | + printf(" example: %s rootpd\n", program_name); |
| 87 | + printf(" (no arguments) start daemon for root PD (default domain)\n\n"); |
| 88 | +#else |
| 89 | + printf("\n"); |
| 90 | +#endif |
| 91 | + |
| 92 | + printf("Note that this daemon runs continuously and automatically restarts on errors.\n"); |
| 93 | + printf("It exits only when the fastRPC device node is not accessible.\n"); |
| 94 | +} |
| 95 | + |
37 | 96 | // Result struct for dlopen. |
38 | 97 | struct dlopen_result { |
39 | 98 | void *handle; |
@@ -93,6 +152,25 @@ int main(int argc, char *argv[]) { |
93 | 152 | #else |
94 | 153 | goto bail; |
95 | 154 | #endif |
| 155 | + |
| 156 | + // Parse command-line options |
| 157 | + static struct option long_options[] = { |
| 158 | + {"help", no_argument, 0, 'h'}, |
| 159 | + {0, 0, 0, 0} |
| 160 | + }; |
| 161 | + |
| 162 | + int opt; |
| 163 | + while ((opt = getopt_long(argc, argv, "h", long_options, NULL)) != -1) { |
| 164 | + switch (opt) { |
| 165 | + case 'h': |
| 166 | + print_help(argv[0], dsp_name); |
| 167 | + return 0; |
| 168 | + default: |
| 169 | + fprintf(stderr, "Try '%s --help' for more information.\n", argv[0]); |
| 170 | + return 1; |
| 171 | + } |
| 172 | + } |
| 173 | + |
96 | 174 | VERIFY_EPRINTF("%s daemon starting", dsp_name); |
97 | 175 |
|
98 | 176 | while (1) { |
|
0 commit comments