/******************************************************************************
 *
 * Copyright 2017, Lattice Semiconductor, Inc. All rights reserved.
 * No part of this work may be reproduced, modified, distributed, transmitted,
 * transcribed, or translated into any language or computer format, in any form
 * or by any means without written permission of Lattice Semiconductor Inc.,
 * 111 SW 5th Ave, Suite 700, Portland, OR 97204.
 *
 *****************************************************************************/
/**
 * @file sii_sys_obj_api.h
 *
 * @brief Object base class
 *
 *****************************************************************************/

#ifndef SI_SYS_OBJ_API_H
#define SI_SYS_OBJ_API_H

/***** #include statements ***************************************************/

#include "sii_datatypes.h"

/***** public macro definitions **********************************************/

/******************************************************************************/
/**
* @brief	Converts external instantiation reference to pointer of
*		instantiation object as defined locally in module.
*		Creates an assertion if user would provide a reference
*		to a different class of instantiation.
*
* @param[in]	inst	External reference to instantiation.
*
* @return	Pointer to instantiation object.
*
*******************************************************************************/

#ifdef SII_ENV_BUILD_ASSERT
  #if (SII_ENV_BUILD_ASSERT)
    #define SII_SYS_OBJ_CHECK(list_inst, obj_inst)  \
		((sii_sys_obj_check(list_inst, SII_INST2OBJ(obj_inst))) ? \
		(SII_INST2OBJ(obj_inst)) : (SII_ASSERT(0)))
  #else
    #define SII_SYS_OBJ_CHECK(list_inst, obj_inst)	(SII_INST2OBJ(obj_inst))
  #endif
#else
  #define SII_SYS_OBJ_CHECK(list_inst, obj_inst)	(SII_INST2OBJ(obj_inst))
#endif

#define SII_SYS_OBJ_PARENT_INST_GET(child_inst) \
		(sii_sys_obj_parent_inst_get(SII_INST2OBJ(child_inst)))

/***** public functions ******************************************************/

void *sii_sys_obj_singleton_create(const char *class_str,
	void *p_parent_inst, uint16_t size);
void sii_sys_obj_singleton_delete(void *p_obj);

void *sii_sys_obj_list_create(const char *class_str, uint16_t size);
void sii_sys_obj_list_delete(void *p_list_inst);

void *sii_sys_obj_instance_create(void *p_list_inst, void *p_parent_inst,
	const char *inst_str);
void sii_sys_obj_instance_delete(void *p_obj);

void *sii_sys_obj_first_get(void *p_list_inst);
bool_t sii_sys_obj_check(void *p_list_inst, void *p_obj);
void *sii_sys_obj_parent_inst_get(void *p_obj);

const char *sii_sys_obj_list_name_get(void *p_obj);
const char *sii_sys_obj_name_get(void *p_obj);
void *sii_sys_obj_next_get(void *p_obj);
void sii_sys_obj_move(void *p_obj_des, void *p_obj_src);

#endif /* SI_SYS_OBJ_API_H */

/***** end of file ***********************************************************/
