Skip to content

Commit d1e70ea

Browse files
committed
dsprpcd: Add help functionality
Add -h/--help support to display daemon usage, functionality, and command-line options with appropriate examples for each DSP subsystem. Signed-off-by: Vinayak Katoch <vkatoch@qti.qualcomm.com>
1 parent 29458c2 commit d1e70ea

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

src/dsprpcd.c

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <stdio.h>
1515
#include <unistd.h>
1616
#include <string.h>
17+
#include <getopt.h>
1718

1819
#ifndef ADSP_LISTENER_VERSIONED
1920
#define ADSP_LISTENER_VERSIONED "libadsp_default_listener.so.1"
@@ -34,6 +35,64 @@
3435

3536
typedef int (*dsp_default_listener_start_t)(int argc, char *argv[]);
3637

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+
3796
// Result struct for dlopen.
3897
struct dlopen_result {
3998
void *handle;
@@ -93,6 +152,25 @@ int main(int argc, char *argv[]) {
93152
#else
94153
goto bail;
95154
#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+
96174
VERIFY_EPRINTF("%s daemon starting", dsp_name);
97175

98176
while (1) {

0 commit comments

Comments
 (0)