/*
 * Copyright (c) 2019,2021 Qualcomm Technologies, Inc.
 * All Rights Reserved.
 * Confidential and Proprietary - Qualcomm Technologies, Inc.
 */

#ifndef BUFFERALLOCATORSIM_H
#define BUFFERALLOCATORSIM_H

/**
  @brief APIs to create a simulated ION buffer.
  @file  BufferAllocatorSim.h

  @addtogroup client_api_ion_sim
  @{
*/

#include <stddef.h>
#include <stdint.h>
#include <unordered_map>
#include "qlist.h"

#ifdef __cplusplus

class BufferAllocatorSimHandle {
  private:
    int32_t fd;          ///< A simulated file descriptor representing this buffer.
    void *buffer;        ///< Pointer to the simulated buffer.
    size_t buffer_size;  ///< Size of the simulated buffer.

  public:
/**
  Allocate a simulated ion buffer represented by a handle.

  @param[in] handle    Pointer to the handle representing a simulated ion buffer.
  @param[in] size      Size of the allocated buffer.
  @param[in] alignment Alignment of the allocated buffer.

  @return
  0 on success, \n
  negative otherwise.
**/
    int AllocSim(size_t size, size_t alignment);


/**
  Frees a simulated ion buffer represented by a handle.

  @param[in] handle    Pointer to the handle representing a simulated ion buffer.
**/
    static void freeSim(int32_t fd);

    int32_t getFd();

    void *getBuffer();

    size_t getBufferSize();
    
    static void * getAddrFromFd(int32_t fd);

};

#endif
#endif /* BUFFERALLOCATORSIM_H */
