// File: /workspace/github_cpp_makefile_star2_O3/CDISC2020[P]Projet_satellite_agile/src/communication/comGroundManager.cpp
// Function: main
int main (int argc, char* argv[])
{
	// Ecriture du pid dans un fichier
	int pid=getpid();
	ofstream fichierPid;
	fichierPid.open("pid_COM");
	if(!fichierPid)	{
		cout << "Failed to open pid_COM" << endl;
		exit(1);
	}
	fichierPid << pid << endl;
	fichierPid.close();

	// Recuperation du hostname
	if (gethostname(s, 100) != 0){
		perror("S-> gethostname");
		exit(1);
	}
	cout << "Host name " << s << endl;

	// Init des tableaux
	for(int i=0; i<1024; i++) buffer[i]='\0';
	for(int i=0; i<50; i++) cmde[i]=' ';

	// Signal
	signal(SIGINT, (sig_t)bye);


	/* CREATION DES THREADS	*/
	pthread_attr_t *thread_attributes;
	pthread_t *thread;

/////////* creation du thread processus communication au sol */
	tid_sol = 1;

	thread_attributes=(pthread_attr_t *)malloc(sizeof(pthread_attr_t));
	thread=(pthread_t *)malloc(sizeof(pthread_t));

	pthread_attr_init(thread_attributes);
	if (pthread_create(thread, thread_attributes, &Communic_Sol, (void*) NULL) != 0)
		perror ("Thread_Server-> Connection to ground error!");

/////////* creation du thread processus communication interne */
	tid_interne=2;

	thread_attributes=(pthread_attr_t *)malloc(sizeof(pthread_attr_t));
	thread=(pthread_t *)malloc(sizeof(pthread_t));

	pthread_attr_init(thread_attributes);
	if (pthread_create(thread, thread_attributes, &Communic_Interne, (void *) NULL) != 0)
		perror ("Thread_Server-> Internal connection error!");

/////////* creation du thread processus I'm alive */
	tid_alive=3;

	thread_attributes=(pthread_attr_t *)malloc(sizeof(pthread_attr_t));
	thread=(pthread_t *)malloc(sizeof(pthread_t));

	pthread_attr_init(thread_attributes);
	if (pthread_create(thread, thread_attributes, &am_alive, (void *)  NULL) != 0)
		perror ("Thread_Server-> I am alive error!");

	while (1) {usleep(100);}  /* DOES NOTHING */ ;

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x200, %rsp            # imm = 0x200
callq 0x2390
movl %eax, %ebx
leaq -0x210(%rbp), %r14
movq %r14, %rdi
callq 0x2440
leaq 0x110c(%rip), %rsi      # 0x542a
movq %r14, %rdi
movl $0x10, %edx
callq 0x2060
movq -0x210(%rbp), %rax
movq -0x18(%rax), %rax
testb $0x5, -0x1f0(%rbp,%rax)
jne 0x454d
leaq -0x210(%rbp), %rdi
movl %ebx, %esi
callq 0x2450
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x22a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x21a0
leaq -0x210(%rbp), %rdi
callq 0x2380
leaq 0x4f61(%rip), %rdi      # 0x92f0
movl $0x64, %esi
callq 0x23b0
testl %eax, %eax
jne 0x457b
movq 0x3c30(%rip), %rdi      # 0x7fd8
leaq 0x1093(%rip), %rsi      # 0x5442
movl $0xa, %edx
callq 0x2300
leaq 0x4f30(%rip), %r14      # 0x92f0
movq %r14, %rdi
callq 0x2130
movq 0x3c09(%rip), %rbx      # 0x7fd8
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x2300
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x22a0
movsbl %al, %esi
movq 0x3bdd(%rip), %rdi      # 0x7fd8
callq 0x2030
movq %rax, %rdi
callq 0x21a0
leaq 0x4f51(%rip), %rdi      # 0x9360
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x2180
movaps 0xe5e(%rip), %xmm0      # 0x5280
movaps %xmm0, 0x5337(%rip)     # 0x9760
movaps %xmm0, 0x5340(%rip)     # 0x9770
movaps %xmm0, 0x5349(%rip)     # 0x9780
movw $0x2020, 0x5350(%rip)   # imm = 0x2020
leaq -0x16b(%rip), %rsi      # 0x42dc
movl $0x2, %edi
callq 0x2320
movl $0x1, 0x3e39(%rip)      # 0x8294
movl $0x38, %edi
callq 0x2350
movq %rax, %rbx
movl $0x8, %edi
callq 0x2350
movq %rax, %r14
movq %rbx, %rdi
callq 0x2340
leaq -0xdca(%rip), %rdx      # 0x36ba
movq %r14, %rdi
movq %rbx, %rsi
xorl %ecx, %ecx
callq 0x24a0
testl %eax, %eax
je 0x44a1
leaq 0xfb1(%rip), %rdi       # 0x544d
callq 0x2210
movl $0x2, 0x3ded(%rip)      # 0x8298
movl $0x38, %edi
callq 0x2350
movq %rax, %rbx
movl $0x8, %edi
callq 0x2350
movq %rax, %r14
movq %rbx, %rdi
callq 0x2340
leaq -0x47c(%rip), %rdx      # 0x4058
movq %r14, %rdi
movq %rbx, %rsi
xorl %ecx, %ecx
callq 0x24a0
testl %eax, %eax
je 0x44f1
leaq 0xf8d(%rip), %rdi       # 0x5479
callq 0x2210
movl $0x3, 0x3da1(%rip)      # 0x829c
movl $0x38, %edi
callq 0x2350
movq %rax, %rbx
movl $0x8, %edi
callq 0x2350
movq %rax, %r14
movq %rbx, %rdi
callq 0x2340
leaq -0x2be(%rip), %rdx      # 0x4266
movq %r14, %rdi
movq %rbx, %rsi
xorl %ecx, %ecx
callq 0x24a0
testl %eax, %eax
je 0x4541
leaq 0xf68(%rip), %rdi       # 0x54a4
callq 0x2210
movl $0x64, %edi
callq 0x2370
jmp 0x4541
movq 0x3a84(%rip), %rdi      # 0x7fd8
leaq 0xec0(%rip), %rsi       # 0x541b
movl $0x16, %edx
callq 0x2300
movq 0x3a6c(%rip), %rdi      # 0x7fd8
callq 0x2150
movl $0x1, %edi
callq 0x2330
leaq 0xeb0(%rip), %rdi       # 0x5432
callq 0x2210
jmp 0x4571
jmp 0x458b
movq %rax, %rbx
movq 0x3a3b(%rip), %rax      # 0x7fd0
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq -0x208(%rbp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, -0x210(%rbp,%rcx)
callq 0x2220
leaq -0x118(%rbp), %rdi
callq 0x2100
movq %rbx, %rdi
callq 0x2470