/**
 * @file session_manager.h
 * @brief Simple TA session mamger for separating session contexts declarations
 * @author Iaroslav Makarchuk (i.makarchuk@samsung.com)
 * @date Created Oct 3, 2016
 * @par In Samsung Ukraine R&D Center (SURC) under a contract between
 * @par LLC "Samsung Electronics Ukraine Company" (Kiev, Ukraine) and
 * @par "Samsung Elecrtronics Co", Ltd (Seoul, Republic of Korea)
 * @par Copyright: (c) Samsung Electronics Co, Ltd 2015. All rights reserved.
 *
 * This software is proprietary of Samsung Electronics.
 * No part of this software, either material or conceptual may be copied
 * or distributed, transmitted, transcribed, stored in a retrieval system
 * or translated into any human or computer language in any form by any means,
 * electronic, mechanical, manual or otherwise, or disclosed to third parties
 * without the express written permission of Samsung Electronics.
 */

#ifndef MULTIBUILD_SESSION_MANAGER_H_
#define MULTIBUILD_SESSION_MANAGER_H_

#include <mb_list.h>
#include <tee_internal_api.h>

typedef struct TeeSessionStruct {
  struct list_head list;
  void *handle;
  void *session_context;
  void *instance_data;
} TeeSession;

/**
 * @brief Adds session instance to the list of active sessions
 *
 * @param[in]   session  A pointer to the session structure to be added to the
 *                       list
 *
 * @retval TEE_SUCCESS              The session added to the list successfully
 * @retval TEE_ERROR_BAD_PARAMETERS Bad parameters passed to the function
 */
TEE_Result SessionManagerAddSession(TeeSession *session);

/**
 * @brief Removes session instance from the list of active sessions
 *
 * @param[in]   session  A pointer to the session structure to be removed from
 *                       the list
 *
 * @retval TEE_SUCCESS              The session removed successfully
 * @retval TEE_ERROR_BAD_PARAMETERS Bad parameters passed to the function
 * @retval TEE_ERROR_ITEM_NOT_FOUND The session is not present in the session
 *                                  list
 */
TEE_Result SessionManagerRemoveSession(TeeSession *session);

/**
 * @brief Returns the session instance from the active sessions list by handle
 *
 * @param[in]    handle   Session handle to find the session by
 * @param[out]   session  A pointer to the session structure where the instance
 *                        should be put
 *
 * @retval TEE_SUCCESS              The session found and returned
 * @retval TEE_ERROR_BAD_PARAMETERS Bad parameters passed to the function
 * @retval TEE_ERROR_ITEM_NOT_FOUND The session is not present in the session
 *                                  list
 */
TEE_Result SessionManagerGetSession(void *handle, TeeSession **session);

#endif /* MULTIBUILD_SESSION_MANAGER_H_ */
