// File: /workspace/github_cpp_makefile_star2_O2/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 0x2340
movl %eax, %ebx
leaq -0x210(%rbp), %r14
movq %r14, %rdi
callq 0x23f0
leaq 0xa21(%rip), %rsi       # 0x43e4
pushq $0x10
popq %rdx
movq %r14, %rdi
callq 0x2050
movq -0x210(%rbp), %rax
movq -0x18(%rax), %rax
testb $0x5, -0x1f0(%rbp,%rax)
jne 0x3a5c
leaq -0x210(%rbp), %rdi
movl %ebx, %esi
callq 0x2400
movq %rax, %rdi
callq 0x2160
leaq -0x210(%rbp), %rdi
callq 0x2330
leaq 0x48b4(%rip), %rdi      # 0x82c0
pushq $0x64
popq %rsi
callq 0x2360
testl %eax, %eax
jne 0x3a7f
movq 0x35b9(%rip), %rdi      # 0x6fd8
leaq 0x9d6(%rip), %rsi       # 0x43fc
callq 0x2260
leaq 0x488e(%rip), %rsi      # 0x82c0
movq %rax, %rdi
callq 0x2260
movq %rax, %rdi
callq 0x2160
xorl %eax, %eax
leaq 0x48e5(%rip), %rcx      # 0x8330
cmpq $0x400, %rax            # imm = 0x400
je 0x3a8d
movb $0x0, (%rax,%rcx)
incq %rax
jmp 0x3a4b
movq 0x3575(%rip), %rdi      # 0x6fd8
leaq 0x96b(%rip), %rsi       # 0x43d5
callq 0x2260
movq %rax, %rdi
callq 0x2160
pushq $0x1
popq %rdi
callq 0x22c0
leaq 0x966(%rip), %rdi       # 0x43ec
callq 0x21d0
jmp 0x3a77
xorl %eax, %eax
leaq 0x4c9a(%rip), %rcx      # 0x8730
cmpq $0x32, %rax
je 0x3aa5
movb $0x20, (%rax,%rcx)
incq %rax
jmp 0x3a96
leaq -0x12b(%rip), %rsi      # 0x3981
pushq $0x2
popq %rdi
callq 0x22b0
movl $0x1, 0x37a6(%rip)      # 0x7264
pushq $0x38
popq %rdi
callq 0x22f0
movq %rax, %rbx
pushq $0x8
popq %rdi
callq 0x22f0
movq %rax, %r14
movq %rbx, %rdi
callq 0x22d0
leaq -0x9d9(%rip), %rdx      # 0x310a
movq %r14, %rdi
movq %rbx, %rsi
xorl %ecx, %ecx
callq 0x2440
testl %eax, %eax
je 0x3b00
leaq 0x90c(%rip), %rdi       # 0x4407
callq 0x21d0
movl $0x2, 0x375e(%rip)      # 0x7268
pushq $0x38
popq %rdi
callq 0x22f0
movq %rax, %rbx
pushq $0x8
popq %rdi
callq 0x22f0
movq %rax, %r14
movq %rbx, %rdi
callq 0x22d0
leaq -0x39e(%rip), %rdx      # 0x3791
movq %r14, %rdi
movq %rbx, %rsi
xorl %ecx, %ecx
callq 0x2440
testl %eax, %eax
je 0x3b4c
leaq 0x8ec(%rip), %rdi       # 0x4433
callq 0x21d0
movl $0x3, 0x3716(%rip)      # 0x726c
pushq $0x38
popq %rdi
callq 0x22f0
movq %rax, %rbx
pushq $0x8
popq %rdi
callq 0x22f0
movq %rax, %r14
movq %rbx, %rdi
callq 0x22d0
leaq -0x271(%rip), %rdx      # 0x390a
movq %r14, %rdi
movq %rbx, %rsi
xorl %ecx, %ecx
callq 0x2440
testl %eax, %eax
je 0x3b98
leaq 0x8cb(%rip), %rdi       # 0x445e
callq 0x21d0
pushq $0x64
popq %rbx
movl %ebx, %edi
callq 0x2320
jmp 0x3b9b
jmp 0x3ba6
movq %rax, %rbx
leaq -0x210(%rbp), %rdi
callq 0x2350
movq %rbx, %rdi
callq 0x2420
nop