summaryrefslogtreecommitdiff
path: root/source4/pidl/lib/Parse/Pidl/ODL.pm
blob: 082deaea1d7e7b09e36003c6fc322b3b9fc351ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
##########################################
# Converts ODL stuctures to IDL structures
# (C) 2004-2005 Jelmer Vernooij <jelmer@samba.org>

package Parse::Pidl::ODL;

use Parse::Pidl::Util qw(has_property);
use Parse::Pidl::Typelist qw(hasType getType);
use strict;

use vars qw($VERSION);
$VERSION = '0.01';

#####################################################################
# find an interface in an array of interfaces
sub get_interface($$)
{
	my($if) = shift;
	my($n) = shift;

	foreach(@{$if}) {
		if($_->{NAME} eq $n) { return $_; }
	}
	
	return 0;
}

sub FunctionAddObjArgs($)
{
	my $e = shift;
	
	unshift(@{$e->{ELEMENTS}}, {
		'NAME' => 'ORPCthis',
		'POINTERS' => 0,
		'PROPERTIES' => { 'in' => '1' },
		'TYPE' => 'ORPCTHIS'
	});
	unshift(@{$e->{ELEMENTS}}, {
		'NAME' => 'ORPCthat',
		'POINTERS' => 0,
		'PROPERTIES' => { 'out' => '1' },
		'TYPE' => 'ORPCTHAT'
	});
}

sub ReplaceInterfacePointers($)
{
	my $e = shift;

	foreach my $x (@{$e->{ELEMENTS}}) {
		next unless (hasType($x->{TYPE}));
		next unless getType($x->{TYPE})->{DATA}->{TYPE} eq "INTERFACE";
		
		$x->{TYPE} = "MInterfacePointer";
	}
}

# Add ORPC specific bits to an interface.
sub ODL2IDL($)
{
	my $odl = shift;
	
	foreach my $x (@{$odl}) {
		# Add [in] ORPCTHIS *this, [out] ORPCTHAT *that
		# and replace interfacepointers with MInterfacePointer
		# for 'object' interfaces
		if (has_property($x, "object")) {
			foreach my $e (@{$x->{DATA}}) {
				($e->{TYPE} eq "FUNCTION") && FunctionAddObjArgs($e);
				ReplaceInterfacePointers($e);
			}
			# Object interfaces use ORPC
			my @depends = ();
			if(has_property($x, "depends")) {
				@depends = split /,/, $x->{PROPERTIES}->{depends};
			}
			push @depends, "orpc";
			$x->{PROPERTIES}->{depends} = join(',',@depends);
		}

		if ($x->{BASE}) {
			my $base = get_interface($odl, $x->{BASE});

			foreach my $fn (reverse @{$base->{DATA}}) {
				next unless ($fn->{TYPE} eq "FUNCTION");
				unshift (@{$x->{DATA}}, $fn);
				push (@{$x->{INHERITED_FUNCTIONS}}, $fn->{NAME});
			}
		}
	}

	return $odl;
}

1;