程序代写代做代考 Design

Design
Project Report
The server consists of 3 files: roadmap.cpp, roadmap.h and server.cpp. Roadmap.cpp and roadmap.h implement the map road system. server.cpp is responsible for bind and listen to port, accept connection from client, run the producer thread to take request command from client and run the consumer thread to execute the command and respond to client.
The server can take request from multiple clients at the same time. Whenever a new client connects to the server, the server will create a producer thread that constantly receives the command from client until the connection closes. When the producer thread receives a command, it adds the command to queue. The consumer threads constantly check whether there are commands left in the queue, if there is at least 1 command in the queue, it takes the command out of the queue, invoke the API of road map system to execute the command and reply to the client. To avoid race condition, I use the pthread_mutex_t to synchronize the access to the queue.
There are two clients: mapManageClient and queryClient.

mapManageClient is used to add map data and queryClient is used to query the shortest path between two vertexes. The reason to have two clients is that in a real system, we would like different users have different authority. For example, we would want only administer can change the map data and the average users can only query on the map.
Command format for mapManageClient:
1. addVertex
VertexType: 0 for point of interest and 1 for intersection Example: addVertex s 0
This command add vertex s which is a point of interest.
2. addEdge
edge event: 0 for normal , 1 for closure, 2 for car stopped, 3 for debris
Example: addEdge s t 40 10 0
This command add edge from vertex s to vertex t, this edge has speed limit 40 kilometers per hour and length 10 kilometers and the event type is normal.
The mapManageClient sends the command input by the user in the console through TCP connection to the server and displays the response

from the server to the console. The response will be ¡°success¡± if server successfully execute the command, or ¡°failure¡± with its reason if the command is invalid. For example, if the command name is incorrect or add edge with non-existing vertex.
The queryClient will send the start vertex and end vertex to server and displays the path sent by the server or the reason for failure if the query is invalid. For example, if the start or end vertex doesn¡¯t exist in the road map system.
Results
I test the system with 3 cases.
Case1 tests with valid commands, valid queries and uses only 1 query client.
Case 2 tests also with invalid commands and invalid queries. The invalid commands include incorrect command name and add edge with non- existing vertex. The invalid query includes scenario where the input vertex doesn¡¯t exist.
Case 3 tests with multiple query client to query at the same time.

Screenshots