// File: /workspace/github_cpp_makefile_star2_O1/CDISC2020[P]Projet_satellite_agile/src/planManager/main_PM.cpp
// Function: main
int  main (int argc,char* argv[])
{
	// Ecriture du pid dans un fichier
	int pid=getpid();
	ofstream fichierPid;
	fichierPid.open("pid_PM");
	if(!fichierPid) {
		cout << "Failed to open pid_PM" << 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;

	signal(SIGINT, (sig_t)bye);

	channelFDIR = new QueuingPort(0, 18002, s);		// Client FDIR
	channelSM = new QueuingPort(0, 18003, s); 		// Client COM
	channelReceptionPM = new QueuingPort(1, 18001, s); 	// Server

	usleep(500000);

	channelFDIR->Display();
	channelSM->Display();
	channelReceptionPM->Display();

	// generate thread
	pthread_attr_t *thread_attributes;
	pthread_t *thread;

	/* creation du thread Server1 */
	tid_FD = 1;

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

	thread1 = thread;
	pthread_attr_init(thread_attributes);
	if (pthread_create(thread, thread_attributes, Server_PM,(void *) NULL) != 0)
		perror ("Thread_Server-> Failure detector thread pb!");

	/* creation du thread Client1 */
	tid_FP = 2;

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

	thread2 = thread;
	pthread_attr_init(thread_attributes);
	if (pthread_create(thread, thread_attributes, Client_PM,(void *) NULL) != 0)
		perror ("Thread_Client-> Failure detector thread pb!");

	/* creation du thread Client2 */
	tid_A = 3;

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

	thread2 = thread;
	pthread_attr_init(thread_attributes);
	if (pthread_create(thread, thread_attributes, Alive,(void *) NULL) != 0)
		perror ("Thread_Alive-> Failure detector thread pb!");

	while(1) {usleep(100);}

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x200, %rsp            # imm = 0x200
callq 0x3390
movl %eax, %ebx
leaq -0x210(%rbp), %r14
movq %r14, %rdi
callq 0x3440
leaq 0x12a1(%rip), %rsi      # 0x7785
movq %r14, %rdi
movl $0x10, %edx
callq 0x3060
movq -0x210(%rbp), %rax
movq -0x18(%rax), %rax
testb $0x5, -0x1f0(%rbp,%rax)
jne 0x677d
leaq -0x210(%rbp), %rdi
movl %ebx, %esi
callq 0x3450
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3190
leaq -0x210(%rbp), %rdi
callq 0x3370
leaq 0x3dfb(%rip), %rdi      # 0xa350
movl $0x64, %esi
callq 0x33c0
testl %eax, %eax
jne 0x67cd
movq 0x3a62(%rip), %rdi      # 0x9fd0
leaq 0x1227(%rip), %rsi      # 0x779c
movl $0xa, %edx
callq 0x32f0
leaq 0x3dca(%rip), %rbx      # 0xa350
movq %rbx, %rdi
callq 0x3130
movq 0x3a3b(%rip), %rdi      # 0x9fd0
movq %rbx, %rsi
movq %rax, %rdx
callq 0x32f0
movq 0x3a29(%rip), %rdi      # 0x9fd0
callq 0x3150
leaq -0x120(%rip), %rsi      # 0x6493
movl $0x2, %edi
callq 0x3300
movl $0x4c8, %edi            # imm = 0x4C8
callq 0x32a0
movq %rax, %r14
leaq 0x3d7f(%rip), %rcx      # 0xa350
movq %rax, %rdi
xorl %esi, %esi
movl $0x4652, %edx           # imm = 0x4652
callq 0x3ab6
movq %r14, 0x3dd1(%rip)      # 0xa3b8
movl $0x4c8, %edi            # imm = 0x4C8
callq 0x32a0
movq %rax, %r14
leaq 0x3d55(%rip), %rcx      # 0xa350
movq %rax, %rdi
xorl %esi, %esi
movl $0x4653, %edx           # imm = 0x4653
callq 0x3ab6
movq %r14, 0x3daf(%rip)      # 0xa3c0
movl $0x4c8, %edi            # imm = 0x4C8
callq 0x32a0
movq %rax, %r14
leaq 0x3d2b(%rip), %rcx      # 0xa350
movq %rax, %rdi
movl $0x1, %esi
movl $0x4651, %edx           # imm = 0x4651
callq 0x3ab6
movq %r14, 0x3d8a(%rip)      # 0xa3c8
movl $0x7a120, %edi          # imm = 0x7A120
callq 0x3360
movq 0x3d69(%rip), %rdi      # 0xa3b8
callq 0x3ff8
movq 0x3d65(%rip), %rdi      # 0xa3c0
callq 0x3ff8
movq 0x3d61(%rip), %rdi      # 0xa3c8
callq 0x3ff8
movl $0x1, 0x3c2e(%rip)      # 0xa2a4
movl $0x38, %edi
callq 0x3340
movq %rax, %rbx
movl $0x8, %edi
callq 0x3340
movq %rax, %r14
movq %rax, 0x3c19(%rip)      # 0xa2b0
movq %rbx, %rdi
callq 0x3320
leaq -0x4fa(%rip), %rdx      # 0x61ac
movq %r14, %rdi
movq %rbx, %rsi
xorl %ecx, %ecx
callq 0x34a0
testl %eax, %eax
je 0x66c3
leaq 0x10e9(%rip), %rdi      # 0x77a7
callq 0x3200
movl $0x2, 0x3bdb(%rip)      # 0xa2a8
movl $0x38, %edi
callq 0x3340
movq %rax, %rbx
movl $0x8, %edi
callq 0x3340
movq %rax, %r14
movq %rax, 0x3bca(%rip)      # 0xa2b8
movq %rbx, %rdi
callq 0x3320
leaq -0x2af(%rip), %rdx      # 0x644e
movq %r14, %rdi
movq %rbx, %rsi
xorl %ecx, %ecx
callq 0x34a0
testl %eax, %eax
je 0x671a
leaq 0x10be(%rip), %rdi      # 0x77d3
callq 0x3200
movl $0x3, 0x3b88(%rip)      # 0xa2ac
movl $0x38, %edi
callq 0x3340
movq %rax, %rbx
movl $0x8, %edi
callq 0x3340
movq %rax, %r14
movq %rax, 0x3b73(%rip)      # 0xa2b8
movq %rbx, %rdi
callq 0x3320
leaq -0x2f1(%rip), %rdx      # 0x6463
movq %r14, %rdi
movq %rbx, %rsi
xorl %ecx, %ecx
callq 0x34a0
testl %eax, %eax
je 0x6771
leaq 0x1093(%rip), %rdi      # 0x77ff
callq 0x3200
movl $0x64, %edi
callq 0x3360
jmp 0x6771
movq 0x384c(%rip), %rbx      # 0x9fd0
leaq 0xfeb(%rip), %rsi       # 0x7776
movl $0x15, %edx
movq %rbx, %rdi
callq 0x32f0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq 0x381a(%rip), %rdi      # 0x9fd0
callq 0x3030
movq %rax, %rdi
callq 0x3190
movl $0x1, %edi
callq 0x3310
leaq 0xfb8(%rip), %rdi       # 0x778c
callq 0x3200
jmp 0x67c3
jmp 0x67ee
jmp 0x67e1
jmp 0x67e1
movq %rax, %rbx
movq %r14, %rdi
callq 0x3260
jmp 0x67f1
movq %rax, %rbx
movq 0x37d0(%rip), %rax      # 0x9fc8
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 0x3210
leaq -0x118(%rbp), %rdi
callq 0x30f0
movq %rbx, %rdi
callq 0x3480
nop