r15591: Generate function calls correctly as well.
authorJelmer Vernooij <jelmer@samba.org>
Sat, 13 May 2006 23:58:16 +0000 (23:58 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 19:06:01 +0000 (14:06 -0500)
(This used to be commit b0439779b8eba68680cfd49ea2364affc739300e)

source4/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm
source4/pidl/lib/Parse/Pidl/Samba4/SWIG.pm

index 3b8c92ebe4bf6fded91a3b1deb80c226ed5f26bf..fa629e6101c21a63fbc90fffb494f072e27ec678 100644 (file)
@@ -26,27 +26,6 @@ sub fatal($$) { my ($e,$s) = @_; die("$e->{ORIGINAL}->{FILE}:$e->{ORIGINAL}->{LI
 sub warning($$) { my ($e,$s) = @_; warn("$e->{ORIGINAL}->{FILE}:$e->{ORIGINAL}->{LINE}: $s\n"); }
 sub fn_declare($) { my ($n) = @_; pidl $n; pidl_hdr "$n;"; }
 
-sub CopyLevel($$$$)
-{
-       sub CopyLevel($$$$);
-       my ($e,$l,$argument,$member) = @_;
-
-       if ($l->{TYPE} eq "DATA") {
-               pidl "*$argument = *$member;";
-       } elsif ($l->{TYPE} eq "POINTER") {
-               pidl "if (r.ptr$l->{POINTER_INDEX}_$e->{NAME}) {";
-               indent;
-               pidl "*$argument = talloc_size(mem_ctx, sizeof(void *));";
-               CopyLevel($e,GetNextLevel($e,$l),"*$argument", $member);
-               deindent;
-               pidl "}";
-       } elsif ($l->{TYPE} eq "SWITCH") {
-               CopyLevel($e,GetNextLevel($e,$l),$argument,$member);    
-       } elsif ($l->{TYPE} eq "ARRAY") {
-               pidl "*$argument = $member;";
-       }
-}
-
 sub ParseFunction($$)
 {
        my ($if,$fn) = @_;
@@ -84,7 +63,7 @@ sub ParseFunction($$)
 
                fatal($e, "[out] argument is not a pointer") if ($e->{LEVELS}[0]->{TYPE} ne "POINTER");
 
-               CopyLevel($e, $e->{LEVELS}[1], $e->{NAME}, "r.out.$e->{NAME}");
+               pidl "*$e->{NAME} = *r.out.$e->{NAME};";
        }
 
        pidl"";
index 22061f46af3a35089002574174e37baeb10779f6..57ff007d1b27ea1f854a4992d430538bcb71c8b9 100644 (file)
@@ -9,6 +9,7 @@ package Parse::Pidl::Samba4::SWIG;
 use vars qw($VERSION);
 use Parse::Pidl::Samba4 qw(DeclLong);
 use Parse::Pidl::Typelist qw(mapType);
+use Parse::Pidl::Util qw(has_property);
 $VERSION = '0.01';
 
 use strict;
@@ -25,30 +26,35 @@ sub pidl($)
 sub indent() { $tabs.="\t"; }
 sub deindent() { $tabs = substr($tabs,0,-1); }
 
+sub IgnoreInterface($$)
+{
+       my ($basename,$if) = @_;
+
+       foreach (@{$if->{TYPES}}) {
+               next unless (has_property($_, "public"));
+               pidl "\%types($_->{NAME});";
+       }
+}
+
 sub ParseInterface($$)
 {
        my ($basename,$if) = @_;
 
-       pidl "\%{";
-       pidl "struct $if->{NAME} {";
-       indent;
-       pidl "struct dcerpc_pipe *pipe;";
-       deindent;
-       pidl "};";
-       pidl "%}";
+       pidl "\%inline {";
+       pidl "struct $if->{NAME} { struct dcerpc_pipe *pipe; };";
+       pidl "}";
        pidl "";
-
        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 "$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 "status = dcerpc_pipe_connect(mem_ctx, &ret->pipe, binding, &dcerpc_table_$if->{NAME}, cred, event);";
        pidl "if (NT_STATUS_IS_ERR(status)) {";
-       pidl "\tsamba_nt_status_exception(status);";
+       pidl "\tntstatus_exception(status);";
        pidl "\treturn NULL;";
        pidl "}";
        pidl "";
@@ -75,21 +81,38 @@ sub ParseInterface($$)
                pidl "{";
                indent;
                pidl "struct $fn->{NAME} r;";
-               my $assign = "";
-               if (defined($fn->{RETURN_TYPE})) {
-                       pidl mapType($fn->{RETURN_TYPE}) . " ret;";
-                       $assign = "ret = ";
-               }
+               pidl "NTSTATUS status;";
                pidl "";
                pidl "/* Fill r structure */";
-               pidl "/* FIXME */";
+
+               foreach (@{$fn->{ELEMENTS}}) {
+                       if (grep(/in/, @{$_->{DIRECTION}})) {
+                               pidl "r.in.$_->{NAME} = $_->{NAME};";
+                       } 
+               }
+
                pidl "";
-               pidl $assign."dcerpc_$fn->{NAME}(self->pipe, mem_ctx, &r);";
+               pidl "status = dcerpc_$fn->{NAME}(self->pipe, mem_ctx, &r);";
+               pidl "if (NT_STATUS_IS_ERR(status)) {";
+               pidl "\tntstatus_exception(status);";
+               if (defined($fn->{RETURN_TYPE})) {
+                       pidl "\treturn r.out.result;";
+               } else {
+                       pidl "\treturn;";
+               }
+               pidl "}";
                pidl "";
                pidl "/* Set out arguments */";
-               pidl "/* FIXME */";
+               foreach (@{$fn->{ELEMENTS}}) {
+                       next unless (grep(/out/, @{$_->{DIRECTION}}));
+
+                       pidl ("/* FIXME: $_->{NAME} [out] argument is not a pointer */") if ($_->{LEVELS}[0]->{TYPE} ne "POINTER");
+
+                       pidl "*$_->{NAME} = *r.out.$_->{NAME};";
+               }
+
                if (defined($fn->{RETURN_TYPE})) {
-                       pidl "return ret;";
+                       pidl "return r.out.result;";
                }
                deindent;
                pidl "}";
@@ -97,7 +120,7 @@ sub ParseInterface($$)
        }
 
        deindent();
-       pidl "}";
+       pidl "};";
        pidl "";
 
        foreach (@{$if->{TYPES}}) {
@@ -121,10 +144,23 @@ sub Parse($$$$)
 
        pidl "\%{";
        pidl "#include \"includes.h\"";
+       pidl "#include \"auth/credentials/credentials.h\"";
        pidl "#include \"$header\"";
+       pidl "#include \"$gen_header\"";
        pidl "%}";
-       pidl "\%include \"samba.i\"";
-       pidl "\%include \"$gen_header\"";
+       pidl "\%import \"samba.i\"";
+       pidl "";
+       pidl "\%inline {";
+       pidl "void ntstatus_exception(NTSTATUS status)"; 
+       pidl "{";
+       pidl "\t/* FIXME */";
+       pidl "}";
+       pidl "}";
+       pidl "";
+       foreach (@$ndr) {
+               IgnoreInterface($basename, $_) if ($_->{TYPE} eq "INTERFACE");
+       }
+       pidl "";
 
        pidl "";