/****************************************************************************
 * This file is part of the project AqHome.
 * AqHome (c) by 2025 Martin Preuss, all rights reserved.
 *
 * The license for this file can be found in the file COPYING which you
 * should have received along with this file.
 ****************************************************************************/

#ifndef AQH_OBJECT_H
#define AQH_OBJECT_H

#include <aqhome/api.h>

#include <gwenhywfar/inherit.h>
#include <gwenhywfar/list.h>
#include <gwenhywfar/list2.h>

#include <stdint.h>



#define AQH_OBJECT_FLAGS_ENABLED 0x80000000L
#define AQH_OBJECT_FLAGS_FIRE    0x40000000L
#define AQH_OBJECT_FLAGS_DELETE  0x20000000L


enum {
  AQH_OBJECT_SIGNAL_LAST=10 /* reserve signal ids 0-9 */
};



/* ------------------------------------------------------------------------------------------------
 * @name Type Definition
 */
/*@{*/
typedef struct AQH_OBJECT AQH_OBJECT;
GWEN_INHERIT_FUNCTION_LIB_DEFS(AQH_OBJECT, AQHOME_API)
GWEN_LIST_FUNCTION_LIB_DEFS(AQH_OBJECT, AQH_Object, AQHOME_API)
GWEN_LIST2_FUNCTION_LIB_DEFS(AQH_OBJECT, AQH_Object, AQHOME_API)
/*@}*/


#include <aqhome/events2/eventloop.h>



/* ------------------------------------------------------------------------------------------------
 * @name Virtual Function Declarations
 */
/*@{*/
typedef int (*AQH_OBJECT_SIGNALHANDLER_FN)(AQH_OBJECT *o, uint32_t slotId, AQH_OBJECT *senderObject, int param1, void *param2);
typedef void (*AQH_OBJECT_ENABLE_FN)(AQH_OBJECT *o);
typedef void (*AQH_OBJECT_DISABLE_FN)(AQH_OBJECT *o);
/*@}*/



/* ------------------------------------------------------------------------------------------------
 * @name Construction, Destruction
 */
/*@{*/
AQHOME_API AQH_OBJECT *AQH_Object_new(AQH_EVENT_LOOP *eventLoop);
AQHOME_API void AQH_Object_IncRefCount(AQH_OBJECT *o);
AQHOME_API void AQH_Object_free(AQH_OBJECT *o);
/*@}*/



/* ------------------------------------------------------------------------------------------------
 * @name Manipulate Flags
 */
/*@{*/
AQHOME_API uint32_t AQH_Object_GetFlags(const AQH_OBJECT *o);
AQHOME_API void AQH_Object_SetFlags(AQH_OBJECT *o, uint32_t i);
AQHOME_API void AQH_Object_AddFlags(AQH_OBJECT *o, uint32_t i);
AQHOME_API void AQH_Object_SubFlags(AQH_OBJECT *o, uint32_t i);
/*@}*/



/* ------------------------------------------------------------------------------------------------
 * @name Getters, Setters
 */
/*@{*/
AQHOME_API AQH_EVENT_LOOP *AQH_Object_GetEventLoop(const AQH_OBJECT *o);
/*@}*/



/* ------------------------------------------------------------------------------------------------
 * @name Link Handling
 */
/*@{*/
AQHOME_API void AQH_Object_AddLink(AQH_OBJECT *o, uint32_t signalId, uint32_t slotId, AQH_OBJECT *targetObject);
AQHOME_API void AQH_Object_DelLink(AQH_OBJECT *o, uint32_t signalId, uint32_t slotId, AQH_OBJECT *targetObject);
/*@}*/



/* ------------------------------------------------------------------------------------------------
 * @name Virtual Function Declarations
 */
/*@{*/
AQHOME_API int AQH_Object_EmitSignal(AQH_OBJECT *o, uint32_t signalId, int param1, void *param2);
AQHOME_API int AQH_Object_HandleSignal(AQH_OBJECT *o, uint32_t slotId, AQH_OBJECT *senderObject, int param1, void *param2);
AQHOME_API void AQH_Object_Enable(AQH_OBJECT *o);
AQHOME_API void AQH_Object_Disable(AQH_OBJECT *o);
/*@}*/



/* ------------------------------------------------------------------------------------------------
 * @name Setter for Virtual Functions
 */
/*@{*/
AQHOME_API AQH_OBJECT_SIGNALHANDLER_FN AQH_Object_SetSignalHandlerFn(AQH_OBJECT *o, AQH_OBJECT_SIGNALHANDLER_FN f);
AQHOME_API AQH_OBJECT_ENABLE_FN AQH_Object_SetEnableFn(AQH_OBJECT *o, AQH_OBJECT_ENABLE_FN f);
AQHOME_API AQH_OBJECT_DISABLE_FN AQH_Object_SetDisableFn(AQH_OBJECT *o, AQH_OBJECT_DISABLE_FN f);
/*@}*/



#endif
