| 1 | /* | 
|---|
| 2 | * CORBA echo test | 
|---|
| 3 | * | 
|---|
| 4 | * This program is free software; you can redistribute it and/or modify it | 
|---|
| 5 | * under the terms of the GNU General Public License as published by the | 
|---|
| 6 | * Free Software Foundation; either version 2, or (at your option) any | 
|---|
| 7 | * later version. | 
|---|
| 8 | * | 
|---|
| 9 | * This program is distributed in the hope that it will be useful, | 
|---|
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
| 12 | * GNU General Public License for more details. | 
|---|
| 13 | * | 
|---|
| 14 | * You should have received a copy of the GNU General Public License | 
|---|
| 15 | * along with this program; if not, write to the Free Software Foundation, | 
|---|
| 16 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 
|---|
| 17 | * | 
|---|
| 18 | * Author: Elliot Lee <sopwith@redhat.com> | 
|---|
| 19 | */ | 
|---|
| 20 | #include <stdio.h> | 
|---|
| 21 | #include <stdlib.h> | 
|---|
| 22 |  | 
|---|
| 23 | #include "echo.h" | 
|---|
| 24 |  | 
|---|
| 25 |  | 
|---|
| 26 | #define ABORT_IF_EXCEPTION(_ev, _message)                    \ | 
|---|
| 27 | if ((_ev)->_major != CORBA_NO_EXCEPTION) {                   \ | 
|---|
| 28 | g_error("%s: %s", _message, CORBA_exception_id (_ev));     \ | 
|---|
| 29 | CORBA_exception_free (_ev);                                \ | 
|---|
| 30 | abort();                                                   \ | 
|---|
| 31 | } | 
|---|
| 32 |  | 
|---|
| 33 | static Echo echo_client, bec; | 
|---|
| 34 |  | 
|---|
| 35 | gboolean echo_opt_quiet = FALSE; | 
|---|
| 36 |  | 
|---|
| 37 | int | 
|---|
| 38 | main (int argc, char *argv[]) { | 
|---|
| 39 | CORBA_Environment ev; | 
|---|
| 40 | CORBA_ORB orb; | 
|---|
| 41 | CORBA_double rv; | 
|---|
| 42 | char buf[30]; | 
|---|
| 43 | int i; | 
|---|
| 44 |  | 
|---|
| 45 | int niters = 1000; | 
|---|
| 46 |  | 
|---|
| 47 | CORBA_exception_init(&ev); | 
|---|
| 48 | orb = CORBA_ORB_init(&argc, argv, "orbit-local-orb", &ev); | 
|---|
| 49 |  | 
|---|
| 50 | /* read IOR from command line as first argument */ | 
|---|
| 51 | if(argc < 2) { | 
|---|
| 52 | g_print ("ERROR, usage: %s <ior> [<#iterations>]\n", argv[0]); | 
|---|
| 53 | return 1; | 
|---|
| 54 | } | 
|---|
| 55 |  | 
|---|
| 56 | if (argv[1][0] == '$') | 
|---|
| 57 | argv[1] = getenv (argv[1]+1); | 
|---|
| 58 |  | 
|---|
| 59 | /* read (optional) number of iterations from command line as | 
|---|
| 60 | * second argument (100) */ | 
|---|
| 61 | if(argc == 3) | 
|---|
| 62 | niters = atoi(argv[2]); | 
|---|
| 63 |  | 
|---|
| 64 | /* bind to object */ | 
|---|
| 65 | echo_client = CORBA_ORB_string_to_object(orb, argv[1], &ev); | 
|---|
| 66 | ABORT_IF_EXCEPTION (&ev, "cannot bind to object"); | 
|---|
| 67 | g_assert (echo_client!=NULL); | 
|---|
| 68 |  | 
|---|
| 69 | /* Iterate various times.  Each time the client invokes | 
|---|
| 70 | * 'echoString(..)'  a new reference to service is returned which | 
|---|
| 71 | * is used for next loop. At end of each loop the old | 
|---|
| 72 | * obj. reference is released. */ | 
|---|
| 73 | for(i = 0; i < niters; i++) { | 
|---|
| 74 | /* Method call without any argument, usefull to tell | 
|---|
| 75 | * lifeness */ | 
|---|
| 76 | Echo_doNothing(echo_client, &ev); | 
|---|
| 77 | ABORT_IF_EXCEPTION (&ev, "service raised exception "); | 
|---|
| 78 |  | 
|---|
| 79 | /* Ask echo-service to print string 'buf' on console. The | 
|---|
| 80 | * service returns random double float value in 'vr' */ | 
|---|
| 81 | g_snprintf(buf, sizeof(buf), "Hello, world [%d]", i); | 
|---|
| 82 | bec = Echo_echoString(echo_client, buf, &rv, &ev); | 
|---|
| 83 | ABORT_IF_EXCEPTION (&ev, "service raised exception "); | 
|---|
| 84 |  | 
|---|
| 85 | /* print random value generated by echo-service */ | 
|---|
| 86 | if ( !echo_opt_quiet ) | 
|---|
| 87 | g_message("[client] %g", rv); | 
|---|
| 88 |  | 
|---|
| 89 | /* Asynchronous/oneway method call, the function returns | 
|---|
| 90 | * immediately.  Usefull for log-message transfer */ | 
|---|
| 91 | Echo_doOneWay(echo_client, "log message ", &ev); | 
|---|
| 92 | ABORT_IF_EXCEPTION (&ev, "service raised exception "); | 
|---|
| 93 |  | 
|---|
| 94 | /* release first object reference and use the new one for | 
|---|
| 95 | * next loop */ | 
|---|
| 96 | CORBA_Object_release(echo_client, &ev); | 
|---|
| 97 | ABORT_IF_EXCEPTION (&ev, "service raised exception "); | 
|---|
| 98 |  | 
|---|
| 99 | /* swap object references */ | 
|---|
| 100 | echo_client = bec; bec = CORBA_OBJECT_NIL; | 
|---|
| 101 | } | 
|---|
| 102 |  | 
|---|
| 103 | /* release initial object reference */ | 
|---|
| 104 | CORBA_Object_release(echo_client, &ev); | 
|---|
| 105 | ABORT_IF_EXCEPTION (&ev, "service raised exception "); | 
|---|
| 106 |  | 
|---|
| 107 | /* shutdown ORB, shutdown IO channels */ | 
|---|
| 108 | CORBA_ORB_shutdown (orb, FALSE, &ev); | 
|---|
| 109 | ABORT_IF_EXCEPTION(&ev, "ORB shutdown ..."); | 
|---|
| 110 |  | 
|---|
| 111 | /* destroy local ORB */ | 
|---|
| 112 | CORBA_ORB_destroy(orb, &ev); | 
|---|
| 113 | ABORT_IF_EXCEPTION (&ev, "destroying local ORB raised exception"); | 
|---|
| 114 |  | 
|---|
| 115 | return 0; | 
|---|
| 116 | } | 
|---|