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


#include "./server.h"
#include "aqhome-nodes/types/device.h"

#include "aqhome/nodes/nodedb.h"
#include "aqhome/ipc2/msgrequest.h"

#include <termios.h>


/* default values */
#define AQHOMED_DEFAULT_NODEADDR          240
#define AQHOMED_DEFAULT_PIDFILE           "/var/run/aqhomed-node.pid"
#define AQHOMED_DEFAULT_DEVICE            "/dev/ttyUSB0"
#define AQHOMED_DEFAULT_IPC_PORT          45454
#define AQHOMED_DEFAULT_BROKER_PORT       1899
#define AQHOMED_DEFAULT_BROKER_CLIENTID   "nodes"



typedef struct AQH_NODE_SERVER AQH_NODE_SERVER;
struct AQH_NODE_SERVER {
  AQH_OBJECT *ttyEndpoint;
  AQH_OBJECT *brokerEndpoint;

  AQH_OBJECT *ipcEndpoint;
  AQH_OBJECT_LIST *ipcClientList;

  AQH_NODE_DB *nodeDb;
  AQHNODE_DEVICE_LIST *deviceDefList;

  AQH_MSG_REQUEST *requestTree;

  GWEN_DB_NODE *dbArgs;

  char *dbFile;
  char *logFile;
  char *pidFile;

  int timeout;   /* timeout for run e.g. inside valgrind */
  char *devicePath;

  char *tcpAddress;
  int tcpPort;

  char *brokerAddress;
  int brokerPort;
  char *brokerClientId;

  time_t timestampTtyDown;
  time_t timestampBrokerDown;

  int nodeAddress;

  struct termios initialTermiosState;

  int timeoutInSeconds;

  uint8_t protoId;
  uint8_t protoVer;

  int noAttn;
};


AQH_NODE_SERVER *AQH_NodeServer_GetServerData(const AQH_OBJECT *o);


#endif

