/usr/share/doc/polyorb-doc/html/polyorb_ug/echo-example.html is in polyorb-doc 2.11~20140418-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- This is free software; you can redistribute it and/or modify it under
terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version. This software is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License and
a copy of the GCC Runtime Library Exception along with this program;
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
<http://www.gnu.org/licenses/>. -->
<!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
<head>
<title>PolyORB User’s Guide: echo example</title>
<meta name="description" content="PolyORB User’s Guide: echo example">
<meta name="keywords" content="PolyORB User’s Guide: echo example">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="About-This-Guide.html#About-This-Guide" rel="start" title="About This Guide">
<link href="Index.html#Index" rel="index" title="Index">
<link href="About-This-Guide.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Building-a-CORBA-application-with-PolyORB.html#Building-a-CORBA-application-with-PolyORB" rel="up" title="Building a CORBA application with PolyORB">
<link href="Other-examples.html#Other-examples" rel="next" title="Other examples">
<link href="Building-a-CORBA-application-with-PolyORB.html#Building-a-CORBA-application-with-PolyORB" rel="prev" title="Building a CORBA application with PolyORB">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.indentedblock {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
div.smalllisp {margin-left: 3.2em}
kbd {font-style:oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nocodebreak {white-space:nowrap}
span.nolinebreak {white-space:nowrap}
span.roman {font-family:serif; font-weight:normal}
span.sansserif {font-family:sans-serif; font-weight:normal}
ul.no-bullet {list-style: none}
-->
</style>
</head>
<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
<a name="echo-example"></a>
<div class="header">
<p>
Next: <a href="Other-examples.html#Other-examples" accesskey="n" rel="next">Other examples</a>, Up: <a href="Building-a-CORBA-application-with-PolyORB.html#Building-a-CORBA-application-with-PolyORB" accesskey="u" rel="up">Building a CORBA application with PolyORB</a> [<a href="About-This-Guide.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<a name="echo-example-1"></a>
<h4 class="subsection">6.6.1 <code>echo</code> example</h4>
<p>We consider building a simple “Echo” CORBA server and client. This
application echoes a string. The source code for this example is
located in the <samp>examples/corba/echo</samp> directory in the PolyORB
distribution. This applications uses only basic elements of CORBA.
</p>
<p>To build this application, you need the following pieces of code:
</p>
<ol>
<li> IDL definition of an <code>echo</code> object
</li><li> Implementation code for the <code>echo</code> object
</li><li> Code for client and server nodes
</li></ol>
<a name="IDL-definition-of-an-echo-object"></a>
<h4 class="subsubsection">6.6.1.1 IDL definition of an <code>echo</code> object</h4>
<p>This interface defines an <code>echo</code> object with a unique method
<code>echoString</code>. Per construction, this method returns its argument.
</p>
<div class="smallexample">
<table class="cartouche" border="1"><tr><td>
<pre class="smallexample">
<b>interface</b> Echo {
string echoString (<b>in</b> string Mesg);
};
</pre></td></tr></table>
</div>
<a name="Implementation-code-for-the-echo-object"></a>
<h4 class="subsubsection">6.6.1.2 Implementation code for the <code>echo</code> object</h4>
<p>Package <code>Echo.Impl</code> is an implementation of this interface. This
implementation follows the <em>IDL-to-Ada</em> mapping.
</p>
<div class="smallexample">
<pre class="smallexample">
------------------------------------------------------------------------------
-- --
-- POLYORB COMPONENTS --
-- --
-- E C H O . I M P L --
-- --
-- S p e c --
-- --
-- Copyright (C) 2002-2012, Free Software Foundation, Inc. --
-- --
-- This is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. This software is distributed in the hope that it will be useful, --
-- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- --
-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public --
-- License for more details. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- PolyORB is maintained by AdaCore --
-- (email: sales@adacore.com) --
-- --
------------------------------------------------------------------------------
<b>with</b> CORBA;
<b>with</b> PortableServer;
<b>package</b> Echo.Impl <b>is</b>
-- My own implementation of echo object.
-- This is simply used to define the operations.
<b>type</b> Object <b>is</b> <b>new</b> PortableServer.Servant_Base <b>with</b> <b>null</b> <b>record</b>;
<b>type</b> Object_Acc <b>is</b> <b>access</b> Object;
<b>function</b> EchoString
(Self : <b>access</b> Object;
Mesg : CORBA.String)
<b>return</b> CORBA.String;
<b>end</b> Echo.Impl;
</pre></div>
<div class="smallexample">
<pre class="smallexample">
------------------------------------------------------------------------------
-- --
-- POLYORB COMPONENTS --
-- --
-- E C H O . I M P L --
-- --
-- B o d y --
-- --
-- Copyright (C) 2002-2012, Free Software Foundation, Inc. --
-- --
-- This is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. This software is distributed in the hope that it will be useful, --
-- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- --
-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public --
-- License for more details. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- PolyORB is maintained by AdaCore --
-- (email: sales@adacore.com) --
-- --
------------------------------------------------------------------------------
<b>with</b> Ada.Text_IO;
<b>with</b> Echo.Skel;
<b>pragma</b> Warnings (Off, Echo.Skel);
-- No entity from Echo.Skel is referenced.
<b>package</b> <b>body</b> Echo.Impl <b>is</b>
----------------
-- EchoString --
----------------
<b>function</b> EchoString
(Self : <b>access</b> Object;
Mesg : CORBA.String)
<b>return</b> CORBA.String
<b>is</b>
<b>pragma</b> Warnings (Off);
<b>pragma</b> Unreferenced (Self);
<b>pragma</b> Warnings (On);
S : String := CORBA.To_Standard_String (Mesg);
L : Natural := S'Last;
<b>begin</b>
<b>if</b> S'Length > 13 <b>then</b>
L := S'First + 12;
S (L - 2 .. L) := (<b>others</b> => '.');
<b>end</b> <b>if</b>;
Ada.Text_IO.Put_Line
("Echoing string: « " & S (S'First .. L) & " »");
<b>return</b> Mesg;
<b>end</b> EchoString;
<b>end</b> Echo.Impl;
</pre></div>
<p><i>Note: <code>Echo.Impl</code> body requires a dependency on
<code>Echo.Skel</code> to ensure the elaboration of skeleton code and the
correct setup of PolyORB’s internals.</i>
</p>
<a name="Test-code-for-client-and-server-nodes"></a>
<h4 class="subsubsection">6.6.1.3 Test code for client and server nodes</h4>
<p>Client and server code demonstrate how to make a remote invocation on
a CORBA object, and how to set up an object on a server node.
</p>
<p><em>Note: the dependency on <code>PolyORB.Setup.Client</code> or
<code>PolyORB.Setup.No_Tasking_Server</code> enforces compile-time
configuration, see <a href="Sample-files.html#Sample-files">Sample files</a>.</em>
</p>
<ul>
<li> Client code tests a simple remote invocation on
an object. It is a no-tasking client. A reference to the object is built
from a stringified reference (or <code>IOR</code>), which is passed on command
line.
<div class="smallexample">
<pre class="smallexample">
------------------------------------------------------------------------------
-- --
-- POLYORB COMPONENTS --
-- --
-- C L I E N T --
-- --
-- B o d y --
-- --
-- Copyright (C) 2002-2012, Free Software Foundation, Inc. --
-- --
-- This is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. This software is distributed in the hope that it will be useful, --
-- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- --
-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public --
-- License for more details. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- PolyORB is maintained by AdaCore --
-- (email: sales@adacore.com) --
-- --
------------------------------------------------------------------------------
-- Echo client
<b>with</b> Ada.Command_Line;
<b>with</b> Ada.Text_IO;
<b>with</b> CORBA.ORB;
<b>with</b> Echo;
<b>with</b> PolyORB.Setup.Client;
<b>pragma</b> Warnings (Off, PolyORB.Setup.Client);
<b>with</b> PolyORB.Utils.Report;
<b>procedure</b> Client <b>is</b>
<b>use</b> Ada.Command_Line;
<b>use</b> Ada.Text_IO;
<b>use</b> PolyORB.Utils.Report;
<b>use</b> <b>type</b> CORBA.String;
Sent_Msg, Rcvd_Msg : CORBA.String;
myecho : Echo.Ref;
Length : Natural := 0;
Calls : Natural := 1;
<b>begin</b>
New_Test ("Echo client");
CORBA.ORB.Initialize ("ORB");
<b>if</b> Argument_Count <b>not</b> <b>in</b> 1 .. 3 <b>then</b>
Put_Line
("usage: client <IOR_string_from_server>|-i [strlen [num <b>of</b> calls]]");
<b>return</b>;
<b>end</b> <b>if</b>;
-- Getting the CORBA.Object
CORBA.ORB.String_To_Object
(CORBA.To_CORBA_String (Ada.Command_Line.Argument (1)), myecho);
-- Get optional arguments Length and Calls
<b>if</b> Argument_Count >= 2 <b>then</b>
Length := Natural'Value (Ada.Command_Line.Argument (2));
<b>end</b> <b>if</b>;
<b>if</b> Argument_Count >= 3 <b>then</b>
Calls := Natural'Value (Ada.Command_Line.Argument (3));
<b>end</b> <b>if</b>;
-- Checking if it worked
<b>if</b> Echo.Is_Nil (myecho) <b>then</b>
Put_Line ("main : cannot <b>in</b>voke on a nil reference");
<b>return</b>;
<b>end</b> <b>if</b>;
-- Sending message
<b>if</b> Length = 0 <b>then</b>
Sent_Msg := CORBA.To_CORBA_String (Standard.String'("Hello Ada !"));
<b>else</b>
Sent_Msg := CORBA.To_CORBA_String
(Standard.String'(1 .. Length => 'X'));
<b>end</b> <b>if</b>;
<b>for</b> J <b>in</b> 1 .. Calls <b>loop</b>
Rcvd_Msg := Echo.echoString (myecho, Sent_Msg);
<b>end</b> <b>loop</b>;
<b>if</b> Rcvd_Msg /= Sent_Msg <b>then</b>
<b>raise</b> Program_Error <b>with</b> "<b>in</b>correct string <b>return</b>ed by server";
<b>end</b> <b>if</b>;
-- Printing result
<b>if</b> Length = 0 <b>then</b>
Put_Line ("I said : " & CORBA.To_Standard_String (Sent_Msg));
Put_Line
("The object answered : " & CORBA.To_Standard_String (Rcvd_Msg));
<b>else</b>
Put_Line ("I said : 'X' *" & Length'Img);
Put_Line ("The object answered the same.");
<b>end</b> <b>if</b>;
End_Report;
<b>exception</b>
<b>when</b> E : CORBA.Transient =>
Output ("echo test", False);
<b>declare</b>
Memb : CORBA.System_Exception_Members;
<b>begin</b>
CORBA.Get_Members (E, Memb);
Put ("received <b>exception</b> transient, minor");
Put (CORBA.Unsigned_Long'Image (Memb.Minor));
Put (", completion status: ");
Put_Line (CORBA.Completion_Status'Image (Memb.Completed));
End_Report;
<b>end</b>;
<b>end</b> Client;
</pre></div>
</li><li> The server code sets up a no-tasking node. The object is registered to
the <code>RootPOA</code>. Then an <code>IOR</code> reference is built to enable
interaction with other nodes.
<div class="smallexample">
<pre class="smallexample">
------------------------------------------------------------------------------
-- --
-- POLYORB COMPONENTS --
-- --
-- S E R V E R --
-- --
-- B o d y --
-- --
-- Copyright (C) 2002-2012, Free Software Foundation, Inc. --
-- --
-- This is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. This software is distributed in the hope that it will be useful, --
-- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- --
-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public --
-- License for more details. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- PolyORB is maintained by AdaCore --
-- (email: sales@adacore.com) --
-- --
------------------------------------------------------------------------------
<b>with</b> Ada.Exceptions;
<b>with</b> Ada.Text_IO; <b>use</b> Ada.Text_IO;
<b>with</b> CORBA.Impl;
<b>with</b> CORBA.Object;
<b>with</b> CORBA.ORB;
<b>with</b> PortableServer.POA.Helper;
<b>with</b> PortableServer.POAManager;
<b>with</b> Echo.Impl;
<b>with</b> PolyORB.CORBA_P.CORBALOC;
-- Setup server node: use no tasking default configuration
<b>with</b> PolyORB.Setup.No_Tasking_Server;
<b>pragma</b> Warnings (Off, PolyORB.Setup.No_Tasking_Server);
<b>procedure</b> Server <b>is</b>
<b>begin</b>
<b>declare</b>
Argv : CORBA.ORB.Arg_List := CORBA.ORB.Command_Line_Arguments;
<b>begin</b>
CORBA.ORB.Init (CORBA.ORB.To_CORBA_String ("ORB"), Argv);
<b>declare</b>
Root_POA : PortableServer.POA.Local_Ref;
Ref : CORBA.Object.Ref;
Obj : <b>constant</b> CORBA.Impl.Object_Ptr := <b>new</b> Echo.Impl.Object;
<b>begin</b>
-- Retrieve Root POA
Root_POA := PortableServer.POA.Helper.To_Local_Ref
(CORBA.ORB.Resolve_Initial_References
(CORBA.ORB.To_CORBA_String ("RootPOA")));
PortableServer.POAManager.Activate
(PortableServer.POA.Get_The_POAManager (Root_POA));
-- Set up new object
Ref := PortableServer.POA.Servant_To_Reference
(Root_POA, PortableServer.Servant (Obj));
-- Output IOR
Put_Line
("'"
& CORBA.To_Standard_String (CORBA.Object.Object_To_String (Ref))
& "'");
New_Line;
-- Output corbaloc
Put_Line
("'"
& CORBA.To_Standard_String
(PolyORB.CORBA_P.CORBALOC.Object_To_Corbaloc (Ref))
& "'");
-- Launch the server. CORBA.ORB.Run is supposed to never return,
-- print a message if it does.
CORBA.ORB.Run;
Put_Line ("ORB main <b>loop</b> <b>terminate</b>d!");
<b>end</b>;
<b>end</b>;
<b>exception</b>
<b>when</b> E : <b>others</b> =>
Put_Line
("Echo server <b>raise</b>d " & Ada.Exceptions.Exception_Information (E));
<b>raise</b>;
<b>end</b> Server;
</pre></div>
</li></ul>
<a name="Compilation-and-execution"></a>
<h4 class="subsubsection">6.6.1.4 Compilation and execution</h4>
<p>To compile this demo,
</p><ol>
<li> Process the IDL file with <code>idlac</code> (or <code>iac</code>)
<div class="smallexample">
<pre class="smallexample"> $ idlac echo.idl
</pre></div>
</li><li> Compile the client node
<div class="smallexample">
<pre class="smallexample"> $ gnatmake client.adb `polyorb-config`
</pre></div>
</li><li> Compile the server node
<div class="smallexample">
<pre class="smallexample"> $ gnatmake server.adb `polyorb-config`
</pre></div>
</li></ol>
<p>Note the use of backticks (‘). This means that
<code>polyorb-config</code> is first executed, and then the command line
is replaced with the output of the script, setting up library and
include paths and library names.
</p>
<p>To run this demo:
</p>
<ul>
<li> run <samp>server</samp>, the server outputs its IOR, a hexadecimal
string with the IOR: prefix:
<div class="smallexample">
<pre class="smallexample">$ ./server
Loading configuration from polyorb.conf
No polyorb.conf configuration file.
'IOR:01534f410d00000049444c3[..]'
</pre></div>
</li><li> In another shell, run <samp>client</samp>, passing cut-and-pasting the
complete IOR on the command line:
<div class="smallexample">
<pre class="smallexample">$ ./client 'IOR:01534f410d00000049444c3[..]'
Echoing string: " Hello Ada ! "
I said : Hello Ada !
The object answered : Hello Ada !
</pre></div>
</li></ul>
<hr>
<div class="header">
<p>
Next: <a href="Other-examples.html#Other-examples" accesskey="n" rel="next">Other examples</a>, Up: <a href="Building-a-CORBA-application-with-PolyORB.html#Building-a-CORBA-application-with-PolyORB" accesskey="u" rel="up">Building a CORBA application with PolyORB</a> [<a href="About-This-Guide.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>
|