File: node44.html

package info (click to toggle)
babel 0.10.2-1
  • links: PTS
  • area: contrib
  • in suites: sarge
  • size: 43,932 kB
  • ctags: 29,707
  • sloc: java: 74,695; ansic: 73,142; cpp: 40,649; sh: 18,411; f90: 10,062; fortran: 6,727; python: 6,406; makefile: 3,866; xml: 118; perl: 48
file content (248 lines) | stat: -rw-r--r-- 9,608 bytes parent folder | download | duplicates (2)
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<!--Converted with LaTeX2HTML 2002-2-1 (1.70)
original version by:  Nikos Drakos, CBLU, University of Leeds
* revised and updated by:  Marcus Hennecke, Ross Moore, Herb Swan
* with significant contributions from:
  Jens Lippmann, Marek Rouchal, Martin Wilck and others -->
<HTML>
<HEAD>
<TITLE>Writing the Implementation</TITLE>
<META NAME="description" CONTENT="Writing the Implementation">
<META NAME="keywords" CONTENT="users_guide">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">

<META NAME="Generator" CONTENT="LaTeX2HTML v2002-2-1">
<META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css">

<LINK REL="STYLESHEET" HREF="users_guide.css">

<LINK REL="next" HREF="node45.html">
<LINK REL="previous" HREF="node43.html">
<LINK REL="up" HREF="node41.html">
<LINK REL="next" HREF="node45.html">
</HEAD>

<BODY >

<DIV CLASS="navigation"><!--Navigation Panel-->
<A NAME="tex2html1227"
  HREF="node45.html">
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next.png"></A> 
<A NAME="tex2html1221"
  HREF="node41.html">
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up.png"></A> 
<A NAME="tex2html1215"
  HREF="node43.html">
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="prev.png"></A> 
<A NAME="tex2html1223"
  HREF="node14.html">
<IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents.png"></A> 
<A NAME="tex2html1225"
  HREF="node317.html">
<IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index.png"></A> 
<BR>
<B> Next:</B> <A NAME="tex2html1228"
  HREF="node45.html">Writing the Client</A>
<B> Up:</B> <A NAME="tex2html1222"
  HREF="node41.html">Hello World Tutorial</A>
<B> Previous:</B> <A NAME="tex2html1216"
  HREF="node43.html">Writing the SIDL File</A>
 &nbsp; <B>  <A NAME="tex2html1224"
  HREF="node14.html">Contents</A></B> 
 &nbsp; <B>  <A NAME="tex2html1226"
  HREF="node317.html">Index</A></B> 
<BR>
<BR></DIV>
<!--End of Navigation Panel-->

<H1><A NAME="SECTION02330000000000000000"></A><A NAME="1514"></A>
<BR>
Writing the Implementation
</H1>

<P>
We will write the implementation in the lib/ subdirectory of hello/.  
The first step is to run the Babel shell script to generate the library 
implementation code for the SIDL file.<A NAME="1515"></A> 
We will implement the library in C++.  
The simplified command to generate the Babel library code (assuming Babel is in 
your PATH) is <A NAME="tex2html23"
  HREF="footnode.html#foot1580"><SUP><SPAN CLASS="arabic">5</SPAN>.<SPAN CLASS="arabic">1</SPAN></SUP></A>: 

<P>
<BLOCKQUOTE>
<TT> <TT>%</TT> <TT><B>babel -sC++ -olib ../hello.sidl</B></TT>
<BR>
</TT></BLOCKQUOTE>
<P>
In this Babel command, the ``<TT>-sC++</TT>'' flag, or its long form 
``<TT>-server=C++</TT>'', indicates that we wish to generate C++ bindings
for an implementation<A NAME="tex2html24"
  HREF="footnode.html#foot1581"><SUP><SPAN CLASS="arabic">5</SPAN>.<SPAN CLASS="arabic">2</SPAN></SUP></A>.  The ``<TT>-olib</TT>''
flag, or its long form ``<TT>-output-dir=lib</TT>'', defines the root
directory of where the generated code should be placed.  

<P>
This command will generate a large number of C and C++ header 
and source files.  It is often surprising to newcomers just how
much code is generated by Babel. Rest assured, each file
has a purpose and there is a lot of important things being
done as efficiently as possible under the hood.

<P>
Files are named after the fully-qualified
class-name.  For instance, a package <TT><I CLASS="slanted">Hello</I></TT> and class
<TT><I CLASS="slanted">World</I></TT> would have a fully qualified name (in SIDL) as
<TT><I CLASS="slanted">Hello.World</I></TT>.  This corresponds to file names
beginning with <TT>Hello_World</TT><A NAME="tex2html25"
  HREF="footnode.html#foot1529"><SUP><SPAN CLASS="arabic">5</SPAN>.<SPAN CLASS="arabic">3</SPAN></SUP></A>.  For each class, 
there will be files with <TT>_IOR</TT>, 
<TT>_skel</TT>,  <TT>_stub</TT>, or <TT>_impl</TT> appended after the
fully qualified name.
<SPAN  CLASS="textit">IOR files</SPAN><A NAME="1535"></A> are always in ANSI C (source and headers), 
containing Babel's Intermediate Object Representation.
<SPAN  CLASS="textit">Impl files</SPAN><A NAME="1537"></A> contain the actual implementation, and 
can be in any language that Babel supports, in this 
case, they're C++ files.  Impl files are the only files
that a developer need look at or touch after generating
code from the SIDL source.  <SPAN  CLASS="textit">Skel files</SPAN><A NAME="1539"></A> perform translations
between the IORs and the Impls.  In some cases (like Fortran)
the Skels are split into a few files: some in C, some in 
the Impl language.  In the case of C++, the Skels are pure
C++ code wrapped in <TT>extern "C" {}</TT> declarations.
If the file is neither an IOR, Skel, nor Impl, then it
is likely a <SPAN  CLASS="textit">Stub</SPAN><A NAME="1542"></A>.  Stubs are the proxy classes
of Babel, performing translations
between the caller language and the IOR.  
Finally, the file babel.make is a Makefile fragment that will 
simplify writing the Makefile necessary to compile the library.  
You may ignore the babel.make file if you wish.  

<P>
The only files that should be modified by the developer
(that's you since you're implementing Hello World)
are the ``Impls'', which are in this case
files ending with <TT>_Impl.hh</TT> or <TT>_Impl.cc</TT>
Babel generates these implementation files as a starting 
point for developers.  
These files will contain the implementation of the Hello library.
Every implementation file contains many pairs of comment ``splicer''
lines<A NAME="1545"></A> 
such as the following:

<P>
<BR>
<PRE  CLASS="verbatim">std::string
Hello::World_impl::getMsg()
throw ()
{
    // DO-NOT-DELETE splicer.begin(Hello.World.getMsg)
    // Insert code here...
    // DO-NOT-DELETE splicer.end(Hello.World.getMsg)
}
</PRE></td></tr></table></blockquote>
<P>
Any modifications between these splicer lines will be
saved after subsequent invocations of the Babel tool.  
Any changes outside the splicer lines will be lost.  
This splicer feature was developed to make it
easy to do incremental development using Babel.
By keeping your edits within the splicer blocks, 
you can add new methods to the hello.sidl file
and rerun Babel without the loss of your previous 
method implementations.  You shouldn't ever need to edit the file
outside the splicer blocks.

<P>
For our hello application, the implementation is trivial.  
Add the following return statement between the splicer lines 
in the <TT>lib/Hello_World_Impl.cc</TT> file:

<P>
<BR>
<PRE  CLASS="verbatim">std::string
Hello::World_impl::getMsg()
throw ()
{
    // DO-NOT-DELETE splicer.begin(Hello.World.getMsg)
    return std::string("Hello World!");
    // DO-NOT-DELETE splicer.end(Hello.World.getMsg)
}
</PRE></td></tr></table></blockquote>
<P>
To keep the Makefile<A NAME="1549"></A> simple, we will use some GNU Make features. This
Makefile may not work with other make implementations. The GNU gcc and
g++ compilers are used in this example.  The following Makefile in the
lib/ subdirectory will compile the library files and create a shared
library named <TT>libhello.so</TT>:
<A NAME="1551"></A>

<P>
<BR>
<PRE  CLASS="verbatim">.cc.o:
    g++ -fPIC -I$(HOME)/babel/include -c $&lt;
.c.o:
    gcc -fPIC -I$(HOME)/babel/include -c $&lt; 

include babel.make
OBJS = ${IMPLSRCS:.cc=.o} ${IORSRCS:.c=.o} \
       ${SKELSRCS:.cc=.o} ${STUBSRCS:.cc=.o}

libhello.so: ${OBJS}
    g++ -shared -o $@ ${OBJS}

clean:
    ${RM} *.o libhello.so
</PRE></td></tr></table></blockquote>
<P>
You do not necessarily need to create a shared library for this example; 
you may generate a standard static library (e.g., libhello.a).  
However, in general, you must generate a shared library if you will be 
calling your library from Python or Java.  
To create the shared library archive libhello.so, simply execute make as
follows: 

<P>
<BLOCKQUOTE>
<TT> <TT>%</TT> <TT><B>cd lib/</B></TT>
<BR><TT>%</TT> <TT><B>make libhello.so</B></TT>
<BR>
</TT></BLOCKQUOTE>
<P>

<DIV CLASS="navigation"><HR>
<!--Navigation Panel-->
<A NAME="tex2html1227"
  HREF="node45.html">
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next.png"></A> 
<A NAME="tex2html1221"
  HREF="node41.html">
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up.png"></A> 
<A NAME="tex2html1215"
  HREF="node43.html">
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="prev.png"></A> 
<A NAME="tex2html1223"
  HREF="node14.html">
<IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents.png"></A> 
<A NAME="tex2html1225"
  HREF="node317.html">
<IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index.png"></A> 
<BR>
<B> Next:</B> <A NAME="tex2html1228"
  HREF="node45.html">Writing the Client</A>
<B> Up:</B> <A NAME="tex2html1222"
  HREF="node41.html">Hello World Tutorial</A>
<B> Previous:</B> <A NAME="tex2html1216"
  HREF="node43.html">Writing the SIDL File</A>
 &nbsp; <B>  <A NAME="tex2html1224"
  HREF="node14.html">Contents</A></B> 
 &nbsp; <B>  <A NAME="tex2html1226"
  HREF="node317.html">Index</A></B> </DIV>
<!--End of Navigation Panel-->
<ADDRESS>
<br><br>babel-0.10.2<br>users_guide Last Modified 2005-03-23<br><br><a href="http://www.llnl.gov/CASC/components">http://www.llnl.gov/CASC/components</a><br><a href="mailto:components@llnl.gov">components@llnl.gov</a>
</ADDRESS>
</BODY>
</HTML>