static PyObject * pyorbit_poa_activate_object_with_id(PyCORBA_Object *self, PyObject *args) { CORBA_Environment ev; PyPortableServer_Servant *pyservant; PortableServer_ServantBase *servant; PortableServer_ObjectId *id; Py_ssize_t id_length; id = (PortableServer_ObjectId *)CORBA_sequence_CORBA_octet__alloc(); id->_release = CORBA_FALSE; if (!PyArg_ParseTuple(args, "s#O!:POA.activate_object_with_id", &id->_buffer, &id_length, &PyPortableServer_Servant_Type, &pyservant)) { CORBA_free(id); return NULL; } id->_length = id_length; id->_length++; /* account for nul termination */ servant = PYSERVANT_TO_SERVANT(pyservant); CORBA_exception_init(&ev); PortableServer_POA_activate_object_with_id((PortableServer_POA)self->objref, id, servant, &ev); CORBA_free(id); if (pyorbit_check_ex(&ev)) return NULL; Py_INCREF(Py_None); return Py_None; }
void corba_init(void *p) { PortableServer_ObjectId objid = {0, sizeof("Freeamp-ORBit"), "Freeamp-ORBit"}; PortableServer_POA poa; CORBA_Environment ev; char *retval; CORBA_ORB orb; FILE * ofp; int argc=1; char *argv; char *homedir; char iorfile[1024]; char tmpbuf[1] = {0}; tptr = p; // :TODO: this should be fixed to pass on argv? argv=&tmpbuf[0]; CORBA_exception_init(&ev); orb = CORBA_ORB_init(&argc, &argv, "orbit-local-orb", &ev); POA_Freeamp__init(&poa_freeamp_servant, &ev); poa = (PortableServer_POA)CORBA_ORB_resolve_initial_references(orb, "RootPOA", &ev); PortableServer_POAManager_activate(PortableServer_POA__get_the_POAManager(poa, &ev), &ev); PortableServer_POA_activate_object_with_id(poa, &objid, &poa_freeamp_servant, &ev); freeamp_client = PortableServer_POA_servant_to_reference(poa, &poa_freeamp_servant, &ev); if (!freeamp_client) { printf("Cannot get objref\n"); return; } homedir = getenv("HOME"); strncpy(iorfile, homedir, 1024); // :TODO: add error checking strncat(iorfile, "/.freeamp.ior", 1024); retval = CORBA_ORB_object_to_string(orb, freeamp_client, &ev); ofp = fopen(iorfile,"w"); fprintf(ofp,"%s", retval); fclose(ofp); CORBA_free(retval); fprintf(stdout,"FreeAMP-CORBA Ready. | Waiting for commands.\n"); fflush(stdout); CORBA_ORB_run(orb, &ev); }
poatest poatest_run (PortableServer_POA rootpoa, PortableServer_POAManager rootpoa_mgr) { CORBA_Environment ev; poatest poatest_obj; CORBA_PolicyList *poa_policies; PortableServer_ObjectId *objid; CORBA_exception_init (&ev); /* * Create child POA with USER_ID Id Assignment and PERSISTENT lifespan policy. */ poa_policies = CORBA_PolicyList__alloc (); poa_policies->_maximum = 2; poa_policies->_length = 2; poa_policies->_buffer = CORBA_PolicyList_allocbuf (2); CORBA_sequence_set_release (poa_policies, CORBA_TRUE); poa_policies->_buffer[0] = (CORBA_Policy) PortableServer_POA_create_id_assignment_policy ( rootpoa, PortableServer_USER_ID, &ev); poa_policies->_buffer[1] = (CORBA_Policy) PortableServer_POA_create_lifespan_policy ( rootpoa, PortableServer_PERSISTENT, &ev); child_poa = PortableServer_POA_create_POA (rootpoa, "User Id and Persistent POA", rootpoa_mgr, poa_policies, &ev); if (POATEST_EX (&ev)) { POATEST_PRINT_EX ("create_POA : ", &ev); return CORBA_OBJECT_NIL; } /* * Initialise the servant. */ POA_poatest__init (&poatest_servant, &ev); if (POATEST_EX (&ev)) { POATEST_PRINT_EX ("POA_poatest__init : ", &ev); return CORBA_OBJECT_NIL; } /* * Set up the ObjectId. */ objid = PortableServer_string_to_ObjectId ("Test Id", &ev); if (POATEST_EX (&ev)) { POATEST_PRINT_EX ("string_to_ObjectId : ", &ev); return CORBA_OBJECT_NIL; } /* * Activate object with user assigned Id. */ PortableServer_POA_activate_object_with_id (child_poa, objid, &poatest_servant, &ev); if (POATEST_EX (&ev)) { POATEST_PRINT_EX ("activate_object_with_id : ", &ev); return CORBA_OBJECT_NIL; } /* * Get reference for object. */ poatest_obj = PortableServer_POA_servant_to_reference (child_poa, &poatest_servant, &ev); if (POATEST_EX (&ev)) { POATEST_PRINT_EX ("servant_to_reference : ", &ev); return CORBA_OBJECT_NIL; } /* * Deactivate object and destroy POA */ PortableServer_POA_deactivate_object(child_poa, objid, &ev); if (POATEST_EX (&ev)) { POATEST_PRINT_EX ("deactivate_object : ", &ev); return CORBA_OBJECT_NIL; } PortableServer_POA_destroy (child_poa, CORBA_FALSE, CORBA_FALSE, &ev); if (POATEST_EX (&ev)) { POATEST_PRINT_EX ("POA_destroy : ", &ev); return CORBA_OBJECT_NIL; } /* * Re-create POA and re-activate the object. */ child_poa = PortableServer_POA_create_POA (rootpoa, "User Id and Persistent POA", rootpoa_mgr, poa_policies, &ev); if (POATEST_EX (&ev)) { POATEST_PRINT_EX ("create_POA : ", &ev); return CORBA_OBJECT_NIL; } PortableServer_POA_activate_object_with_id (child_poa, objid, &poatest_servant, &ev); if (POATEST_EX (&ev)) { POATEST_PRINT_EX ("activate_object_with_id : ", &ev); return CORBA_OBJECT_NIL; } /* * Reference should still be valid. */ CORBA_free (objid); CORBA_Policy_destroy (poa_policies->_buffer[0], &ev); CORBA_Policy_destroy (poa_policies->_buffer[1], &ev); CORBA_free (poa_policies); /* * Activate the POAManager. POA will now accept requests */ PortableServer_POAManager_activate( rootpoa_mgr, &ev ); if (POATEST_EX (&ev)) { POATEST_PRINT_EX ("POAManager_activate : ", &ev); return CORBA_OBJECT_NIL; } return poatest_obj; }
poatest poatest_run (PortableServer_POA rootpoa, PortableServer_POAManager rootpoa_mgr) { CORBA_Environment ev; poatest poatest_obj; CORBA_PolicyList *poa_policies; PortableServer_ObjectId *objid; CORBA_exception_init (&ev); /* * Create child POA with USER_ID Id Assignment policy. */ poa_policies = CORBA_PolicyList__alloc (); poa_policies->_maximum = 1; poa_policies->_length = 1; poa_policies->_buffer = CORBA_PolicyList_allocbuf (1); CORBA_sequence_set_release (poa_policies, CORBA_TRUE); poa_policies->_buffer[0] = (CORBA_Policy) PortableServer_POA_create_id_assignment_policy ( rootpoa, PortableServer_USER_ID, &ev); child_poa = PortableServer_POA_create_POA (rootpoa, "User Id POA", rootpoa_mgr, poa_policies, &ev); if (POATEST_EX (&ev)) { POATEST_PRINT_EX ("create_POA : ", &ev); return CORBA_OBJECT_NIL; } CORBA_Policy_destroy (poa_policies->_buffer[0], &ev); CORBA_free (poa_policies); /* * Initialise the servant. */ POA_poatest__init (&poatest_servant, &ev); if (POATEST_EX (&ev)) { POATEST_PRINT_EX ("POA_poatest__init : ", &ev); return CORBA_OBJECT_NIL; } /* * Set up the ObjectId. */ objid = PortableServer_string_to_ObjectId ("Test Id", &ev); if (POATEST_EX (&ev)) { POATEST_PRINT_EX ("string_to_ObjectId : ", &ev); return CORBA_OBJECT_NIL; } /* * Activate object with user assigned Id. */ PortableServer_POA_activate_object_with_id (child_poa, objid, &poatest_servant, &ev); if (POATEST_EX (&ev)) { POATEST_PRINT_EX ("activate_object_with_id : ", &ev); return CORBA_OBJECT_NIL; } CORBA_free (objid); poatest_obj = PortableServer_POA_servant_to_reference (child_poa, &poatest_servant, &ev); if (POATEST_EX (&ev)) { POATEST_PRINT_EX ("servant_to_reference : ", &ev); return CORBA_OBJECT_NIL; } /* * Activate the POAManager. POA will now accept requests */ PortableServer_POAManager_activate (rootpoa_mgr, &ev); if (POATEST_EX (&ev)) { POATEST_PRINT_EX ("POAManager_activate : ", &ev); return CORBA_OBJECT_NIL; } return poatest_obj; }