/*------------------------------------------------------------------------
 *
 *  File:	o1k_network.h
 *  Revision:	1.11
 *  Last Mod:	14:03:20, 03/01/97
 *
 *  Description:
 *     Defines the O1kNetwork class for the o1k_conf example.
 *	
 *----------------------------------------------------------------------*/
#pragma ident	"@(#)o1k_network.h	1.11\t97/03/01  "

#ifndef _O1K_NETWORK_H
#define _O1K_NETWORK_H

#include <sys/types.h>
#include <netinet/in.h>
#include <poll.h>

#define MAX_NAME_SIZE 120
#define MAXSENDTO      32

/*
 * There are 3 different network channel 'types' used in this
 * conference example. These being control, audio and video.
 */
#define NET_MAX_TYPES 3

/* INDEX's are used as array indices */
#define NET_TYPE_VIDEO 0
#define NET_TYPE_AUDIO 1
#define NET_TYPE_CNTRL 2

/* ID's are used as bitmasks  */
#define NET_ID_VIDEO (1<<NET_TYPE_VIDEO)
#define NET_ID_AUDIO (1<<NET_TYPE_AUDIO)
#define NET_ID_CNTRL (1<<NET_TYPE_CNTRL)

typedef enum _NetworkStatus { NS_PACKETS_VT, NS_PACKETS_VR, NS_DROPS_V, 
                              NS_PACKETS_AT, NS_PACKETS_AR, NS_DROPS_A }  NetworkStatus;

class O1kNetwork;

#include "receive.h"
#include "transmit.h"

/* network status information */
typedef struct {    
  int packets_t_v;
  int packets_r_v;
  int drops_v;
  int packets_t_a;
  int packets_r_a;  
  int drops_a;
} NetworkParamsStatus;

/*------------------------------------------------------------------------
 *
 *  Class:	O1kNetwork
 *
 * Description:
 *     The O1kNetwork class contains the network state information
 *     for both transmit and receive. The work of transmitting and
 *     receiving data is done by individual network 'worker' threads.
 *     Each thread is responsible for a single function (either
 *     transmit or receive) and for a single network 'type' (control,
 *     audio or video). The worker threads for these types can be
 *     started and stopped and data is passed to/from them by the
 *     two functions:
 *        o1k_conf_network_transmit() and o1k_conf_network_receive()
 *
 * Notes:
 *     Currently, the O1kNetwork supports only single point connections
 *     although portions of the object already have the ability to
 *     support multicast.
 *
 *----------------------------------------------------------------------*/

class O1kNetwork {

public:
  
  char destination[MAX_NAME_SIZE];
  char hostname[MAXSENDTO][MAX_NAME_SIZE];
  int  hostnameknt;
  int  rchannel;
  int  tchannel;
  int  polling;
  int  type;

  NetworkParamsStatus status;
  
  TransmitState *tstate[NET_MAX_TYPES];
  ReceiveState  *rstate[NET_MAX_TYPES];

  /* network threads */
  O1kThread* aud_thread_t;
  O1kThread* aud_thread_r;
  O1kThread* vid_thread_t;
  O1kThread* vid_thread_r;
  O1kThread* ctl_thread_t;
  O1kThread* ctl_thread_r;
  
  O1kNetwork();
  ~O1kNetwork();

  void settings();
  void addHost(char* hname);
  void setUserHost(char* value);

  int startTransmit(int netids);
  int stopTransmit(int netids);
  int startReceive(int netids);
  int stopReceive(int netids);
  
  char* getStatus(NetworkStatus ns);

};

extern int o1k_conf_network_transmit(unsigned char* data, unsigned int size, unsigned int timeout, int type);
extern int o1k_conf_network_receive(unsigned char* data, unsigned int* size, unsigned int timeout, int type);
#endif
