// File: /workspace/github_cpp_makefile_star2_O2/sjtuwrk[P]SunwayMR/tools/SunwayMRHelper.hpp
// Function: SunwayMRHelper::messageReceived(int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&)
void SunwayMRHelper::messageReceived(int localListenPort, string fromHost, int msgType, string &msg) {
	if (localListenPort != this->listenPort || fromHost == "" || msg == "") return;

	stringstream received;
	received << "SunwayMRHelper: listening port: " << localListenPort
			<< ", message received from: " << fromHost
			<< ", message type: " << msgType
			<< ", message content: " << msg;
	Logging::logVerbose(received.str());

	switch(msgType) {
	case HOST_RESOURCE_INFO:
	{
		vector<string> ss = splitString(msg, ' ');
		if (ss.size() == 3) {
			HostResource hr = {
					fromHost,
					atoi(ss[0].c_str()),
					atoi(ss[1].c_str()),
					atoi(ss[2].c_str())
			};
			update(hr);
		}
		break;
	}

	case FILE_INFO:
	{
		vector<string> ss = splitString(msg, ' '); // msg: fileUID, appUID, fileName
		if (ss.size() == 3) {
			int file_uid = atoi(ss[0].c_str());
			fileInfoMap[file_uid] = msg;
		}
		break;
	}

	case SHELL_COMMAND:
	{
		int ret = system(msg.c_str());
		if (ret == -1) {
			stringstream error;
			error << "SunwayMRHelper:: failed to execute shell: " << endl << msg.c_str() << endl;
			Logging::logError(error.str());
		}
		break;
	}

	default:
	{
		if(fileInfoMap.find(msgType) != fileInfoMap.end()) {
			string file_info = fileInfoMap[msgType];
			vector<string> vs = splitString(file_info, ' ');
			stringstream sstr;
			sstr << fileSaveDir << vs[1] << "/";
			bool ret = writeFile(sstr.str(), vs[2], msg);
			if (!ret) {
				stringstream error;
				error << "SunwayMRHelper: unable to write file: " << sstr.str() << vs[2];
				Logging::	logError(error.str());
			}
			fileInfoMap.erase(msgType);
			Logging::logInfo("SunwayMRHelper: file received: "
					+ sstr.str() + vs[2]);
		}

	}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x5a8, %rsp            # imm = 0x5A8
movl %ecx, 0x4(%rsp)
cmpl %esi, 0x13c(%rdi)
jne 0x8754
movq %r8, %rbx
movq %rdx, %r15
movl %esi, %ebp
movq %rdi, %r14
leaq 0x3e30(%rip), %rsi      # 0xc09b
movq %rdx, %rdi
callq 0x91d8
testb %al, %al
jne 0x8754
leaq 0x3e19(%rip), %rsi      # 0xc09b
movq %rbx, %rdi
callq 0x91d8
testb %al, %al
jne 0x8754
leaq 0x420(%rsp), %rdi
callq 0x3230
leaq 0x430(%rsp), %rdi
leaq 0x44c7(%rip), %rsi      # 0xc775
callq 0x3360
movq %rax, %rdi
movl %ebp, %esi
callq 0x35e0
leaq 0x44d2(%rip), %rsi      # 0xc796
movq %rax, %rdi
callq 0x3360
movq %rax, %rdi
movq %r15, %rsi
callq 0x3300
leaq 0x44d2(%rip), %rsi      # 0xc7b0
movq %rax, %rdi
callq 0x3360
movl 0x4(%rsp), %esi
movq %rax, %rdi
callq 0x35e0
leaq 0x44c8(%rip), %rsi      # 0xc7c1
movq %rax, %rdi
callq 0x3360
movq %rax, %rdi
movq %rbx, %rsi
callq 0x3300
leaq 0x438(%rsp), %rsi
leaq 0x110(%rsp), %rdi
callq 0x3550
leaq 0x110(%rsp), %rdi
callq 0x4c7c
leaq 0x110(%rsp), %rdi
callq 0x36e8
movl 0x4(%rsp), %eax
testl %eax, %eax
je 0x844c
cmpl $0x1, %eax
je 0x83e7
cmpl $0x2, %eax
jne 0x8504
movq (%rbx), %rdi
callq 0x32e0
cmpl $-0x1, %eax
jne 0x8747
leaq 0x110(%rsp), %rdi
callq 0x3230
leaq 0x120(%rsp), %rdi
leaq 0x444f(%rip), %rsi      # 0xc7d5
callq 0x3360
movq %rax, %rdi
callq 0x31b0
movq (%rbx), %rsi
movq %rax, %rdi
callq 0x3360
movq %rax, %rdi
callq 0x31b0
leaq 0x128(%rsp), %rsi
leaq 0x298(%rsp), %rdi
callq 0x3550
leaq 0x298(%rsp), %rdi
callq 0x4efc
leaq 0x298(%rsp), %rdi
callq 0x36e8
leaq 0x110(%rsp), %rdi
callq 0x3260
jmp 0x8747
leaq 0x110(%rsp), %rdi
pushq $0x20
popq %rdx
movq %rbx, %rsi
callq 0x3a53
movq 0x110(%rsp), %rax
movq 0x118(%rsp), %rcx
subq %rax, %rcx
cmpq $0x60, %rcx
jne 0x843f
movq (%rax), %rdi
callq 0x3540
leaq 0x298(%rsp), %rsi
movl %eax, (%rsi)
addq $0x158, %r14            # imm = 0x158
movq %r14, %rdi
callq 0x9482
movq %rax, %rdi
movq %rbx, %rsi
callq 0x31e0
leaq 0x110(%rsp), %rdi
jmp 0x84fa
leaq 0x298(%rsp), %rdi
pushq $0x20
popq %rdx
movq %rbx, %rsi
callq 0x3a53
movq 0x2a0(%rsp), %rax
subq 0x298(%rsp), %rax
cmpq $0x60, %rax
jne 0x84f2
leaq 0x110(%rsp), %rdi
movq %r15, %rsi
callq 0x3490
movq 0x298(%rsp), %r15
movq (%r15), %rdi
callq 0x3540
leaq 0x110(%rsp), %rbx
movl %eax, 0x20(%rbx)
movq 0x20(%r15), %rdi
callq 0x3540
movl %eax, 0x24(%rbx)
movq 0x40(%r15), %rdi
callq 0x3540
movl %eax, 0x28(%rbx)
leaq 0xe0(%rsp), %rdi
movq %rbx, %rsi
callq 0x945c
leaq 0xe0(%rsp), %rsi
movq %r14, %rdi
callq 0x88d4
leaq 0xe0(%rsp), %rdi
callq 0x36e8
leaq 0x110(%rsp), %rdi
callq 0x36e8
leaq 0x298(%rsp), %rdi
callq 0x904e
jmp 0x8747
leaq 0x158(%r14), %r15
leaq 0x4(%rsp), %rsi
movq %r15, %rdi
callq 0xaf3c
addq $0x160, %r14            # imm = 0x160
cmpq %r14, %rax
je 0x8747
leaq 0x4(%rsp), %rsi
movq %r15, %rdi
callq 0x9482
leaq 0xc0(%rsp), %rdi
movq %rax, %rsi
callq 0x3490
leaq 0x28(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
pushq $0x20
popq %rdx
callq 0x3a53
leaq 0x110(%rsp), %rdi
callq 0x3230
leaq 0x120(%rsp), %rdi
leaq 0x9e7a(%rip), %rsi      # 0x123f0
callq 0x3300
movq 0x28(%rsp), %rsi
addq $0x20, %rsi
movq %rax, %rdi
callq 0x3300
leaq 0x3d9b(%rip), %rsi      # 0xc32e
movq %rax, %rdi
callq 0x3360
leaq 0x128(%rsp), %r14
leaq 0xa0(%rsp), %rdi
movq %r14, %rsi
callq 0x3550
movq 0x28(%rsp), %rsi
addq $0x40, %rsi
leaq 0x80(%rsp), %rdi
callq 0x3490
leaq 0x60(%rsp), %rdi
movq %rbx, %rsi
callq 0x3490
leaq 0xa0(%rsp), %rdi
leaq 0x80(%rsp), %rsi
leaq 0x60(%rsp), %rdx
callq 0x41d9
movl %eax, %ebx
leaq 0x60(%rsp), %rdi
callq 0x36e8
leaq 0x80(%rsp), %rdi
callq 0x36e8
leaq 0xa0(%rsp), %rdi
callq 0x36e8
testb %bl, %bl
jne 0x86aa
leaq 0x298(%rsp), %rdi
callq 0x3230
leaq 0x2a8(%rsp), %rdi
leaq 0x41c6(%rip), %rsi      # 0xc800
callq 0x3360
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x3550
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x3300
movq 0x28(%rsp), %rsi
addq $0x40, %rsi
movq %rax, %rdi
callq 0x3300
leaq 0x8(%rsp), %rdi
callq 0x36e8
leaq 0x2b0(%rsp), %rsi
leaq 0x8(%rsp), %rdi
callq 0x3550
leaq 0x8(%rsp), %rdi
callq 0x4efc
leaq 0x8(%rsp), %rdi
callq 0x36e8
leaq 0x298(%rsp), %rdi
callq 0x3260
leaq 0x4(%rsp), %rsi
movq %r15, %rdi
callq 0xaf70
leaq 0x40(%rsp), %rdi
movq %r14, %rsi
callq 0x3550
leaq 0x415c(%rip), %rsi      # 0xc827
leaq 0x8(%rsp), %rdi
leaq 0x40(%rsp), %rdx
callq 0x94ef
movq 0x28(%rsp), %rdx
addq $0x40, %rdx
leaq 0x298(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x94d0
leaq 0x298(%rsp), %rdi
callq 0x4dbc
leaq 0x298(%rsp), %rdi
callq 0x36e8
leaq 0x8(%rsp), %rdi
callq 0x36e8
leaq 0x40(%rsp), %rdi
callq 0x36e8
leaq 0x110(%rsp), %rdi
callq 0x3260
leaq 0x28(%rsp), %rdi
callq 0x904e
leaq 0xc0(%rsp), %rdi
callq 0x36e8
leaq 0x420(%rsp), %rdi
callq 0x3260
addq $0x5a8, %rsp            # imm = 0x5A8
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
jmp 0x87fb
jmp 0x876b
jmp 0x876b
movq %rax, %rbx
jmp 0x8808
jmp 0x8884
movq %rax, %rbx
leaq 0x298(%rsp), %rdi
callq 0x36e8
jmp 0x8875
jmp 0x8872
jmp 0x88bc
movq %rax, %rbx
leaq 0xe0(%rsp), %rdi
callq 0x36e8
jmp 0x87ac
movq %rax, %rbx
leaq 0x110(%rsp), %rdi
callq 0x36e8
jmp 0x87be
movq %rax, %rbx
leaq 0x298(%rsp), %rdi
jmp 0x885f
movq %rax, %rbx
leaq 0x298(%rsp), %rdi
callq 0x36e8
jmp 0x87e0
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x36e8
jmp 0x87ef
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
jmp 0x8843
jmp 0x8884
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x36e8
leaq 0x298(%rsp), %rdi
callq 0x3260
jmp 0x8887
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x36e8
jmp 0x8829
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x36e8
jmp 0x883b
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0x36e8
jmp 0x8887
movq %rax, %rbx
jmp 0x8894
movq %rax, %rbx
jmp 0x889e
movq %rax, %rbx
leaq 0x110(%rsp), %rdi
callq 0x904e
jmp 0x88bf
jmp 0x88bc
jmp 0x88bc
jmp 0x88bc
jmp 0x88bc
jmp 0x8884
jmp 0x88bc
movq %rax, %rbx
leaq 0x110(%rsp), %rdi
callq 0x3260
jmp 0x88bf
movq %rax, %rbx
leaq 0x110(%rsp), %rdi
callq 0x3260
leaq 0x28(%rsp), %rdi
callq 0x904e
leaq 0xc0(%rsp), %rdi
jmp 0x88b3
movq %rax, %rbx
leaq 0x110(%rsp), %rdi
callq 0x36e8
jmp 0x88bf
jmp 0x88bc
movq %rax, %rbx
leaq 0x420(%rsp), %rdi
callq 0x3260
movq %rbx, %rdi
callq 0x3610