static void receiveCapabilityMessage(TransformerCapabilityMessage *message) { EMBX_ERROR err; EMBX_PORT replyPort; MMEReceiverFactory *factory; message->result = MME_NOMEM; /* preliminary result */ /* connect to the reply port */ if (EMBX_SUCCESS != EMBX_Connect(manager->transportHandle, message->portName, &replyPort)) { MME_Assert(0); /* cannot recover */ return; } /* TODO: no lock on this list */ for (factory = manager->factoryList; factory; factory = factory->next) { if (0 == strcmp(factory->transformerType, message->transformerType)) { break; } } message->capability.TransformerInfo_p = (void *) (message->capability.TransformerInfoSize ? message + 1 : 0); message->result = (factory ? factory->getTransformerCapabilityFunc(&message->capability) : MME_UNKNOWN_TRANSFORMER); /* post the reply back again */ err = EMBX_SendMessage(replyPort, message, message->messageSize); MME_Assert(EMBX_SUCCESS == err); /* cannot recover */ err = EMBX_ClosePort(replyPort); MME_Assert(EMBX_SUCCESS == err); /* cannot recover */ }
static MME_ERROR RemoteTransformer_KillCommand(Transformer_t* transformer, MME_CommandId_t commandId) { RemoteTransformer_t *remoteTransformer = (RemoteTransformer_t *) transformer; MME_ERROR result; EMBX_ERROR err; CommandSlot_t *slot; EMBX_VOID *buffer; TransformerTransformMessage *message; EMBX_PORT replyPort; /* TODO: shouldn't this be asserted! */ if (!remoteTransformer->sendPort.valid) { MME_Info(MME_INFO_TRANSFORMER, (DEBUG_ERROR_STR "MME port does not exist\n")); return MME_DRIVER_NOT_INITIALIZED; } /* confirm that the command is actually pending on the companion before we * issue the abort */ slot = &(remoteTransformer->commandSlots[MME_CMDID_GET_COMMAND(commandId)]); if (slot->status != MME_RUNNING || commandId != slot->command->CmdStatus.CmdId) { return MME_INVALID_ARGUMENT; } /* mark the command as complete */ slot->command->CmdStatus.Error = MME_COMMAND_ABORTED; slot->command->CmdStatus.State = MME_COMMAND_FAILED; /* fake up a completed transform request */ result = createTransformMessage(remoteTransformer, slot->command, &buffer); if (result != MME_SUCCESS) { return result; } /* connect to our own reply port */ err = EMBX_Connect(remoteTransformer->super.info->handle, remoteTransformer->replyPort.name, &replyPort); if (EMBX_SUCCESS != err) { return MME_EMBX_ERROR; } /* send the message */ message = (TransformerTransformMessage *) buffer; err = EMBX_SendMessage(replyPort, message, message->messageSize); if (EMBX_SUCCESS != err) { return MME_EMBX_ERROR; } EMBX_ClosePort(replyPort); return MME_SUCCESS; }
static MME_ERROR issueTerminateMMEMessages(TransportInfo_t* tpInfo) { EMBX_ERROR err; MME_ERROR res; int i; MME_Assert(manager); MME_Assert(tpInfo); for (i=0; i<4; i++) { char adminPortName[] = "MMECompanionAdmin#0"; EMBX_PORT adminPort; TransformerTerminateMMEMessage *message = NULL; /* Generate the port name we want to examine */ adminPortName[sizeof(adminPortName) - 2] = '0' + i; /* Attempt to connect to the admin port */ err = EMBX_Connect(tpInfo->handle, adminPortName, &adminPort); if (EMBX_PORT_NOT_BIND == err) { continue; }; MME_Assert(EMBX_SUCCESS == err); /* no recovery possible */ /* Allocate the terminate message */ res = createTerminateMMEMessage(tpInfo, &message); MME_Assert(MME_SUCCESS == res); /* no recovery possible */ /* Send the request and disconnect */ err = EMBX_SendMessage(adminPort, message, message->messageSize); MME_Assert(MME_SUCCESS == res); /* no recovery possible */ /* Close the admin port */ err = EMBX_ClosePort(adminPort); MME_Assert(MME_SUCCESS == res); /* no recovery possible */ } return MME_SUCCESS; }
int main() { EMBX_TRANSPORT hTrans; EMBX_PORT bufferpool, consumer, mypoolconnection; EMBX_ERROR err; int i; embxRuntimeInit(); err = EMBX_OpenTransport("shm", &hTrans); assert(EMBX_SUCCESS == err); /* Create the port which will hold the pool of work buffers */ err = EMBX_CreatePort(hTrans, "bufferpool", &bufferpool); assert(EMBX_SUCCESS == err); /* Make a connection to the port we just created so we can inject * empty buffers onto the port's queue as part of the initialization */ err = EMBX_Connect(hTrans, "bufferpool", &mypoolconnection); assert(EMBX_SUCCESS == err); /* Now wait for the consumer port to come into existence and * make a connection to it. */ err = EMBX_ConnectBlock(hTrans, "consumer", &consumer); assert(EMBX_SUCCESS == err); /* Inject empty buffers into the buffer pool */ for(i=0;i<BUFFER_POOL_SIZE;i++) { EMBX_VOID *buffer; err = EMBX_Alloc(hTrans, BUFFER_SIZE, &buffer); assert(EMBX_SUCCESS == err); /* Send empty buffer to the buffer pool port */ err = EMBX_SendMessage(mypoolconnection, buffer, 0); assert(EMBX_SUCCESS == err); } /* We don't need our connection to the buffer pool anymore * so close it down. */ EMBX_ClosePort(mypoolconnection); for(i=0;i<100;i++) { EMBX_RECEIVE_EVENT ev; EMBX_UINT buffersize; /* Jabber ... */ printf("producer: Issuing message %d of 100\n", i+1); /* Get an empty buffer from the pool */ err = EMBX_ReceiveBlock(bufferpool, &ev); assert(EMBX_SUCCESS == err); /* The event size field does not represent the actual * size of the buffer in this case, hence if you need * to find that out use the following. However in this * case where all the buffers are the same known size * it wouldn't be necessary expect as self checking debug. */ err = EMBX_GetBufferSize(ev.data, &buffersize); assert(EMBX_SUCCESS == err); /* Do something to fill the buffer with stuff to be used * by the consumer...... use your imagination ...... */ /* Now send the buffer to the consumer with the real amount * of data in the buffer as the size argument (this can be * less than the buffer size). For this example we assume * the whole buffer contains valid data. */ err = EMBX_SendMessage(consumer, ev.data, buffersize); assert(EMBX_SUCCESS == err); } /* Shut the communication system down. This has the side effect * of causing the consumer to also close down, almost certainly * before outstanding messages have been processed. */ EMBX_ClosePort(bufferpool); EMBX_ClosePort(consumer); EMBX_CloseTransport(hTrans); EMBX_Deinit(); return 0; }
int run_test(void) { EMBX_ERROR res; EMBX_TPINFO tpinfo1; EMBX_BOOL bFailed; EMBX_TRANSPORT tp; EMBX_PORT localPort,remotePort; EMBX_VOID *buffer1,*buffer2; EMBX_FACTORY factory; bFailed = EMBX_FALSE; tp = EMBX_INVALID_HANDLE_VALUE; buffer1 = buffer2 = 0; /* Test 1 */ res = EMBX_SendMessage(EMBX_INVALID_HANDLE_VALUE, buffer1, 0); if(res != EMBX_INVALID_PORT) { EMBX_Info(EMBX_TRUE, ("Test1 failed, res = %s\n",error_strings[res])); bFailed = EMBX_TRUE; } res = EMBX_RegisterTransport(EMBXLB_loopback_factory,&loopback_config,sizeof(EMBXLB_Config_t),&factory); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Transport Registration failed, res = %s, exiting\n",error_strings[res])); goto skip_remaining_tests; } /* Test 2 */ res = EMBX_Init(); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test2 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 3 */ res = EMBX_GetFirstTransport(&tpinfo1); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test3 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 4 */ res = EMBX_OpenTransport(tpinfo1.name, &tp); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test4 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 5 */ res = EMBX_CreatePort(tp, "testport", &localPort); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test5 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 6 */ res = EMBX_Connect(tp, "testport", &remotePort); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test6 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 7 */ res = EMBX_Alloc(tp, BUFFER_SIZE, &buffer1); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test7 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 8 */ res = EMBX_SendMessage(tp, buffer1, 0); if(res != EMBX_INVALID_PORT) { EMBX_Info(EMBX_TRUE, ("Test8 failed, res = %s\n",error_strings[res])); bFailed = EMBX_TRUE; } /* Test 9 */ res = EMBX_SendMessage(localPort, buffer1, 0); if(res != EMBX_INVALID_PORT) { EMBX_Info(EMBX_TRUE, ("Test9 failed, res = %s\n",error_strings[res])); bFailed = EMBX_TRUE; } /* Test 10 */ res = EMBX_SendMessage(remotePort, 0, 0); if(res != EMBX_INVALID_ARGUMENT) { EMBX_Info(EMBX_TRUE, ("Test10 failed, res = %s\n",error_strings[res])); bFailed = EMBX_TRUE; } /* Test 11 */ res = EMBX_SendMessage(remotePort, buffer1, BUFFER_SIZE+1); if(res != EMBX_INVALID_ARGUMENT) { EMBX_Info(EMBX_TRUE, ("Test11 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 12 */ res = EMBX_SendMessage(remotePort, buffer1, BUFFER_SIZE); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test12 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 13 - Ensure this allocation happens before buffer1 gets free'd * when the port is closed, so buffer1 and buffer2 will not point to * the same memory which is important for later tests. */ res = EMBX_Alloc(tp, BUFFER_SIZE, &buffer2); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test13 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 14 */ res = EMBX_ClosePort(localPort); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test14 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 15 - buffer1 has been freed by test14 so should be garbage */ res = EMBX_SendMessage(remotePort, buffer1, 0); if(res != EMBX_INVALID_ARGUMENT) { EMBX_Info(EMBX_TRUE, ("Test15 failed, res = %s\n",error_strings[res])); bFailed = EMBX_TRUE; } /* Test 16 */ res = EMBX_SendMessage(remotePort, buffer2, BUFFER_SIZE); if(res != EMBX_INVALID_PORT) { EMBX_Info(EMBX_TRUE, ("Test16 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 17 */ res = EMBX_ClosePort(remotePort); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test17 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 18 */ res = EMBX_CloseTransport(tp); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test18 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 19 */ res = EMBX_Deinit(); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test19 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* These test a different code path to the identical tests done before * EMBX_Init. */ /* Test 20 - Depends on buffer2 not having been freed so we get through * to checking the state of the driver. */ res = EMBX_SendMessage(remotePort, buffer2, 0); if(res != EMBX_INVALID_PORT) { EMBX_Info(EMBX_TRUE, ("Test20 failed, res = %s\n",error_strings[res])); bFailed = EMBX_TRUE; } /* Test 21 */ res = EMBX_UnregisterTransport(factory); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test21 failed, res = %s\n",error_strings[res])); bFailed = EMBX_TRUE; } return bFailed?-1:0; skip_remaining_tests: EMBX_Info(EMBX_TRUE, ("Skipping Remaining Tests\n")); return -1; }
int run_test(void) { EMBX_UINT i; EMBX_ERROR res; EMBX_TPINFO tpinfo1; EMBX_BOOL bFailed; EMBX_PORT localPort,remotePort; EMBX_VOID *buffer1; EMBX_FACTORY factory; EMBX_RECEIVE_EVENT ev; bFailed = EMBX_FALSE; buffer1 = 0; /* Test 1 */ res = EMBX_ReceiveBlock(EMBX_INVALID_HANDLE_VALUE, &ev); if(res != EMBX_INVALID_PORT) { EMBX_Info(EMBX_TRUE, ("Test1 failed, res = %s\n",error_strings[res])); bFailed = EMBX_TRUE; } res = EMBX_RegisterTransport(EMBXLB_loopback_factory, &loopback_config, sizeof(EMBXLB_Config_t), &factory); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Transport Registration failed, res = %s, exiting\n",error_strings[res])); goto skip_remaining_tests; } /* Test 2 */ res = EMBX_Init(); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test2 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 3 */ res = EMBX_GetFirstTransport(&tpinfo1); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test3 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 4 */ res = EMBX_OpenTransport(tpinfo1.name, &tp); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test4 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 5 */ res = EMBX_CreatePort(tp, "testport", &localPort); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test5 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 6 */ res = EMBX_Connect(tp, "testport", &remotePort); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test6 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 7 */ res = EMBX_ReceiveBlock(tp, &ev); if(res != EMBX_INVALID_PORT) { EMBX_Info(EMBX_TRUE, ("Test7 failed, res = %s\n",error_strings[res])); bFailed = EMBX_TRUE; } /* Test 8 */ res = EMBX_ReceiveBlock(remotePort, &ev); if(res != EMBX_INVALID_PORT) { EMBX_Info(EMBX_TRUE, ("Test8 failed, res = %s\n",error_strings[res])); bFailed = EMBX_TRUE; } /* Test 9 */ res = EMBX_ReceiveBlock(localPort, 0); if(res != EMBX_INVALID_ARGUMENT) { EMBX_Info(EMBX_TRUE, ("Test9 failed, res = %s\n",error_strings[res])); bFailed = EMBX_TRUE; } /* Test 10 */ res = EMBX_Alloc(tp, BUFFER_SIZE, &buffer1); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test10 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } for(i=0;i<BUFFER_SIZE;i++) { ((unsigned char *)buffer1)[i] = (unsigned char)i; } /* Test 11 */ res = EMBX_SendMessage(remotePort, buffer1, BUFFER_SIZE); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test11 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 12 */ res = EMBX_ReceiveBlock(localPort, &ev); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test12 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } if(ev.handle != EMBX_INVALID_HANDLE_VALUE || ev.offset != 0 || ev.type != EMBX_REC_MESSAGE || ev.size != BUFFER_SIZE) { EMBX_Info(EMBX_TRUE, ("Test13 failed, event structure incorrect\n")); goto skip_remaining_tests; } for(i=0;i<ev.size;i++) { if( ((unsigned char *)ev.data)[i] != (unsigned char)i ) { EMBX_Info(EMBX_TRUE, ("Test13 failed, buffer contents incorrect\n")); bFailed = EMBX_TRUE; break; } } /* Test 13 */ res = EMBX_Free(ev.data); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test13 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } if(!EMBX_OS_ThreadCreate(send_thread, (void *)remotePort, EMBX_DEFAULT_THREAD_PRIORITY, "send")) { EMBX_Info(EMBX_TRUE, ("Unable to create thread\n")); goto skip_remaining_tests; } /* Test 14 */ res = EMBX_ReceiveBlock(localPort, &ev); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test14 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } if(ev.handle != EMBX_INVALID_HANDLE_VALUE || ev.offset != 0 || ev.type != EMBX_REC_MESSAGE || ev.size != BUFFER_SIZE) { EMBX_Info(EMBX_TRUE, ("Test15 failed, event structure incorrect\n")); goto skip_remaining_tests; } /* Test 15 */ res = EMBX_Free(ev.data); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test15 failed, res = %s\n",error_strings[res])); bFailed = EMBX_TRUE; } /* Test 16 */ res = EMBX_ClosePort(remotePort); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test16 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 17 */ res = EMBX_ClosePort(localPort); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test17 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 18 */ res = EMBX_CloseTransport(tp); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test18 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 19 */ res = EMBX_Deinit(); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test19 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* These test a different code path to the identical tests done before * EMBX_Init */ /* Test 20 */ res = EMBX_ReceiveBlock(localPort, &ev); if(res != EMBX_INVALID_PORT) { EMBX_Info(EMBX_TRUE, ("Test20 failed, res = %s\n",error_strings[res])); bFailed = EMBX_TRUE; } /* Test 21 */ res = EMBX_UnregisterTransport(factory); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test21 failed, res = %s\n",error_strings[res])); bFailed = EMBX_TRUE; } return bFailed?-1:0; skip_remaining_tests: EMBX_Info(EMBX_TRUE, ("Skipping Remaining Tests\n")); return -1; }
static MME_ERROR RemoteTransformer_TermOrKill(Transformer_t* transformer, int doKill) { RemoteTransformer_t *remoteTransformer = (RemoteTransformer_t *) transformer; EMBX_ERROR err; EMBX_VOID *buffer; TransformerTerminateMessage *message; MME_ERROR result, res; result = MME_NOMEM; if (!remoteTransformer->sendPort.valid) { DP("MME port does not exist\n"); return MME_INVALID_ARGUMENT; } /* No command must be pending on the companion side */ if (remoteTransformer->numCommandSlots > 0) { DP("RemoteTransformer::Terminate() failed, commands pending\n"); return MME_COMMAND_STILL_EXECUTING; } res = createTerminateMessage(remoteTransformer, 0, &buffer); if (res != MME_SUCCESS) { DP("CreateTerminateMsg() failed, error=%d\n", res); return res; } /* Send the message */ message = (TransformerTerminateMessage *) buffer; DP("Sending %s message @$%08x...\n", message, (doKill ? "kill" : "terminate")); if (doKill) { EMBX_PORT replyPort; /* connect to our own reply port */ err = EMBX_Connect(remoteTransformer->super.info->handle, remoteTransformer->replyPort.name, &replyPort); if (EMBX_SUCCESS != err) { DP("RemoteTransformer_Term(): failed to connect to self\n"); cleanupTerminateMessage(remoteTransformer, message); return MME_EMBX_ERROR; } err = EMBX_SendMessage(replyPort, message, message->messageSize); if (EMBX_SUCCESS != err) { DP("RemoteTransformer_Term(): failed to send message to self\n"); cleanupTerminateMessage(remoteTransformer, message); return MME_EMBX_ERROR; } EMBX_ClosePort(replyPort); } else { err = EMBX_SendMessage(remoteTransformer->adminPort, message, message->messageSize); if (EMBX_SUCCESS != err) { DP("RemoteTransformer_Term(): failed to send message to coprocessor\n"); cleanupTerminateMessage(remoteTransformer, message); return MME_EMBX_ERROR; } } /* lost ownership */ message = NULL; /* Wait for ReceiverThread to terminate itself after receiving the reply message */ DP("Waiting for ReceiverThread to terminate itself...\n"); DP("terminateWasReplied 0x%08x\n", remoteTransformer->terminateWasReplied); EMBX_OS_EVENT_WAIT(&remoteTransformer->terminateWasReplied); if (remoteTransformer->terminationResult != MME_SUCCESS) { DP("Failed to terminate receiver thread properly\n"); return MME_INTERNAL_ERROR; } err = EMBX_OS_ThreadDelete(remoteTransformer->receiverThread); if (err != EMBX_SUCCESS) { DP("EMBX_OS_ThreadDelete() failed, error=d\n", err); } remoteTransformer->receiverThread = NULL; /* Close the MME port */ DP("Close mmePort...\n"); err = EMBX_ClosePort(remoteTransformer->sendPort.port); if (err != EMBX_SUCCESS) { DP("EMBX_ClosePort(mmePort) failed, error=d\n", err); } /* Close the reply port */ DP("Invalidate replyPort...\n"); err = EMBX_InvalidatePort(remoteTransformer->replyPort.port); if (err != EMBX_SUCCESS) { DP("EMBX_InvalidatePort(replyPort) failed, error=%d\n", err); } DP("Close replyPort...\n"); err = EMBX_ClosePort(remoteTransformer->replyPort.port); if (err != EMBX_SUCCESS) { DP("EMBX_ClosePort(replyPort) failed, error=%d\n", err); } remoteTransformer->replyPort.valid = EMBX_FALSE; return MME_SUCCESS; }
static MME_ERROR findTransformerWithinTransport(TransportInfo_t *tpInfo, const char *name, EMBX_PORT *adminPort_p) { MME_ERROR res; EMBX_ERROR err; TransformerRegisteredMessage *msg = 0; EMBX_PORT adminPort = 0; MME_UINT i; MME_Assert(manager); MME_Assert(name); MME_Assert(tpInfo); res = createRegisteredMessage(tpInfo, name, &msg); if (MME_SUCCESS != res) { return res; } for (i=0; i<4; i++) { char adminPortName[] = "MMECompanionAdmin#0"; EMBX_RECEIVE_EVENT event; /* generate the port name we want to examine */ adminPortName[sizeof(adminPortName) - 2] = '0' + i; /* attempt to connect to the admin port */ err = EMBX_Connect(tpInfo->handle, adminPortName, &adminPort); if (EMBX_PORT_NOT_BIND == err) { continue; } else if (EMBX_SUCCESS != err) { goto error_recovery; } /* send the request and disconnect from the port */ err = EMBX_SendMessage(adminPort, msg, sizeof(*msg)); if (EMBX_SUCCESS != err) { goto error_recovery; } msg = 0; /* wait for the reply */ /* TIMEOUT SUPPORT: Allow the receive to timeout */ err = EMBX_ReceiveBlockTimeout(tpInfo->replyPort, &event, MME_TRANSFORMER_TIMEOUT); if (EMBX_SUCCESS != err) { goto error_recovery; } MME_Assert(event.type == EMBX_REC_MESSAGE); MME_Assert(event.size == sizeof(*msg)); /* interpret said reply */ msg = event.data; MME_Assert(msg->messageSize == sizeof(*msg)); if (MME_SUCCESS == msg->result) { break; } err = EMBX_ClosePort(adminPort); if (EMBX_SUCCESS != err) { goto error_recovery; } adminPort = 0; } cleanupRegisteredMessage(tpInfo, msg); if (i < 4) { *adminPort_p = adminPort; return MME_SUCCESS; } else { return MME_UNKNOWN_TRANSFORMER; } error_recovery: /* TIMEOUT SUPPORT: Return MME_TRANSFORMER_NOT_RESPONDING if timeout occurs */ res = (EMBX_NOMEM == err ? MME_NOMEM : (EMBX_SYSTEM_TIMEOUT == err ? MME_TRANSFORMER_NOT_RESPONDING : MME_EMBX_ERROR)); if (adminPort) { err = EMBX_ClosePort(adminPort); MME_Assert(EMBX_SUCCESS == err); } if (msg) { cleanupRegisteredMessage(tpInfo, msg); } return res; }
int run_test(void) { EMBX_UINT i; EMBX_ERROR res; EMBX_TPINFO tpinfo1; EMBX_BOOL bFailed; EMBX_TRANSPORT tp; EMBX_PORT localPort,remotePort; EMBX_HANDLE hObj; EMBX_FACTORY factory; EMBX_RECEIVE_EVENT ev; bFailed = EMBX_FALSE; tp = EMBX_INVALID_HANDLE_VALUE; hObj = EMBX_INVALID_HANDLE_VALUE; /* Test 1 */ res = EMBX_Receive(EMBX_INVALID_HANDLE_VALUE, &ev); if(res != EMBX_INVALID_PORT) { EMBX_Info(EMBX_TRUE, ("Test1 failed, res = %s\n",error_strings[res])); bFailed = EMBX_TRUE; } res = EMBX_RegisterTransport(EMBXLB_loopback_factory, &loopback_config, sizeof(EMBXLB_Config_t), &factory); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Transport Registration failed, res = %s, exiting\n",error_strings[res])); goto skip_remaining_tests; } /* Test 2 */ res = EMBX_Init(); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test2 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 3 */ res = EMBX_GetFirstTransport(&tpinfo1); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test3 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 4 */ res = EMBX_OpenTransport(tpinfo1.name, &tp); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test4 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 5 */ res = EMBX_CreatePort(tp, "testport", &localPort); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test5 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 6 */ res = EMBX_Connect(tp, "testport", &remotePort); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test6 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 7 */ res = EMBX_RegisterObject(tp, object, BUFFER_SIZE, &hObj); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test7 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } for(i=0;i<BUFFER_SIZE;i++) { ((unsigned char *)object)[i] = (unsigned char)i; } /* Test 8 */ res = EMBX_SendObject(remotePort, hObj, 0, BUFFER_SIZE); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test8 failed, res = %s\n",error_strings[res])); bFailed = EMBX_TRUE; } /* Test 9 */ res = EMBX_Receive(localPort, &ev); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test9 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } if(ev.handle != hObj || /* This is a specific quirk of the loopback transport */ ev.offset != 0 || ev.type != EMBX_REC_OBJECT || ev.size != BUFFER_SIZE) { EMBX_Info(EMBX_TRUE, ("Test9 failed, event structure incorrect\n")); goto skip_remaining_tests; } for(i=0;i<ev.size;i++) { if( ((unsigned char *)ev.data)[i] != (unsigned char)i ) { EMBX_Info(EMBX_TRUE, ("Test9 failed, buffer contents incorrect\n")); bFailed = EMBX_TRUE; break; } } /* Test 10 */ res = EMBX_UpdateObject(remotePort, hObj, 0, BUFFER_SIZE); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test10 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 11 */ res = EMBX_Receive(localPort, &ev); if(res != EMBX_INVALID_STATUS) { EMBX_Info(EMBX_TRUE, ("Test11 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 12 */ res = EMBX_DeregisterObject(tp, hObj); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test12 failed, res = %s\n",error_strings[res])); bFailed = EMBX_TRUE; } /* Test 13 */ res = EMBX_ClosePort(remotePort); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test13 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 14 */ res = EMBX_ClosePort(localPort); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test14 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 15 */ res = EMBX_CloseTransport(tp); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test15 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 16 */ res = EMBX_Deinit(); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test16 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 17 */ res = EMBX_UnregisterTransport(factory); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test17 failed, res = %s\n",error_strings[res])); bFailed = EMBX_TRUE; } return bFailed?-1:0; skip_remaining_tests: EMBX_Info(EMBX_TRUE, ("Skipping Remaining Tests\n")); return -1; }