#!/usr/bin/perl

use strict;
use warnings;

use CORBA::IDL      2.60;
use CORBA::Perl;
# visitors
use CORBA::IDL::RepositoryIdVisitor;
use CORBA::Perl::NameVisitor;
use CORBA::Perl::LiteralVisitor;
use CORBA::Perl::ClientVisitor;

my $parser = CORBA::IDL::ParserFactory::create('3.0');
$parser->getopts('hi:J:vx');
if ($parser->YYData->{opt_v}) {
    print "CORBA::Perl $CORBA::Perl::VERSION\n";
    print "CORBA::IDL $CORBA::IDL::VERSION\n";
    print "IDL $CORBA::IDL::Parser::IDL_VERSION\n";
    print "$0\n";
    print "Perl $] on $^O\n";
    exit;
}
if ($parser->YYData->{opt_h}) {
    use Pod::Usage;
    pod2usage(-verbose => 1);
}

my $cflags = '-D__idl2pmrpc';
if ($CORBA::IDL::Parser::IDL_VERSION lt '3.0') {
    $cflags .= ' -D_PRE_3_0_COMPILER_';
}
my $preprocessor;
if ($^O eq 'MSWin32') {
    $preprocessor = 'cpp -C ' . $cflags;
#    $preprocessor = 'CL /E /C /nologo ' . $cflags;      # Microsoft VC
}
else {
    $preprocessor = 'cpp -C ' . $cflags;
}
$parser->Configure(
        'preprocessor'          => $preprocessor,
        'verbose_error'         => 1,   # 0, 1
        'verbose_warning'       => 1,   # 0, 1
        'verbose_info'          => 1,   # 0, 1
        'verbose_deprecated'    => 0,   # 0, 1 (concerns only version '2.4' and upper)
#        'collision_allowed'     => 1,
);
$parser->Run(@ARGV);
$parser->DisplayStatus();
my $root = $parser->getRoot();
if (defined $root) {
    $root->visit(new CORBA::IDL::RepositoryIdVisitor($parser));
    if ($parser->YYData->{opt_x}) {
        $parser->Export();
    }
    $root->visit(new CORBA::Perl::NameVisitor($parser, $parser->YYData->{opt_J}));
    $root->visit(new CORBA::Perl::LiteralVisitor($parser));
    $root->visit(new CORBA::Perl::ClientVisitor($parser, $parser->YYData->{opt_J}));
}

__END__

=head1 NAME

idl2pmrpc - IDL compiler to Perl RPC-GIOP

=head1 SYNOPSYS

idl2pmrpc [options] I<spec>.idl

=head1 OPTIONS

All options are forwarded to C preprocessor, except -h -i -J -v -x.

With the GNU C Compatible Compiler Processor, useful options are :

=over 8

=item B<-D> I<name>

=item B<-D> I<name>=I<definition>

=item B<-I> I<directory>

=item B<-I->

=item B<-nostdinc>

=back

Specific options :

=over 8

=item B<-h>

Display help.

=item B<-i> I<directory>

Specify a path for import (only for version 3.0).

=item B<-J> I<directory>

Specify a path for Perl package importation (use I<package>;).

=item B<-v>

Display version.

=item B<-x>

Enable export (only for version 3.0).

=back

=head1 DESCRIPTION

B<idl2pmrpc> parses the given input file (IDL) and generates :

=over 4

=item *
a Perl client stub & server skeleton I<spec>.pm for RPC-GIOP

=back

B<idl2pmrpc> is a Perl OO application what uses the visitor design pattern.
The parser is generated by Parse::Yapp.

B<idl2pmrpc> needs a B<cpp> executable.

CORBA Specifications, including IDL (Interface Definition Language) are
available on E<lt>http://www.omg.org/E<gt>.

CORBA mapping for Perl [mapping.pod - Draft 1, 7 October 1999] comes with the package
CORBA::MICO or CORBA::ORBit.

=head1 TUTORIAL

=head2 RPC-GIOP

RPC-GIOP is an another RPC (Remote Procedure Call) mecanism.

RPC-GIOP reuses a subset of CORBA GIOP messages, but don't deal with
any CORBA ORB (Object Request Broker). RPC-GIOP reuses the CORBA CDR
(Common Data Representation) transfer syntax.

An interface (a set of operations) is defined with CORBA IDL
(Interface Definition Language).

RPC-GIOP has a lot of common properties with CORBA GIOP :

=over 8

=item *
needs a reliable transport layer (typically TCP/IP)

=item *
uses a binary format (CDR)

=item *
is interoperable (byte-order)

=back

=head2 EXAMPLE 1

Use F<rpc1> as current directory.

The file F<calculator.idl> describes the interface of a simple calculator.

First, run :

    idl2pmrpc calculator.idl

Second, run the server (see srv_calc.pm that contains the implementation) :

    perl server.pl

Third, run the client (Tkinter based)

    perl client.pl

=head1 SEE ALSO

cpp, idl2html, idl2pm

=head1 COPYRIGHT

(c) 2004-2008 FranE<ccedil>ois PERRAD, France. All rights reserved.

This program and all CORBA::Perl modules are distributed
under the terms of the Artistic Licence.

=head1 AUTHOR

FranE<ccedil>ois PERRAD, francois.perrad@gadz.org

=cut

