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
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- This document was generated using DocBuilder 3.3.3 -->
<HTML>
<HEAD>
<TITLE>The C Client Back-end</TITLE>
<SCRIPT type="text/javascript" src="../../../../doc/erlresolvelinks.js">
</SCRIPT>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#FF00FF"
ALINK="#FF0000">
<CENTER>
<A HREF="http://www.erlang.se"><IMG BORDER=0 ALT="[Ericsson AB]" SRC="min_head.gif"></A>
</CENTER>
<A NAME="7"><!-- Empty --></A>
<H2>7 The C Client Back-end</H2>
<A NAME="7.1"><!-- Empty --></A>
<H3>7.1 Introduction</H3>
<P> With the option <CODE>{be, c_client}</CODE> the IDL Compiler generates
C client stubs according to the IDL to C mapping, on top of the
Erlang distribution and gen_server protocols.
<P> The developer has to write additional code, that together with
the generated C client stubs, form a hidden Erlang node. That
additional code uses <CODE>erl_interface</CODE> functions for defining
the hidden node, and for establishing connections to other
Erlang nodes.
<A NAME="7.2"><!-- Empty --></A>
<H3>7.2 Generated Stub Files</H3>
<P> The generated stub files are:
<P>
<UL>
<LI>
For each IDL interface, a C source file, the name of which
is <CODE><Scoped Interface Name>.c</CODE>. Each operation of the
IDL interface is mapped to a C function (with scoped name)
in that file;
<BR>
</LI>
<LI>
C source files that contain functions for type conversion,
memory allocation, and data encoding/decoding;
<BR>
</LI>
<LI>
C header files that contain function prototypes and type
definitions.
<BR>
</LI>
</UL>
<P> All C functions are exported (i.e. not declared static).
<A NAME="7.3"><!-- Empty --></A>
<H3>7.3 C Interface Functions</H3>
<P> For each IDL operation a C interface function is
generated, the prototype of which is:
<P> <CODE><Return Value> <Scoped Function Name>(<Interface Object>
oe_obj, <Parameters>, CORBA_Environment *oe_env);</CODE>
<P>where
<P>
<UL>
<LI>
<CODE><Return Value></CODE> is the value to be returned as defined
by the IDL specification;
<BR>
</LI>
<LI>
<CODE><Interface Object> oe_obj</CODE> is the client interface
object;
<BR>
</LI>
<LI>
<CODE><Parameters></CODE> is a list of parameters of the
operation, defined in the same order as defined by the IDL
specdication;
<BR>
</LI>
<LI>
<CODE>CORBA_Environment *oe_env</CODE> is a pointer to the current
client environment. It contains the current file descriptor,
the current input and output buffers, etc. For details see
<A HREF="ch_c_corba_env.html#corbaenv">CORBA_Environment
C Structure</A>.
<BR>
</LI>
</UL>
<A NAME="7.4"><!-- Empty --></A>
<H3>7.4 Generating, Compiling and Linking</H3>
<P> To generate the C client stubs type the following in an
appropriate shell:
<P>
<CODE>erlc -I ICROOT/include "+{be, c_client}" File.idl</CODE>,
<P> where <CODE>ICROOT</CODE> is the root of the IC application. The
<CODE>-I ICROOT/include</CODE> is only needed if <CODE>File.idl</CODE>
refers to <CODE>erlang.idl</CODE>.
<P> When compiling a generated C stub file, the directories
<CODE>ICROOT/include</CODE> and <CODE>EICROOT/include</CODE>, have to be
specified as include directories, where <CODE>EIROOT</CODE> is the
root directory of the Erl_interface application.
<P> When linking object files the <CODE>EIROOT/lib</CODE> and
<CODE>ICROOT/priv/lib</CODE> directories have to be specified.
<A NAME="7.5"><!-- Empty --></A>
<H3>7.5 An Example</H3>
<P> In this example the IDL specification file "random.idl" is used
for generating C client stubs (the file is contained in the IC
<CODE>/examples/c-client</CODE> directory):
<PRE>
module rmod {
interface random {
double produce();
oneway void init(in long seed1, in long seed2, in long seed3);
};
};
</PRE>
<P>Generate the C client stubs:
<PRE>
erlc '+{be, c_client}' random.idl
Erlang IDL compiler version X.Y.Z
</PRE>
<P> Six files are generated.
<P>Compile the C client stubs:
<P> Please read the <CODE>ReadMe</CODE> file att the
<CODE>examples/c-client</CODE> directory
<P>In the same
directory you can find all the code for this example.
<P> In particular you will find the <CODE>client.c</CODE> file that contains
all the additional code that must be written to obtain a complete
client.
<P> In the <CODE>examples/c-client</CODE> directory you will also find
source code for an Erlang server, which can be used for testing
the C client.
<CENTER>
<HR>
<SMALL>
Copyright © 1991-2006
<A HREF="http://www.erlang.se">Ericsson AB</A><BR>
</SMALL>
</CENTER>
</BODY>
</HTML>
|