Re: [PATCH] remote: Handle functions thar return optional strings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Jun 16, 2011 at 11:43:53AM +0200, Matthias Bolte wrote:
> ---
>  daemon/remote.c              |   64 ------------------------------------------
>  daemon/remote_generator.pl   |   28 ++++++++++++++++++
>  src/remote/remote_protocol.x |    2 +-
>  3 files changed, 29 insertions(+), 65 deletions(-)
> 
> diff --git a/daemon/remote.c b/daemon/remote.c
> index 8e0f47d..f2e193d 100644
> --- a/daemon/remote.c
> +++ b/daemon/remote.c
> @@ -1485,70 +1485,6 @@ cleanup:
>  }
>  
>  static int
> -remoteDispatchDomainScreenshot(struct qemud_server *server ATTRIBUTE_UNUSED,
> -                               struct qemud_client *client,
> -                               virConnectPtr conn,
> -                               remote_message_header *hdr,
> -                               remote_error *rerr,
> -                               remote_domain_screenshot_args *args,
> -                               remote_domain_screenshot_ret *ret)
> -{
> -    int rv = -1;
> -    struct qemud_client_stream *stream = NULL;
> -    virDomainPtr dom = NULL;
> -    char *mime, **mime_p;
> -
> -    if (!conn) {
> -        virNetError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not open"));
> -        goto cleanup;
> -    }
> -
> -    ret->mime = NULL;
> -
> -    if (!(dom = get_nonnull_domain (conn, args->dom)))
> -        goto cleanup;
> -
> -    if (!(stream = remoteCreateClientStream(conn, hdr)))
> -        goto cleanup;
> -
> -    if (!(mime = virDomainScreenshot(dom, stream->st, args->screen, args->flags)))
> -        goto cleanup;
> -
> -    if (remoteAddClientStream(client, stream, 1) < 0) {
> -        virStreamAbort(stream->st);
> -        goto cleanup;
> -    }
> -
> -    if (VIR_ALLOC(mime_p) < 0) {
> -        virReportOOMError();
> -        goto cleanup;
> -    }
> -
> -    *mime_p = strdup(mime);
> -    if (*mime_p == NULL) {
> -        virReportOOMError();
> -        VIR_FREE(mime_p);
> -        goto cleanup;
> -    }
> -
> -    ret->mime = mime_p;
> -
> -    rv = 0;
> -
> -cleanup:
> -    if (rv < 0)
> -        remoteDispatchError(rerr);
> -    VIR_FREE(mime);
> -    if (dom)
> -        virDomainFree(dom);
> -    if (stream && rv != 0) {
> -        virStreamAbort(stream->st);
> -        remoteFreeClientStream(client, stream);
> -    }
> -    return rv;
> -}
> -
> -static int
>  remoteDispatchNodeGetCPUStats (struct qemud_server *server ATTRIBUTE_UNUSED,
>                                 struct qemud_client *client ATTRIBUTE_UNUSED,
>                                 virConnectPtr conn,
> diff --git a/daemon/remote_generator.pl b/daemon/remote_generator.pl
> index bcf5fd4..d9d9ded 100755
> --- a/daemon/remote_generator.pl
> +++ b/daemon/remote_generator.pl
> @@ -351,6 +351,7 @@ elsif ($opt_b) {
>          my @optionals_list = ();
>          my @getters_list = ();
>          my @args_list = ();
> +        my @prepare_ret_list = ();
>          my @ret_list = ();
>          my @free_list = ();
>          my @free_list_on_error = ("remoteDispatchError(rerr);");
> @@ -551,6 +552,27 @@ elsif ($opt_b) {
>                      $single_ret_var = $1;
>                      $single_ret_by_ref = 0;
>                      $single_ret_check = " == NULL";
> +                } elsif ($ret_member =~ m/^remote_string (\S+);/) {
> +                    push(@vars_list, "char *$1 = NULL");
> +                    push(@vars_list, "char **$1_p = NULL");
> +                    push(@ret_list, "ret->$1 = $1_p;");
> +                    push(@free_list, "    VIR_FREE($1);");
> +                    push(@free_list_on_error, "VIR_FREE($1_p);");
> +                    push(@prepare_ret_list,
> +                         "if (VIR_ALLOC($1_p) < 0) {\n" .
> +                         "        virReportOOMError();\n" .
> +                         "        goto cleanup;\n" .
> +                         "    }\n" .
> +                         "    \n" .
> +                         "    *$1_p = strdup($1);\n" .
> +                         "    if (*$1_p == NULL) {\n" .
> +                         "        virReportOOMError();\n" .
> +                         "        goto cleanup;\n" .
> +                         "    }\n");
> +
> +                    $single_ret_var = $1;
> +                    $single_ret_by_ref = 0;
> +                    $single_ret_check = " == NULL";
>                  } elsif ($ret_member =~ m/^remote_nonnull_(domain|network|storage_pool|storage_vol|interface|node_device|secret|nwfilter|domain_snapshot) (\S+);/) {
>                      my $type_name = name_to_ProcName($1);
>  
> @@ -864,6 +886,12 @@ elsif ($opt_b) {
>              print "\n";
>          }
>  
> +        if (@prepare_ret_list) {
> +            print "    ";
> +            print join("\n    ", @prepare_ret_list);
> +            print "\n";
> +        }
> +
>          if (@ret_list) {
>              print "    ";
>              print join("\n    ", @ret_list);
> diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
> index b136e41..0aa3dfb 100644
> --- a/src/remote/remote_protocol.x
> +++ b/src/remote/remote_protocol.x
> @@ -2386,7 +2386,7 @@ enum remote_procedure {
>      REMOTE_PROC_STORAGE_VOL_DOWNLOAD = 209, /* autogen autogen | readstream@1 */
>      REMOTE_PROC_DOMAIN_INJECT_NMI = 210, /* autogen autogen */
>  
> -    REMOTE_PROC_DOMAIN_SCREENSHOT = 211, /* skipgen autogen | readstream@1 */
> +    REMOTE_PROC_DOMAIN_SCREENSHOT = 211, /* autogen autogen | readstream@1 */
>      REMOTE_PROC_DOMAIN_GET_STATE = 212, /* skipgen skipgen */
>      REMOTE_PROC_DOMAIN_MIGRATE_BEGIN3 = 213, /* skipgen skipgen */
>      REMOTE_PROC_DOMAIN_MIGRATE_PREPARE3 = 214, /* skipgen skipgen */

ACK,

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel@xxxxxxxxxxxx  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]