| 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 6 : poatest-basic06.c | 
|---|
| 23 | *     o POA with MULTIPLE_ID Object Id Uniqueness policy. | 
|---|
| 24 | *     o activate two objects with the same servant. | 
|---|
| 25 | */ | 
|---|
| 26 |  | 
|---|
| 27 | #include <stdio.h> | 
|---|
| 28 | #include <stdlib.h> | 
|---|
| 29 |  | 
|---|
| 30 | #include <orbit/orbit.h> | 
|---|
| 31 |  | 
|---|
| 32 | #include "poatest-basic-shell.h" | 
|---|
| 33 |  | 
|---|
| 34 | static void | 
|---|
| 35 | poatest_test_impl (PortableServer_Servant servant, CORBA_Environment *ev) { } | 
|---|
| 36 |  | 
|---|
| 37 | PortableServer_ServantBase__epv base_epv = { | 
|---|
| 38 | NULL,    /* _private    */ | 
|---|
| 39 | NULL,    /* finalize    */ | 
|---|
| 40 | NULL     /* default_POA */ | 
|---|
| 41 | }; | 
|---|
| 42 |  | 
|---|
| 43 | POA_poatest__epv poatest_epv = { | 
|---|
| 44 | NULL,                /* _private */ | 
|---|
| 45 | poatest_test_impl    /* test     */ | 
|---|
| 46 | }; | 
|---|
| 47 |  | 
|---|
| 48 | POA_poatest__vepv poatest_vepv = { | 
|---|
| 49 | &base_epv,         /* _base_epv    */ | 
|---|
| 50 | &poatest_epv       /* poatest_epv  */ | 
|---|
| 51 | }; | 
|---|
| 52 |  | 
|---|
| 53 | POA_poatest poatest_servant = { | 
|---|
| 54 | NULL,             /* _private */ | 
|---|
| 55 | &poatest_vepv     /* vepv     */ | 
|---|
| 56 | }; | 
|---|
| 57 |  | 
|---|
| 58 | poatest | 
|---|
| 59 | poatest_run (PortableServer_POA        rootpoa, | 
|---|
| 60 | PortableServer_POAManager rootpoa_mgr) | 
|---|
| 61 | { | 
|---|
| 62 | CORBA_Environment        ev; | 
|---|
| 63 | poatest                  poatest_obj; | 
|---|
| 64 | CORBA_PolicyList        *poa_policies; | 
|---|
| 65 | PortableServer_ObjectId *obj1id, *obj2id; | 
|---|
| 66 |  | 
|---|
| 67 | CORBA_exception_init (&ev); | 
|---|
| 68 |  | 
|---|
| 69 | /* | 
|---|
| 70 | * Create child POA with MULTIPLE_ID Object Id Uniqueness policy. | 
|---|
| 71 | */ | 
|---|
| 72 | poa_policies           = CORBA_PolicyList__alloc (); | 
|---|
| 73 | poa_policies->_maximum = 1; | 
|---|
| 74 | poa_policies->_length  = 1; | 
|---|
| 75 | poa_policies->_buffer  = CORBA_PolicyList_allocbuf (1); | 
|---|
| 76 | CORBA_sequence_set_release (poa_policies, CORBA_TRUE); | 
|---|
| 77 |  | 
|---|
| 78 | poa_policies->_buffer[0] = (CORBA_Policy) | 
|---|
| 79 | PortableServer_POA_create_id_uniqueness_policy ( | 
|---|
| 80 | rootpoa, | 
|---|
| 81 | PortableServer_MULTIPLE_ID, | 
|---|
| 82 | &ev); | 
|---|
| 83 |  | 
|---|
| 84 | child_poa = PortableServer_POA_create_POA (rootpoa, | 
|---|
| 85 | "Multiple Id POA", | 
|---|
| 86 | rootpoa_mgr, | 
|---|
| 87 | poa_policies, | 
|---|
| 88 | &ev); | 
|---|
| 89 | if (POATEST_EX (&ev)) { | 
|---|
| 90 | POATEST_PRINT_EX ("create_POA : ", &ev); | 
|---|
| 91 | return CORBA_OBJECT_NIL; | 
|---|
| 92 | } | 
|---|
| 93 |  | 
|---|
| 94 | CORBA_Policy_destroy (poa_policies->_buffer[0], &ev); | 
|---|
| 95 | CORBA_free (poa_policies); | 
|---|
| 96 |  | 
|---|
| 97 | /* | 
|---|
| 98 | * Initialise the servant. | 
|---|
| 99 | */ | 
|---|
| 100 | POA_poatest__init (&poatest_servant, &ev); | 
|---|
| 101 | if (POATEST_EX (&ev)) { | 
|---|
| 102 | POATEST_PRINT_EX ("POA_poatest__init : ", &ev); | 
|---|
| 103 | return CORBA_OBJECT_NIL; | 
|---|
| 104 | } | 
|---|
| 105 |  | 
|---|
| 106 | /* | 
|---|
| 107 | * Activate two objects. | 
|---|
| 108 | */ | 
|---|
| 109 | obj1id = PortableServer_POA_activate_object (child_poa, &poatest_servant, &ev); | 
|---|
| 110 | if (POATEST_EX (&ev)) { | 
|---|
| 111 | POATEST_PRINT_EX ("activate_object : ", &ev); | 
|---|
| 112 | return CORBA_OBJECT_NIL; | 
|---|
| 113 | } | 
|---|
| 114 | CORBA_free (obj1id); | 
|---|
| 115 |  | 
|---|
| 116 | obj2id = PortableServer_POA_activate_object (child_poa, &poatest_servant, &ev); | 
|---|
| 117 | if (POATEST_EX (&ev)) { | 
|---|
| 118 | POATEST_PRINT_EX ("activate_object : ", &ev); | 
|---|
| 119 | return CORBA_OBJECT_NIL; | 
|---|
| 120 | } | 
|---|
| 121 |  | 
|---|
| 122 | /* | 
|---|
| 123 | * Get reference for second object. | 
|---|
| 124 | */ | 
|---|
| 125 | poatest_obj = PortableServer_POA_id_to_reference (child_poa, obj2id, &ev); | 
|---|
| 126 | if (POATEST_EX (&ev)) { | 
|---|
| 127 | POATEST_PRINT_EX ("id_to_reference : ", &ev); | 
|---|
| 128 | return CORBA_OBJECT_NIL; | 
|---|
| 129 | } | 
|---|
| 130 | CORBA_free (obj2id); | 
|---|
| 131 |  | 
|---|
| 132 | /* | 
|---|
| 133 | * Activate the POAManager. POA will now accept requests | 
|---|
| 134 | */ | 
|---|
| 135 | PortableServer_POAManager_activate (rootpoa_mgr, &ev); | 
|---|
| 136 | if (POATEST_EX (&ev)) { | 
|---|
| 137 | POATEST_PRINT_EX ("POAManager_activate : ", &ev); | 
|---|
| 138 | return CORBA_OBJECT_NIL; | 
|---|
| 139 | } | 
|---|
| 140 |  | 
|---|
| 141 | return poatest_obj; | 
|---|
| 142 | } | 
|---|