-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
83 lines (74 loc) · 2.04 KB
/
Copy pathmain.cpp
File metadata and controls
83 lines (74 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <stdio.h>
#include <map>
#include "TcpServer.h"
#include "textSync.h"
#include "TemporaryData.h"
#include "SyncImage.h"
int getDeviceInformation(PhoneLinkDevice *args, DeviceUnit *device)
{
return 0;
}
int setDeviceInformation(PhoneLinkDevice *args, DeviceUnit *device)
{
struct sockaddr_in in;
uint32_t inLen = sizeof(in);
getpeername(device->in->socket, (struct sockaddr *)&in, &inLen);
char *buff = inet_ntoa(in.sin_addr);
device->information->ip = new char[strlen(buff)];
memcpy(device->information->ip, buff, strlen(buff));
return 0;
}
ShellType funFrom[] = {
textSync, (char*)"textSync",
GetTemporaryData, (char*)"GetTemporaryData",
SyncImage, (char*)"SyncImage",
};
int fun(PhoneLinkDevice *args, DeviceUnit *device)
{
size_t len;
messageOut("0x%X\n", args->key);
while (true)
{
char *businessStr = device->in->socketRead(&len);
if (businessStr == NULL)
{
//设备断开,将设备离线
device->OffLink();
return -1;
}
for (size_t i = 0; i < sizeof(funFrom) / sizeof(ShellType); i++)
{
if (strncmp(businessStr, funFrom[i].matchKey, len) == 0)
{
args->lock->lock();
int funSign = funFrom[i].businessFun(args, device);
messageOut("目标函数执行成功,返回值为%d\n", funSign);
args->lock->unlock();
goto funEXIT;
}
}
device->in->socketSendString((char*)"ON business FUN");
funEXIT:
DeleteDataMemory(businessStr);
}
return 0;
}
/* Catch Signal Handler functio */
void signal_callback_handler(int signum)
{
printf("Caught signal SIGPIPE %d\n", signum);
fflush(stdout);
}
int main()
{
signal(SIGPIPE, signal_callback_handler);
printf("hello word!");
TcpServer server(SOCKET_PORT, &fun);
fflush(stdout);
if (server.threadLocal != NULL)
{
server.threadLocal->join();
}
printf("时间到达\n");
return 0;
}