From 23c8476b38377c9d9f6379b7e387557cc0284f21 Mon Sep 17 00:00:00 2001 From: Justin Sobota Date: Mon, 12 Nov 2012 14:50:57 -0500 Subject: [PATCH] completed request/response infrastructure --- include/rmtransportloc.h | 46 +++++++ rm_policy.h => rmpolicy.h | 0 rmservices.h | 4 + rmtransport.h | 17 +-- src/rm.c | 257 ++++++++++++++++++++++++++++++++------ src/rmnameserver.c | 73 +++++++++++ src/rmpolicy.c | 53 ++++++++ src/rmservices.c | 27 +++- src/rmtransport.c | 157 ++++++++++++----------- 9 files changed, 505 insertions(+), 129 deletions(-) rename rm_policy.h => rmpolicy.h (100%) create mode 100644 src/rmnameserver.c create mode 100644 src/rmpolicy.c diff --git a/include/rmtransportloc.h b/include/rmtransportloc.h index f736f4a..9550b54 100644 --- a/include/rmtransportloc.h +++ b/include/rmtransportloc.h @@ -194,6 +194,52 @@ typedef struct { char policyData[RM_MAX_POLICY_SIZE_BYTES]; } Rm_PolicyChangePkt; +/** + * @brief Resource Pool Modification Request Packet Types + */ +typedef enum { + /** Resource pool allocation request */ + Rm_resPoolModType_ALLOCATE = 0, + /** Resource pool free request */ + Rm_resPoolModType_FREE = 1 +} Rm_ResourcePoolModReqType; + +/** + * @brief Resource Pool Modification Request Packet - Packet sent to RM Server from + * RM Client Delegates in order to request resource pool modifications on + * the Client Delegate. The Client Delegate can request more resource's for + * its local resource pool or it can free resources from its resource pool back + * to the Server. */ +typedef struct { + /** The transaction ID associated with the request packet */ + uint32_t requestId; + /** The resource pool modification request type */ + Rm_ResourcePoolModReqType resourcePoolModReqType; + /** Name of RM Client Delegate instance that is issuing the resource pool + * modification request. The instance name will be used to validate the + * request against the RM policy defined for the instance. */ + char instName[RM_INST_NAME_MAX_CHARS]; + /** Resource pool resource request information */ + Rm_ResourceInfo resourceInfo; +} Rm_ResourcePoolModRequestPkt; + +/** + * @brief Resource Pool Modification Response Packet - Packet sent to RM Client + * Delegates from RM Servers in response to resource pool modification requests. + * The packet will contain resource response information based on the request + */ +typedef struct { + /** responseID will equal the requestId received in the resource pool mod request + * packet. This ID should be associated with a transaction stored in + * the RM instance that sent the resource request packet */ + uint32_t responseId; + /** Result of the resource pool mod request. Resource request, denied, or error. The + * return values are externally visible so they're tracked in rmservice.h */ + int32_t requestResult; + /* Resource pool resource response information */ + Rm_ResourceInfo resourceInfo; +} Rm_ResourcePoolModResponsePkt; + #ifdef __cplusplus } #endif diff --git a/rm_policy.h b/rmpolicy.h similarity index 100% rename from rm_policy.h rename to rmpolicy.h diff --git a/rmservices.h b/rmservices.h index 1f4facf..f4f8227 100644 --- a/rmservices.h +++ b/rmservices.h @@ -113,6 +113,10 @@ extern "C" { #define RM_SERVICE_ERROR_INVALID_TRANSACTION_RECEIVED_ON_CLIENT (RM_SERVICE_ERROR_BASE-13) /** A failure occurred within a registered transport's packet free API */ #define RM_SERVICE_ERROR_TRANSPORT_FREE_PKT_ERROR (RM_SERVICE_ERROR_BASE-14) +/** Invalid NameServer object create on non-Server instance */ +#define RM_SERVICE_ERROR_NAMESERVER_OBJECT_CREATE_ON_INVALID_INSTANCE (RM_SERVICE_ERROR_BASE-15) +/** Invalid NameServer object delete on non-Server instance */ +#define RM_SERVICE_ERROR_NAMESERVER_OBJECT_DELETE_ON_INVALID_INSTANCE (RM_SERVICE_ERROR_BASE-16) /** RM Transport Error Code Base */ #define RM_TRANSPORT_ERROR_BASE (-128) diff --git a/rmtransport.h b/rmtransport.h index cb04008..8d12fa5 100644 --- a/rmtransport.h +++ b/rmtransport.h @@ -64,6 +64,8 @@ extern "C" { #define RM_TRANSPORT_ERROR_HANDLE_HAS_NOT_BEEN_REGISTERED (RM_TRANSPORT_ERROR_BASE-1) /** No transports have been registered with the RM instance */ #define RM_TRANSPORT_ERROR_NO_TRANSPORTS_REGISTERED (RM_TRANSPORT_ERROR_BASE-2) +/** RM packets are available but an error was encountered during reception */ +#define RM_TRANSPORT_ERROR_PACKET_RECEPTION_ERROR (RM_TRANSPORT_ERROR_BASE-3) /** * @brief Result of RM transport layer operations @@ -106,7 +108,11 @@ typedef enum { /** Policy request packet */ Rm_pktType_POLICY_REQUEST = 4, /** Policy response packet */ - Rm_pktType_POLICY_CHANGE = 5 + Rm_pktType_POLICY_CHANGE = 5, + /** Resource pool modification request */ + Rm_pktType_RESOURCE_POOL_MODIFICATION_REQUEST = 6, + /** Resource pool modification response */ + Rm_pktType_RESOURCE_POOL_MODIFICATION_RESPONSE = 7 } Rm_pktType; /** @@ -202,15 +208,12 @@ typedef struct { * @param[in] transportHandle * Which application transport to retrieve a packet from * - * @param[in] pkt - * Pointer to received resource packet. - * * @retval - * 0 - Packet reception okay. + * Non-NULL - Pointer to received RM packet. * @retval - * Non-zero - Packet receive failed. + * NULL - Packet receive failed. */ - int32_t (*rmReceive)(Rm_TransportHandle transportHandle, Rm_Packet *pkt); + void * (*rmReceive)(Rm_TransportHandle transportHandle); /** * @b Description diff --git a/src/rm.c b/src/rm.c index e546fc3..2e8c790 100644 --- a/src/rm.c +++ b/src/rm.c @@ -272,6 +272,19 @@ void Rm_transactionResponder (Rm_Inst *rmInst, Rm_Transaction *transaction, Rm_transactionQueueDelete(rmInst, transaction->id); } +void Rm_allocationHandler (Rm_Inst *rmInst, Rm_Transaction *transaction, + Rm_TransactionReceipt *receipt) +{ + +} + +void Rm_freeHandler (Rm_Inst *rmInst, Rm_Transaction *transaction, + Rm_TransactionReceipt *receipt) +{ + +} + + /* Function used to forward RM transactions to higher level agents */ void Rm_transactionForwarder (Rm_Inst *rmInst, Rm_Transaction *transaction, Rm_TransactionReceipt *receipt) @@ -286,10 +299,14 @@ void Rm_transactionForwarder (Rm_Inst *rmInst, Rm_Transaction *transaction, return; } - /* Find the transport for the higher level agent. Check for a remote Client Delegate first. - * If a connection does not exist check for a connection to a Server */ - dstTransportNode = Rm_transportNodeFindRemoteInstType(rmInst, Rm_instType_CLIENT_DELEGATE); - if (dstTransportNode == NULL) + /* Find the transport for the higher level agent. Check for a connection to a Client Delegate + * or a Server. Clients will be connected to either a Client Delegate or a Server. Client + * Delegates will be connected to a Server. */ + if (rmInst->instType == Rm_instType_CLIENT) + { + dstTransportNode = Rm_transportNodeFindRemoteInstType(rmInst, Rm_instType_CLIENT_DELEGATE); + } + else if (rmInst->instType == Rm_instType_CLIENT_DELEGATE) { dstTransportNode = Rm_transportNodeFindRemoteInstType(rmInst, Rm_instType_SERVER); } @@ -353,8 +370,14 @@ void Rm_transactionProcessor (Rm_Inst *rmInst, Rm_Transaction *transaction, Rm_TransactionReceipt *receipt) { Rm_Transaction *queuedTransaction = NULL; - - if (rmInst->instType == Rm_instType_CLIENT) + + /* Handle auto-forwarded transactions. These transactions include: + * - All request transactions received on Clients are forwarded to the Client Delegate + * - NameServer requests received on the Client Delegate are forwarded to the Server */ + if ((rmInst->instType == Rm_instType_CLIENT) || + ((rmInst->instType == Rm_instType_CLIENT_DELEGATE) && + (transaction->type == Rm_service_RESOURCE_MAP_TO_NAME) || + (transaction->type == Rm_service_RESOURCE_UNMAP_NAME))) { /* Check if the new transaction's ID matches any transactions waiting for * responses. A transaction received as a response will have an ID that @@ -363,9 +386,36 @@ void Rm_transactionProcessor (Rm_Inst *rmInst, Rm_Transaction *transaction, { if (queuedTransaction->state == Rm_transactionState_AWAITING_RESPONSE) { - /* Found a transaction awaiting a response. Pass both transactions - * to the service responder for response processing */ - Rm_serviceResponder(rmInst, transaction, queuedTransaction, receipt); + if (rmInst->instType == Rm_instType_CLIENT) + { + /* Client found a transaction awaiting a response. Pass both transactions + * to the service responder for response processing */ + Rm_serviceResponder(rmInst, transaction, queuedTransaction, receipt); + } + else if (rmInst->instType == Rm_instType_CLIENT_DELEGATE) + { + /* Client Delegate found a NameServer transaction awaiting a response. Send the + * response to either the transaction or service responder based on the + * source instance */ + if (strcmp(queuedTransaction->sourceInstName, rmInst->name) + { + /* NameServer transaction originated from another instance. Use the + * transaction responder to send the NameServer result to the source instance. + * Need to transfer the NameServer result details to the request transaction + * which will be reused for the response. */ + queuedTransaction->details = transaction->details; + Rm_transactionResponder(rmInst, queuedTransaction, receipt); + /* Delete the response transaction */ + Rm_transactionQueueDelete(rmInst, transaction->id); + } + else + { + /* NameServer request originated on the Client Delegate instance. Send to the + * service responder */ + Rm_serviceResponder(rmInst, transaction, queuedTransaction, + receipt); + } + } } else { @@ -387,47 +437,180 @@ void Rm_transactionProcessor (Rm_Inst *rmInst, Rm_Transaction *transaction, } else { - /* All service requests on Clients are forwarded to the higher level RM agent - * either a Client Delegate or Server, based on the RM system architecture */ + /* All service requests on Clients are forwarded to the higher level RM Client + * Delegate. NameServer requests on Client Delegates are forwarded to the Server. */ Rm_transactionForwarder(rmInst, transaction, receipt); } } } else { - /* Execute a command processor based on the command type */ - switch (transaction->transCommand) + /* Client Delegate and Server transaction processors. */ + switch (transaction->type) { - case Rm_command_ALLOCATE: - case Rm_command_BLOCK_ALLOCATE: - case Rm_command_ALLOCATE_NAMED: - Rm_allocate(rmInst, transaction, receipt); - break; - case Rm_command_FREE: - case Rm_command_BLOCK_FREE: - case Rm_command_FREE_NAMED: - Rm_free(rmInst, transaction, receipt); - break; - case Rm_command_MAP_NAME: - Rm_nsAddObject(rmInst, transaction, receipt); + case Rm_service_RESOURCE_ALLOCATE: + case Rm_service_RESOURCE_BLOCK_ALLOCATE: + case Rm_service_RESOURCE_ALLOCATE_BY_NAME: + /* Run the transaction through the response handler to take care of any + * transactions that are responses to sent allocation requests. */ + if (queuedTransaction = Rm_transactionQueueFind(rmInst, transaction->id)) + { + if (queuedTransaction->state == Rm_transactionState_AWAITING_RESPONSE) + { + /* If source instance name does not match the current instance + * name the allocation request came from a client. The result + * must be sent back to the Client */ + if (strcmp(queuedTransaction->sourceInstName, rmInst->name)) + { + /* Names don't match. Copy the allocation response resource data + * into the original transaction and send it back to the Client */ + queuedTransaction->details = transaction->details; + memcpy ((void *)&(queuedTransaction->resourceInfo), + (void *)&(transaction->resourceInfo), sizeof(Rm_ResourceInfo)); + Rm_transactionResponder(rmInst, queuedTransaction, receipt); + /* Delete the response transaction */ + Rm_transactionQueueDelete(rmInst, transaction->id); + } + else + { + /* Resource allocation request originated locally on Client Delegate + * instance. Send the response via the service responder. */ + Rm_serviceResponder(rmInst, transaction, queuedTransaction, + receipt); + } + } + else + { + /* Request transaction was not in the awaiting response state. Flag the + * error in the receipt and return */ + receipt->serviceResult = RM_SERVICE_ERROR_INVALID_REQUEST_TRANSACTION_STATE_UPON_RESPONSE; + } + + } + else + { + /* This is a new transaction request originating from an RM instance with fewer + * allocate/free privileges. Run the allocation handler to see if the resource + * request can be handled locally or if it needs to be forwarded to a higher level + * agent */ + Rm_allocationHandler(rmInst, transaction, receipt); + } break; - case Rm_command_UNMAP_NAME: - Rm_nsDeleteObject(rmInst, transaction, receipt); - break; - case Rm_command_RESOURCE_STATUS: - Rm_getResourceStatus(rmInst, transaction, receipt); - break; - case Rm_command_RESOURCE_RESPONSE: - + case Rm_service_RESOURCE_FREE: + case Rm_service_RESOURCE_BLOCK_FREE: + case Rm_service_RESOURCE_FREE_BY_NAME: + /* Run the transaction through the response handler to take care of any + * transactions that are responses to sent free requests. */ + if (queuedTransaction = Rm_transactionQueueFind(rmInst, transaction->id)) + { + if (queuedTransaction->state == Rm_transactionState_AWAITING_RESPONSE) + { + /* If source instance name does not match the current instance + * name the allocation request came from a client. The result + * must be sent back to the Client */ + if (strcmp(queuedTransaction->sourceInstName, rmInst->name)) + { + /* Names don't match. Copy the free response resource data + * into the original transaction and send it back to the Client */ + queuedTransaction->details = transaction->details; + memcpy ((void *)&(queuedTransaction->resourceInfo), + (void *)&(transaction->resourceInfo), sizeof(Rm_ResourceInfo)); + Rm_transactionResponder(rmInst, queuedTransaction, receipt); + /* Delete the response transaction */ + Rm_transactionQueueDelete(rmInst, transaction->id); + } + else + { + /* Resource free request originated locally on Client Delegate + * instance. Send the response via the service responder. */ + Rm_serviceResponder(rmInst, transaction, queuedTransaction, + receipt); + } + } + else + { + /* Request transaction was not in the awaiting response state. Flag the + * error in the receipt and return */ + receipt->serviceResult = RM_SERVICE_ERROR_INVALID_REQUEST_TRANSACTION_STATE_UPON_RESPONSE; + } + + } + else + { + /* This is a new transaction request originating from an RM instance with fewer + * allocate/free privileges. Run the free handler to see if the resource + * request can be handled locally or if it needs to be forwarded to a higher level + * agent */ + Rm_freeHandler(rmInst, transaction, receipt); + } + break; - case Rm_command_POLICY_REQUEST: + case Rm_service_RESOURCE_MAP_TO_NAME: + /* Server is the only RM instance capable of adding NameServer objects */ + if (rmInst->instType == Rm_instType_SERVER) + { + /* Create a new NameServer object with the request transaction information */ + Rm_nsAddObject(rmInst, transaction, receipt); + + /* Return the result of the NameServer addition to the RM instance + * that requested it */ + transaction->details = receipt->serviceResult; + + /* If source instance name does not match the current instance + * name the NameServer request came from a Client or Client Delegate. The + * result must be sent back to the Client or Client Delegate */ + if (strcmp(transaction->sourceInstName, rmInst->name)) + { + Rm_transactionResponder(rmInst, queuedTransaction, receipt); + } + else + { + /* NameServer addition request originated locally on Server + * instance. Send the response via the service responder. In this case + * the request transaction will be passed as NULL since the request + * is being reused as the response */ + Rm_serviceResponder(rmInst, transaction, NULL, receipt); + } + } + else + { + receipt->serviceResult = RM_SERVICE_ERROR_NAMESERVER_OBJECT_CREATE_ON_INVALID_INSTANCE; + } break; - case Rm_command_POLICY_RESPONSE: + case Rm_service_RESOURCE_UNMAP_NAME: + /* Server is the only RM instance capable of deleting NameServer objects */ + if (rmInst->instType == Rm_instType_SERVER) + { + /* Delete an existing NameServer object with the request transaction information */ + Rm_nsDeleteObject(rmInst, transaction, receipt); + + /* Return the result of the NameServer deletion to the RM instance + * that requested it */ + transaction->details = receipt->serviceResult; + + /* If source instance name does not match the current instance + * name the NameServer request came from a Client or Client Delegate. The + * result must be sent back to the Client or Client Delegate */ + if (strcmp(transaction->sourceInstName, rmInst->name)) + { + Rm_transactionResponder(rmInst, queuedTransaction, receipt); + } + else + { + /* NameServer delete request originated locally on Server + * instance. Send the response via the service responder. In this case + * the request transaction will be passed as NULL since the request + * is being reused as the response */ + Rm_serviceResponder(rmInst, transaction, NULL, receipt); + } + } + else + { + receipt->serviceResult = RM_SERVICE_ERROR_NAMESERVER_OBJECT_DELETE_ON_INVALID_INSTANCE; + } break; } - } - } /********************************************************************** diff --git a/src/rmnameserver.c b/src/rmnameserver.c new file mode 100644 index 0000000..fe52b8c --- /dev/null +++ b/src/rmnameserver.c @@ -0,0 +1,73 @@ +/** + * @file rmnameserver.c + * + * @brief + * This is the Resource Manager NameServer source. + * + * \par + * ============================================================================ + * @n (C) Copyright 2012, Texas Instruments, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * \par +*/ + +/* RM Types */ +#include + +/* RM external API includes */ + + +/* RM internal API includes */ +#include +#include + +/* RM OSAL layer */ +#include + +/********************************************************************** + ********************** Internal Functions **************************** + **********************************************************************/ + +void Rm_nsAddObject(Rm_Inst *rmInst, Rm_Transaction *transaction, + Rm_TransactionReceipt *receipt) +{ + /* STUB APPROVED FOR NOW */ + receipt->serviceResult = RM_SERVICE_APPROVED; + +} + +void Rm_nsDeleteObject(Rm_Inst *rmInst, Rm_Transaction *transaction, + Rm_TransactionReceipt *receipt) +{ + /* STUB APPROVED FOR NOW */ + receipt->serviceResult = RM_SERVICE_APPROVED; +} + diff --git a/src/rmpolicy.c b/src/rmpolicy.c new file mode 100644 index 0000000..db4d0bd --- /dev/null +++ b/src/rmpolicy.c @@ -0,0 +1,53 @@ +/** + * @file rmpolicy.c + * + * @brief + * This is the Resource Manager Policy source. + * + * \par + * ============================================================================ + * @n (C) Copyright 2012, Texas Instruments, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * \par +*/ + +/* RM Types */ +#include + +/* RM external API includes */ +#include + +/* RM internal API includes */ +#include + +/* RM OSAL layer */ +#include + diff --git a/src/rmservices.c b/src/rmservices.c index 12ea88b..4336824 100644 --- a/src/rmservices.c +++ b/src/rmservices.c @@ -170,25 +170,40 @@ void Rm_serviceResponder (Rm_Inst *rmInst, Rm_Transaction *responseTransaction, serviceResponse.serviceResult = responseTransaction->details; /* Pass back the ID that was provided to the component when it requested * the service */ - serviceResponse.requestId = requestTransaction->id; + serviceResponse.requestId = responseTransaction->id; /* Service was approved and service was an allocate request. The resource * data is passed back to the component */ if ((serviceResponse->serviceResult == RM_SERVICE_APPROVED) && - ((requestTransaction.type == Rm_service_RESOURCE_ALLOCATE) || - (requestTransaction.type == Rm_service_RESOURCE_BLOCK_ALLOCATE) || - (requestTransaction.type == Rm_service_RESOURCE_ALLOCATE_BY_NAME))) + ((responseTransaction.type == Rm_service_RESOURCE_ALLOCATE) || + (responseTransaction.type == Rm_service_RESOURCE_BLOCK_ALLOCATE) || + (responseTransaction.type == Rm_service_RESOURCE_ALLOCATE_BY_NAME))) { serviceResponse->resourceBase = receipt.resourceBase; serviceResponse->resourceRange = receipt.resourceRange; } /* Issue the callback to the requesting component with the response information */ - requestTransaction->callback(&serviceResponse); + if (requestTransaction != NULL) + { + /* The requestTransaction will be NULL if the request transaction is handled + * by the same RM instance it was created on. Typically this applies to RM + * Client Delegate and RM Server instances. In these cases the response + * transaction will be a copy of the request transaction, meaning it will contain + * the proper callback information */ + requestTransaction->callback(&serviceResponse); + } + else + { + responseTransaction->callback(&serviceResponse); + } /* Delete both transactions from the transaction queue */ Rm_transactionQueueDelete(rmInst,responseTransaction->id); - Rm_transactionQueueDelete(rmInst,requestTransaction->id); + if (requestTransaction != NULL) + { + Rm_transactionQueueDelete(rmInst,requestTransaction->id); + } /* Response to component completed */ receipt.serviceResult = RM_SERVICE_ACTION_OKAY; diff --git a/src/rmtransport.c b/src/rmtransport.c index 3971489..ab503df 100644 --- a/src/rmtransport.c +++ b/src/rmtransport.c @@ -443,10 +443,10 @@ Rm_TransportHandle Rm_transportRegister (Rm_Handle rmHandle, Rm_TransportCfg *tr /* Verify Clients and Client Delegates are not registering with more than one * Client Delegate or Server. Assuming a Client Delegate can register with another * Client Delegate that can "act" as a server */ - if (((rmInst->instType == Rm_instType_CLIENT) || - (rmInst->instType == Rm_instType_CLIENT_DELEGATE)) && - ((transportCfg->rmRemoteInstType == Rm_instType_CLIENT_DELEGATE) || - (transportCfg->rmRemoteInstType == Rm_instType_SERVER)) && + if (((rmInst->instType == Rm_instType_CLIENT) && + (transportCfg->remoteInstType == Rm_instType_CLIENT_DELEGATE)) || + ((rmInst->instType == Rm_instType_CLIENT_DELEGATE) && + (transportCfg->remoteInstType == Rm_instType_SERVER)) && rmInst->registeredWithDelegateOrServer) { Rm_osalLocalCsExit(key); @@ -505,14 +505,6 @@ Rm_TransportResult Rm_transportUnregister (Rm_Handle rmHandle, Rm_TransportHandl return (retVal); } - -Rm_TransVerifyResult Rm_transportVerify (Rm_Handle rmHandle, uint32_t timeout, - Rm_TransFailData *failData) -{ - -} - - /* Used by the application to pass RM packets received from a transport to RM. * CODE THE FUNCTION SUCH THAT IT CAN BE CALLED DIRECTLY BY APP OR BE PLUGGED * AS PART OF AN ISR HANDLER FOR THE TRANSACTION RECEIVE */ @@ -587,34 +579,6 @@ int32_t Rm_receivePktIsr(Rm_Handle rmHandle, Rm_TransportHandle transportHandle, * request transaction's ID */ transaction = Rm_transactionQueueAdd(rmInst, resourceRespPkt->responseId); - /* Transfer the rest of the data into the transaction */ - if (resourceRespPkt->resourceReqType = Rm_resReqPktType_ALLOCATE) - { - transaction->type = Rm_service_RESOURCE_ALLOCATE; - } - else if (resourceRespPkt->resourceReqType = Rm_resReqPktType_BLOCK_ALLOCATE) - { - transaction->type = Rm_service_RESOURCE_BLOCK_ALLOCATE; - } - else if (resourceRespPkt->resourceReqType = Rm_resReqPktType_ALLOCATE_NAMED) - { - transaction->type = Rm_service_RESOURCE_ALLOCATE_BY_NAME; - } - else if (resourceRespPkt->resourceReqType = Rm_resReqPktType_FREE) - { - transaction->type = Rm_service_RESOURCE_FREE; - } - else if (resourceRespPkt->resourceReqType = Rm_resReqPktType_BLOCK_FREE) - { - transaction->type = case Rm_service_RESOURCE_BLOCK_FREE; - } - else if (resourceRespPkt->resourceReqType = Rm_resReqPktType_FREE_NAMED) - { - transaction->type = Rm_service_RESOURCE_FREE_BY_NAME; - } - - strcpy(transaction->sourceInstName, resourceReqPkt->instName); - if (resourceRespPkt->requestResult = RM_SERVICE_APPROVED) { transaction->state = Rm_transactionState_RESOURCE_APPROVED; @@ -622,7 +586,7 @@ int32_t Rm_receivePktIsr(Rm_Handle rmHandle, Rm_TransportHandle transportHandle, else if ((resourceRespPkt->requestResult >= RM_SERVICE_DENIED_BEGIN) && (resourceRespPkt->requestResult <= RM_SERVICE_DENIED_END) { - transaction->state - Rm_transactionState_RESOURCE_DENIED; + transaction->state = Rm_transactionState_RESOURCE_DENIED; } /* The result of the request should be placed in the details field of the * response transaction */ @@ -634,12 +598,65 @@ int32_t Rm_receivePktIsr(Rm_Handle rmHandle, Rm_TransportHandle transportHandle, Rm_transactionProcessor(rmInst, transaction, &receipt); break; case Rm_pktType_NAMESERVER_REQUEST: + Rm_NsRequestPkt *nsRequestPkt = (Rm_NsRequestPkt *)pkt->data; + + transaction = Rm_transactionQueueAdd(rmInst, nsRequestPkt->requestId); + + if (nsRequestPkt->nsRequestType == Rm_nsReqPktType_MAP_RESOURCE) + { + transaction->type = Rm_service_RESOURCE_MAP_TO_NAME; + } + else if (nsRequestPkt->nsRequestType == Rm_nsReqPktType_UNMAP_RESOURCE) + { + transaction->type = Rm_service_RESOURCE_UNMAP_NAME; + } + + strcpy(transaction->sourceInstName, nsRequestPkt->instName); + transaction->state = Rm_transactionState_PROCESSING; + memcpy ((void *)&(transaction->resourceInfo), (void *)&(nsRequestPkt->resourceInfo), + sizeof(Rm_ResourceInfo)); + + /* Process the transaction */ + Rm_transactionProcessor(rmInst, transaction, &receipt); break; case Rm_pktType_NAMESERVER_RESPONSE: + Rm_NsResponsePkt *nsResponsePkt = (Rm_NsResponsePkt *)pkt->data; + + transaction = Rm_transactionQueueAdd(rmInst, nsResponsePkt->responseId); + transaction->details = nsResponsePkt->requestResult; + + if (nsResponsePkt->requestResult = RM_SERVICE_APPROVED) + { + transaction->state = Rm_transactionState_RESOURCE_APPROVED; + } + else if ((nsResponsePkt->requestResult >= RM_SERVICE_DENIED_BEGIN) && + (nsResponsePkt->requestResult <= RM_SERVICE_DENIED_END) + { + transaction->state = Rm_transactionState_RESOURCE_DENIED; + } + + /* Process the transaction */ + Rm_transactionProcessor(rmInst, transaction, &receipt); break; + case Rm_pktType_POLICY_REQUEST: + Rm_PolicyRequestPkt *policyRequestPkt = (Rm_PolicyRequestPkt *)pkt->data; + + /* FILL IN POLICY API INFORMATION */ + break; case Rm_pktType_POLICY_CHANGE: + Rm_PolicyChangePkt *policyChangePkt = (Rm_PolicyChangePkt *)pkt->data; + + /* FILL IN POLICY API INFORMATION */ break; - case Rm_pktType_POLICY_REQUEST: + case Rm_pktType_RESOURCE_POOL_MODIFICATION_REQUEST: + Rm_ResourcePoolModRequestPkt *resPoolModReqPkt = (Rm_ResourcePoolModRequestPkt *)pkt->data; + + /* FILL IN RESOURCE POOL MODIFICATION API */ + break; + case Rm_pktType_RESOURCE_POOL_MODIFICATION_RESPONSE: + Rm_ResourcePoolModResponsePkt *resPoolModRespPkt = (Rm_ResourcePoolModResponsePkt *)pkt->data; + + /* FILL IN RESOURCE POOL MODIFICAITON API */ break; default: /* Invalid packet type. Free the packet and return */ @@ -647,6 +664,9 @@ int32_t Rm_receivePktIsr(Rm_Handle rmHandle, Rm_TransportHandle transportHandle, return (RM_TRANSPORT_ERROR_INVALID_PACKET_TYPE); } + /* Free the packet after it has been processed */ + rmInst->transport.rmFreePkt(transportHandle, pkt); + /* Return the receipt's service result which contains the result return code * for the receive packet */ return (receipt->serviceResult); @@ -654,61 +674,40 @@ int32_t Rm_receivePktIsr(Rm_Handle rmHandle, Rm_TransportHandle transportHandle, /* Application can call this API so that RM handles reception of packets based on * the RM handle and transport handle provided */ -Rm_Result Rm_receivePktPolling(Rm_Handle rmHandle, Rm_TransportHandle transHandle) +int32_t Rm_receivePktPolling(Rm_Handle rmHandle, Rm_TransportHandle transportHandle) { Rm_Inst *rmInst = (Rm_Inst *)rmHandle; - Rm_TransRouteMapNode *transNode = rmInst->routeMap; - Rm_Packet *rmPkt = NULL; - Rm_Result retVal = 0; - void *key; - - /* Lock access to the RM instance's transaction queue */ - key = Rm_osalLocalCsEnter(); - - /* Verify the transport handle is registered with the RM handle */ - while (transNode != NULL) - { - if (transNode->transHandle == transHandle) - { - /* Break out of loop if an entry in the route map has been found */ - break; - } - transNode = transNode->nextNode; - } + Rm_Packet *pkt = NULL; + int32_t retVal = RM_SERVICE_ACTION_BASE; - if (transNode == NULL) + /* Make sure the transport handle is registered with the provided RM instance */ + if (Rm_transportNodeFindTransportHandle(rmInst, transportHandle) == NULL) { - Rm_osalLocalCsExit(key); - return (-1) /* ERROR: THE TRANSPORT HANDLE IS NOT REGISTERED WITH THE RM HANDLE */ + /* Transport is not registered with the RM instance. Return an error. + * The packet cannot be freed since the transport handle is not valid. */ + return (RM_TRANSPORT_ERROR_TRANSPORT_HANDLE_NOT_REGISTERED_WITH_INSTANCE); } /* Check to see if any RM packets are available. Process any available packets. */ - while (rmInst->transport.rmNumPktsReceived(transHandle)) + while (rmInst->transport.rmNumPktsReceived(transportHandle)) { - rmInst->transport.rmReceive(transHandle, rmPkt); + pkt = rmInst->transport.rmReceive(transportHandle); - if (rmPkt == NULL) + if (pkt == NULL) { - retVal = -1; /* ERROR - PACKET RECEIVED FROM TRANSPORT IS NULL */ + return (RM_TRANSPORT_ERROR_PACKET_RECEPTION_ERROR); } - /* Pass the packet to RM */ - retVal = Rm_receiveRmPkt(rmHandle, transHandle, rmPkt); - /* Delete the packet */ - rmInst->transport.rmFreePkt(transHandle, rmPkt); - - if (retVal) + /* Pass the packet to RM. The packet will be freed within the PktIsr API */ + if (retVal = Rm_receivePktIsr(rmHandle, transportHandle, pkt) <= RM_SERVICE_ERROR_BASE) { - /* If retVal is not 0 (Okay) there was an error so break out of loop and return */ - break; + /* Return if an error is encountered */ + return (retVal); } } - - Rm_osalLocalCsExit(key); return (retVal); } - /** @} */ -- 2.39.2