<commit_before>/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/pldm/runtime/pldmrp_rt.C $                            */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2020                             */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */

/** @file  pldmrp_rt.C
 *  @brief Source code for hbrt's PLDM resource provider.
 */
#include "../common/pldmtrace.H"
#include "pldmrp_rt.H"
#include <pldm/pldmif.H>
#include <runtime/interface.h>
#include <pldm/extended/pdr_manager.H>

using namespace PLDM;

pldmrp_rt_rc PLDM::cache_next_pldm_msg(const void * const i_next_msg,
                                       const size_t i_len)
{
    return Singleton<PldmRP>::instance().cache_next_pldm_msg(
                                      static_cast<const uint8_t *>(i_next_msg),
                                      i_len);
}

const std::vector<uint8_t> & PLDM::get_next_response(void)
{
    return Singleton<PldmRP>::instance().iv_next_response;
}

void PLDM::clear_next_response(void)
{
    Singleton<PldmRP>::instance().iv_next_response.clear();
}

const std::vector<uint8_t> & PLDM::get_next_request(void)
{
    return Singleton<PldmRP>::instance().iv_next_request;
}

void PLDM::clear_next_request(void)
{
    Singleton<PldmRP>::instance().iv_next_request.clear();
}

pldmrp_rt_rc PldmRP::cache_next_pldm_msg(const uint8_t * const i_next_msg,
                                         const size_t i_len)
{
    pldmrp_rt_rc rc = RC_PLDMRP_RT_SUCCESS;
    do{

    if(i_len < sizeof(pldm_msg_hdr))
    {
        rc = RC_INVALID_MESSAGE_LEN;
        break;
    }

    const pldm_msg_hdr * pldm_hdr =
        reinterpret_cast<const pldm_msg_hdr *>(i_next_msg);

    const uint8_t * const i_next_msg_end = i_next_msg + i_len;

    // Update our cached request/response appropriately if they
    // are empty, otherwise return a RC indicating we are full.
    if(pldm_hdr->request)
    {
        if(iv_next_request.empty())
        {
            iv_next_request.assign(i_next_msg,
                                   i_next_msg_end);
        }
        else
        {
            rc = RC_NEXT_REQUEST_FULL;
        }
    }
    else
    {
        if(iv_next_response.empty())
        {
            iv_next_response.assign(i_next_msg,
                                    i_next_msg_end);
        }
        else
        {
            rc = RC_NEXT_RESPONSE_FULL;
        }
    }

    }while(0);
    return rc;
}

void init_pldm(void)
{
    PLDM_ENTER("init_pldm");
    PLDM::thePdrManager().resetPdrs();
    PLDM::thePdrManager().addLocalPdrs();
    PLDM_EXIT("init_pldm");
}

struct registerinitPldm
{
    registerinitPldm()
    {
        // Register interface for Host to call<commit_msg>Disable call to build PDR repo in HBRT until PHYP makes changes<commit_after>/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/pldm/runtime/pldmrp_rt.C $                            */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2020                             */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */

/** @file  pldmrp_rt.C
 *  @brief Source code for hbrt's PLDM resource provider.
 */
#include "../common/pldmtrace.H"
#include "pldmrp_rt.H"
#include <pldm/pldmif.H>
#include <runtime/interface.h>
#include <pldm/extended/pdr_manager.H>

using namespace PLDM;

pldmrp_rt_rc PLDM::cache_next_pldm_msg(const void * const i_next_msg,
                                       const size_t i_len)
{
    return Singleton<PldmRP>::instance().cache_next_pldm_msg(
                                      static_cast<const uint8_t *>(i_next_msg),
                                      i_len);
}

const std::vector<uint8_t> & PLDM::get_next_response(void)
{
    return Singleton<PldmRP>::instance().iv_next_response;
}

void PLDM::clear_next_response(void)
{
    Singleton<PldmRP>::instance().iv_next_response.clear();
}

const std::vector<uint8_t> & PLDM::get_next_request(void)
{
    return Singleton<PldmRP>::instance().iv_next_request;
}

void PLDM::clear_next_request(void)
{
    Singleton<PldmRP>::instance().iv_next_request.clear();
}

pldmrp_rt_rc PldmRP::cache_next_pldm_msg(const uint8_t * const i_next_msg,
                                         const size_t i_len)
{
    pldmrp_rt_rc rc = RC_PLDMRP_RT_SUCCESS;
    do{

    if(i_len < sizeof(pldm_msg_hdr))
    {
        rc = RC_INVALID_MESSAGE_LEN;
        break;
    }

    const pldm_msg_hdr * pldm_hdr =
        reinterpret_cast<const pldm_msg_hdr *>(i_next_msg);

    const uint8_t * const i_next_msg_end = i_next_msg + i_len;

    // Update our cached request/response appropriately if they
    // are empty, otherwise return a RC indicating we are full.
    if(pldm_hdr->request)
    {
        if(iv_next_request.empty())
        {
            iv_next_request.assign(i_next_msg,
                                   i_next_msg_end);
        }
        else
        {
            rc = RC_NEXT_REQUEST_FULL;
        }
    }
    else
    {
        if(iv_next_response.empty())
        {
            iv_next_response.assign(i_next_msg,
                                    i_next_msg_end);
        }
        else
        {
            rc = RC_NEXT_RESPONSE_FULL;
        }
    }

    }while(0);
    return rc;
}

void init_pldm(void)
{
    PLDM_ENTER("init_pldm");
    PLDM::thePdrManager().resetPdrs();
    // TODO RTC:255114 re-enable when PHYP supports PLDM request from HBRT during init
//     PLDM::thePdrManager().addRemotePdrs();
    PLDM_EXIT("init_pldm");
}

struct registerinitPldm
{
    registerinitPldm()
    {
        // Register interface for Host to call
{'fraction_non_alphanumeric': 0.09079473985134362, 'fraction_numerical': 0.0038879359634076617, 'mean_word_length': 1.2581977794990964, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 76, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2209699', 'n_tokens_mistral': 2362, 'n_tokens_neox': 2314, 'n_words': 486}