| 1 |
# COM Header generation |
| 2 |
# (C) 2005 Jelmer Vernooij <[email protected]> |
| 3 |
|
| 4 |
package Parse::Pidl::Samba4::COM::Header; |
| 5 |
|
| 6 |
use Parse::Pidl::Typelist qw(mapTypeName); |
| 7 |
use Parse::Pidl::Util qw(has_property is_constant); |
| 8 |
|
| 9 |
use vars qw($VERSION); |
| 10 |
$VERSION = '0.01'; |
| 11 |
|
| 12 |
use strict; |
| 13 |
use warnings; |
| 14 |
|
| 15 |
sub GetArgumentProtoList($) |
| 16 |
{ |
| 17 |
my $f = shift; |
| 18 |
my $res = ""; |
| 19 |
|
| 20 |
foreach my $a (@{$f->{ELEMENTS}}) { |
| 21 |
|
| 22 |
$res .= ", " . mapTypeName($a->{TYPE}) . " "; |
| 23 |
|
| 24 |
my $l = $a->{POINTERS}; |
| 25 |
$l-- if (Parse::Pidl::Typelist::scalar_is_reference($a->{TYPE})); |
| 26 |
foreach my $i (1..$l) { |
| 27 |
$res .= "*"; |
| 28 |
} |
| 29 |
|
| 30 |
if (defined $a->{ARRAY_LEN}[0] && !is_constant($a->{ARRAY_LEN}[0]) && |
| 31 |
!$a->{POINTERS}) { |
| 32 |
$res .= "*"; |
| 33 |
} |
| 34 |
$res .= $a->{NAME}; |
| 35 |
if (defined $a->{ARRAY_LEN}[0] && is_constant($a->{ARRAY_LEN}[0])) { |
| 36 |
$res .= "[$a->{ARRAY_LEN}[0]]"; |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
return $res; |
| 41 |
} |
| 42 |
|
| 43 |
sub GetArgumentList($) |
| 44 |
{ |
| 45 |
my $f = shift; |
| 46 |
my $res = ""; |
| 47 |
|
| 48 |
foreach (@{$f->{ELEMENTS}}) { $res .= ", $_->{NAME}"; } |
| 49 |
|
| 50 |
return $res; |
| 51 |
} |
| 52 |
|
| 53 |
##################################################################### |
| 54 |
# generate vtable structure for COM interface |
| 55 |
sub HeaderVTable($) |
| 56 |
{ |
| 57 |
my $interface = shift; |
| 58 |
my $res; |
| 59 |
$res .= "#define " . uc($interface->{NAME}) . "_METHODS \\\n"; |
| 60 |
if (defined($interface->{BASE})) { |
| 61 |
$res .= "\t" . uc($interface->{BASE} . "_METHODS") . "\\\n"; |
| 62 |
} |
| 63 |
|
| 64 |
my $data = $interface->{DATA}; |
| 65 |
foreach my $d (@{$data}) { |
| 66 |
$res .= "\t" . mapTypeName($d->{RETURN_TYPE}) . " (*$d->{NAME}) (struct $interface->{NAME} *d, TALLOC_CTX *mem_ctx" . GetArgumentProtoList($d) . ");\\\n" if ($d->{TYPE} eq "FUNCTION"); |
| 67 |
} |
| 68 |
$res .= "\n"; |
| 69 |
$res .= "struct $interface->{NAME}_vtable {\n"; |
| 70 |
$res .= "\tstruct GUID iid;\n"; |
| 71 |
$res .= "\t" . uc($interface->{NAME}) . "_METHODS\n"; |
| 72 |
$res .= "};\n\n"; |
| 73 |
|
| 74 |
return $res; |
| 75 |
} |
| 76 |
|
| 77 |
sub ParseInterface($) |
| 78 |
{ |
| 79 |
my $if = shift; |
| 80 |
my $res; |
| 81 |
|
| 82 |
$res .= "\n#ifndef _$if->{NAME}_\n"; |
| 83 |
$res .= "#define _$if->{NAME}_\n"; |
| 84 |
|
| 85 |
$res .="\n\n/* $if->{NAME} */\n"; |
| 86 |
|
| 87 |
$res .="#define COM_" . uc($if->{NAME}) . "_UUID $if->{PROPERTIES}->{uuid}\n\n"; |
| 88 |
|
| 89 |
$res .="struct $if->{NAME}_vtable;\n\n"; |
| 90 |
|
| 91 |
$res .="struct $if->{NAME} { |
| 92 |
struct OBJREF obj; |
| 93 |
struct com_context *ctx; |
| 94 |
struct $if->{NAME}_vtable *vtable; |
| 95 |
void *object_data; |
| 96 |
};\n\n"; |
| 97 |
|
| 98 |
$res.=HeaderVTable($if); |
| 99 |
|
| 100 |
foreach my $d (@{$if->{DATA}}) { |
| 101 |
next if ($d->{TYPE} ne "FUNCTION"); |
| 102 |
|
| 103 |
$res .= "#define $if->{NAME}_$d->{NAME}(interface, mem_ctx" . GetArgumentList($d) . ") "; |
| 104 |
|
| 105 |
$res .= "((interface)->vtable->$d->{NAME}(interface, mem_ctx" . GetArgumentList($d) . "))"; |
| 106 |
|
| 107 |
$res .="\n"; |
| 108 |
} |
| 109 |
|
| 110 |
$res .= "#endif\n"; |
| 111 |
|
| 112 |
return $res; |
| 113 |
} |
| 114 |
|
| 115 |
sub ParseCoClass($) |
| 116 |
{ |
| 117 |
my ($c) = @_; |
| 118 |
my $res = ""; |
| 119 |
$res .= "#define CLSID_" . uc($c->{NAME}) . " $c->{PROPERTIES}->{uuid}\n"; |
| 120 |
if (has_property($c, "progid")) { |
| 121 |
$res .= "#define PROGID_" . uc($c->{NAME}) . " $c->{PROPERTIES}->{progid}\n"; |
| 122 |
} |
| 123 |
$res .= "\n"; |
| 124 |
return $res; |
| 125 |
} |
| 126 |
|
| 127 |
sub Parse($$) |
| 128 |
{ |
| 129 |
my ($idl,$ndr_header) = @_; |
| 130 |
my $res = ""; |
| 131 |
my $has_obj = 0; |
| 132 |
|
| 133 |
$res .= "#include \"librpc/gen_ndr/orpc.h\"\n" . |
| 134 |
"#include \"$ndr_header\"\n\n"; |
| 135 |
|
| 136 |
foreach (@{$idl}) |
| 137 |
{ |
| 138 |
if ($_->{TYPE} eq "INTERFACE" && has_property($_, "object")) { |
| 139 |
$res .="struct $_->{NAME};\n"; |
| 140 |
$has_obj = 1; |
| 141 |
} |
| 142 |
} |
| 143 |
|
| 144 |
foreach (@{$idl}) |
| 145 |
{ |
| 146 |
if ($_->{TYPE} eq "INTERFACE" && has_property($_, "object")) { |
| 147 |
$res.=ParseInterface($_); |
| 148 |
$has_obj = 1; |
| 149 |
} |
| 150 |
|
| 151 |
if ($_->{TYPE} eq "COCLASS") { |
| 152 |
$res.=ParseCoClass($_); |
| 153 |
$has_obj = 1; |
| 154 |
} |
| 155 |
} |
| 156 |
|
| 157 |
return $res if ($has_obj); |
| 158 |
return undef; |
| 159 |
} |
| 160 |
|
| 161 |
1; |