summaryrefslogtreecommitdiff
path: root/source4/pidl/lib
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2006-05-13 21:36:15 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:06:00 -0500
commitf9dd0263553c4f04fbc0d067e5384a9e46cd98bc (patch)
tree89b4bf38881ddde78fc1a3b80ef68abe83fd2714 /source4/pidl/lib
parent8903abc4c896a781e70a63ea355dd608b8f10812 (diff)
downloadsamba-f9dd0263553c4f04fbc0d067e5384a9e46cd98bc.tar.gz
samba-f9dd0263553c4f04fbc0d067e5384a9e46cd98bc.tar.bz2
samba-f9dd0263553c4f04fbc0d067e5384a9e46cd98bc.zip
r15585: Revive pidl's SWIG file generator. It now generates simple
object oriented wrappers for the interfaces (still need to fix the actual function calls) (This used to be commit bf5da20869eae29aea92386cbb13413b507fc55f)
Diffstat (limited to 'source4/pidl/lib')
-rw-r--r--source4/pidl/lib/Parse/Pidl/Samba4/SWIG.pm129
1 files changed, 80 insertions, 49 deletions
diff --git a/source4/pidl/lib/Parse/Pidl/Samba4/SWIG.pm b/source4/pidl/lib/Parse/Pidl/Samba4/SWIG.pm
index b6c268edeb..d42960be28 100644
--- a/source4/pidl/lib/Parse/Pidl/Samba4/SWIG.pm
+++ b/source4/pidl/lib/Parse/Pidl/Samba4/SWIG.pm
@@ -1,6 +1,7 @@
###################################################
# Samba4 parser generator for swig wrappers
# Copyright tpot@samba.org 2004,2005
+# Copyright jelmer@samba.org 2006
# released under the GNU GPL
package Parse::Pidl::Samba4::SWIG;
@@ -10,70 +11,100 @@ $VERSION = '0.01';
use strict;
+my $ret = "";
+my $tabs = "";
+
sub pidl($)
{
- print OUT shift;
+ my $p = shift;
+ $ret .= $tabs. $p . "\n";
}
-#####################################################################
-# rewrite autogenerated header file
-sub RewriteHeader($$$)
-{
- my($idl) = shift;
- my($input) = shift;
- my($output) = shift;
-
- open(IN, "<$input") || die "can't open $input for reading";
- open(OUT, ">$output") || die "can't open $output for writing";
-
- pidl "%{\n";
- pidl "#define data_in in\n";
- pidl "#define data_out out\n";
- pidl "%}\n\n";
-
- while(<IN>) {
+sub indent() { $tabs.="\t"; }
+sub deindent() { $tabs = substr($tabs,0,-1); }
- # Rename dom_sid2 to dom_sid as we don't care about the difference
- # for the swig wrappers.
-
- s/dom_sid2/dom_sid/g;
+sub ParseInterface($)
+{
+ my $if = shift;
+
+ pidl "\%{";
+ pidl "struct $if->{NAME} {";
+ indent;
+ pidl "struct dcerpc_pipe *pipe;";
+ deindent;
+ pidl "};";
+ pidl "%}";
+ pidl "";
+
+ # FIXME: Generate ignores for all manual functions
+
+ pidl "\%extend $if->{NAME} {";
+ indent();
+ pidl "struct $if->{NAME} *$if->{NAME} (const char *binding, struct cli_credentials *cred = NULL, TALLOC_CTX *mem_ctx = NULL, struct event_context *event = NULL)";
+ pidl "{";
+ indent;
+ pidl "struct $if->{NAME} *ret = talloc(mem_ctx, struct $if->{NAME});";
+ pidl "NTSTATUS status;";
+ pidl "";
+ pidl "status = dcerpc_pipe_connect(mem_ctx, &ret->pipe, &dcerpc_table_$if->{NAME}, cred, event);";
+ pidl "if (NT_STATUS_IS_ERR(status)) {";
+ pidl "\tsamba_nt_status_exception(status);";
+ pidl "\treturn NULL;";
+ pidl "}";
+ pidl "";
+ pidl "return ret;";
+ deindent;
+ pidl "}";
+ pidl "";
+ pidl "~$if->{NAME}() {";
+ pidl "\ttalloc_free(self);";
+ pidl "}";
+ pidl "";
+
+ foreach (@{$if->{FUNCTIONS}}) {
+ pidl "/* $_->{NAME} */";
+ }
- # Copy structure and union definitions
+ deindent();
+ pidl "}";
+ pidl "";
- if (/^(struct|union) .*? {$/ .. /^\};$/) {
- s/\} (in|out);/\} data_$1;/; # "in" is a Python keyword
- pidl $_;
- next;
+ foreach (@{$if->{TYPES}}) {
+ pidl "/* $_->{NAME} */";
}
+
+ pidl "";
+}
- # Copy dcerpc functions
-
- pidl $_ if /^NTSTATUS dcerpc_.*?\(struct dcerpc_pipe/;
+sub Parse($$$$)
+{
+ my($ndr,$basename,$header,$gen_header) = @_;
- # Copy interface definitions
+ $ret = "";
- pidl $_
- if /^\#define DCERPC_.*?_UUID/ or /^\#define DCERPC_.*?_VERSION/;
- }
+ pidl "/* This file is autogenerated by pidl. DO NOT EDIT */";
- close(OUT);
-}
+ pidl "\%module $basename";
+
+ pidl "";
-#####################################################################
-# rewrite autogenerated header file
-sub RewriteC($$$)
-{
- my($idl) = shift;
- my($input) = shift;
- my($output) = shift;
+ pidl "\%{";
+ pidl "#include \"includes.h\"";
+ pidl "#include \"$header\"";
+ pidl "%}";
+ pidl "\%include \"samba.i\"";
+ pidl "\%include \"$gen_header\"";
- open(IN, "<$input") || die "can't open $input for reading";
- open(OUT, ">>$output") || die "can't open $output for writing";
-
- while(<IN>) {
- }
+ pidl "";
- close(OUT);
+ foreach (@$ndr) {
+ ParseInterface($_) if ($_->{TYPE} eq "INTERFACE");
+ }
+ #FIXME: Foreach ref pointer, set NONNULL
+ #FIXME: Foreach unique/full pointer, set MAYBENULL
+ #FIXME: Foreach [out] parameter, set OUTPARAM
+ #
+ return $ret;
}
1;