| 1 | #include <stdio.h>
|
|---|
| 2 | #include <unistd.h>
|
|---|
| 3 |
|
|---|
| 4 | #include "everything.h"
|
|---|
| 5 | #include "constants.h"
|
|---|
| 6 |
|
|---|
| 7 | extern PortableServer_POA global_poa;
|
|---|
| 8 |
|
|---|
| 9 | typedef struct {
|
|---|
| 10 | POA_test_PingPongServer baseServant;
|
|---|
| 11 |
|
|---|
| 12 | CORBA_Object registered;
|
|---|
| 13 | } test_PingPongServer_Servant;
|
|---|
| 14 |
|
|---|
| 15 | static void
|
|---|
| 16 | PingPongServer_set (PortableServer_Servant servant,
|
|---|
| 17 | CORBA_Object object,
|
|---|
| 18 | const CORBA_char *name,
|
|---|
| 19 | CORBA_Environment *ev)
|
|---|
| 20 | {
|
|---|
| 21 | test_PingPongServer_Servant *this;
|
|---|
| 22 |
|
|---|
| 23 | this = (test_PingPongServer_Servant *) servant;
|
|---|
| 24 |
|
|---|
| 25 | this->registered = CORBA_Object_duplicate (object, ev);
|
|---|
| 26 | }
|
|---|
| 27 |
|
|---|
| 28 | static CORBA_Object
|
|---|
| 29 | PingPongServer_get (PortableServer_Servant servant,
|
|---|
| 30 | const CORBA_char *name,
|
|---|
| 31 | CORBA_Environment *ev)
|
|---|
| 32 | {
|
|---|
| 33 | test_PingPongServer_Servant *this;
|
|---|
| 34 |
|
|---|
| 35 | this = (test_PingPongServer_Servant *) servant;
|
|---|
| 36 |
|
|---|
| 37 | return CORBA_Object_duplicate (this->registered, ev);
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | static void
|
|---|
| 41 | PingPongServer_opSleep (PortableServer_Servant servant,
|
|---|
| 42 | const char *large_string,
|
|---|
| 43 | CORBA_Environment *ev)
|
|---|
| 44 | {
|
|---|
| 45 | /* Don't process the buffer - it should fill up at the other end */
|
|---|
| 46 | g_usleep (10000);
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | static void
|
|---|
| 50 | PingPongServer_opOneWay (PortableServer_Servant servant,
|
|---|
| 51 | const CORBA_long l,
|
|---|
| 52 | CORBA_Environment *ev)
|
|---|
| 53 | {
|
|---|
| 54 | /* Do nothing, but try and confuse the queue */
|
|---|
| 55 | link_main_iteration (FALSE);
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | static void
|
|---|
| 59 | PingPongServer_opOneWayCallback (PortableServer_Servant servant,
|
|---|
| 60 | test_PingPongServer remote_obj,
|
|---|
| 61 | CORBA_Environment *ev)
|
|---|
| 62 | {
|
|---|
| 63 | static int depth = 0;
|
|---|
| 64 |
|
|---|
| 65 | depth++;
|
|---|
| 66 | if (depth % 400 == 0 && depth > 1)
|
|---|
| 67 | fprintf (stderr, " recursion depth %d\n", depth);
|
|---|
| 68 |
|
|---|
| 69 | g_assert (ORBit_small_get_connection_status (remote_obj)
|
|---|
| 70 | != ORBIT_CONNECTION_IN_PROC);
|
|---|
| 71 |
|
|---|
| 72 | /* While this is blocking, loads more incoming
|
|---|
| 73 | * calls will trash our stack - quite possibly */
|
|---|
| 74 | test_PingPongServer_opRoundTrip (remote_obj, ev);
|
|---|
| 75 |
|
|---|
| 76 | depth--;
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | static void
|
|---|
| 80 | PingPongServer_opRoundTrip (PortableServer_Servant servant,
|
|---|
| 81 | CORBA_Environment *ev)
|
|---|
| 82 | {
|
|---|
| 83 | /* do nothing, but forces a round-trip */
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | static CORBA_long
|
|---|
| 87 | PingPongServer_pingPong (PortableServer_Servant servant,
|
|---|
| 88 | const test_PingPongServer replyTo,
|
|---|
| 89 | const CORBA_long idx,
|
|---|
| 90 | CORBA_Environment *ev)
|
|---|
| 91 | {
|
|---|
| 92 | CORBA_long ret;
|
|---|
| 93 | CORBA_Object me;
|
|---|
| 94 |
|
|---|
| 95 | me = PortableServer_POA_servant_to_reference (
|
|---|
| 96 | global_poa, servant, ev);
|
|---|
| 97 | g_assert (ev->_major == CORBA_NO_EXCEPTION);
|
|---|
| 98 |
|
|---|
| 99 | test_PingPongServer_opOneWay (replyTo, 3, ev);
|
|---|
| 100 |
|
|---|
| 101 | if (idx > 0)
|
|---|
| 102 | ret = test_PingPongServer_pingPong (replyTo, me, idx - 1, ev);
|
|---|
| 103 | else
|
|---|
| 104 | ret = 0;
|
|---|
| 105 |
|
|---|
| 106 | CORBA_Object_release (me, ev);
|
|---|
| 107 |
|
|---|
| 108 | return ret;
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | static void
|
|---|
| 112 | ping_pong_finalize (PortableServer_Servant servant,
|
|---|
| 113 | CORBA_Environment *ev)
|
|---|
| 114 | {
|
|---|
| 115 | test_PingPongServer_Servant *this;
|
|---|
| 116 |
|
|---|
| 117 | this = (test_PingPongServer_Servant *) servant;
|
|---|
| 118 |
|
|---|
| 119 | CORBA_Object_release (this->registered, ev);
|
|---|
| 120 |
|
|---|
| 121 | g_free (servant);
|
|---|
| 122 | }
|
|---|
| 123 |
|
|---|
| 124 | PortableServer_ServantBase__epv PingPongServer_base_epv = {
|
|---|
| 125 | NULL, ping_pong_finalize, NULL
|
|---|
| 126 | };
|
|---|
| 127 |
|
|---|
| 128 | POA_test_PingPongServer__epv PingPongServer_epv = {
|
|---|
| 129 | NULL,
|
|---|
| 130 | PingPongServer_opSleep,
|
|---|
| 131 | PingPongServer_opOneWay,
|
|---|
| 132 | PingPongServer_opOneWayCallback,
|
|---|
| 133 | PingPongServer_opRoundTrip,
|
|---|
| 134 | PingPongServer_pingPong,
|
|---|
| 135 | PingPongServer_set,
|
|---|
| 136 | PingPongServer_get
|
|---|
| 137 | };
|
|---|
| 138 |
|
|---|
| 139 | POA_test_PingPongServer__vepv PingPongServer_vepv = {
|
|---|
| 140 | &PingPongServer_base_epv,
|
|---|
| 141 | &PingPongServer_epv
|
|---|
| 142 | };
|
|---|
| 143 |
|
|---|
| 144 | static POA_test_PingPongServer *
|
|---|
| 145 | create_ping_pong_servant (void)
|
|---|
| 146 | {
|
|---|
| 147 | CORBA_Environment ev[1];
|
|---|
| 148 | test_PingPongServer_Servant *servant;
|
|---|
| 149 |
|
|---|
| 150 | servant = g_new0 (test_PingPongServer_Servant, 1);
|
|---|
| 151 | servant->baseServant.vepv = &PingPongServer_vepv;
|
|---|
| 152 |
|
|---|
| 153 | servant->registered = CORBA_OBJECT_NIL;
|
|---|
| 154 |
|
|---|
| 155 | CORBA_exception_init (ev);
|
|---|
| 156 | POA_test_PingPongServer__init (servant, ev);
|
|---|
| 157 | g_assert (ev->_major == CORBA_NO_EXCEPTION);
|
|---|
| 158 | CORBA_exception_free (ev);
|
|---|
| 159 |
|
|---|
| 160 | return (POA_test_PingPongServer *) servant;
|
|---|
| 161 | };
|
|---|