grab: use grab_client_cmdline_parser_string()
authorAndre <maan@p133.(none)>
Tue, 16 May 2006 19:38:04 +0000 (21:38 +0200)
committerAndre <maan@p133.(none)>
Tue, 16 May 2006 19:38:04 +0000 (21:38 +0200)
No more need to use split_args().

Makefile.in
alsa_writer.c
audiod.c
grab_client.c
grab_client.h

index e22149452f71ecd4ffa3fe52bb1a274bfc451c4f..c9eb46fd9f98578e93f1882fed74a0e0788bb70c 100644 (file)
@@ -111,6 +111,7 @@ module_ggo_opts := --set-version="(@PACKAGE_STRING@, $(codename))"
 
 grab_client.cmdline.h grab_client.cmdline.c: grab_client.ggo
        gengetopt $(module_ggo_opts) \
 
 grab_client.cmdline.h grab_client.cmdline.c: grab_client.ggo
        gengetopt $(module_ggo_opts) \
+               -S \
                --set-package=grab \
                --no-handle-help \
                --no-handle-error \
                --set-package=grab \
                --no-handle-help \
                --no-handle-error \
index 601353aaac84b7a8969d4bf9b5dc01d68242de19..5aa908518b113305372d126ead651ec961243046 100644 (file)
@@ -128,6 +128,8 @@ static int alsa_open(struct writer_node *w)
                return -E_SW_PARAMS;
        pad->bytes_per_frame = snd_pcm_format_physical_width(FORMAT)
                * conf.channels_arg / 8;
                return -E_SW_PARAMS;
        pad->bytes_per_frame = snd_pcm_format_physical_width(FORMAT)
                * conf.channels_arg / 8;
+//     if (snd_pcm_nonblock(pad->handle, 1))
+//             PARA_ERROR_LOG("%s\n", "failed to set nonblock mode");
        return period_size * pad->bytes_per_frame;
 }
 
        return period_size * pad->bytes_per_frame;
 }
 
index 00cdf34533eb87b824136fa4498f20920177bc1b..3d01931173f2d09112f7035c4b1af614a35f094e 100644 (file)
--- a/audiod.c
+++ b/audiod.c
@@ -104,6 +104,7 @@ struct audiod_command {
 const char *name;
 /** pointer to the function that handles the command */
 int (*handler)(int, int, char**);
 const char *name;
 /** pointer to the function that handles the command */
 int (*handler)(int, int, char**);
+int (*line_handler)(int, char*);
 /** one-line description of the command */
 const char *description;
 /** summary of the command line options */
 /** one-line description of the command */
 const char *description;
 /** summary of the command line options */
@@ -114,7 +115,7 @@ const char *help;
 
 extern const char *status_item_list[NUM_STAT_ITEMS];
 
 
 extern const char *status_item_list[NUM_STAT_ITEMS];
 
-static int com_grab(int, int, char **);
+static int com_grab(int, char *);
 static int com_cycle(int, int, char **);
 static int com_help(int, int, char **);
 static int com_off(int, int, char **);
 static int com_cycle(int, int, char **);
 static int com_help(int, int, char **);
 static int com_off(int, int, char **);
@@ -150,7 +151,7 @@ static struct audiod_command cmds[] = {
 },
 {
 .name = "grab",
 },
 {
 .name = "grab",
-.handler = com_grab,
+.line_handler = com_grab,
 .description = "grab the audio stream",
 .synopsis = "-- grab [grab_options]",
 .help =
 .description = "grab the audio stream",
 .synopsis = "-- grab [grab_options]",
 .help =
@@ -1333,16 +1334,15 @@ static char *list_filters(void)
 }
 #endif
 
 }
 #endif
 
-static int com_grab(int fd, int argc, char **argv)
+
+static int com_grab(int fd, char *cmdline)
 {
        struct grab_client *gc;
        struct filter_node *fn;
        int i, err;
        char *msg;
 
 {
        struct grab_client *gc;
        struct filter_node *fn;
        int i, err;
        char *msg;
 
-       PARA_INFO_LOG("argc: %d, argv[0]: %s, optind: %d\n", argc, argv[0], optind);
-       gc = grab_client_new(fd, argc, argv, &err);
-       PARA_INFO_LOG("argc: %d, argv[0]: %s, optind: %d\n", argc, argv[0], optind);
+       gc = grab_client_new(fd, cmdline, &err);
        if (!gc)
                goto err_out;
        fn = find_filter_node(gc->conf->slot_arg, gc->audio_format_num, gc->conf->filter_num_arg);
        if (!gc)
                goto err_out;
        fn = find_filter_node(gc->conf->slot_arg, gc->audio_format_num, gc->conf->filter_num_arg);
@@ -1431,7 +1431,7 @@ static int check_perms(uid_t uid)
 static int handle_connect(void)
 {
        int i, argc, ret, clifd = -1;
 static int handle_connect(void)
 {
        int i, argc, ret, clifd = -1;
-       char *buf = para_malloc(MAXLINE), **argv = NULL;
+       char *p, *buf = para_malloc(MAXLINE), **argv = NULL;
        struct sockaddr_un unix_addr;
 
        ret = para_accept(audiod_socket, &unix_addr, sizeof(struct sockaddr_un));
        struct sockaddr_un unix_addr;
 
        ret = para_accept(audiod_socket, &unix_addr, sizeof(struct sockaddr_un));
@@ -1441,16 +1441,33 @@ static int handle_connect(void)
        ret = recv_cred_buffer(clifd, buf, MAXLINE - 1);
        if (ret < 0)
                goto out;
        ret = recv_cred_buffer(clifd, buf, MAXLINE - 1);
        if (ret < 0)
                goto out;
-       PARA_INFO_LOG("connection from user %i\n",  ret);
+       PARA_INFO_LOG("connection from user %i, buf: %s\n",  ret, buf);
        ret = check_perms(ret);
        if (ret < 0)
                goto out;
        ret = check_perms(ret);
        if (ret < 0)
                goto out;
-       argc = split_args(buf, &argv, "\n");
-       PARA_INFO_LOG("argv[0]: %s, argc= %d\n", argv[0], argc);
+       ret = -E_INVALID_AUDIOD_CMD;
+       p = strchr(buf, '\n');
+       if (!p)
+               p = "";
+       else {
+               *p = '\0';
+               p++;
+       }
        for (i = 0; cmds[i].name; i++) {
        for (i = 0; cmds[i].name; i++) {
-               if (strcmp(cmds[i].name, argv[0]))
+               int j;
+               if (strcmp(cmds[i].name, buf))
                        continue;
                        continue;
-               ret = cmds[i].handler(clifd, argc, argv);
+               if (cmds[i].handler) {
+                       argc = split_args(buf, &argv, "\n");
+                       PARA_INFO_LOG("argv[0]: %s, argc= %d\n", argv[0], argc);
+                       ret = cmds[i].handler(clifd, argc, argv);
+                       goto out;
+               }
+               for (j = 0; p[j]; j++)
+                       if (p[j] == '\n')
+                               p[j] = ' ';
+               PARA_INFO_LOG("cmd: %s, options: %s\n", buf, p);
+               ret = cmds[i].line_handler(clifd, p);
                goto out;
        }
        ret = -E_INVALID_AUDIOD_CMD; /* cmd not found */
                goto out;
        }
        ret = -E_INVALID_AUDIOD_CMD; /* cmd not found */
index 026211fdcb9fca9c6e4e99b635e5de43c8592fb5..e81ad992733b8d0fad16ded17694891513875713 100644 (file)
@@ -235,20 +235,14 @@ void activate_inactive_grab_clients(int slot, int audio_format_num,
  * argc, argv get freed when com_grab() returns, so we have to make a
  * copy.
  */
  * argc, argv get freed when com_grab() returns, so we have to make a
  * copy.
  */
-struct grab_client *grab_client_new(int fd, int argc, char **argv, int *err)
+struct grab_client *grab_client_new(int fd, char *line, int *err)
 {
 {
-       int i, ret;
+       int ret;
        struct grab_client *gc = para_calloc(sizeof(struct grab_client));
 
        gc->conf = para_calloc(sizeof(struct grab_client_args_info));
        struct grab_client *gc = para_calloc(sizeof(struct grab_client));
 
        gc->conf = para_calloc(sizeof(struct grab_client_args_info));
-       gc->argc = argc;
-       gc->argv = para_calloc((argc + 2) * sizeof(char *));
 
 
-       for (i = 0; argv[i]; i++) {
-               gc->argv[i] = para_strdup(argv[i]);
-               PARA_INFO_LOG("argc: %d, argv[%d]: %s\n", argc, i, gc->argv[i]);
-       }
-       ret = grab_client_cmdline_parser(gc->argc, gc->argv , gc->conf);
+       ret = grab_client_cmdline_parser_string(line, gc->conf, "grab");
        *err = -E_GC_SYNTAX;
        if (ret)
                goto err_out;
        *err = -E_GC_SYNTAX;
        if (ret)
                goto err_out;
@@ -274,9 +268,6 @@ struct grab_client *grab_client_new(int fd, int argc, char **argv, int *err)
        add_inactive_gc(gc);
        return gc;
 err_out:
        add_inactive_gc(gc);
        return gc;
 err_out:
-       for (i = 0; i < argc; i++)
-               free(gc->argv[i]);
-       free(gc->argv);
        free(gc->conf);
        free(gc);
        return NULL;
        free(gc->conf);
        free(gc);
        return NULL;
index 8cc0a20331b3ea781d671a2b64fdcdcb1fb306e4..5b1fa74b436654b442bd5b613cdd4b8ab721042b 100644 (file)
@@ -54,7 +54,7 @@ struct grab_client {
        char **argv;
 };
 
        char **argv;
 };
 
-__malloc struct grab_client *grab_client_new(int fd, int argc, char **argv, int *err);
+__malloc struct grab_client *grab_client_new(int fd, char *line, int *err);
 void activate_inactive_grab_clients(int slot, int audio_format_num, struct list_head *filter_list);
 void activate_grab_client(struct grab_client *gc, struct filter_node *fn);
 void init_grabbing(void);
 void activate_inactive_grab_clients(int slot, int audio_format_num, struct list_head *filter_list);
 void activate_grab_client(struct grab_client *gc, struct filter_node *fn);
 void init_grabbing(void);