/** * @file rm_services.c * * @brief * This is the Resource Manager services source. * * \par * ============================================================================ * @n (C) Copyright 2012-2013, 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 */ /* Standard includes */ #include /* RM external API includes */ #include /* RM internal API includes */ #include /* RM OSAL layer */ #include /********************************************************************** ********************** Application visible APIs ********************** **********************************************************************/ /* FUNCTION PURPOSE: Handles application component service requests *********************************************************************** * DESCRIPTION: Receives service requests from application components * and routes them to the transaction processor. If * the service can be handled immediately the response * will be provided in the service response. If the * service requires a blocking operation the handler * will provide a service ID back to the application. * The response will be sent at a later time via the * application supplied callback function. */ void Rm_serviceHandler (void *rmHandle, const Rm_ServiceReqInfo *serviceRequest, Rm_ServiceRespInfo *serviceResponse) { Rm_Inst *rmInst = (Rm_Inst *)rmHandle; Rm_Transaction *transaction; if (rmInst->isLocked) { serviceResponse->serviceState = RM_SERVICE_DENIED_RM_INSTANCE_LOCKED; return; } if (serviceRequest->callback.serviceCallback == NULL) { serviceResponse->serviceState = RM_ERROR_CALLBACK_NOT_PROVIDED; return; } if (serviceRequest->type >= Rm_service_LAST) { serviceResponse->serviceState = RM_ERROR_INVALID_SERVICE_TYPE; return; } transaction = rmTransactionQueueAdd(rmInst); if (transaction) { transaction->type = serviceRequest->type; strncpy(transaction->serviceSrcInstName, rmInst->instName, RM_NAME_MAX_CHARS); transaction->callback.serviceCallback = serviceRequest->callback.serviceCallback; transaction->state = RM_SERVICE_PROCESSING; if (serviceRequest->resourceName) { strncpy(transaction->resourceInfo.name, serviceRequest->resourceName, RM_NAME_MAX_CHARS); } transaction->resourceInfo.base = serviceRequest->resourceBase; transaction->resourceInfo.length = serviceRequest->resourceLength; transaction->resourceInfo.alignment = serviceRequest->resourceAlignment; if (serviceRequest->resourceNsName) { strncpy(transaction->resourceInfo.nameServerName, serviceRequest->resourceNsName, RM_NAME_MAX_CHARS); } rmTransactionProcessor (rmInst, transaction); memset((void *)serviceResponse, 0, sizeof(Rm_ServiceRespInfo)); serviceResponse->serviceState = transaction->state; if ((serviceResponse->serviceState == RM_SERVICE_PROCESSING) || (serviceResponse->serviceState == RM_SERVICE_APPROVED_STATIC)) { /* Service still being processed. Static requests will have their validation responses sent once * all transports have been established. Provide transaction ID back to component so it can sort * service responses received via callback function */ serviceResponse->serviceId = transaction->localId; } if ((serviceResponse->serviceState == RM_SERVICE_APPROVED) || (serviceResponse->serviceState == RM_SERVICE_APPROVED_STATIC)) { strncpy(serviceResponse->resourceName, transaction->resourceInfo.name, RM_NAME_MAX_CHARS); serviceResponse->resourceBase = transaction->resourceInfo.base; serviceResponse->resourceLength = transaction->resourceInfo.length; } /* Transactions still processing not deleted from queue. Includes static transactions which will be * verified once all transports are up */ if ((serviceResponse->serviceState != RM_SERVICE_PROCESSING) && (serviceResponse->serviceState != RM_SERVICE_APPROVED_STATIC)) { rmTransactionQueueDelete(rmInst, transaction->localId); } } else { serviceResponse->serviceState = RM_ERROR_SERVICE_TRANS_NOT_CREATED; } return; } /* FUNCTION PURPOSE: Opens the RM instance service handle *********************************************************************** * DESCRIPTION: Returns the service handle for an RM instance. Only * one service handle can be opened per instance. */ Rm_ServiceHandle *Rm_serviceOpenHandle(Rm_Handle rmHandle, int32_t *result) { Rm_Inst *rmInst = (Rm_Inst *)rmHandle; Rm_ServiceHandle *newServiceHandle = NULL; *result = RM_OK; if (rmInst->serviceHandle == NULL) { newServiceHandle = Rm_osalMalloc (sizeof(Rm_ServiceHandle)); if (newServiceHandle) { newServiceHandle->rmHandle = rmHandle; newServiceHandle->Rm_serviceHandler = Rm_serviceHandler; rmInst->serviceHandle = newServiceHandle; } else { *result = RM_ERROR_SERVICE_HANDLE_MEM_ALLOC_FAILED; } } else { *result = RM_ERROR_SERVICE_HANDLE_ALREADY_OPENED; } return (newServiceHandle); } /* FUNCTION PURPOSE: Closes the RM instance service handle *********************************************************************** * DESCRIPTION: Closes the service handle for an RM instance. */ int32_t Rm_serviceCloseHandle(Rm_ServiceHandle *rmServiceHandle) { Rm_Inst *rmInst = (Rm_Inst *)rmServiceHandle->rmHandle; int32_t retVal = RM_OK; if (rmInst->serviceHandle) { Rm_osalFree((void *)rmServiceHandle, sizeof(Rm_ServiceHandle)); rmInst->serviceHandle = NULL; } else { retVal = RM_ERROR_SERVICE_HANDLE_ALREADY_CLOSED; } return(retVal); }