1 ###################################################
2 # Samba4 parser generator for swig wrappers
3 # Copyright tpot@samba.org 2004,2005
4 # Copyright jelmer@samba.org 2006
5 # released under the GNU GPL
7 package Parse::Pidl::Samba4::SWIG;
10 use Parse::Pidl::Samba4 qw(DeclLong);
11 use Parse::Pidl::Typelist qw(mapTypeName);
12 use Parse::Pidl::Util qw(has_property);
23 $ret .= $tabs. $p . "\n";
26 sub indent() { $tabs.=" "; }
27 sub deindent() { $tabs = substr($tabs,0,-2); }
29 sub IgnoreInterface($$)
31 my ($basename,$if) = @_;
33 foreach (@{$if->{TYPES}}) {
34 next unless (has_property($_, "public"));
35 pidl "\%types($_->{NAME});";
39 sub GenerateResultTypemap($)
42 pidl "%typemap(in,numinputs=0) $name*result ($name tmp) {";
48 pidl "%typemap(argout) $name*result {";
50 pidl "\$result = SWIG_NewPointerObj(*\$1, \$1_descriptor, 0);";
55 sub ParseInterface($$)
57 my ($basename,$if) = @_;
60 pidl "typedef struct $if->{NAME} { struct dcerpc_pipe *pipe; } $if->{NAME};";
63 pidl "%talloctype($if->{NAME});";
65 pidl "\%extend $if->{NAME} {";
67 pidl "$if->{NAME} () {";
69 pidl "return talloc(NULL, struct $if->{NAME});";
73 pidl "NTSTATUS connect (const char *binding, struct cli_credentials *cred, struct event_context *event)";
76 pidl "return dcerpc_pipe_connect(\$self, &\$self->pipe, binding, &ndr_table_$if->{NAME}, cred, event);";
81 foreach my $fn (@{$if->{FUNCTIONS}}) {
82 pidl "/* $fn->{NAME} */";
84 foreach (@{$fn->{ELEMENTS}}) {
85 $args .= DeclLong($_) . ", ";
87 my $name = $fn->{NAME};
88 $name =~ s/^$if->{NAME}_//g;
89 $name =~ s/^$basename\_//g;
90 $args .= "TALLOC_CTX *mem_ctx, " . mapTypeName($fn->{RETURN_TYPE}) . " *result";
91 pidl "NTSTATUS $name($args)";
94 pidl "struct $fn->{NAME} r;";
95 pidl "NTSTATUS status;";
97 pidl "/* Fill r structure */";
99 foreach (@{$fn->{ELEMENTS}}) {
100 if (grep(/in/, @{$_->{DIRECTION}})) {
101 pidl "r.in.$_->{NAME} = $_->{NAME};";
106 pidl "status = dcerpc_$fn->{NAME}(\$self->pipe, mem_ctx, &r);";
107 pidl "if (NT_STATUS_IS_ERR(status)) {";
108 indent; pidl "return status;"; deindent;
111 pidl "/* Set out arguments */";
112 foreach (@{$fn->{ELEMENTS}}) {
113 next unless (grep(/out/, @{$_->{DIRECTION}}));
115 pidl ("/* FIXME: $_->{NAME} [out] argument is not a pointer */") if ($_->{LEVELS}[0]->{TYPE} ne "POINTER");
117 pidl "*$_->{NAME} = *r.out.$_->{NAME};";
120 if (defined($fn->{RETURN_TYPE})) {
121 pidl "*result = r.out.result;";
123 pidl "return NT_STATUS_OK;";
133 foreach (@{$if->{TYPES}}) {
134 pidl "/* $_->{NAME} */";
142 my($ndr,$basename,$header,$gen_header) = @_;
146 pidl "/* This file is autogenerated by pidl. DO NOT EDIT */";
148 pidl "\%module $basename";
153 pidl "#include \"includes.h\"";
154 pidl "#include \"$header\"";
155 pidl "#include \"$gen_header\"";
157 pidl "\%import \"../rpc/dcerpc.i\"";
158 pidl "\%import \"../../libcli/util/errors.i\"";
159 pidl "\%import \"../../lib/talloc/talloc.i\"";
162 IgnoreInterface($basename, $_) if ($_->{TYPE} eq "INTERFACE");
169 ParseInterface($basename, $_) if ($_->{TYPE} eq "INTERFACE");
171 #FIXME: Foreach ref pointer, set NONNULL
172 #FIXME: Foreach unique/full pointer, set MAYBENULL
173 #FIXME: Foreach [out] parameter, set OUTPARAM