remote generator, client: Handle functions with simple return values

This commit is contained in:
Matthias Bolte 2011-04-23 16:33:57 +02:00
parent f68bb4edb3
commit 9de503f957
3 changed files with 1120 additions and 1180 deletions

View File

@ -754,63 +754,42 @@ elsif ($opt_k) {
"AuthPolkit", "AuthPolkit",
"CPUBaseline", "CPUBaseline",
"CPUCompare",
"DomainBlockStats", "DomainBlockStats",
"DomainCreate", "DomainCreate",
"DomainCreateXML", "DomainCreateXML",
"DomainDefineXML", "DomainDefineXML",
"DomainDestroy", "DomainDestroy",
"DomainDumpXML",
"DomainGetAutostart", "DomainGetAutostart",
"DomainGetBlockInfo", "DomainGetBlockInfo",
"DomainGetInfo", "DomainGetInfo",
"StoragePoolLookupByUUID", "StoragePoolLookupByUUID",
"StoragePoolNumOfVolumes",
"NodeDeviceCreateXML", "NodeDeviceCreateXML",
"DomainGetJobInfo", "DomainGetJobInfo",
"DomainGetMaxMemory",
"DomainGetOSType",
"DomainGetVcpusFlags",
"HasCurrentSnapshot",
"DomainInterfaceStats", "DomainInterfaceStats",
"DomainIsActive",
"DomainIsPersistent",
"DomainIsUpdated",
"DomainLookupByID", "DomainLookupByID",
"DomainLookupByName", "DomainLookupByName",
"DomainLookupByUIID", "DomainLookupByUIID",
"DomainMigrateFinish", "DomainMigrateFinish",
"DomainGetMaxVcpus",
"DomainHasCurrentSnapshot",
"NWFilterDefineXML", "NWFilterDefineXML",
"NumOfStoragePools",
"NWFilterLookupByName", "NWFilterLookupByName",
"NWFilterLookupByUUID", "NWFilterLookupByUUID",
"SecretLookupByUUID", "SecretLookupByUUID",
"SecretLookupByUsage", "SecretLookupByUsage",
"StoragePoolCreateXML", "StoragePoolCreateXML",
"StoragePoolIsActive",
"DomainHasManagedSaveImage",
"DomainLookupByUUID", "DomainLookupByUUID",
"DomainMigratePerform", "DomainMigratePerform",
"DomainMigrateFinish2", "DomainMigrateFinish2",
"DomainSnapshotCreateXML", "DomainSnapshotCreateXML",
"DomainSnapshotDumpXML",
"DomainSnapshotNum",
"DomainSnapshotCurrent", "DomainSnapshotCurrent",
"DomainSnapshotListNames", "DomainSnapshotListNames",
"GetCapabilities",
"GetHostname",
"GetLibVersion", "GetLibVersion",
"GetMaxVcpus", "GetMaxVcpus",
"DomainSnapshotLookupByName", "DomainSnapshotLookupByName",
"DomainXMLFromNative", "DomainXMLFromNative",
"FindStoragePoolSources", "FindStoragePoolSources",
"GetSysinfo",
"GetVersion", "GetVersion",
"GetLibVersion", "GetLibVersion",
"InterfaceDefineXML", "InterfaceDefineXML",
"InterfaceGetXMLDesc",
"InterfaceLookupByName", "InterfaceLookupByName",
"IsSecure", "IsSecure",
"ListDefinedDomains", "ListDefinedDomains",
@ -823,40 +802,22 @@ elsif ($opt_k) {
"StorageVolCreateXML", "StorageVolCreateXML",
"StorageVolLookupByName", "StorageVolLookupByName",
"StorageVolLookupByKey", "StorageVolLookupByKey",
"StoragePoolIsPersistent",
"StoragePoolGetInfo", "StoragePoolGetInfo",
"StorageVolGetPath",
"StorageVolCreateXMLFrom", "StorageVolCreateXMLFrom",
"StoragePoolLookupByName", "StoragePoolLookupByName",
"SecretGetXMLDesc",
"NWFilterGetXMLDesc",
"NumOfNWFilters",
"NumOfInterfaces",
"NumOfDomains",
"NumOfDefinedStoragePools",
"NodeListDevices", "NodeListDevices",
"NodeGetCellsFreeMemory", "NodeGetCellsFreeMemory",
"NodeDeviceDumpXML",
"NetworkIsActive",
"ListDefinedNetworks", "ListDefinedNetworks",
"DomainXMLToNative", "DomainXMLToNative",
"StorageVolDumpXML",
"StoragePoolListVolumes", "StoragePoolListVolumes",
"StoragePoolDumpXML",
"SecretDefineXML", "SecretDefineXML",
"NumOfDefinedNetworks",
"InterfaceIsActive",
"ListDomains", "ListDomains",
"ListStoragePools", "ListStoragePools",
"NetworkDumpXML",
"NetworkGetAutostart", "NetworkGetAutostart",
"NetworkGetBridgeName",
"StoragePoolLookupByVolume", "StoragePoolLookupByVolume",
"StoragePoolGetAutostart", "StoragePoolGetAutostart",
"SecretSetValue", "SecretSetValue",
"NumOfDefinedInterfaces",
"StoragePoolDefineXML", "StoragePoolDefineXML",
"NodeNumOfDevices",
"NodeGetInfo", "NodeGetInfo",
"GetURI", "GetURI",
"InterfaceLookupByMACString", "InterfaceLookupByMACString",
@ -864,18 +825,13 @@ elsif ($opt_k) {
"NetworkDefineXML", "NetworkDefineXML",
"NetworkLookupByName", "NetworkLookupByName",
"ListDefinedStoragePools", "ListDefinedStoragePools",
"NetworkIsPersistent",
"NodeDeviceDettach", "NodeDeviceDettach",
"NodeDeviceLookupByName", "NodeDeviceLookupByName",
"NodeGetFreeMemory", "NodeGetFreeMemory",
"NumOfDefinedDomains",
"ListNetworks", "ListNetworks",
"NodeDeviceListCaps", "NodeDeviceListCaps",
"NodeDeviceReset", "NodeDeviceReset",
"NumOfNetworks",
"NetworkLookupByUUID", "NetworkLookupByUUID",
"NodeDeviceNumOfCaps",
"NumOfSecrets",
"NodeDeviceReAttach", "NodeDeviceReAttach",
"ListSecrets", "ListSecrets",
@ -919,13 +875,16 @@ elsif ($opt_k) {
my @args_list = (); my @args_list = ();
my @vars_list = (); my @vars_list = ();
my @setters_list = (); my @setters_list = ();
my @ret_list = ();
my $priv_src = "conn"; my $priv_src = "conn";
my $priv_name = "privateData"; my $priv_name = "privateData";
my $args = "&args"; my $call_args = "&args";
my $ret = "&ret"; my $call_ret = "&ret";
my $single_ret_var = "int rv = -1";
my $single_ret_type = "int";
if ($call->{args} eq "void") { if ($call->{args} eq "void") {
$args = "NULL"; $call_args = "NULL";
} else { } else {
push(@vars_list, "$call->{args} args"); push(@vars_list, "$call->{args} args");
@ -933,14 +892,14 @@ elsif ($opt_k) {
my $has_node_device = 0; my $has_node_device = 0;
# node device is special # node device is special
if ($call->{args} =~ m/^remote_node_device_/) { if ($call->{args} =~ m/^remote_node_/) {
$has_node_device = 1; $has_node_device = 1;
$priv_name = "devMonPrivateData";
} }
foreach my $args_member (@{$call->{args_members}}) { foreach my $args_member (@{$call->{args_members}}) {
if ($args_member =~ m/^remote_nonnull_string name;/ and $has_node_device) { if ($args_member =~ m/^remote_nonnull_string name;/ and $has_node_device) {
$priv_src = "dev->conn"; $priv_src = "dev->conn";
$priv_name = "devMonPrivateData";
push(@args_list, "virNodeDevicePtr dev"); push(@args_list, "virNodeDevicePtr dev");
push(@setters_list, "args.name = dev->name;"); 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+);/) { } elsif ($args_member =~ m/^remote_nonnull_(domain|network|storage_pool|storage_vol|interface|secret|nwfilter|domain_snapshot) (\S+);/) {
@ -963,6 +922,9 @@ elsif ($opt_k) {
push(@args_list, "vir${type_name}Ptr $2"); push(@args_list, "vir${type_name}Ptr $2");
push(@setters_list, "make_nonnull_$1(&args.$2, $2);"); push(@setters_list, "make_nonnull_$1(&args.$2, $2);");
} elsif ($args_member =~ m/^remote_string (\S+);/) {
push(@args_list, "const char *$1");
push(@setters_list, "args.$1 = $1 ? (char **)&$1 : NULL;");
} elsif ($args_member =~ m/^remote_nonnull_string (\S+);/) { } elsif ($args_member =~ m/^remote_nonnull_string (\S+);/) {
push(@args_list, "const char *$1"); push(@args_list, "const char *$1");
push(@setters_list, "args.$1 = (char *)$1;"); push(@setters_list, "args.$1 = (char *)$1;");
@ -979,7 +941,9 @@ elsif ($opt_k) {
if ($type_name eq "int") { if ($type_name eq "int") {
# fix bad decisions in the xdr protocol # fix bad decisions in the xdr protocol
if ($arg_name eq "flags" and if ($arg_name eq "flags" and
$call->{ProcName} ne "DomainCoreDump") { $call->{ProcName} ne "DomainCoreDump" and
$call->{ProcName} ne "DomainDumpXML" and
$call->{ProcName} ne "NetworkDumpXML") {
$type_name = "unsigned int"; $type_name = "unsigned int";
} elsif ($arg_name eq "nvcpus" and } elsif ($arg_name eq "nvcpus" and
$call->{ProcName} eq "DomainSetVcpus") { $call->{ProcName} eq "DomainSetVcpus") {
@ -1008,22 +972,53 @@ elsif ($opt_k) {
} }
} }
# fix priv_name for the NumOf* functions
if ($priv_name eq "privateData" and
!($call->{ProcName} =~ m/Domains/) and
$call->{ProcName} =~ m/NumOf(Defined|Domain)*(\S+)s/) {
my $prefix = lc $2;
$prefix =~ s/(pool|vol)$//;
$priv_name = "${prefix}PrivateData";
}
if ($call->{ret} eq "void") { if ($call->{ret} eq "void") {
$ret = "NULL"; $call_ret = "NULL";
} else { } else {
push(@vars_list, "$call->{ret} ret"); push(@vars_list, "$call->{ret} ret");
foreach my $ret_member (@{$call->{ret_members}}) {
if ($ret_member =~ m/remote_nonnull_string (\S+);/) {
push(@ret_list, "rv = ret.$1;");
$single_ret_var = "char *rv = NULL";
$single_ret_type = "char *";
} elsif ($ret_member =~ m/^int (\S+);/) {
push(@ret_list, "rv = ret.$1;");
$single_ret_var = "int rv = -1";
$single_ret_type = "int";
} elsif ($ret_member =~ m/hyper (\S+);/) {
push(@ret_list, "rv = ret.$1;");
$single_ret_var = "unsigned long rv = 0";
$single_ret_type = "unsigned long";
} else {
die "unhandled type for return value: $ret_member";
}
}
}
if (! @args_list) {
push(@args_list, "virConnectPtr conn");
} }
# print function # print function
print "\n"; print "\n";
print "static int\n"; print "static $single_ret_type\n";
print "remote$call->{ProcName}("; print "remote$call->{ProcName}(";
print join(", ", @args_list); print join(", ", @args_list);
print ")\n"; print ")\n";
print "{\n"; print "{\n";
print " int rv = -1;\n"; print " $single_ret_var;\n";
print " struct private_data *priv = $priv_src->$priv_name;\n"; print " struct private_data *priv = $priv_src->$priv_name;\n";
foreach my $var (@vars_list) { foreach my $var (@vars_list) {
@ -1032,9 +1027,9 @@ elsif ($opt_k) {
print "\n"; print "\n";
print " remoteDriverLock(priv);\n"; print " remoteDriverLock(priv);\n";
print "\n";
if (@setters_list) { if (@setters_list) {
print "\n";
print " "; print " ";
} }
@ -1044,13 +1039,26 @@ elsif ($opt_k) {
print "\n"; print "\n";
} }
if ($call->{ret} ne "void") {
print "\n";
print " memset(&ret, 0, sizeof ret);\n";
}
print "\n"; print "\n";
print " if (call($priv_src, priv, 0, ${procprefix}_PROC_$call->{UC_NAME},\n"; print " if (call($priv_src, priv, 0, ${procprefix}_PROC_$call->{UC_NAME},\n";
print " (xdrproc_t)xdr_$call->{args}, (char *)$args,\n"; print " (xdrproc_t)xdr_$call->{args}, (char *)$call_args,\n";
print " (xdrproc_t)xdr_$call->{ret}, (char *)$ret) == -1)\n"; print " (xdrproc_t)xdr_$call->{ret}, (char *)$call_ret) == -1)\n";
print " goto done;\n"; print " goto done;\n";
print "\n"; print "\n";
if (@ret_list) {
print " ";
print join("\n ", @ret_list);
print "\n";
} else {
print " rv = 0;\n"; print " rv = 0;\n";
}
print "\n"; print "\n";
print "done:\n"; print "done:\n";
print " remoteDriverUnlock(priv);\n"; print " remoteDriverUnlock(priv);\n";

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff