#include "sp.h"

#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>

#include "threads.h"

#ifndef _SPREAD

#define _SPREAD


#define DEBUG

typedef struct{ 
  mailbox Mbox;
  char spreadName[80];
  char group[MAX_GROUP_NAME];
  char user[80];
  char privateGroup[MAX_GROUP_NAME];
} infSpread;

infSpread my_infSpread;

int	Previous_len;

sp_time heartbeat_time;

int Num_sent;

#define MAX_MESSLEN     102400

#endif

int sp_sendUnicast ();
int sp_sendMulticast ();
void sp_initEventHandler ();
void *sp_eventHandler ();
void sp_startHandler ();
void sp_stopHandler ();
void sp_heartbeat ();

/** join a group. -1 if error, 0 if ok */
int sp_join (mailbox mbox, char group[80]);

/** leave a group. -1 if error, 0 if ok */
int sp_leave (mailbox mbox, char group[80]);

/** connect to spread. -1 if error, 0 if ok
sp_server = port@machine. Ej. : 4802@adapt16 */
int sp_connect (char *sp_server, char *user, char *unicastAddr, mailbox *mbox);

int sp_disconnect (mailbox mbox);

void sp_readMessage ();

void User_command();
void Print_menu();
void Usage(int argc, char *argv[]);
void Print_help();
void Bye();
