2011-04-24 07:58:01 +00:00
|
|
|
#!/usr/bin/perl -w
|
|
|
|
#
|
|
|
|
# This script parses remote_protocol.x or qemu_protocol.x and produces lots of
|
|
|
|
# boilerplate code for both ends of the remote connection.
|
|
|
|
#
|
|
|
|
# The first non-option argument specifies the prefix to be searched for, and
|
|
|
|
# output to, the boilerplate code. The second non-option argument is the
|
|
|
|
# file you want to operate on. For instance, to generate the dispatch table
|
|
|
|
# for both remote_protocol.x and qemu_protocol.x, you would run the
|
|
|
|
# following:
|
|
|
|
#
|
|
|
|
# remote_generator.pl -c -t remote ../src/remote/remote_protocol.x
|
|
|
|
# remote_generator.pl -t qemu ../src/remote/qemu_protocol.x
|
|
|
|
#
|
|
|
|
# By Richard Jones <rjones@redhat.com>
|
2011-04-22 18:35:34 +00:00
|
|
|
# Extended by Matthias Bolte <matthias.bolte@googlemail.com>
|
2011-04-24 07:58:01 +00:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
|
|
|
use Getopt::Std;
|
|
|
|
|
|
|
|
# Command line options.
|
2011-04-23 10:53:57 +00:00
|
|
|
our ($opt_p, $opt_t, $opt_a, $opt_r, $opt_d, $opt_c, $opt_b, $opt_k);
|
|
|
|
getopts ('ptardcbk');
|
2011-04-24 07:58:01 +00:00
|
|
|
|
2011-05-11 19:28:39 +00:00
|
|
|
my $structprefix = shift or die "missing prefix argument";
|
|
|
|
my $protocol = shift or die "missing protocol argument";
|
|
|
|
my @autogen;
|
|
|
|
|
2011-04-24 07:58:01 +00:00
|
|
|
my $procprefix = uc $structprefix;
|
|
|
|
|
|
|
|
# Convert name_of_call to NameOfCall.
|
|
|
|
sub name_to_ProcName {
|
|
|
|
my $name = shift;
|
|
|
|
my @elems = split /_/, $name;
|
|
|
|
@elems = map ucfirst, @elems;
|
2011-04-22 13:36:52 +00:00
|
|
|
@elems = map { $_ =~ s/Nwfilter/NWFilter/; $_ =~ s/Xml/XML/;
|
2011-04-22 16:54:51 +00:00
|
|
|
$_ =~ s/Uri/URI/; $_ =~ s/Uuid/UUID/; $_ =~ s/Id/ID/;
|
2011-04-23 06:19:46 +00:00
|
|
|
$_ =~ s/Mac/MAC/; $_ =~ s/Cpu/CPU/; $_ =~ s/Os/OS/;
|
2011-05-10 08:26:04 +00:00
|
|
|
$_ =~ s/Nmi/NMI/; $_ } @elems;
|
2011-04-24 07:58:01 +00:00
|
|
|
join "", @elems
|
|
|
|
}
|
|
|
|
|
|
|
|
# Read the input file (usually remote_protocol.x) and form an
|
|
|
|
# opinion about the name, args and return type of each RPC.
|
2011-05-21 09:24:28 +00:00
|
|
|
my ($name, $ProcName, $id, $flags, %calls, @calls);
|
2011-04-24 07:58:01 +00:00
|
|
|
|
|
|
|
# only generate a close method if -c was passed
|
|
|
|
if ($opt_c) {
|
|
|
|
# REMOTE_PROC_CLOSE has no args or ret.
|
|
|
|
$calls{close} = {
|
|
|
|
name => "close",
|
|
|
|
ProcName => "Close",
|
|
|
|
UC_NAME => "CLOSE",
|
|
|
|
args => "void",
|
|
|
|
ret => "void",
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2011-04-22 18:35:34 +00:00
|
|
|
my $collect_args_members = 0;
|
2011-04-22 15:09:33 +00:00
|
|
|
my $collect_ret_members = 0;
|
2011-04-22 18:35:34 +00:00
|
|
|
my $last_name;
|
|
|
|
|
2011-05-11 19:28:39 +00:00
|
|
|
open PROTOCOL, "<$protocol" or die "cannot open $protocol: $!";
|
|
|
|
|
|
|
|
while (<PROTOCOL>) {
|
2011-04-22 18:35:34 +00:00
|
|
|
if ($collect_args_members) {
|
|
|
|
if (/^};/) {
|
|
|
|
$collect_args_members = 0;
|
|
|
|
} elsif ($_ =~ m/^\s*(.*\S)\s*$/) {
|
|
|
|
push(@{$calls{$name}->{args_members}}, $1);
|
|
|
|
}
|
2011-04-22 15:09:33 +00:00
|
|
|
} elsif ($collect_ret_members) {
|
|
|
|
if (/^};/) {
|
|
|
|
$collect_ret_members = 0;
|
|
|
|
} elsif ($_ =~ m/^\s*(.*\S)\s*$/) {
|
|
|
|
push(@{$calls{$name}->{ret_members}}, $1);
|
|
|
|
}
|
2011-04-22 18:35:34 +00:00
|
|
|
} elsif (/^struct ${structprefix}_(.*)_args/) {
|
2011-04-24 07:58:01 +00:00
|
|
|
$name = $1;
|
|
|
|
$ProcName = name_to_ProcName ($name);
|
|
|
|
|
|
|
|
die "duplicate definition of ${structprefix}_${name}_args"
|
|
|
|
if exists $calls{$name};
|
|
|
|
|
|
|
|
$calls{$name} = {
|
|
|
|
name => $name,
|
|
|
|
ProcName => $ProcName,
|
|
|
|
UC_NAME => uc $name,
|
|
|
|
args => "${structprefix}_${name}_args",
|
2011-04-22 18:35:34 +00:00
|
|
|
args_members => [],
|
|
|
|
ret => "void"
|
2011-04-24 07:58:01 +00:00
|
|
|
};
|
|
|
|
|
2011-04-22 18:35:34 +00:00
|
|
|
$collect_args_members = 1;
|
2011-04-22 15:09:33 +00:00
|
|
|
$collect_ret_members = 0;
|
2011-04-22 18:35:34 +00:00
|
|
|
$last_name = $name;
|
2011-04-24 07:58:01 +00:00
|
|
|
} elsif (/^struct ${structprefix}_(.*)_ret/) {
|
|
|
|
$name = $1;
|
|
|
|
$ProcName = name_to_ProcName ($name);
|
|
|
|
|
|
|
|
if (exists $calls{$name}) {
|
|
|
|
$calls{$name}->{ret} = "${structprefix}_${name}_ret";
|
|
|
|
} else {
|
|
|
|
$calls{$name} = {
|
|
|
|
name => $name,
|
|
|
|
ProcName => $ProcName,
|
|
|
|
UC_NAME => uc $name,
|
|
|
|
args => "void",
|
2011-04-22 15:09:33 +00:00
|
|
|
ret => "${structprefix}_${name}_ret",
|
|
|
|
ret_members => []
|
2011-04-24 07:58:01 +00:00
|
|
|
}
|
|
|
|
}
|
2011-04-22 18:35:34 +00:00
|
|
|
|
|
|
|
$collect_args_members = 0;
|
2011-04-22 15:09:33 +00:00
|
|
|
$collect_ret_members = 1;
|
|
|
|
$last_name = $name;
|
2011-04-24 07:58:01 +00:00
|
|
|
} elsif (/^struct ${structprefix}_(.*)_msg/) {
|
|
|
|
$name = $1;
|
|
|
|
$ProcName = name_to_ProcName ($name);
|
|
|
|
|
|
|
|
$calls{$name} = {
|
|
|
|
name => $name,
|
|
|
|
ProcName => $ProcName,
|
|
|
|
UC_NAME => uc $name,
|
|
|
|
msg => "${structprefix}_${name}_msg"
|
2011-04-22 18:35:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$collect_args_members = 0;
|
2011-04-22 15:09:33 +00:00
|
|
|
$collect_ret_members = 0;
|
2011-05-11 19:28:39 +00:00
|
|
|
} elsif (/^\s*${procprefix}_PROC_(.*?)\s*=\s*(\d+)\s*,?(.*)$/) {
|
2011-04-24 07:58:01 +00:00
|
|
|
$name = lc $1;
|
|
|
|
$id = $2;
|
2011-05-11 19:28:39 +00:00
|
|
|
$flags = $3;
|
2011-04-24 07:58:01 +00:00
|
|
|
$ProcName = name_to_ProcName ($name);
|
|
|
|
|
2011-05-11 19:28:39 +00:00
|
|
|
if ($opt_b or $opt_k) {
|
2011-05-21 09:24:28 +00:00
|
|
|
if (!($flags =~ m/^\s*\/\*\s*(\S+)\s+(\S+)\s*(.*)\*\/\s*$/)) {
|
2011-05-11 19:28:39 +00:00
|
|
|
die "invalid generator flags for ${procprefix}_PROC_${name}"
|
|
|
|
}
|
|
|
|
|
2011-05-21 09:24:28 +00:00
|
|
|
my $genmode = $opt_b ? $1 : $2;
|
|
|
|
my $genflags = $3;
|
2011-05-11 19:28:39 +00:00
|
|
|
|
2011-05-21 09:24:28 +00:00
|
|
|
if ($genmode eq "autogen") {
|
2011-05-11 19:28:39 +00:00
|
|
|
push(@autogen, $ProcName);
|
2011-05-21 09:24:28 +00:00
|
|
|
} elsif ($genmode eq "skipgen") {
|
2011-05-11 19:28:39 +00:00
|
|
|
# ignore it
|
|
|
|
} else {
|
|
|
|
die "invalid generator flags for ${procprefix}_PROC_${name}"
|
|
|
|
}
|
2011-05-21 09:24:28 +00:00
|
|
|
|
|
|
|
if (defined $genflags and $genflags ne "") {
|
|
|
|
if ($genflags =~ m/^\|\s*(read|write)stream@(\d+)\s*$/) {
|
|
|
|
$calls{$name}->{streamflag} = $1;
|
|
|
|
$calls{$name}->{streamoffset} = int($2);
|
|
|
|
} else {
|
|
|
|
die "invalid generator flags for ${procprefix}_PROC_${name}"
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$calls{$name}->{streamflag} = "none";
|
|
|
|
}
|
2011-05-11 19:28:39 +00:00
|
|
|
}
|
|
|
|
|
2011-04-24 07:58:01 +00:00
|
|
|
$calls[$id] = $calls{$name};
|
2011-04-22 18:35:34 +00:00
|
|
|
|
|
|
|
$collect_args_members = 0;
|
2011-04-22 15:09:33 +00:00
|
|
|
$collect_ret_members = 0;
|
2011-04-22 18:35:34 +00:00
|
|
|
} else {
|
|
|
|
$collect_args_members = 0;
|
2011-04-22 15:09:33 +00:00
|
|
|
$collect_ret_members = 0;
|
2011-04-24 07:58:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-11 19:28:39 +00:00
|
|
|
close(PROTOCOL);
|
|
|
|
|
2011-05-30 10:58:57 +00:00
|
|
|
# this hash contains the procedures that are allowed to map [unsigned] hyper
|
|
|
|
# to [unsigned] long for legacy reasons in their signature and return type.
|
|
|
|
# this list is fixed. new procedures and public APIs have to map [unsigned]
|
|
|
|
# hyper to [unsigned] long long
|
|
|
|
my $long_legacy = {
|
|
|
|
DomainGetMaxMemory => { ret => { memory => 1 } },
|
|
|
|
DomainGetInfo => { ret => { maxMem => 1, memory => 1 } },
|
|
|
|
DomainMigrate => { arg => { flags => 1, resource => 1 } },
|
|
|
|
DomainMigrate2 => { arg => { flags => 1, resource => 1 } },
|
|
|
|
DomainMigrateBegin3 => { arg => { flags => 1, resource => 1 } },
|
|
|
|
DomainMigrateConfirm3 => { arg => { flags => 1, resource => 1 } },
|
|
|
|
DomainMigrateDirect => { arg => { flags => 1, resource => 1 } },
|
|
|
|
DomainMigrateFinish => { arg => { flags => 1 } },
|
|
|
|
DomainMigrateFinish2 => { arg => { flags => 1 } },
|
|
|
|
DomainMigrateFinish3 => { arg => { flags => 1 } },
|
|
|
|
DomainMigratePeer2Peer => { arg => { flags => 1, resource => 1 } },
|
|
|
|
DomainMigratePerform => { arg => { flags => 1, resource => 1 } },
|
|
|
|
DomainMigratePerform3 => { arg => { flags => 1, resource => 1 } },
|
|
|
|
DomainMigratePrepare => { arg => { flags => 1, resource => 1 } },
|
|
|
|
DomainMigratePrepare2 => { arg => { flags => 1, resource => 1 } },
|
|
|
|
DomainMigratePrepare3 => { arg => { flags => 1, resource => 1 } },
|
|
|
|
DomainMigratePrepareTunnel => { arg => { flags => 1, resource => 1 } },
|
|
|
|
DomainMigratePrepareTunnel3 => { arg => { flags => 1, resource => 1 } },
|
|
|
|
DomainMigrateToURI => { arg => { flags => 1, resource => 1 } },
|
|
|
|
DomainMigrateToURI2 => { arg => { flags => 1, resource => 1 } },
|
|
|
|
DomainMigrateVersion1 => { arg => { flags => 1, resource => 1 } },
|
|
|
|
DomainMigrateVersion2 => { arg => { flags => 1, resource => 1 } },
|
|
|
|
DomainMigrateVersion3 => { arg => { flags => 1, resource => 1 } },
|
|
|
|
DomainMigrateSetMaxSpeed => { arg => { bandwidth => 1 } },
|
|
|
|
DomainSetMaxMemory => { arg => { memory => 1 } },
|
|
|
|
DomainSetMemory => { arg => { memory => 1 } },
|
|
|
|
DomainSetMemoryFlags => { arg => { memory => 1 } },
|
|
|
|
GetLibVersion => { ret => { lib_ver => 1 } },
|
|
|
|
GetVersion => { ret => { hv_ver => 1 } },
|
|
|
|
NodeGetInfo => { ret => { memory => 1 } },
|
|
|
|
};
|
|
|
|
|
|
|
|
sub hyper_to_long
|
|
|
|
{
|
|
|
|
my $proc_name = shift;
|
|
|
|
my $ret_or_arg = shift;
|
|
|
|
my $member = shift;
|
|
|
|
|
|
|
|
if ($long_legacy->{$proc_name} and
|
|
|
|
$long_legacy->{$proc_name}->{$ret_or_arg} and
|
|
|
|
$long_legacy->{$proc_name}->{$ret_or_arg}->{$member}) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-24 07:58:01 +00:00
|
|
|
#----------------------------------------------------------------------
|
|
|
|
# Output
|
|
|
|
|
|
|
|
print <<__EOF__;
|
|
|
|
/* Automatically generated by remote_generator.pl.
|
|
|
|
* Do not edit this file. Any changes you make will be lost.
|
|
|
|
*/
|
|
|
|
__EOF__
|
|
|
|
|
2011-04-23 10:53:57 +00:00
|
|
|
if (!$opt_b and !$opt_k) {
|
|
|
|
print "\n";
|
|
|
|
}
|
|
|
|
|
2011-04-24 07:58:01 +00:00
|
|
|
# Debugging.
|
|
|
|
if ($opt_d) {
|
|
|
|
my @keys = sort (keys %calls);
|
|
|
|
foreach (@keys) {
|
|
|
|
print "$_:\n";
|
|
|
|
print " name $calls{$_}->{name} ($calls{$_}->{ProcName})\n";
|
|
|
|
print " $calls{$_}->{args} -> $calls{$_}->{ret}\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Prototypes for dispatch functions ("remote_dispatch_prototypes.h").
|
|
|
|
elsif ($opt_p) {
|
|
|
|
my @keys = sort (keys %calls);
|
|
|
|
foreach (@keys) {
|
|
|
|
# Skip things which are REMOTE_MESSAGE
|
|
|
|
next if $calls{$_}->{msg};
|
|
|
|
|
|
|
|
print "static int ${structprefix}Dispatch$calls{$_}->{ProcName}(\n";
|
|
|
|
print " struct qemud_server *server,\n";
|
|
|
|
print " struct qemud_client *client,\n";
|
|
|
|
print " virConnectPtr conn,\n";
|
|
|
|
print " remote_message_header *hdr,\n";
|
|
|
|
print " remote_error *rerr,\n";
|
|
|
|
print " $calls{$_}->{args} *args,\n";
|
|
|
|
print " $calls{$_}->{ret} *ret);\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Union of all arg types
|
|
|
|
# ("remote_dispatch_args.h").
|
|
|
|
elsif ($opt_a) {
|
|
|
|
for ($id = 0 ; $id <= $#calls ; $id++) {
|
|
|
|
if (defined $calls[$id] &&
|
|
|
|
!$calls[$id]->{msg} &&
|
|
|
|
$calls[$id]->{args} ne "void") {
|
|
|
|
print " $calls[$id]->{args} val_$calls[$id]->{args};\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Union of all arg types
|
|
|
|
# ("remote_dispatch_ret.h").
|
|
|
|
elsif ($opt_r) {
|
|
|
|
for ($id = 0 ; $id <= $#calls ; $id++) {
|
|
|
|
if (defined $calls[$id] &&
|
|
|
|
!$calls[$id]->{msg} &&
|
|
|
|
$calls[$id]->{ret} ne "void") {
|
|
|
|
print " $calls[$id]->{ret} val_$calls[$id]->{ret};\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Inside the switch statement, prepare the 'fn', 'args_filter', etc
|
|
|
|
# ("remote_dispatch_table.h").
|
|
|
|
elsif ($opt_t) {
|
|
|
|
for ($id = 0 ; $id <= $#calls ; $id++) {
|
|
|
|
if (defined $calls[$id] && !$calls[$id]->{msg}) {
|
|
|
|
print "{ /* $calls[$id]->{ProcName} => $id */\n";
|
|
|
|
print " .fn = (dispatch_fn) ${structprefix}Dispatch$calls[$id]->{ProcName},\n";
|
|
|
|
if ($calls[$id]->{args} ne "void") {
|
|
|
|
print " .args_filter = (xdrproc_t) xdr_$calls[$id]->{args},\n";
|
|
|
|
} else {
|
|
|
|
print " .args_filter = (xdrproc_t) xdr_void,\n";
|
|
|
|
}
|
|
|
|
if ($calls[$id]->{ret} ne "void") {
|
|
|
|
print " .ret_filter = (xdrproc_t) xdr_$calls[$id]->{ret},\n";
|
|
|
|
} else {
|
|
|
|
print " .ret_filter = (xdrproc_t) xdr_void,\n";
|
|
|
|
}
|
|
|
|
print "},\n";
|
|
|
|
} else {
|
|
|
|
if ($calls[$id]->{msg}) {
|
|
|
|
print "{ /* Async event $calls[$id]->{ProcName} => $id */\n";
|
|
|
|
} else {
|
|
|
|
print "{ /* (unused) => $id */\n";
|
|
|
|
}
|
|
|
|
print " .fn = NULL,\n";
|
|
|
|
print " .args_filter = (xdrproc_t) xdr_void,\n";
|
|
|
|
print " .ret_filter = (xdrproc_t) xdr_void,\n";
|
|
|
|
print "},\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-04-22 18:35:34 +00:00
|
|
|
|
2011-05-06 19:54:32 +00:00
|
|
|
# Bodies for dispatch functions ("remote_dispatch_bodies.h").
|
2011-04-22 18:35:34 +00:00
|
|
|
elsif ($opt_b) {
|
2011-05-11 19:28:39 +00:00
|
|
|
my %generate = map { $_ => 1 } @autogen;
|
2011-04-22 18:35:34 +00:00
|
|
|
my @keys = sort (keys %calls);
|
|
|
|
|
|
|
|
foreach (@keys) {
|
2011-05-15 06:14:35 +00:00
|
|
|
my $call = $calls{$_};
|
|
|
|
|
2011-04-22 18:35:34 +00:00
|
|
|
# skip things which are REMOTE_MESSAGE
|
2011-05-15 06:14:35 +00:00
|
|
|
next if $call->{msg};
|
2011-04-22 18:35:34 +00:00
|
|
|
|
2011-05-11 19:28:39 +00:00
|
|
|
# skip procedures not on generate list
|
2011-05-15 06:14:35 +00:00
|
|
|
next if ! exists($generate{$call->{ProcName}});
|
2011-04-22 18:35:34 +00:00
|
|
|
|
|
|
|
my $has_node_device = 0;
|
|
|
|
my @vars_list = ();
|
2011-04-22 18:31:05 +00:00
|
|
|
my @optionals_list = ();
|
2011-04-22 18:35:34 +00:00
|
|
|
my @getters_list = ();
|
|
|
|
my @args_list = ();
|
2011-04-22 15:09:33 +00:00
|
|
|
my @ret_list = ();
|
2011-04-22 18:35:34 +00:00
|
|
|
my @free_list = ();
|
2011-04-23 06:35:03 +00:00
|
|
|
my @free_list_on_error = ("remoteDispatchError(rerr);");
|
2011-04-22 18:35:34 +00:00
|
|
|
|
2011-04-23 07:40:14 +00:00
|
|
|
# handle arguments to the function
|
2011-05-15 06:14:35 +00:00
|
|
|
if ($call->{args} ne "void") {
|
2011-04-22 18:35:34 +00:00
|
|
|
# node device is special, as it's identified by name
|
2011-05-15 06:14:35 +00:00
|
|
|
if ($call->{args} =~ m/^remote_node_device_/ and
|
|
|
|
!($call->{args} =~ m/^remote_node_device_lookup_by_name_/) and
|
|
|
|
!($call->{args} =~ m/^remote_node_device_create_xml_/)) {
|
2011-04-22 18:35:34 +00:00
|
|
|
$has_node_device = 1;
|
|
|
|
push(@vars_list, "virNodeDevicePtr dev = NULL");
|
|
|
|
push(@getters_list,
|
|
|
|
" if (!(dev = virNodeDeviceLookupByName(conn, args->name)))\n" .
|
|
|
|
" goto cleanup;\n");
|
|
|
|
push(@args_list, "dev");
|
|
|
|
push(@free_list,
|
|
|
|
" if (dev)\n" .
|
|
|
|
" virNodeDeviceFree(dev);");
|
|
|
|
}
|
|
|
|
|
2011-05-15 06:14:35 +00:00
|
|
|
foreach my $args_member (@{$call->{args_members}}) {
|
2011-04-22 18:35:34 +00:00
|
|
|
if ($args_member =~ m/^remote_nonnull_string name;/ and $has_node_device) {
|
|
|
|
# ignore the name arg for node devices
|
|
|
|
next
|
2011-04-22 22:19:14 +00:00
|
|
|
} elsif ($args_member =~ m/^remote_nonnull_(domain|network|storage_pool|storage_vol|interface|secret|nwfilter) (\S+);/) {
|
|
|
|
my $type_name = name_to_ProcName($1);
|
|
|
|
|
|
|
|
push(@vars_list, "vir${type_name}Ptr $2 = NULL");
|
2011-04-22 18:35:34 +00:00
|
|
|
push(@getters_list,
|
2011-04-22 22:19:14 +00:00
|
|
|
" if (!($2 = get_nonnull_$1(conn, args->$2)))\n" .
|
2011-04-22 18:35:34 +00:00
|
|
|
" goto cleanup;\n");
|
2011-04-22 22:19:14 +00:00
|
|
|
push(@args_list, "$2");
|
2011-04-22 18:35:34 +00:00
|
|
|
push(@free_list,
|
2011-04-22 22:19:14 +00:00
|
|
|
" if ($2)\n" .
|
|
|
|
" vir${type_name}Free($2);");
|
2011-04-22 18:35:34 +00:00
|
|
|
} elsif ($args_member =~ m/^remote_nonnull_domain_snapshot /) {
|
|
|
|
push(@vars_list, "virDomainPtr dom = NULL");
|
|
|
|
push(@vars_list, "virDomainSnapshotPtr snapshot = NULL");
|
|
|
|
push(@getters_list,
|
2011-04-22 13:40:31 +00:00
|
|
|
" if (!(dom = get_nonnull_domain(conn, args->snap.dom)))\n" .
|
2011-04-22 18:35:34 +00:00
|
|
|
" goto cleanup;\n" .
|
|
|
|
"\n" .
|
|
|
|
" if (!(snapshot = get_nonnull_domain_snapshot(dom, args->snap)))\n" .
|
|
|
|
" goto cleanup;\n");
|
|
|
|
push(@args_list, "snapshot");
|
|
|
|
push(@free_list,
|
|
|
|
" if (snapshot)\n" .
|
|
|
|
" virDomainSnapshotFree(snapshot);\n" .
|
|
|
|
" if (dom)\n" .
|
|
|
|
" virDomainFree(dom);");
|
2011-05-07 06:15:51 +00:00
|
|
|
} elsif ($args_member =~ m/^(remote_string|remote_nonnull_string|remote_uuid|opaque) (\S+)<\S+>;/) {
|
2011-04-22 18:35:34 +00:00
|
|
|
if (! @args_list) {
|
|
|
|
push(@args_list, "conn");
|
|
|
|
}
|
|
|
|
|
2011-05-15 06:14:35 +00:00
|
|
|
if ($call->{ProcName} eq "SecretSetValue") {
|
2011-05-07 06:15:51 +00:00
|
|
|
push(@args_list, "(const unsigned char *)args->$2.$2_val");
|
2011-05-15 06:14:35 +00:00
|
|
|
} elsif ($call->{ProcName} eq "CPUBaseline") {
|
2011-05-07 06:15:51 +00:00
|
|
|
push(@args_list, "(const char **)args->$2.$2_val");
|
2011-04-22 18:35:34 +00:00
|
|
|
} else {
|
2011-05-07 06:15:51 +00:00
|
|
|
push(@args_list, "args->$2.$2_val");
|
2011-04-22 18:35:34 +00:00
|
|
|
}
|
|
|
|
|
2011-05-07 06:15:51 +00:00
|
|
|
push(@args_list, "args->$2.$2_len");
|
2011-05-30 18:27:37 +00:00
|
|
|
} elsif ($args_member =~ m/^remote_typed_param (\S+)<(\S+)>;/) {
|
|
|
|
push(@vars_list, "virTypedParameterPtr $1 = NULL");
|
|
|
|
push(@vars_list, "int n$1");
|
|
|
|
push(@args_list, "$1");
|
|
|
|
push(@args_list, "n$1");
|
|
|
|
push(@getters_list, " if (($1 = remoteDeserializeTypedParameters(args->$1.$1_val,\n" .
|
|
|
|
" args->$1.$1_len,\n" .
|
|
|
|
" $2,\n" .
|
|
|
|
" &n$1)) == NULL)\n" .
|
|
|
|
" goto cleanup;\n");
|
|
|
|
push(@free_list, " VIR_FREE(params);");
|
2011-05-07 06:15:51 +00:00
|
|
|
} elsif ($args_member =~ m/<\S+>;/ or $args_member =~ m/\[\S+\];/) {
|
|
|
|
# just make all other array types fail
|
|
|
|
die "unhandled type for argument value: $args_member";
|
|
|
|
} elsif ($args_member =~ m/^remote_uuid (\S+);/) {
|
2011-04-22 18:35:34 +00:00
|
|
|
if (! @args_list) {
|
|
|
|
push(@args_list, "conn");
|
|
|
|
}
|
|
|
|
|
2011-05-07 06:15:51 +00:00
|
|
|
push(@args_list, "(unsigned char *) args->$1");
|
|
|
|
} elsif ($args_member =~ m/^remote_string (\S+);/) {
|
|
|
|
if (! @args_list) {
|
|
|
|
push(@args_list, "conn");
|
2011-04-22 16:54:51 +00:00
|
|
|
}
|
2011-05-07 06:15:51 +00:00
|
|
|
|
|
|
|
push(@vars_list, "char *$1");
|
|
|
|
push(@optionals_list, "$1");
|
|
|
|
push(@args_list, "$1");
|
|
|
|
} elsif ($args_member =~ m/^remote_nonnull_string (\S+);/) {
|
|
|
|
if (! @args_list) {
|
|
|
|
push(@args_list, "conn");
|
|
|
|
}
|
|
|
|
|
|
|
|
push(@args_list, "args->$1");
|
2011-05-30 10:58:57 +00:00
|
|
|
} elsif ($args_member =~ m/^(unsigned )?int (\S+);/) {
|
2011-05-07 06:15:51 +00:00
|
|
|
if (! @args_list) {
|
|
|
|
push(@args_list, "conn");
|
|
|
|
}
|
|
|
|
|
2011-05-30 10:58:57 +00:00
|
|
|
push(@args_list, "args->$2");
|
|
|
|
} elsif ($args_member =~ m/^(unsigned )?hyper (\S+);/) {
|
|
|
|
if (! @args_list) {
|
|
|
|
push(@args_list, "conn");
|
|
|
|
}
|
|
|
|
|
|
|
|
my $arg_name = $2;
|
|
|
|
|
|
|
|
if (hyper_to_long($call->{ProcName}, "arg", $arg_name)) {
|
|
|
|
my $type_name = $1; $type_name .= "long";
|
|
|
|
my $sign = ""; $sign = "U" if ($1);
|
|
|
|
|
|
|
|
push(@vars_list, "$type_name $arg_name");
|
|
|
|
push(@getters_list, " HYPER_TO_${sign}LONG($arg_name, args->$arg_name);\n");
|
|
|
|
push(@args_list, "$arg_name");
|
|
|
|
} else {
|
|
|
|
push(@args_list, "args->$arg_name");
|
|
|
|
}
|
2011-05-07 05:36:21 +00:00
|
|
|
} elsif ($args_member =~ m/^(\/)?\*/) {
|
2011-04-23 07:36:33 +00:00
|
|
|
# ignore comments
|
|
|
|
} else {
|
|
|
|
die "unhandled type for argument value: $args_member";
|
2011-04-22 18:35:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-23 07:40:14 +00:00
|
|
|
# handle return values of the function
|
2011-04-22 15:09:33 +00:00
|
|
|
my $single_ret_var = "undefined";
|
|
|
|
my $single_ret_by_ref = 0;
|
|
|
|
my $single_ret_check = " == undefined";
|
2011-04-22 20:48:25 +00:00
|
|
|
my $single_ret_as_list = 0;
|
|
|
|
my $single_ret_list_name = "undefined";
|
|
|
|
my $single_ret_list_max_var = "undefined";
|
|
|
|
my $single_ret_list_max_define = "undefined";
|
2011-04-23 07:36:33 +00:00
|
|
|
my $multi_ret = 0;
|
|
|
|
|
2011-05-15 06:14:35 +00:00
|
|
|
if ($call->{ret} ne "void" and
|
|
|
|
scalar(@{$call->{ret_members}}) > 1) {
|
2011-04-23 07:36:33 +00:00
|
|
|
$multi_ret = 1;
|
|
|
|
}
|
2011-04-22 15:09:33 +00:00
|
|
|
|
2011-05-15 06:14:35 +00:00
|
|
|
if ($call->{ret} ne "void") {
|
|
|
|
foreach my $ret_member (@{$call->{ret_members}}) {
|
2011-04-23 07:36:33 +00:00
|
|
|
if ($multi_ret) {
|
2011-05-07 06:15:51 +00:00
|
|
|
if ($ret_member =~ m/^(unsigned )?(char|short|int|hyper) (\S+)\[\S+\];/) {
|
2011-05-30 10:58:57 +00:00
|
|
|
if ($2 eq "hyper" and hyper_to_long($call->{ProcName}, "ret", $3)) {
|
|
|
|
die "legacy [u]long hyper arrays aren't supported";
|
|
|
|
}
|
|
|
|
|
2011-05-07 06:15:51 +00:00
|
|
|
push(@ret_list, "memcpy(ret->$3, tmp.$3, sizeof ret->$3);");
|
|
|
|
} elsif ($ret_member =~ m/^(unsigned )?(char|short|int|hyper) (\S+);/) {
|
|
|
|
push(@ret_list, "ret->$3 = tmp.$3;");
|
2011-04-23 07:36:33 +00:00
|
|
|
} else {
|
|
|
|
die "unhandled type for multi-return-value: $ret_member";
|
|
|
|
}
|
2011-05-21 09:16:07 +00:00
|
|
|
} elsif ($ret_member =~ m/^remote_nonnull_string (\S+)<(\S+)>;\s*\/\*\s*insert@(\d+)\s*\*\//) {
|
2011-04-22 20:48:25 +00:00
|
|
|
push(@vars_list, "int len");
|
2011-05-21 09:16:07 +00:00
|
|
|
splice(@args_list, int($3), 0, ("ret->$1.$1_val"));
|
2011-04-22 20:48:25 +00:00
|
|
|
push(@ret_list, "ret->$1.$1_len = len;");
|
2011-04-23 06:35:03 +00:00
|
|
|
push(@free_list_on_error, "VIR_FREE(ret->$1.$1_val);");
|
2011-04-22 20:48:25 +00:00
|
|
|
$single_ret_var = "len";
|
|
|
|
$single_ret_by_ref = 0;
|
|
|
|
$single_ret_check = " < 0";
|
|
|
|
$single_ret_as_list = 1;
|
|
|
|
$single_ret_list_name = $1;
|
|
|
|
$single_ret_list_max_var = "max$1";
|
|
|
|
$single_ret_list_max_define = $2;
|
2011-05-21 09:16:07 +00:00
|
|
|
} elsif ($ret_member =~ m/^remote_nonnull_string (\S+)<\S+>;/) {
|
|
|
|
# error out on unannotated arrays
|
|
|
|
die "remote_nonnull_string array without insert@<offset> annotation: $ret_member";
|
2011-05-07 06:15:51 +00:00
|
|
|
} elsif ($ret_member =~ m/^remote_nonnull_string (\S+);/) {
|
2011-05-16 18:10:06 +00:00
|
|
|
if ($call->{ProcName} eq "GetType") {
|
|
|
|
# SPECIAL: virConnectGetType returns a constant string that must
|
|
|
|
# not be freed. Therefore, duplicate the string here.
|
|
|
|
push(@vars_list, "const char *$1");
|
|
|
|
push(@ret_list, "/* We have to strdup because remoteDispatchClientRequest will");
|
|
|
|
push(@ret_list, " * free this string after it's been serialised. */");
|
|
|
|
push(@ret_list, "if (!(ret->type = strdup(type))) {");
|
|
|
|
push(@ret_list, " virReportOOMError();");
|
|
|
|
push(@ret_list, " goto cleanup;");
|
|
|
|
push(@ret_list, "}");
|
|
|
|
} else {
|
|
|
|
push(@vars_list, "char *$1");
|
|
|
|
push(@ret_list, "ret->$1 = $1;");
|
|
|
|
}
|
|
|
|
|
2011-04-22 15:09:33 +00:00
|
|
|
$single_ret_var = $1;
|
|
|
|
$single_ret_by_ref = 0;
|
|
|
|
$single_ret_check = " == NULL";
|
2011-05-07 06:15:51 +00:00
|
|
|
} elsif ($ret_member =~ m/^remote_nonnull_(domain|network|storage_pool|storage_vol|interface|node_device|secret|nwfilter|domain_snapshot) (\S+);/) {
|
2011-04-22 22:19:14 +00:00
|
|
|
my $type_name = name_to_ProcName($1);
|
|
|
|
|
2011-05-20 15:58:34 +00:00
|
|
|
if ($call->{ProcName} eq "DomainCreateWithFlags") {
|
|
|
|
# SPECIAL: virDomainCreateWithFlags updates the given
|
|
|
|
# domain object instead of returning a new one
|
|
|
|
push(@ret_list, "make_nonnull_$1(&ret->$2, $2);");
|
|
|
|
$single_ret_var = undef;
|
|
|
|
$single_ret_by_ref = 1;
|
|
|
|
} else {
|
|
|
|
push(@vars_list, "vir${type_name}Ptr $2 = NULL");
|
|
|
|
push(@ret_list, "make_nonnull_$1(&ret->$2, $2);");
|
|
|
|
push(@free_list,
|
|
|
|
" if ($2)\n" .
|
|
|
|
" vir${type_name}Free($2);");
|
|
|
|
$single_ret_var = $2;
|
|
|
|
$single_ret_by_ref = 0;
|
|
|
|
$single_ret_check = " == NULL";
|
|
|
|
}
|
2011-05-21 09:16:07 +00:00
|
|
|
} elsif ($ret_member =~ m/^int (\S+)<(\S+)>;\s*\/\*\s*insert@(\d+)\s*\*\//) {
|
2011-04-22 20:48:25 +00:00
|
|
|
push(@vars_list, "int len");
|
2011-05-21 09:16:07 +00:00
|
|
|
splice(@args_list, int($3), 0, ("ret->$1.$1_val"));
|
2011-04-22 20:48:25 +00:00
|
|
|
push(@ret_list, "ret->$1.$1_len = len;");
|
2011-04-23 06:35:03 +00:00
|
|
|
push(@free_list_on_error, "VIR_FREE(ret->$1.$1_val);");
|
2011-04-22 20:48:25 +00:00
|
|
|
$single_ret_var = "len";
|
|
|
|
$single_ret_by_ref = 0;
|
|
|
|
$single_ret_check = " < 0";
|
|
|
|
$single_ret_as_list = 1;
|
|
|
|
$single_ret_list_name = $1;
|
|
|
|
$single_ret_list_max_var = "max$1";
|
|
|
|
$single_ret_list_max_define = $2;
|
2011-05-21 09:16:07 +00:00
|
|
|
} elsif ($ret_member =~ m/^int (\S+)<\S+>;/) {
|
|
|
|
# error out on unannotated arrays
|
|
|
|
die "int array without insert@<offset> annotation: $ret_member";
|
2011-05-07 06:15:51 +00:00
|
|
|
} elsif ($ret_member =~ m/^int (\S+);/) {
|
2011-04-22 15:09:33 +00:00
|
|
|
push(@vars_list, "int $1");
|
|
|
|
push(@ret_list, "ret->$1 = $1;");
|
|
|
|
$single_ret_var = $1;
|
|
|
|
|
2011-05-15 06:14:35 +00:00
|
|
|
if ($call->{ProcName} =~ m/GetAutostart$/) {
|
2011-04-22 15:09:33 +00:00
|
|
|
$single_ret_by_ref = 1;
|
|
|
|
} else {
|
|
|
|
$single_ret_by_ref = 0;
|
2011-04-23 06:19:46 +00:00
|
|
|
|
2011-05-15 06:14:35 +00:00
|
|
|
if ($call->{ProcName} eq "CPUCompare") {
|
2011-04-23 06:19:46 +00:00
|
|
|
$single_ret_check = " == VIR_CPU_COMPARE_ERROR";
|
|
|
|
} else {
|
|
|
|
$single_ret_check = " < 0";
|
|
|
|
}
|
2011-04-22 15:09:33 +00:00
|
|
|
}
|
2011-05-21 10:24:40 +00:00
|
|
|
} elsif ($ret_member =~ m/^(?:unsigned )?hyper (\S+)<(\S+)>;\s*\/\*\s*insert@(\d+)\s*\*\//) {
|
2011-05-30 10:58:57 +00:00
|
|
|
if (hyper_to_long($call->{ProcName}, "ret", $1)) {
|
|
|
|
die "legacy [u]long hyper arrays aren't supported";
|
|
|
|
}
|
|
|
|
|
2011-04-22 20:48:25 +00:00
|
|
|
push(@vars_list, "int len");
|
|
|
|
push(@ret_list, "ret->$1.$1_len = len;");
|
2011-04-23 06:35:03 +00:00
|
|
|
push(@free_list_on_error, "VIR_FREE(ret->$1.$1_val);");
|
2011-04-22 20:48:25 +00:00
|
|
|
$single_ret_var = "len";
|
|
|
|
$single_ret_by_ref = 0;
|
|
|
|
$single_ret_as_list = 1;
|
|
|
|
$single_ret_list_name = $1;
|
2011-05-21 07:52:19 +00:00
|
|
|
$single_ret_list_max_var = "max$1";
|
2011-04-22 20:48:25 +00:00
|
|
|
$single_ret_list_max_define = $2;
|
|
|
|
|
2011-05-15 06:14:35 +00:00
|
|
|
if ($call->{ProcName} eq "NodeGetCellsFreeMemory") {
|
2011-04-22 20:48:25 +00:00
|
|
|
$single_ret_check = " <= 0";
|
2011-05-21 09:16:07 +00:00
|
|
|
splice(@args_list, int($3), 0, ("(unsigned long long *)ret->$1.$1_val"));
|
2011-04-22 20:48:25 +00:00
|
|
|
} else {
|
|
|
|
$single_ret_check = " < 0";
|
2011-05-21 09:16:07 +00:00
|
|
|
splice(@args_list, int($3), 0, ("ret->$1.$1_val"));
|
2011-04-22 20:48:25 +00:00
|
|
|
}
|
2011-05-21 10:24:40 +00:00
|
|
|
} elsif ($ret_member =~ m/^(?:unsigned )?hyper (\S+)<\S+>;/) {
|
2011-05-21 09:16:07 +00:00
|
|
|
# error out on unannotated arrays
|
|
|
|
die "hyper array without insert@<offset> annotation: $ret_member";
|
2011-05-07 06:15:51 +00:00
|
|
|
} elsif ($ret_member =~ m/^(unsigned )?hyper (\S+);/) {
|
2011-05-30 10:58:57 +00:00
|
|
|
my $type_name = $1;
|
2011-05-07 06:15:51 +00:00
|
|
|
my $ret_name = $2;
|
2011-05-30 10:58:57 +00:00
|
|
|
my $ret_assign;
|
2011-05-07 06:15:51 +00:00
|
|
|
|
2011-05-30 10:58:57 +00:00
|
|
|
if (hyper_to_long($call->{ProcName}, "ret", $ret_name)) {
|
|
|
|
my $sign = ""; $sign = "U" if ($1);
|
|
|
|
|
|
|
|
$type_name .= "long";
|
|
|
|
$ret_assign = "HYPER_TO_${sign}LONG(ret->$ret_name, $ret_name);";
|
|
|
|
} else {
|
|
|
|
$type_name .= "long long";
|
|
|
|
$ret_assign = "ret->$ret_name = $ret_name;";
|
|
|
|
}
|
2011-05-07 06:15:51 +00:00
|
|
|
|
|
|
|
push(@vars_list, "$type_name $ret_name");
|
2011-05-30 10:58:57 +00:00
|
|
|
push(@ret_list, $ret_assign);
|
2011-05-07 06:15:51 +00:00
|
|
|
$single_ret_var = $ret_name;
|
2011-04-22 15:09:33 +00:00
|
|
|
|
2011-05-15 06:14:35 +00:00
|
|
|
if ($call->{ProcName} eq "DomainGetMaxMemory" or
|
|
|
|
$call->{ProcName} eq "NodeGetFreeMemory") {
|
2011-05-07 06:15:51 +00:00
|
|
|
# SPECIAL: virDomainGetMaxMemory and virNodeGetFreeMemory
|
|
|
|
# return the actual value directly and 0 indicates
|
|
|
|
# an error
|
2011-04-22 15:09:33 +00:00
|
|
|
$single_ret_by_ref = 0;
|
|
|
|
$single_ret_check = " == 0";
|
|
|
|
} else {
|
|
|
|
$single_ret_by_ref = 1;
|
|
|
|
}
|
2011-05-21 09:24:28 +00:00
|
|
|
} elsif ($ret_member =~ m/^opaque (\S+)<(\S+)>;\s*\/\*\s*insert@(\d+)\s*\*\//) {
|
|
|
|
push(@vars_list, "char *$1 = NULL");
|
|
|
|
push(@vars_list, "int $1_len = 0");
|
|
|
|
splice(@args_list, int($3), 0, ("&$1", "&$1_len"));
|
|
|
|
push(@ret_list, "ret->$1.$1_val = $1;");
|
|
|
|
push(@ret_list, "ret->$1.$1_len = $1_len;");
|
|
|
|
push(@free_list_on_error, "VIR_FREE($1);");
|
|
|
|
$single_ret_var = undef;
|
|
|
|
$single_ret_by_ref = 1;
|
|
|
|
} elsif ($ret_member =~ m/^opaque (\S+)<\S+>;/) {
|
|
|
|
# error out on unannotated arrays
|
|
|
|
die "opaque array without insert@<offset> annotation: $ret_member";
|
2011-05-11 19:28:39 +00:00
|
|
|
} elsif ($ret_member =~ m/^(\/)?\*/) {
|
|
|
|
# ignore comments
|
2011-04-23 07:36:33 +00:00
|
|
|
} else {
|
|
|
|
die "unhandled type for return value: $ret_member";
|
2011-04-22 15:09:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-23 07:40:14 +00:00
|
|
|
# select struct type for multi-return-value functions
|
2011-04-23 07:36:33 +00:00
|
|
|
if ($multi_ret) {
|
|
|
|
if (! @args_list) {
|
|
|
|
push(@args_list, "conn");
|
|
|
|
}
|
|
|
|
|
2011-05-15 06:14:35 +00:00
|
|
|
my $struct_name = $call->{ProcName};
|
2011-04-23 07:36:33 +00:00
|
|
|
$struct_name =~ s/Get//;
|
|
|
|
|
2011-05-15 06:14:35 +00:00
|
|
|
if ($call->{ProcName} eq "DomainGetBlockInfo") {
|
2011-05-07 06:15:51 +00:00
|
|
|
# SPECIAL: virDomainGetBlockInfo has flags parameter after
|
|
|
|
# the struct parameter in its signature
|
2011-04-23 07:36:33 +00:00
|
|
|
my $flags = pop(@args_list);
|
|
|
|
push(@args_list, "&tmp");
|
|
|
|
push(@args_list, $flags);
|
2011-05-15 06:14:35 +00:00
|
|
|
} elsif ($call->{ProcName} eq "DomainBlockStats" ||
|
|
|
|
$call->{ProcName} eq "DomainInterfaceStats") {
|
2011-05-07 06:15:51 +00:00
|
|
|
# SPECIAL: virDomainBlockStats and virDomainInterfaceStats
|
|
|
|
# have a 'Struct' suffix on the actual struct name
|
|
|
|
# and take the struct size as additional argument
|
2011-04-23 07:36:33 +00:00
|
|
|
$struct_name .= "Struct";
|
|
|
|
push(@args_list, "&tmp");
|
|
|
|
push(@args_list, "sizeof tmp");
|
|
|
|
} else {
|
|
|
|
push(@args_list, "&tmp");
|
|
|
|
}
|
|
|
|
|
|
|
|
push(@vars_list, "vir$struct_name tmp");
|
|
|
|
}
|
|
|
|
|
2011-05-21 09:24:28 +00:00
|
|
|
if ($call->{streamflag} ne "none") {
|
|
|
|
splice(@args_list, $call->{streamoffset}, 0, ("stream->st"));
|
|
|
|
push(@free_list_on_error, "if (stream) {");
|
|
|
|
push(@free_list_on_error, " virStreamAbort(stream->st);");
|
|
|
|
push(@free_list_on_error, " remoteFreeClientStream(client, stream);");
|
|
|
|
push(@free_list_on_error, "}");
|
|
|
|
}
|
|
|
|
|
2011-04-23 07:40:14 +00:00
|
|
|
# print functions signature
|
|
|
|
print "\n";
|
|
|
|
print "static int\n";
|
2011-05-15 06:14:35 +00:00
|
|
|
print "${structprefix}Dispatch$call->{ProcName}(\n";
|
2011-04-23 07:40:14 +00:00
|
|
|
print " struct qemud_server *server ATTRIBUTE_UNUSED,\n";
|
|
|
|
print " struct qemud_client *client ATTRIBUTE_UNUSED,\n";
|
|
|
|
print " virConnectPtr conn,\n";
|
|
|
|
print " remote_message_header *hdr ATTRIBUTE_UNUSED,\n";
|
|
|
|
print " remote_error *rerr,\n";
|
2011-05-15 06:14:35 +00:00
|
|
|
print " $call->{args} *args";
|
2011-04-23 07:40:14 +00:00
|
|
|
|
2011-05-15 06:14:35 +00:00
|
|
|
if ($call->{args} eq "void") {
|
2011-04-23 07:40:14 +00:00
|
|
|
print " ATTRIBUTE_UNUSED"
|
|
|
|
}
|
|
|
|
|
|
|
|
print ",\n";
|
2011-05-15 06:14:35 +00:00
|
|
|
print " $call->{ret} *ret";
|
2011-04-23 07:40:14 +00:00
|
|
|
|
2011-05-15 06:14:35 +00:00
|
|
|
if ($call->{ret} eq "void") {
|
2011-04-23 07:40:14 +00:00
|
|
|
print " ATTRIBUTE_UNUSED"
|
|
|
|
}
|
|
|
|
|
|
|
|
print ")\n";
|
|
|
|
|
|
|
|
# print function body
|
|
|
|
print "{\n";
|
|
|
|
print " int rv = -1;\n";
|
|
|
|
|
2011-04-22 18:35:34 +00:00
|
|
|
foreach my $var (@vars_list) {
|
|
|
|
print " $var;\n";
|
|
|
|
}
|
|
|
|
|
2011-05-21 09:24:28 +00:00
|
|
|
if ($call->{streamflag} ne "none") {
|
|
|
|
print " struct qemud_client_stream *stream = NULL;\n";
|
|
|
|
}
|
|
|
|
|
2011-04-22 18:35:34 +00:00
|
|
|
print "\n";
|
|
|
|
print " if (!conn) {\n";
|
|
|
|
print " virNetError(VIR_ERR_INTERNAL_ERROR, \"%s\", _(\"connection not open\"));\n";
|
|
|
|
print " goto cleanup;\n";
|
|
|
|
print " }\n";
|
|
|
|
print "\n";
|
|
|
|
|
2011-04-22 20:48:25 +00:00
|
|
|
if ($single_ret_as_list) {
|
|
|
|
print " if (args->$single_ret_list_max_var > $single_ret_list_max_define) {\n";
|
|
|
|
print " virNetError(VIR_ERR_INTERNAL_ERROR,\n";
|
|
|
|
print " \"%s\", _(\"max$single_ret_list_name > $single_ret_list_max_define\"));\n";
|
|
|
|
print " goto cleanup;\n";
|
|
|
|
print " }\n";
|
|
|
|
print "\n";
|
|
|
|
}
|
|
|
|
|
2011-04-22 18:35:34 +00:00
|
|
|
print join("\n", @getters_list);
|
|
|
|
|
2011-04-22 15:09:33 +00:00
|
|
|
if (@getters_list) {
|
|
|
|
print "\n";
|
|
|
|
}
|
2011-04-22 18:35:34 +00:00
|
|
|
|
2011-04-22 18:31:05 +00:00
|
|
|
foreach my $optional (@optionals_list) {
|
|
|
|
print " $optional = args->$optional ? *args->$optional : NULL;\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (@optionals_list) {
|
|
|
|
print "\n";
|
|
|
|
}
|
|
|
|
|
2011-05-21 09:24:28 +00:00
|
|
|
if ($call->{streamflag} ne "none") {
|
|
|
|
print " if (!(stream = remoteCreateClientStream(conn, hdr)))\n";
|
|
|
|
print " goto cleanup;\n";
|
|
|
|
print "\n";
|
|
|
|
}
|
|
|
|
|
2011-05-15 06:14:35 +00:00
|
|
|
if ($call->{ret} eq "void") {
|
|
|
|
print " if (vir$call->{ProcName}(";
|
2011-04-22 18:35:34 +00:00
|
|
|
print join(', ', @args_list);
|
|
|
|
print ") < 0)\n";
|
|
|
|
print " goto cleanup;\n";
|
|
|
|
print "\n";
|
2011-04-23 07:36:33 +00:00
|
|
|
} elsif (!$multi_ret) {
|
2011-04-22 15:09:33 +00:00
|
|
|
my $prefix = "";
|
2011-05-15 06:14:35 +00:00
|
|
|
my $proc_name = $call->{ProcName};
|
2011-04-22 15:09:33 +00:00
|
|
|
|
|
|
|
if (! @args_list) {
|
|
|
|
push(@args_list, "conn");
|
2011-04-22 16:54:51 +00:00
|
|
|
|
2011-05-15 06:14:35 +00:00
|
|
|
if ($call->{ProcName} ne "NodeGetFreeMemory") {
|
2011-04-22 16:54:51 +00:00
|
|
|
$prefix = "Connect"
|
|
|
|
}
|
2011-04-22 15:09:33 +00:00
|
|
|
}
|
|
|
|
|
2011-05-15 06:14:35 +00:00
|
|
|
if ($call->{ProcName} eq "GetSysinfo" or
|
|
|
|
$call->{ProcName} eq "GetMaxVcpus" or
|
|
|
|
$call->{ProcName} eq "DomainXMLFromNative" or
|
|
|
|
$call->{ProcName} eq "DomainXMLToNative" or
|
|
|
|
$call->{ProcName} eq "FindStoragePoolSources" or
|
|
|
|
$call->{ProcName} =~ m/^List/) {
|
2011-04-22 15:09:33 +00:00
|
|
|
$prefix = "Connect"
|
2011-05-15 06:14:35 +00:00
|
|
|
} elsif ($call->{ProcName} eq "SupportsFeature") {
|
2011-04-22 15:09:33 +00:00
|
|
|
$prefix = "Drv"
|
2011-05-15 06:14:35 +00:00
|
|
|
} elsif ($call->{ProcName} eq "CPUBaseline") {
|
2011-04-23 06:19:46 +00:00
|
|
|
$proc_name = "ConnectBaselineCPU"
|
2011-05-15 06:14:35 +00:00
|
|
|
} elsif ($call->{ProcName} eq "CPUCompare") {
|
2011-04-23 06:19:46 +00:00
|
|
|
$proc_name = "ConnectCompareCPU"
|
2011-04-22 15:09:33 +00:00
|
|
|
}
|
|
|
|
|
2011-04-22 20:48:25 +00:00
|
|
|
if ($single_ret_as_list) {
|
|
|
|
print " /* Allocate return buffer. */\n";
|
|
|
|
print " if (VIR_ALLOC_N(ret->$single_ret_list_name.${single_ret_list_name}_val," .
|
|
|
|
" args->$single_ret_list_max_var) < 0) {\n";
|
|
|
|
print " virReportOOMError();\n";
|
|
|
|
print " goto cleanup;\n";
|
|
|
|
print " }\n";
|
|
|
|
print "\n";
|
|
|
|
}
|
|
|
|
|
2011-04-22 15:09:33 +00:00
|
|
|
if ($single_ret_by_ref) {
|
|
|
|
print " if (vir$prefix$proc_name(";
|
|
|
|
print join(', ', @args_list);
|
2011-05-20 15:58:34 +00:00
|
|
|
|
|
|
|
if (defined $single_ret_var) {
|
|
|
|
print ", &$single_ret_var";
|
|
|
|
}
|
|
|
|
|
|
|
|
print ") < 0)\n";
|
2011-04-22 15:09:33 +00:00
|
|
|
} else {
|
|
|
|
print " if (($single_ret_var = vir$prefix$proc_name(";
|
|
|
|
print join(', ', @args_list);
|
|
|
|
print "))$single_ret_check)\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
print " goto cleanup;\n";
|
|
|
|
print "\n";
|
2011-04-23 07:36:33 +00:00
|
|
|
} else {
|
2011-05-15 06:14:35 +00:00
|
|
|
print " if (vir$call->{ProcName}(";
|
2011-04-23 07:36:33 +00:00
|
|
|
print join(', ', @args_list);
|
|
|
|
print ") < 0)\n";
|
|
|
|
print " goto cleanup;\n";
|
|
|
|
print "\n";
|
2011-05-21 09:24:28 +00:00
|
|
|
}
|
2011-04-23 07:36:33 +00:00
|
|
|
|
2011-05-21 09:24:28 +00:00
|
|
|
if ($call->{streamflag} ne "none") {
|
|
|
|
print " if (remoteAddClientStream(client, stream, ";
|
|
|
|
|
|
|
|
if ($call->{streamflag} eq "write") {
|
|
|
|
print "0";
|
|
|
|
} else {
|
|
|
|
print "1";
|
2011-04-23 07:36:33 +00:00
|
|
|
}
|
|
|
|
|
2011-05-21 09:24:28 +00:00
|
|
|
print ") < 0)\n";
|
|
|
|
print " goto cleanup;\n";
|
|
|
|
print "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (@ret_list) {
|
|
|
|
print " ";
|
2011-04-23 07:36:33 +00:00
|
|
|
print join("\n ", @ret_list);
|
2011-04-22 15:09:33 +00:00
|
|
|
print "\n";
|
2011-04-22 18:35:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
print " rv = 0;\n";
|
|
|
|
print "\n";
|
|
|
|
print "cleanup:\n";
|
2011-04-23 06:35:03 +00:00
|
|
|
print " if (rv < 0)";
|
|
|
|
|
|
|
|
if (scalar(@free_list_on_error) > 1) {
|
|
|
|
print " {";
|
|
|
|
}
|
|
|
|
|
|
|
|
print "\n ";
|
|
|
|
print join("\n ", @free_list_on_error);
|
|
|
|
print "\n";
|
|
|
|
|
|
|
|
if (scalar(@free_list_on_error) > 1) {
|
|
|
|
print " }\n";
|
|
|
|
}
|
2011-04-22 18:35:34 +00:00
|
|
|
|
|
|
|
print join("\n", @free_list);
|
|
|
|
|
2011-04-22 15:09:33 +00:00
|
|
|
if (@free_list) {
|
|
|
|
print "\n";
|
|
|
|
}
|
|
|
|
|
2011-04-22 18:35:34 +00:00
|
|
|
print " return rv;\n";
|
|
|
|
print "}\n";
|
|
|
|
}
|
|
|
|
}
|
2011-04-23 10:53:57 +00:00
|
|
|
|
2011-05-06 19:54:32 +00:00
|
|
|
# Bodies for client functions ("remote_client_bodies.h").
|
2011-04-23 10:53:57 +00:00
|
|
|
elsif ($opt_k) {
|
2011-05-11 19:28:39 +00:00
|
|
|
my %generate = map { $_ => 1 } @autogen;
|
2011-04-23 10:53:57 +00:00
|
|
|
my @keys = sort (keys %calls);
|
|
|
|
|
|
|
|
foreach (@keys) {
|
|
|
|
my $call = $calls{$_};
|
|
|
|
|
|
|
|
# skip things which are REMOTE_MESSAGE
|
|
|
|
next if $call->{msg};
|
|
|
|
|
2011-05-11 19:28:39 +00:00
|
|
|
# skip procedures not on generate list
|
|
|
|
next if ! exists($generate{$call->{ProcName}});
|
2011-04-23 10:53:57 +00:00
|
|
|
|
2011-04-23 19:25:49 +00:00
|
|
|
# handle arguments to the function
|
2011-04-23 10:53:57 +00:00
|
|
|
my @args_list = ();
|
|
|
|
my @vars_list = ();
|
2011-04-24 07:49:42 +00:00
|
|
|
my @args_check_list = ();
|
2011-04-23 10:53:57 +00:00
|
|
|
my @setters_list = ();
|
2011-05-30 18:27:37 +00:00
|
|
|
my @setters_list2 = ();
|
2011-04-23 10:53:57 +00:00
|
|
|
my $priv_src = "conn";
|
|
|
|
my $priv_name = "privateData";
|
2011-04-23 14:33:57 +00:00
|
|
|
my $call_args = "&args";
|
2011-04-23 10:53:57 +00:00
|
|
|
|
|
|
|
if ($call->{args} eq "void") {
|
2011-04-23 14:33:57 +00:00
|
|
|
$call_args = "NULL";
|
2011-04-23 10:53:57 +00:00
|
|
|
} else {
|
|
|
|
push(@vars_list, "$call->{args} args");
|
|
|
|
|
|
|
|
my $is_first_arg = 1;
|
|
|
|
my $has_node_device = 0;
|
|
|
|
|
|
|
|
# node device is special
|
2011-04-23 17:03:14 +00:00
|
|
|
if ($call->{args} =~ m/^remote_node_/ and
|
|
|
|
!($call->{args} =~ m/^remote_node_device_lookup_by_name_/) and
|
|
|
|
!($call->{args} =~ m/^remote_node_device_create_xml_/)) {
|
2011-04-23 10:53:57 +00:00
|
|
|
$has_node_device = 1;
|
2011-04-23 14:33:57 +00:00
|
|
|
$priv_name = "devMonPrivateData";
|
2011-04-23 10:53:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
foreach my $args_member (@{$call->{args_members}}) {
|
|
|
|
if ($args_member =~ m/^remote_nonnull_string name;/ and $has_node_device) {
|
|
|
|
$priv_src = "dev->conn";
|
|
|
|
push(@args_list, "virNodeDevicePtr dev");
|
|
|
|
push(@setters_list, "args.name = dev->name;");
|
|
|
|
} elsif ($args_member =~ m/^remote_nonnull_(domain|network|storage_pool|storage_vol|interface|secret|nwfilter|domain_snapshot) (\S+);/) {
|
|
|
|
my $name = $1;
|
2011-04-23 17:03:14 +00:00
|
|
|
my $arg_name = $2;
|
2011-04-23 10:53:57 +00:00
|
|
|
my $type_name = name_to_ProcName($name);
|
|
|
|
|
|
|
|
if ($is_first_arg) {
|
|
|
|
if ($name eq "domain_snapshot") {
|
2011-04-23 17:03:14 +00:00
|
|
|
$priv_src = "$arg_name->domain->conn";
|
2011-04-23 10:53:57 +00:00
|
|
|
} else {
|
2011-04-23 17:03:14 +00:00
|
|
|
$priv_src = "$arg_name->conn";
|
2011-04-23 10:53:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($name =~ m/^storage_/) {
|
|
|
|
$priv_name = "storagePrivateData";
|
|
|
|
} elsif (!($name =~ m/^domain/)) {
|
|
|
|
$priv_name = "${name}PrivateData";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-23 17:03:14 +00:00
|
|
|
push(@args_list, "vir${type_name}Ptr $arg_name");
|
|
|
|
push(@setters_list, "make_nonnull_$1(&args.$arg_name, $arg_name);");
|
|
|
|
} elsif ($args_member =~ m/^remote_uuid (\S+);/) {
|
|
|
|
push(@args_list, "const unsigned char *$1");
|
|
|
|
push(@setters_list, "memcpy(args.$1, $1, VIR_UUID_BUFLEN);");
|
2011-04-23 14:33:57 +00:00
|
|
|
} elsif ($args_member =~ m/^remote_string (\S+);/) {
|
|
|
|
push(@args_list, "const char *$1");
|
|
|
|
push(@setters_list, "args.$1 = $1 ? (char **)&$1 : NULL;");
|
2011-04-24 07:49:42 +00:00
|
|
|
} elsif ($args_member =~ m/^remote_nonnull_string (\S+)<(\S+)>;/) {
|
|
|
|
push(@args_list, "const char **$1");
|
|
|
|
push(@args_list, "unsigned int ${1}len");
|
|
|
|
push(@setters_list, "args.$1.${1}_val = (char **)$1;");
|
|
|
|
push(@setters_list, "args.$1.${1}_len = ${1}len;");
|
|
|
|
push(@args_check_list, { name => "\"$1\"", arg => "${1}len", limit => $2 });
|
2011-04-23 10:53:57 +00:00
|
|
|
} elsif ($args_member =~ m/^remote_nonnull_string (\S+);/) {
|
|
|
|
push(@args_list, "const char *$1");
|
|
|
|
push(@setters_list, "args.$1 = (char *)$1;");
|
2011-05-07 06:15:51 +00:00
|
|
|
} elsif ($args_member =~ m/^(remote_string|opaque) (\S+)<(\S+)>;/) {
|
|
|
|
my $type_name = $1;
|
|
|
|
my $arg_name = $2;
|
|
|
|
my $limit = $3;
|
|
|
|
|
2011-04-24 07:49:42 +00:00
|
|
|
if ($call->{ProcName} eq "SecretSetValue") {
|
2011-05-07 06:15:51 +00:00
|
|
|
push(@args_list, "const unsigned char *$arg_name");
|
|
|
|
push(@args_list, "size_t ${arg_name}len");
|
2011-04-24 07:49:42 +00:00
|
|
|
} elsif ($call->{ProcName} eq "DomainPinVcpu") {
|
2011-05-07 06:15:51 +00:00
|
|
|
push(@args_list, "unsigned char *$arg_name");
|
|
|
|
push(@args_list, "int ${arg_name}len");
|
2011-04-24 07:49:42 +00:00
|
|
|
} else {
|
2011-05-07 06:15:51 +00:00
|
|
|
push(@args_list, "const char *$arg_name");
|
|
|
|
push(@args_list, "int ${arg_name}len");
|
2011-04-24 07:49:42 +00:00
|
|
|
}
|
|
|
|
|
2011-05-07 06:15:51 +00:00
|
|
|
push(@setters_list, "args.$arg_name.${arg_name}_val = (char *)$arg_name;");
|
|
|
|
push(@setters_list, "args.$arg_name.${arg_name}_len = ${arg_name}len;");
|
|
|
|
push(@args_check_list, { name => "\"$arg_name\"", arg => "${arg_name}len", limit => $limit });
|
2011-05-30 18:27:37 +00:00
|
|
|
} elsif ($args_member =~ m/^remote_typed_param (\S+)<(\S+)>;/) {
|
|
|
|
push(@args_list, "virTypedParameterPtr $1");
|
|
|
|
push(@args_list, "int n$1");
|
|
|
|
push(@setters_list2, "if (remoteSerializeTypedParameters($1, n$1, &args.$1.$1_val, &args.$1.$1_len) < 0) {\n" .
|
|
|
|
" xdr_free((xdrproc_t)xdr_$call->{args}, (char *)&args);\n" .
|
|
|
|
" goto done;\n" .
|
|
|
|
" }");
|
|
|
|
} elsif ($args_member =~ m/^(unsigned )?int (\S+);\s*\/\*\s*call-by-reference\s*\*\//) {
|
|
|
|
my $type_name = $1; $type_name .= "int *";
|
|
|
|
my $arg_name = $2;
|
|
|
|
|
|
|
|
push(@args_list, "$type_name $arg_name");
|
|
|
|
push(@setters_list, "args.$arg_name = *$arg_name;");
|
2011-05-30 10:58:57 +00:00
|
|
|
} elsif ($args_member =~ m/^(unsigned )?int (\S+);/) {
|
|
|
|
my $type_name = $1; $type_name .= "int";
|
|
|
|
my $arg_name = $2;
|
|
|
|
|
|
|
|
push(@args_list, "$type_name $arg_name");
|
|
|
|
push(@setters_list, "args.$arg_name = $arg_name;");
|
|
|
|
} elsif ($args_member =~ m/^(unsigned )?hyper (\S+);/) {
|
|
|
|
my $type_name = $1;
|
|
|
|
my $arg_name = $2;
|
|
|
|
|
|
|
|
if (hyper_to_long($call->{ProcName}, "arg", $arg_name)) {
|
|
|
|
$type_name .= "long";
|
|
|
|
} else {
|
|
|
|
$type_name .= "long long";
|
2011-04-23 10:53:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
push(@args_list, "$type_name $arg_name");
|
|
|
|
push(@setters_list, "args.$arg_name = $arg_name;");
|
2011-05-07 05:36:21 +00:00
|
|
|
} elsif ($args_member =~ m/^(\/)?\*/) {
|
2011-04-23 10:53:57 +00:00
|
|
|
# ignore comments
|
|
|
|
} else {
|
|
|
|
die "unhandled type for argument value: $args_member";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($is_first_arg and $priv_src eq "conn") {
|
|
|
|
unshift(@args_list, "virConnectPtr conn");
|
|
|
|
}
|
|
|
|
|
|
|
|
$is_first_arg = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-23 19:25:49 +00:00
|
|
|
if (! @args_list) {
|
|
|
|
push(@args_list, "virConnectPtr conn");
|
|
|
|
}
|
|
|
|
|
2011-04-23 14:33:57 +00:00
|
|
|
# fix priv_name for the NumOf* functions
|
|
|
|
if ($priv_name eq "privateData" and
|
2011-04-23 21:00:26 +00:00
|
|
|
!($call->{ProcName} =~ m/(Domains|DomainSnapshot)/) and
|
|
|
|
($call->{ProcName} =~ m/NumOf(Defined|Domain)*(\S+)s/ or
|
|
|
|
$call->{ProcName} =~ m/List(Defined|Domain)*(\S+)s/)) {
|
2011-04-23 14:33:57 +00:00
|
|
|
my $prefix = lc $2;
|
|
|
|
$prefix =~ s/(pool|vol)$//;
|
|
|
|
$priv_name = "${prefix}PrivateData";
|
|
|
|
}
|
|
|
|
|
2011-04-23 19:25:49 +00:00
|
|
|
# handle return values of the function
|
|
|
|
my @ret_list = ();
|
2011-05-30 18:27:37 +00:00
|
|
|
my @ret_list2 = ();
|
2011-04-23 19:25:49 +00:00
|
|
|
my $call_ret = "&ret";
|
|
|
|
my $single_ret_var = "int rv = -1";
|
|
|
|
my $single_ret_type = "int";
|
2011-04-23 21:00:26 +00:00
|
|
|
my $single_ret_as_list = 0;
|
|
|
|
my $single_ret_list_error_msg_type = "undefined";
|
|
|
|
my $single_ret_list_name = "undefined";
|
|
|
|
my $single_ret_list_max_var = "undefined";
|
|
|
|
my $single_ret_list_max_define = "undefined";
|
2011-05-30 18:27:37 +00:00
|
|
|
my $single_ret_cleanup = 0;
|
2011-04-23 19:25:49 +00:00
|
|
|
my $multi_ret = 0;
|
|
|
|
|
|
|
|
if ($call->{ret} ne "void" and
|
|
|
|
scalar(@{$call->{ret_members}}) > 1) {
|
|
|
|
$multi_ret = 1;
|
|
|
|
}
|
|
|
|
|
2011-04-23 10:53:57 +00:00
|
|
|
if ($call->{ret} eq "void") {
|
2011-04-23 14:33:57 +00:00
|
|
|
$call_ret = "NULL";
|
2011-04-23 10:53:57 +00:00
|
|
|
} else {
|
|
|
|
push(@vars_list, "$call->{ret} ret");
|
2011-04-23 14:33:57 +00:00
|
|
|
|
|
|
|
foreach my $ret_member (@{$call->{ret_members}}) {
|
2011-04-23 19:25:49 +00:00
|
|
|
if ($multi_ret) {
|
2011-05-07 06:15:51 +00:00
|
|
|
if ($ret_member =~ m/^(unsigned )?(char|short|int|hyper) (\S+)\[\S+\];/) {
|
2011-05-30 10:58:57 +00:00
|
|
|
if ($2 eq "hyper" and hyper_to_long($call->{ProcName}, "ret", $3)) {
|
|
|
|
die "legacy [u]long hyper arrays aren't supported";
|
|
|
|
}
|
|
|
|
|
2011-05-07 06:15:51 +00:00
|
|
|
push(@ret_list, "memcpy(result->$3, ret.$3, sizeof result->$3);");
|
|
|
|
} elsif ($ret_member =~ m/<\S+>;/ or $ret_member =~ m/\[\S+\];/) {
|
|
|
|
# just make all other array types fail
|
2011-05-11 19:28:39 +00:00
|
|
|
die "unhandled type for multi-return-value for " .
|
|
|
|
"procedure $call->{name}: $ret_member";
|
2011-05-07 06:15:51 +00:00
|
|
|
} elsif ($ret_member =~ m/^(unsigned )?(char|short|int|hyper) (\S+);/) {
|
2011-05-30 10:58:57 +00:00
|
|
|
if ($2 eq "hyper" and hyper_to_long($call->{ProcName}, "ret", $3)) {
|
|
|
|
my $sign = ""; $sign = "U" if ($1);
|
|
|
|
|
|
|
|
push(@ret_list, "HYPER_TO_${sign}LONG(result->$3, ret.$3);");
|
|
|
|
} else {
|
|
|
|
push(@ret_list, "result->$3 = ret.$3;");
|
|
|
|
}
|
2011-04-23 19:25:49 +00:00
|
|
|
} else {
|
2011-05-11 19:28:39 +00:00
|
|
|
die "unhandled type for multi-return-value for " .
|
|
|
|
"procedure $call->{name}: $ret_member";
|
2011-04-23 19:25:49 +00:00
|
|
|
}
|
2011-05-21 09:16:07 +00:00
|
|
|
} elsif ($ret_member =~ m/^remote_nonnull_string (\S+)<(\S+)>;\s*\/\*\s*insert@(\d+)\s*\*\//) {
|
|
|
|
splice(@args_list, int($3), 0, ("char **const $1"));
|
|
|
|
push(@ret_list, "rv = ret.$1.$1_len;");
|
|
|
|
$single_ret_var = "int rv = -1";
|
|
|
|
$single_ret_type = "int";
|
2011-04-23 21:00:26 +00:00
|
|
|
$single_ret_as_list = 1;
|
|
|
|
$single_ret_list_name = $1;
|
|
|
|
$single_ret_list_max_var = "max$1";
|
|
|
|
$single_ret_list_max_define = $2;
|
2011-05-21 09:16:07 +00:00
|
|
|
} elsif ($ret_member =~ m/^remote_nonnull_string (\S+)<\S+>;/) {
|
|
|
|
# error out on unannotated arrays
|
|
|
|
die "remote_nonnull_string array without insert@<offset> annotation: $ret_member";
|
2011-05-07 06:15:51 +00:00
|
|
|
} elsif ($ret_member =~ m/^remote_nonnull_string (\S+);/) {
|
2011-04-23 14:33:57 +00:00
|
|
|
push(@ret_list, "rv = ret.$1;");
|
|
|
|
$single_ret_var = "char *rv = NULL";
|
|
|
|
$single_ret_type = "char *";
|
2011-05-14 13:35:27 +00:00
|
|
|
} elsif ($ret_member =~ m/^remote_string (\S+);/) {
|
|
|
|
push(@ret_list, "rv = ret.$1 ? *ret.$1 : NULL;");
|
|
|
|
push(@ret_list, "VIR_FREE(ret.$1);");
|
|
|
|
$single_ret_var = "char *rv = NULL";
|
|
|
|
$single_ret_type = "char *";
|
2011-05-07 06:15:51 +00:00
|
|
|
} elsif ($ret_member =~ m/^remote_nonnull_(domain|network|storage_pool|storage_vol|node_device|interface|secret|nwfilter|domain_snapshot) (\S+);/) {
|
2011-04-23 17:03:14 +00:00
|
|
|
my $name = $1;
|
|
|
|
my $arg_name = $2;
|
|
|
|
my $type_name = name_to_ProcName($name);
|
|
|
|
|
|
|
|
if ($name eq "node_device") {
|
|
|
|
$priv_name = "devMonPrivateData";
|
|
|
|
} elsif ($name =~ m/^storage_/) {
|
|
|
|
$priv_name = "storagePrivateData";
|
|
|
|
} elsif (!($name =~ m/^domain/)) {
|
|
|
|
$priv_name = "${name}PrivateData";
|
|
|
|
}
|
|
|
|
|
2011-05-20 15:58:34 +00:00
|
|
|
if ($call->{ProcName} eq "DomainCreateWithFlags") {
|
|
|
|
# SPECIAL: virDomainCreateWithFlags updates the given
|
|
|
|
# domain object instead of returning a new one
|
|
|
|
push(@ret_list, "dom->id = ret.dom.id;");
|
|
|
|
push(@ret_list, "xdr_free((xdrproc_t)xdr_$call->{ret}, (char *)&ret);");
|
|
|
|
push(@ret_list, "rv = 0;");
|
|
|
|
$single_ret_var = "int rv = -1";
|
|
|
|
$single_ret_type = "int";
|
2011-04-23 17:03:14 +00:00
|
|
|
} else {
|
2011-05-20 15:58:34 +00:00
|
|
|
if ($name eq "domain_snapshot") {
|
|
|
|
push(@ret_list, "rv = get_nonnull_$name(dom, ret.$arg_name);");
|
|
|
|
} else {
|
|
|
|
push(@ret_list, "rv = get_nonnull_$name($priv_src, ret.$arg_name);");
|
|
|
|
}
|
2011-04-23 17:03:14 +00:00
|
|
|
|
2011-05-20 15:58:34 +00:00
|
|
|
push(@ret_list, "xdr_free((xdrproc_t)xdr_$call->{ret}, (char *)&ret);");
|
|
|
|
$single_ret_var = "vir${type_name}Ptr rv = NULL";
|
|
|
|
$single_ret_type = "vir${type_name}Ptr";
|
|
|
|
}
|
2011-05-30 18:27:37 +00:00
|
|
|
} elsif ($ret_member =~ m/^remote_typed_param (\S+)<(\S+)>;\s*\/\*\s*insert@(\d+)\s*\*\//) {
|
|
|
|
splice(@args_list, int($3), 0, ("virTypedParameterPtr $1"));
|
|
|
|
push(@ret_list2, "if (remoteDeserializeTypedParameters(ret.$1.$1_val,\n" .
|
|
|
|
" ret.$1.$1_len,\n" .
|
|
|
|
" $2,\n" .
|
|
|
|
" $1,\n" .
|
|
|
|
" n$1) < 0)\n" .
|
|
|
|
" goto cleanup;\n");
|
|
|
|
$single_ret_cleanup = 1;
|
|
|
|
} elsif ($ret_member =~ m/^remote_typed_param (\S+)<\S+>;/) {
|
|
|
|
# error out on unannotated arrays
|
|
|
|
die "remote_typed_param array without insert@<offset> annotation: $ret_member";
|
2011-04-23 14:33:57 +00:00
|
|
|
} elsif ($ret_member =~ m/^int (\S+);/) {
|
2011-04-23 21:03:44 +00:00
|
|
|
my $arg_name = $1;
|
|
|
|
|
|
|
|
if ($call->{ProcName} =~ m/GetAutostart$/) {
|
|
|
|
push(@args_list, "int *$arg_name");
|
|
|
|
push(@ret_list, "if ($arg_name) *$arg_name = ret.$arg_name;");
|
|
|
|
push(@ret_list, "rv = 0;");
|
|
|
|
} else {
|
|
|
|
push(@ret_list, "rv = ret.$arg_name;");
|
|
|
|
}
|
|
|
|
|
2011-04-23 14:33:57 +00:00
|
|
|
$single_ret_var = "int rv = -1";
|
|
|
|
$single_ret_type = "int";
|
2011-05-07 06:15:51 +00:00
|
|
|
} elsif ($ret_member =~ m/^unsigned hyper (\S+);/) {
|
2011-05-30 10:58:57 +00:00
|
|
|
my $ret_name = $1;
|
2011-05-21 09:24:28 +00:00
|
|
|
|
2011-04-23 21:03:44 +00:00
|
|
|
if ($call->{ProcName} =~ m/Get(Lib)?Version/) {
|
2011-05-30 10:58:57 +00:00
|
|
|
push(@args_list, "unsigned long *$ret_name");
|
|
|
|
push(@ret_list, "if ($ret_name) HYPER_TO_ULONG(*$ret_name, ret.$ret_name);");
|
2011-04-23 21:03:44 +00:00
|
|
|
push(@ret_list, "rv = 0;");
|
|
|
|
$single_ret_var = "int rv = -1";
|
|
|
|
$single_ret_type = "int";
|
2011-05-30 10:58:57 +00:00
|
|
|
} elsif (hyper_to_long($call->{ProcName}, "ret", $ret_name)) {
|
|
|
|
push(@ret_list, "HYPER_TO_ULONG(rv, ret.$ret_name);");
|
2011-05-21 10:24:40 +00:00
|
|
|
$single_ret_var = "unsigned long rv = 0";
|
|
|
|
$single_ret_type = "unsigned long";
|
2011-05-30 10:58:57 +00:00
|
|
|
} else {
|
|
|
|
push(@ret_list, "rv = ret.$ret_name;");
|
|
|
|
$single_ret_var = "unsigned long long rv = 0";
|
|
|
|
$single_ret_type = "unsigned long long";
|
2011-04-23 17:03:14 +00:00
|
|
|
}
|
2011-05-11 19:28:39 +00:00
|
|
|
} elsif ($ret_member =~ m/^(\/)?\*/) {
|
|
|
|
# ignore comments
|
2011-04-23 14:33:57 +00:00
|
|
|
} else {
|
2011-05-11 19:28:39 +00:00
|
|
|
die "unhandled type for return value for procedure " .
|
|
|
|
"$call->{name}: $ret_member";
|
2011-04-23 14:33:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-23 19:25:49 +00:00
|
|
|
# select struct type for multi-return-value functions
|
|
|
|
if ($multi_ret) {
|
|
|
|
my $last_arg;
|
|
|
|
my $struct_name = $call->{ProcName};
|
|
|
|
$struct_name =~ s/Get//;
|
|
|
|
|
|
|
|
if ($call->{ProcName} eq "DomainGetBlockInfo") {
|
2011-05-07 06:15:51 +00:00
|
|
|
# SPECIAL: virDomainGetBlockInfo has flags parameter after
|
|
|
|
# the struct parameter in its signature
|
2011-04-23 19:25:49 +00:00
|
|
|
$last_arg = pop(@args_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
push(@args_list, "vir${struct_name}Ptr result");
|
|
|
|
|
|
|
|
if (defined $last_arg) {
|
|
|
|
push(@args_list, $last_arg);
|
|
|
|
}
|
2011-04-23 10:53:57 +00:00
|
|
|
}
|
|
|
|
|
2011-05-21 09:24:28 +00:00
|
|
|
if ($call->{streamflag} ne "none") {
|
|
|
|
splice(@args_list, $call->{streamoffset}, 0, ("virStreamPtr st"));
|
|
|
|
}
|
|
|
|
|
2011-04-23 10:53:57 +00:00
|
|
|
# print function
|
|
|
|
print "\n";
|
2011-04-23 14:33:57 +00:00
|
|
|
print "static $single_ret_type\n";
|
2011-04-23 10:53:57 +00:00
|
|
|
print "remote$call->{ProcName}(";
|
|
|
|
|
|
|
|
print join(", ", @args_list);
|
|
|
|
|
|
|
|
print ")\n";
|
|
|
|
print "{\n";
|
2011-04-23 14:33:57 +00:00
|
|
|
print " $single_ret_var;\n";
|
2011-04-23 10:53:57 +00:00
|
|
|
print " struct private_data *priv = $priv_src->$priv_name;\n";
|
|
|
|
|
|
|
|
foreach my $var (@vars_list) {
|
|
|
|
print " $var;\n";
|
|
|
|
}
|
|
|
|
|
2011-04-23 21:00:26 +00:00
|
|
|
if ($single_ret_as_list) {
|
|
|
|
print " int i;\n";
|
|
|
|
}
|
|
|
|
|
2011-05-21 09:24:28 +00:00
|
|
|
if ($call->{streamflag} ne "none") {
|
|
|
|
print " struct private_stream_data *privst = NULL;\n";
|
|
|
|
}
|
|
|
|
|
2011-04-23 10:53:57 +00:00
|
|
|
print "\n";
|
|
|
|
print " remoteDriverLock(priv);\n";
|
|
|
|
|
2011-05-21 09:24:28 +00:00
|
|
|
if ($call->{streamflag} ne "none") {
|
|
|
|
print "\n";
|
|
|
|
print " if (!(privst = remoteStreamOpen(st, REMOTE_PROC_$call->{UC_NAME}, priv->counter)))\n";
|
|
|
|
print " goto done;\n";
|
|
|
|
print "\n";
|
|
|
|
print " st->driver = &remoteStreamDrv;\n";
|
|
|
|
print " st->privateData = privst;\n";
|
|
|
|
}
|
|
|
|
|
2011-05-14 13:56:03 +00:00
|
|
|
if ($call->{ProcName} eq "SupportsFeature") {
|
|
|
|
# SPECIAL: VIR_DRV_FEATURE_REMOTE feature is handled directly
|
|
|
|
print "\n";
|
|
|
|
print " if (feature == VIR_DRV_FEATURE_REMOTE) {\n";
|
|
|
|
print " rv = 1;\n";
|
|
|
|
print " goto done;\n";
|
|
|
|
print " }\n";
|
|
|
|
}
|
|
|
|
|
2011-04-24 07:49:42 +00:00
|
|
|
foreach my $args_check (@args_check_list) {
|
|
|
|
print "\n";
|
|
|
|
print " if ($args_check->{arg} > $args_check->{limit}) {\n";
|
|
|
|
print " remoteError(VIR_ERR_RPC,\n";
|
|
|
|
print " _(\"%s length greater than maximum: %d > %d\"),\n";
|
|
|
|
print " $args_check->{name}, (int)$args_check->{arg}, $args_check->{limit});\n";
|
|
|
|
print " goto done;\n";
|
|
|
|
print " }\n";
|
|
|
|
}
|
|
|
|
|
2011-04-23 21:00:26 +00:00
|
|
|
if ($single_ret_as_list) {
|
|
|
|
print "\n";
|
|
|
|
print " if ($single_ret_list_max_var > $single_ret_list_max_define) {\n";
|
|
|
|
print " remoteError(VIR_ERR_RPC,\n";
|
|
|
|
print " _(\"too many remote ${single_ret_list_error_msg_type}s: %d > %d\"),\n";
|
|
|
|
print " $single_ret_list_max_var, $single_ret_list_max_define);\n";
|
|
|
|
print " goto done;\n";
|
|
|
|
print " }\n";
|
|
|
|
}
|
|
|
|
|
2011-04-23 10:53:57 +00:00
|
|
|
if (@setters_list) {
|
2011-04-23 14:33:57 +00:00
|
|
|
print "\n";
|
2011-04-23 10:53:57 +00:00
|
|
|
print " ";
|
|
|
|
}
|
|
|
|
|
|
|
|
print join("\n ", @setters_list);
|
|
|
|
|
|
|
|
if (@setters_list) {
|
|
|
|
print "\n";
|
|
|
|
}
|
|
|
|
|
2011-05-30 18:27:37 +00:00
|
|
|
if (@setters_list2) {
|
|
|
|
print "\n";
|
|
|
|
print " ";
|
|
|
|
}
|
|
|
|
|
|
|
|
print join("\n ", @setters_list2);
|
|
|
|
|
|
|
|
if (@setters_list2) {
|
|
|
|
print "\n";
|
|
|
|
}
|
|
|
|
|
2011-04-23 14:33:57 +00:00
|
|
|
if ($call->{ret} ne "void") {
|
|
|
|
print "\n";
|
|
|
|
print " memset(&ret, 0, sizeof ret);\n";
|
|
|
|
}
|
|
|
|
|
2011-04-23 10:53:57 +00:00
|
|
|
print "\n";
|
|
|
|
print " if (call($priv_src, priv, 0, ${procprefix}_PROC_$call->{UC_NAME},\n";
|
2011-04-23 14:33:57 +00:00
|
|
|
print " (xdrproc_t)xdr_$call->{args}, (char *)$call_args,\n";
|
2011-05-21 09:24:28 +00:00
|
|
|
print " (xdrproc_t)xdr_$call->{ret}, (char *)$call_ret) == -1) {\n";
|
|
|
|
|
|
|
|
if ($call->{streamflag} ne "none") {
|
|
|
|
print " remoteStreamRelease(st);\n";
|
|
|
|
}
|
|
|
|
|
2011-04-23 10:53:57 +00:00
|
|
|
print " goto done;\n";
|
2011-05-21 09:24:28 +00:00
|
|
|
print " }\n";
|
2011-04-23 10:53:57 +00:00
|
|
|
print "\n";
|
2011-04-23 14:33:57 +00:00
|
|
|
|
2011-04-23 21:00:26 +00:00
|
|
|
if ($single_ret_as_list) {
|
|
|
|
print " if (ret.$single_ret_list_name.${single_ret_list_name}_len > $single_ret_list_max_var) {\n";
|
|
|
|
print " remoteError(VIR_ERR_RPC,\n";
|
|
|
|
print " _(\"too many remote ${single_ret_list_error_msg_type}s: %d > %d\"),\n";
|
|
|
|
print " ret.$single_ret_list_name.${single_ret_list_name}_len, $single_ret_list_max_var);\n";
|
|
|
|
print " goto cleanup;\n";
|
|
|
|
print " }\n";
|
|
|
|
print "\n";
|
|
|
|
print " /* This call is caller-frees (although that isn't clear from\n";
|
|
|
|
print " * the documentation). However xdr_free will free up both the\n";
|
|
|
|
print " * names and the list of pointers, so we have to strdup the\n";
|
|
|
|
print " * names here. */\n";
|
|
|
|
print " for (i = 0; i < ret.$single_ret_list_name.${single_ret_list_name}_len; ++i) {\n";
|
|
|
|
print " ${single_ret_list_name}[i] = strdup(ret.$single_ret_list_name.${single_ret_list_name}_val[i]);\n";
|
|
|
|
print "\n";
|
|
|
|
print " if (${single_ret_list_name}[i] == NULL) {\n";
|
|
|
|
print " for (--i; i >= 0; --i)\n";
|
|
|
|
print " VIR_FREE(${single_ret_list_name}[i]);\n";
|
|
|
|
print "\n";
|
|
|
|
print " virReportOOMError();\n";
|
|
|
|
print " goto cleanup;\n";
|
|
|
|
print " }\n";
|
|
|
|
print " }\n";
|
|
|
|
print "\n";
|
|
|
|
}
|
|
|
|
|
2011-05-30 18:27:37 +00:00
|
|
|
if (@ret_list2) {
|
|
|
|
print " ";
|
|
|
|
print join("\n ", @ret_list2);
|
|
|
|
print "\n";
|
|
|
|
}
|
|
|
|
|
2011-04-23 14:33:57 +00:00
|
|
|
if (@ret_list) {
|
|
|
|
print " ";
|
|
|
|
print join("\n ", @ret_list);
|
|
|
|
print "\n";
|
2011-04-23 19:25:49 +00:00
|
|
|
}
|
|
|
|
|
2011-05-14 13:56:03 +00:00
|
|
|
if ($call->{ProcName} eq "DomainDestroy") {
|
|
|
|
# SPECIAL: virDomainDestroy needs to reset the domain id explicitly
|
|
|
|
print " dom->id = -1;\n";
|
|
|
|
}
|
|
|
|
|
2011-04-23 19:25:49 +00:00
|
|
|
if ($multi_ret or !@ret_list) {
|
2011-04-23 14:33:57 +00:00
|
|
|
print " rv = 0;\n";
|
|
|
|
}
|
|
|
|
|
2011-05-30 18:27:37 +00:00
|
|
|
if ($single_ret_as_list or $single_ret_cleanup) {
|
2011-04-23 21:00:26 +00:00
|
|
|
print "\n";
|
|
|
|
print "cleanup:\n";
|
|
|
|
print " xdr_free((xdrproc_t)xdr_remote_$call->{name}_ret, (char *)&ret);\n";
|
|
|
|
}
|
|
|
|
|
2011-04-23 10:53:57 +00:00
|
|
|
print "\n";
|
|
|
|
print "done:\n";
|
|
|
|
print " remoteDriverUnlock(priv);\n";
|
|
|
|
print " return rv;\n";
|
|
|
|
print "}\n";
|
|
|
|
}
|
|
|
|
}
|