| [92] | 1 | #include <stdio.h>
|
|---|
| 2 | #include <stdlib.h>
|
|---|
| 3 | #include <string.h>
|
|---|
| 4 | #include "test-any.h"
|
|---|
| 5 |
|
|---|
| 6 | static TestAny client;
|
|---|
| 7 |
|
|---|
| 8 | static CORBA_any *
|
|---|
| 9 | do_print(PortableServer_Servant servant,
|
|---|
| 10 | const CORBA_any *any,
|
|---|
| 11 | CORBA_Environment *ev);
|
|---|
| 12 |
|
|---|
| 13 | static PortableServer_ServantBase__epv base_epv = {
|
|---|
| 14 | NULL,
|
|---|
| 15 | NULL,
|
|---|
| 16 | NULL
|
|---|
| 17 | };
|
|---|
| 18 |
|
|---|
| 19 | static POA_TestAny__epv TestAny_epv = { NULL, do_print };
|
|---|
| 20 | static POA_TestAny__vepv poa_TestAny_vepv = { &base_epv, &TestAny_epv };
|
|---|
| 21 | static POA_TestAny poa_TestAny_servant = { NULL, &poa_TestAny_vepv };
|
|---|
| 22 |
|
|---|
| 23 | int
|
|---|
| 24 | main (int argc, char *argv[])
|
|---|
| 25 | {
|
|---|
| 26 | FILE *iorfile;
|
|---|
| 27 | PortableServer_ObjectId *objid;
|
|---|
| 28 | PortableServer_POA poa;
|
|---|
| 29 |
|
|---|
| 30 | CORBA_Environment ev;
|
|---|
| 31 | char *retval;
|
|---|
| 32 | CORBA_ORB orb;
|
|---|
| 33 |
|
|---|
| 34 | CORBA_exception_init(&ev);
|
|---|
| 35 | orb = CORBA_ORB_init(&argc, argv, "orbit-local-orb", &ev);
|
|---|
| 36 |
|
|---|
| 37 | POA_TestAny__init(&poa_TestAny_servant, &ev);
|
|---|
| 38 |
|
|---|
| 39 | poa = (PortableServer_POA)
|
|---|
| 40 | CORBA_ORB_resolve_initial_references(orb, "RootPOA", &ev);
|
|---|
| 41 |
|
|---|
| 42 | PortableServer_POAManager_activate(
|
|---|
| 43 | PortableServer_POA__get_the_POAManager(poa, &ev), &ev);
|
|---|
| 44 |
|
|---|
| 45 | objid = PortableServer_POA_activate_object(poa,
|
|---|
| 46 | &poa_TestAny_servant,
|
|---|
| 47 | &ev);
|
|---|
| 48 |
|
|---|
| 49 | client = PortableServer_POA_servant_to_reference(poa,
|
|---|
| 50 | &poa_TestAny_servant,
|
|---|
| 51 | &ev);
|
|---|
| 52 | if (!client) {
|
|---|
| 53 | printf("Cannot get objref\n");
|
|---|
| 54 | return 1;
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | retval = CORBA_ORB_object_to_string(orb, client, &ev);
|
|---|
| 58 |
|
|---|
| 59 | iorfile = fopen ("test-any-server.iorfile", "w");
|
|---|
| 60 | fprintf(iorfile, "%s\n", retval);
|
|---|
| 61 | fclose(iorfile);
|
|---|
| 62 |
|
|---|
| 63 | g_print("%s\n", retval); fflush(stdout);
|
|---|
| 64 |
|
|---|
| 65 | CORBA_free(retval);
|
|---|
| 66 |
|
|---|
| 67 | CORBA_ORB_run(orb, &ev);
|
|---|
| 68 |
|
|---|
| 69 | return 0;
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | static CORBA_any*
|
|---|
| 73 | do_print(PortableServer_Servant servant,
|
|---|
| 74 | const CORBA_any *any,
|
|---|
| 75 | CORBA_Environment *ev)
|
|---|
| 76 | {
|
|---|
| 77 | TestAnyStruct* any_struct = any->_value;
|
|---|
| 78 | CORBA_any *retval;
|
|---|
| 79 |
|
|---|
| 80 | g_message("[server] %d: %s", any_struct->long_value,
|
|---|
| 81 | any_struct->string_value);
|
|---|
| 82 |
|
|---|
| 83 | retval = CORBA_any_alloc();
|
|---|
| 84 | #if 1
|
|---|
| 85 | retval->_type = (CORBA_TypeCode)TC_TestAnyStruct;
|
|---|
| 86 | retval->_value = TestAnyStruct__alloc();
|
|---|
| 87 | ((TestAnyStruct *)retval->_value)->long_value = 84;
|
|---|
| 88 | ((TestAnyStruct *)retval->_value)->string_value
|
|---|
| 89 | = CORBA_string_dup("Hi there");
|
|---|
| 90 | #else
|
|---|
| 91 | retval->_type = (CORBA_TypeCode)TC_null;
|
|---|
| 92 | retval->_value = NULL;
|
|---|
| 93 | #endif
|
|---|
| 94 |
|
|---|
| 95 | CORBA_any_set_release(retval, CORBA_TRUE);
|
|---|
| 96 |
|
|---|
| 97 | return retval;
|
|---|
| 98 | }
|
|---|