* @brief This is the raw function which will be called by the other * side of the embeddded connection to pass a message. * In some sense, all message passing starts here. * * The parameters are defined as "handles". That it, they are opaque * pointers. * * The connection handle is our "EmbeddedConnection" object * which we pass to the other side of the embedded con
| 82 | * |
| 83 | *************************************************************/ |
| 84 | ElementXML_Handle LocalProcessMessage(Connection_Receiver_Handle hReceiverConnection, ElementXML_Handle hIncomingMsg, int action) |
| 85 | { |
| 86 | // This is the connection object we created in this class, passed to the kernel and have |
| 87 | // now received back. |
| 88 | EmbeddedConnection* pConnection = reinterpret_cast<EmbeddedConnection*>(hReceiverConnection) ; |
| 89 | |
| 90 | // Make sure we have been passed a valid connection object. |
| 91 | if (pConnection == NULL) |
| 92 | { |
| 93 | return NULL ; |
| 94 | } |
| 95 | |
| 96 | if (action == SML_MESSAGE_ACTION_CLOSE) |
| 97 | { |
| 98 | // Close our connection to the remote process |
| 99 | pConnection->ClearConnectionHandle() ; |
| 100 | |
| 101 | return NULL ; |
| 102 | } |
| 103 | |
| 104 | // Synch connections are all happening within a single thread |
| 105 | if (action == SML_MESSAGE_ACTION_SYNCH) |
| 106 | { |
| 107 | // Create an object to wrap this message. |
| 108 | ElementXML incomingMsg(hIncomingMsg) ; |
| 109 | |
| 110 | // For a synchronous connection, immediately execute the incoming message, generating a response |
| 111 | // which is immediately passed back to the caller. |
| 112 | ElementXML* pResponse = pConnection->InvokeCallbacks(&incomingMsg) ; |
| 113 | |
| 114 | if (!pResponse) |
| 115 | { |
| 116 | return NULL ; |
| 117 | } |
| 118 | |
| 119 | ElementXML_Handle hResponse = pResponse->Detach() ; |
| 120 | delete pResponse ; |
| 121 | return hResponse ; |
| 122 | } |
| 123 | |
| 124 | // Asynch connections involve a thread switch. The message comes in on |
| 125 | // one thread, is dropped in a message queue and picked up by a second thread. |
| 126 | if (action == SML_MESSAGE_ACTION_ASYNCH) |
| 127 | { |
| 128 | // Store the incoming message on a queue and execute it on the receiver's thread (our thread) at a later point. |
| 129 | EmbeddedConnectionAsynch* eca = static_cast<EmbeddedConnectionAsynch*>(pConnection); |
| 130 | eca->AddToIncomingMessageQueue(hIncomingMsg) ; |
| 131 | |
| 132 | // There is no immediate response to an asynch message. |
| 133 | // The response will be sent back to the caller as another asynch message later, once the command has been executed. |
| 134 | return NULL ; |
| 135 | } |
| 136 | |
| 137 | // Not an action we understand, so just ignore it. |
| 138 | // This allows future versions to use other actions if they wish and |
| 139 | // we'll remain somewhat compatible. |
| 140 | return NULL ; |
| 141 | } |
nothing calls this directly
no test coverage detected