// File: /workspace/github_cpp_makefile_star2_O1/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 0x107f(%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 0x45da
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 0x4ed4(%rip), %rdi      # 0x92f0
movl $0x64, %esi
callq 0x23b0
testl %eax, %eax
jne 0x4608
movq 0x3ba3(%rip), %rdi      # 0x7fd8
leaq 0x1006(%rip), %rsi      # 0x5442
movl $0xa, %edx
callq 0x2300
leaq 0x4ea3(%rip), %r14      # 0x92f0
movq %r14, %rdi
callq 0x2130
movq 0x3b7c(%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 0x3b50(%rip), %rdi      # 0x7fd8
callq 0x2030
movq %rax, %rdi
callq 0x21a0
leaq 0x4ec4(%rip), %rdi      # 0x9360
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x2180
movaps 0xdd1(%rip), %xmm0      # 0x5280
movaps %xmm0, 0x52aa(%rip)     # 0x9760
movaps %xmm0, 0x52b3(%rip)     # 0x9770
movaps %xmm0, 0x52bc(%rip)     # 0x9780
movw $0x2020, 0x52c3(%rip)   # imm = 0x2020
leaq -0x16b(%rip), %rsi      # 0x4369
movl $0x2, %edi
callq 0x2320
movl $0x1, 0x3dac(%rip)      # 0x8294
movl $0x38, %edi
callq 0x2350
movq %rax, %rbx
movl $0x8, %edi
callq 0x2350
movq %rax, %r14
movq %rbx, %rdi
callq 0x2340
leaq -0xdc7(%rip), %rdx      # 0x374a
movq %r14, %rdi
movq %rbx, %rsi
xorl %ecx, %ecx
callq 0x24a0
testl %eax, %eax
je 0x452e
leaq 0xf24(%rip), %rdi       # 0x544d
callq 0x2210
movl $0x2, 0x3d60(%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      # 0x40e5
movq %r14, %rdi
movq %rbx, %rsi
xorl %ecx, %ecx
callq 0x24a0
testl %eax, %eax
je 0x457e
leaq 0xf00(%rip), %rdi       # 0x5479
callq 0x2210
movl $0x3, 0x3d14(%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      # 0x42f3
movq %r14, %rdi
movq %rbx, %rsi
xorl %ecx, %ecx
callq 0x24a0
testl %eax, %eax
je 0x45ce
leaq 0xedb(%rip), %rdi       # 0x54a4
callq 0x2210
movl $0x64, %edi
callq 0x2370
jmp 0x45ce
movq 0x39f7(%rip), %rdi      # 0x7fd8
leaq 0xe33(%rip), %rsi       # 0x541b
movl $0x16, %edx
callq 0x2300
movq 0x39df(%rip), %rdi      # 0x7fd8
callq 0x2150
movl $0x1, %edi
callq 0x2330
leaq 0xe23(%rip), %rdi       # 0x5432
callq 0x2210
jmp 0x45fe
jmp 0x4618
movq %rax, %rbx
movq 0x39ae(%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
nop