source: trunk/ORBit2-2.14.0/test/poa/poatest-basic05.c

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

Orbit2 modified for use with NOM

File size: 5.0 KB
Line 
1/*
2 * CORBA POA tests
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: Mark McLoughlin <mark@skynet.ie>
19 */
20
21/*
22 * Test 5 : poatest-basic05.c
23 * o POA with USER_ID Id Assignment and PERSISTENT lifespan policy.
24 * o object created, activated and reference generated, then
25 * deactivated and POA destroyed.
26 * o POA recreated and object re-activated. Reference should
27 * still be valid.
28 */
29
30#include <stdio.h>
31#include <stdlib.h>
32
33#include <orbit/orbit.h>
34
35#include "poatest-basic-shell.h"
36
37static void
38poatest_test_impl (PortableServer_Servant servant, CORBA_Environment *ev) { }
39
40static PortableServer_ServantBase__epv base_epv = {
41 NULL, /* _private */
42 NULL, /* finalize */
43 NULL /* default_POA */
44};
45
46static POA_poatest__epv poatest_epv = {
47 NULL, /* _private */
48 poatest_test_impl /* test */
49};
50
51static POA_poatest__vepv poatest_vepv = {
52 &base_epv, /* _base_epv */
53 &poatest_epv /* poatest_epv */
54};
55
56static POA_poatest poatest_servant = {
57 NULL, /* _private */
58 &poatest_vepv /* vepv */
59};
60
61poatest
62poatest_run (PortableServer_POA rootpoa,
63 PortableServer_POAManager rootpoa_mgr)
64{
65 CORBA_Environment ev;
66 poatest poatest_obj;
67 CORBA_PolicyList *poa_policies;
68 PortableServer_ObjectId *objid;
69
70 CORBA_exception_init (&ev);
71
72 /*
73 * Create child POA with USER_ID Id Assignment and PERSISTENT lifespan policy.
74 */
75 poa_policies = CORBA_PolicyList__alloc ();
76 poa_policies->_maximum = 2;
77 poa_policies->_length = 2;
78 poa_policies->_buffer = CORBA_PolicyList_allocbuf (2);
79 CORBA_sequence_set_release (poa_policies, CORBA_TRUE);
80
81 poa_policies->_buffer[0] = (CORBA_Policy)
82 PortableServer_POA_create_id_assignment_policy (
83 rootpoa,
84 PortableServer_USER_ID,
85 &ev);
86
87 poa_policies->_buffer[1] = (CORBA_Policy)
88 PortableServer_POA_create_lifespan_policy (
89 rootpoa,
90 PortableServer_PERSISTENT,
91 &ev);
92
93 child_poa = PortableServer_POA_create_POA (rootpoa,
94 "User Id and Persistent POA",
95 rootpoa_mgr,
96 poa_policies,
97 &ev);
98 if (POATEST_EX (&ev)) {
99 POATEST_PRINT_EX ("create_POA : ", &ev);
100 return CORBA_OBJECT_NIL;
101 }
102
103 /*
104 * Initialise the servant.
105 */
106 POA_poatest__init (&poatest_servant, &ev);
107 if (POATEST_EX (&ev)) {
108 POATEST_PRINT_EX ("POA_poatest__init : ", &ev);
109 return CORBA_OBJECT_NIL;
110 }
111
112 /*
113 * Set up the ObjectId.
114 */
115 objid = PortableServer_string_to_ObjectId ("Test Id", &ev);
116 if (POATEST_EX (&ev)) {
117 POATEST_PRINT_EX ("string_to_ObjectId : ", &ev);
118 return CORBA_OBJECT_NIL;
119 }
120
121 /*
122 * Activate object with user assigned Id.
123 */
124 PortableServer_POA_activate_object_with_id (child_poa, objid, &poatest_servant, &ev);
125 if (POATEST_EX (&ev)) {
126 POATEST_PRINT_EX ("activate_object_with_id : ", &ev);
127 return CORBA_OBJECT_NIL;
128 }
129
130 /*
131 * Get reference for object.
132 */
133 poatest_obj = PortableServer_POA_servant_to_reference (child_poa, &poatest_servant, &ev);
134 if (POATEST_EX (&ev)) {
135 POATEST_PRINT_EX ("servant_to_reference : ", &ev);
136 return CORBA_OBJECT_NIL;
137 }
138
139 /*
140 * Deactivate object and destroy POA
141 */
142 PortableServer_POA_deactivate_object(child_poa, objid, &ev);
143 if (POATEST_EX (&ev)) {
144 POATEST_PRINT_EX ("deactivate_object : ", &ev);
145 return CORBA_OBJECT_NIL;
146 }
147
148 PortableServer_POA_destroy (child_poa, CORBA_FALSE, CORBA_FALSE, &ev);
149 if (POATEST_EX (&ev)) {
150 POATEST_PRINT_EX ("POA_destroy : ", &ev);
151 return CORBA_OBJECT_NIL;
152 }
153
154 /*
155 * Re-create POA and re-activate the object.
156 */
157 child_poa = PortableServer_POA_create_POA (rootpoa,
158 "User Id and Persistent POA",
159 rootpoa_mgr,
160 poa_policies,
161 &ev);
162 if (POATEST_EX (&ev)) {
163 POATEST_PRINT_EX ("create_POA : ", &ev);
164 return CORBA_OBJECT_NIL;
165 }
166
167 PortableServer_POA_activate_object_with_id (child_poa, objid, &poatest_servant, &ev);
168 if (POATEST_EX (&ev)) {
169 POATEST_PRINT_EX ("activate_object_with_id : ", &ev);
170 return CORBA_OBJECT_NIL;
171 }
172
173 /*
174 * Reference should still be valid.
175 */
176
177 CORBA_free (objid);
178
179 CORBA_Policy_destroy (poa_policies->_buffer[0], &ev);
180 CORBA_Policy_destroy (poa_policies->_buffer[1], &ev);
181 CORBA_free (poa_policies);
182
183 /*
184 * Activate the POAManager. POA will now accept requests
185 */
186 PortableServer_POAManager_activate( rootpoa_mgr, &ev );
187 if (POATEST_EX (&ev)) {
188 POATEST_PRINT_EX ("POAManager_activate : ", &ev);
189 return CORBA_OBJECT_NIL;
190 }
191
192 return poatest_obj;
193}
Note: See TracBrowser for help on using the repository browser.