#include "rssi-display.h"
#include "rssi_list.h"
#include "pcap-thread.h"
#include "http-server.h"

volatile sig_atomic_t got_sigint;
Element * rssi_list;

sem_t synchro;
pthread_t pcap_thread;
int * pcap_ret;

/* Callback function when a SIGNAL is raised.
 *
 * Input: SIGNAL id.
 * Output: None.
 */
void sigInt_received(int sig) {
    got_sigint=0;
    printf("\nStop sniffing\n");
    exit(-1);
}

int main (int argc, char *argv[]) {

	// Sem Init
	sem_init(&synchro,3,0);	
	sem_post(&synchro);

	// SIGINT handler
    	signal(SIGINT, sigInt_received);
	
        

	/* Sniff Thread with provided pcap func  */
	printf("\nStart Sniffing\n");
	pthread_create(&pcap_thread, NULL, pcap_function, (void *)"wlan0"); //wlan0-1 is in monitor or wlan ? uci show not same as iw dev

	/* MicroHTTPD */
	//printf("[+] Start MicroHTTP daemon.\n");

	start_microhttpd();

        /* Wait for results*/
	//pthread_join ( pcap_thread, (void**)&pcap_ret);

	


   return 0;
}
