const AwaServerExecuteResponse * AwaServerExecuteOperation_GetResponse(const AwaServerExecuteOperation * operation, const char * clientID) { const ResponseCommon * response = NULL; if (operation != NULL) { response = ServerResponse_GetClientResponse(operation->Response, clientID); } // AwaServerExecuteResponse is an alias for ResponseCommon return (const AwaServerExecuteResponse *)response; }
// TODO: is maintaining a separate ClientResponseMap unnecessary? Can the ServerResponse's own Map be used instead? const AwaServerListClientsResponse * AwaServerListClientsOperation_GetResponse(const AwaServerListClientsOperation * operation, const char * clientID) { AwaServerListClientsResponse * listClientsResponse = NULL; if (operation != NULL) { if (clientID != NULL) { if (operation->ServerResponse != NULL) { // check that client response exists: const ResponseCommon * clientResponse = ServerResponse_GetClientResponse(operation->ServerResponse, clientID); if (clientResponse != NULL) { // look up existing Response in map, return it. // if it doesn't exist, create new Response and add to map, return it. Map_Get(operation->ClientResponseMap, clientID, (void *)&listClientsResponse); if (listClientsResponse == NULL) { LogDebug("Create new AwaServerListClientsResponse"); listClientsResponse = Awa_MemAlloc(sizeof(*listClientsResponse)); if (listClientsResponse != NULL) { memset(listClientsResponse, 0, sizeof(*listClientsResponse)); listClientsResponse->Response = clientResponse; // cache the listClientsResponse if (Map_Put(operation->ClientResponseMap, clientID, (void *)listClientsResponse) == false) { // do not return the response if we can't retain it, as it will eventually leak LogErrorWithEnum(AwaError_Internal, "Map put failed"); Awa_MemSafeFree(listClientsResponse); listClientsResponse = NULL; } } else { LogErrorWithEnum(AwaError_OutOfMemory); } } else { LogDebug("Retrieved cached AwaServerListClientsResponse"); } } else { LogErrorWithEnum(AwaError_ClientNotFound, "Client ID %s not found", clientID); } } else { LogErrorWithEnum(AwaError_ResponseInvalid, "operation response is NULL"); } } else { LogErrorWithEnum(AwaError_ClientIDInvalid, "clientID is NULL"); } } else { LogErrorWithEnum(AwaError_OperationInvalid, "operation is NULL"); } return listClientsResponse; }