/****************************************************************************
 * 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_ENDPOINT_H
#define AQH_ENDPOINT_H

#include <aqhome/events2/object.h>
#include <aqhome/ipc2/message.h>


#define AQH_ENDPOINT_FLAGS_WANTUPDATES 0x0001


enum {
  AQH_ENDPOINT_SIGNAL_CLOSED=AQH_OBJECT_SIGNAL_LAST,
};



/**
 * Constructor.
 *
 * Takes over ownership of msgReader and msgWriter, links signal AQH_MSG_READER_SIGNAL_MSGRECVD of msgReader
 * and signal AQH_MSG_WRITER_SIGNAL_MSGSENT of msgWriter to the newly created endpoint object.
 *
 * @param eventLoop pointer to event loop
 * @param msgReader pointer to message reader object (takes over ownership)
 * @param msgWriter pointer to message writer object (takes over ownership)
 */
AQHOME_API AQH_OBJECT *AQH_Endpoint_new(AQH_EVENT_LOOP *eventLoop, AQH_OBJECT *msgReader, AQH_OBJECT *msgWriter);

AQHOME_API int AQH_Endpoint_GetApiCode(const AQH_OBJECT *o);
AQHOME_API void AQH_Endpoint_SetApiCode(AQH_OBJECT *o, int i);

AQHOME_API const char *AQH_Endpoint_GetServiceName(const AQH_OBJECT *o);
AQHOME_API void AQH_Endpoint_SetServiceName(AQH_OBJECT *o, const char *s);

AQHOME_API const char *AQH_Endpoint_GetUserName(const AQH_OBJECT *o);
AQHOME_API void AQH_Endpoint_SetUserName(AQH_OBJECT *o, const char *s);

AQHOME_API uint32_t AQH_Endpoint_GetPermissions(const AQH_OBJECT *o);
AQHOME_API void AQH_Endpoint_SetPermissions(AQH_OBJECT *o, uint32_t i);
AQHOME_API void AQH_Endpoint_AddPermissions(AQH_OBJECT *o, uint32_t i);
AQHOME_API void AQH_Endpoint_SubPermissions(AQH_OBJECT *o, uint32_t i);

AQHOME_API uint32_t AQH_Endpoint_GetFlags(const AQH_OBJECT *o);
AQHOME_API void AQH_Endpoint_SetFlags(AQH_OBJECT *o, uint32_t i);
AQHOME_API void AQH_Endpoint_AddFlags(AQH_OBJECT *o, uint32_t i);
AQHOME_API void AQH_Endpoint_SubFlags(AQH_OBJECT *o, uint32_t i);

AQHOME_API int AQH_Endpoint_GetState(const AQH_OBJECT *o);
AQHOME_API void AQH_Endpoint_SetState(AQH_OBJECT *o, int i);

AQHOME_API uint32_t AQH_Endpoint_GetAcceptedMsgGroups(const AQH_OBJECT *o);
AQHOME_API void AQH_Endpoint_SetAcceptedMsgGroups(AQH_OBJECT *o, uint32_t i);

AQHOME_API AQH_MESSAGE_LIST *AQH_Endpoint_GetMsgOutList(const AQH_OBJECT *o);
AQHOME_API AQH_MESSAGE *AQH_Endpoint_GetNextMsgOut(AQH_OBJECT *o);
AQHOME_API void AQH_Endpoint_AddMsgOut(AQH_OBJECT *o, AQH_MESSAGE *msg);

AQHOME_API AQH_MESSAGE_LIST *AQH_Endpoint_GetMsgInList(const AQH_OBJECT *o);
AQHOME_API AQH_MESSAGE *AQH_Endpoint_GetNextMsgIn(AQH_OBJECT *o);
AQHOME_API void AQH_Endpoint_AddMsgIn(AQH_OBJECT *o, AQH_MESSAGE *msg);

AQHOME_API uint32_t AQH_Endpoint_GetLastMessageId(const AQH_OBJECT *o);
AQHOME_API uint32_t AQH_Endpoint_GetNextMessageId(AQH_OBJECT *o);


#endif

