source: trunk/ORBit2-2.14.0/test/echo-srv.c

Last change on this file was 92, checked in by cinc, 19 years ago

Orbit2 modified for use with NOM

File size: 3.5 KB
Line 
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
21#include <stdio.h>
22#include <stdlib.h>
23#include <string.h>
24#include <ctype.h>
25#include "echo.h"
26#include "echo-share.h"
27
28/**
29 This is used by echo-server.c and echo-local.c
30 It uses echo-skels.c
31**/
32
33static Echo the_echo_client;
34static CORBA_ORB the_orb;
35static PortableServer_POA the_poa;
36static PortableServer_ObjectId* the_objid;
37
38
39static CORBA_Object
40do_echoString(PortableServer_Servant servant,
41 const CORBA_char *astring,
42 CORBA_double *outnum,
43 CORBA_Environment *ev)
44{
45
46 if (!echo_opt_quiet)
47 g_message ("[server] %s", astring);
48
49 *outnum = rand() % 100;
50
51 return CORBA_Object_duplicate (the_echo_client, ev);
52}
53
54static void
55do_doNothing (PortableServer_Servant servant,
56 CORBA_Environment *ev)
57{
58}
59
60static PortableServer_ServantBase__epv base_epv = {
61 NULL,
62 NULL,
63 NULL
64};
65
66static POA_Echo__epv echo_epv = { NULL, do_echoString, do_doNothing, NULL };
67static POA_Echo__vepv poa_echo_vepv = { &base_epv, &echo_epv };
68static POA_Echo poa_echo_servant = { NULL, &poa_echo_vepv };
69
70void
71echo_srv_start_poa (CORBA_ORB orb, CORBA_Environment *ev)
72{
73 PortableServer_POAManager mgr;
74
75 the_orb = orb;
76 the_poa = (PortableServer_POA)
77 CORBA_ORB_resolve_initial_references(orb,
78 "RootPOA", ev);
79
80 mgr = PortableServer_POA__get_the_POAManager(the_poa, ev);
81 PortableServer_POAManager_activate(mgr, ev);
82 CORBA_Object_release((CORBA_Object)mgr, ev);
83}
84
85CORBA_Object
86echo_srv_start_object(CORBA_Environment *ev)
87{
88 POA_Echo__init(&poa_echo_servant, ev);
89 if ( ev->_major ) {
90 printf("object__init failed: %d\n", ev->_major);
91 exit(1);
92 }
93 the_objid = PortableServer_POA_activate_object(the_poa,
94 &poa_echo_servant, ev);
95 if ( ev->_major ) {
96 printf("activate_object failed: %d\n", ev->_major);
97 exit(1);
98 }
99 the_echo_client = PortableServer_POA_servant_to_reference(the_poa,
100 &poa_echo_servant, ev);
101 if ( ev->_major ) {
102 printf("servant_to_reference failed: %d\n", ev->_major);
103 exit(1);
104 }
105 return the_echo_client;
106}
107
108void
109echo_srv_finish_object(CORBA_Environment *ev)
110{
111 CORBA_Object_release(the_echo_client, ev);
112 if ( ev->_major ) {
113 printf("object_release failed: %d\n", ev->_major);
114 exit(1);
115 }
116 the_echo_client = NULL;
117 PortableServer_POA_deactivate_object(the_poa, the_objid, ev);
118 if ( ev->_major ) {
119 printf("deactivate_object failed: %d\n", ev->_major);
120 exit(1);
121 }
122 CORBA_free(the_objid);
123 the_objid = NULL;
124 POA_Echo__fini(&poa_echo_servant, ev);
125 if ( ev->_major ) {
126 printf("object__fini failed: %d\n", ev->_major);
127 exit(1);
128 }
129}
130
131
132void
133echo_srv_finish_poa(CORBA_Environment *ev)
134{
135 CORBA_Object_release((CORBA_Object)the_poa, ev);
136 if ( ev->_major ) {
137 printf("POA release failed: %d\n", ev->_major);
138 exit(1);
139 }
140 the_poa = NULL;
141}
Note: See TracBrowser for help on using the repository browser.