/**
 * @file       task_descriptor.h
 * @brief      Interface to perform task descriptor search in kernel tables
 * @author     Hryhorii Tur (hryhorii.tur@partner.samsung.com)
 * @version    1.0
 * @date       Created Aug 30, 2018
 * @copyright  In Samsung Ukraine R&D Center (SURC) under a contract between
 * @copyright  LLC "Samsung Electronics Ukraine Company" (Kiev, Ukraine) and
 * @copyright  "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
 * @copyright  Copyright: (c) Samsung Electronics Co, Ltd 2016. All rights reserved.
**/

#ifndef PA_TZ_DRV_TASK_DESCRIPTOR_H_
#define PA_TZ_DRV_TASK_DESCRIPTOR_H_

#include "task.h"

typedef enum {
  kTaskDescriptorPidMapNext,
  kTaskDescriptorAppNameMapNext,
  kTaskDescriptorNumberNextPtrs,
} TaskDescriptorNextIndex;

/**
 * @brief PROCA kernel task descriptor structure
 */
typedef struct {
  int           pid;                 //!< PID of the corresponding task
  int           state;               //!< State of the corresponding task
  KernelAddress map_next_ptrs[kTaskDescriptorNumberNextPtrs];
                //!< Pointer to next descriptor struct with same app_name hash value
  KernelAddress task_address;        //!< Task struct address
  KernelAddress task_descr_address;  //!< Pointer to current task descr object struct
  PaIdentity    pa_identity;         //!< PROCA identity structure
} TaskDescriptor;

/**
 * @brief Hash table lookup for task descriptor by PID
 * @param [in] pid
 * @param [out] out_descr
 * @return ::PA_TZ_SUCCESS in case of success, ::PA_TZ_GENERAL_ERROR
 */
PaTzResult TaskDescriptorFindByPid(uint32_t pid, TaskDescriptor *out_descr);

/**
 * @brief Hash table lookup for task descriptor by application name
 * @param [in] app_name_str
 * @param [in] app_name_size
 * @param [out] out_descr
 * @return ::PA_TZ_SUCCESS in case of success, ::PA_TZ_GENERAL_ERROR
 */
PaTzResult TaskDescriptorFindByAppName(const char *app_name_str,
                                       const size_t app_name_size,
                                       TaskDescriptor *out_descr);

#endif //PA_TZ_DRV_TASK_DESCRIPTOR_H_
