-
Notifications
You must be signed in to change notification settings - Fork 0
/
services.c
130 lines (112 loc) · 2.64 KB
/
services.c
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/** @file services.c
* @brief Receive incoming requests from DUT, device them based on the request.
*
* Request can be following
*
* Command execution
* Request for console logs
* Clear console logs
* Reboot assist board
* Start process
* Kill a process
* Check the process state
* Assist board health
*
* @author Yashwanth Dasar (yashwanth_dasar@mentor.com)
* @bug No know bugs.
*/
#include "./include/assist.h"
/** @file services.c
* @brief DUT request is compared and appropriate function is called
*
* DUT request is compared/analised. Based on request appropriate utility is called.
*
* @param sockfd (socket descriptor)
* @return retVal (success 0, failure -1).
*/
int service_request(int sockfd)
{
char* request = NULL;
int retVal = 0;
if((request = read_socket(sockfd)) == NULL)
{
printf("\nAssist : read_socket() fail\n");
write_socket("Assist : read_socket() fail. AssistBoardClose", sockfd);
retVal = -1;
}
#ifdef DEBUG
else
{
printf("\nAssist : Recv/read pass\n");
}
#endif
/* Receive console logs */
if(strcmp(request, "ConsoleLogsRequest") == 0)
{
if(request_console_logs(sockfd) == -1)
{
printf("\nAssist : request_console_logs() fail\n");
write_socket("Assist : request_console_logs() fail. AssistBoardClose", sockfd);
retVal = -1;
}
#ifdef DEBUG
else
{
printf("\nAssist : request_console_logs() pass\n");
}
#endif
}
/* Clear console logs */
else if(strcmp(request, "ConsoleLogsClear") == 0)
{
if(clear_console_logs(sockfd) == -1)
{
printf("\nAssist : clear_console_logs() fail\n");
write_socket("Assist : clear_console_logs() fail. AssistBoardClose", sockfd);
retVal = -1;
}
#ifdef DEBUG
else
{
printf("\nAssist : clear_console_logs() pass\n");
}
#endif
}
/* Rebooting assist board */
else if(strcmp(request, "AssistBoardReboot") == 0)
{
retVal = reboot_assist_board(sockfd);
}
/* Check the health of assit board */
else if(strcmp(request, "AssistBoardHealth") == 0)
{
retVal = health_check_assist_board(sockfd);
}
/* Start a process */
else if(strstr(request, "StartProcess") != 0)
{
retVal = start_process(request, sockfd);
}
/* Check a process is running */
else if(strstr(request, "CheckProcessRunning") != 0)
{
retVal = check_process_running(request, sockfd);
}
/* Kill a running process */
else if(strstr(request, "KillRunningProcess") != 0)
{
retVal = kill_running_process(request, sockfd);
}
/* Execute the command */
else
{
retVal = execute_request(request, sockfd);
}
/* Free the allocated memory */
if(request)
{
free(request);
request = NULL;
}
return retVal;
}