From f50e3384d32150addb4bb02f1334d249b0bd736c Mon Sep 17 00:00:00 2001 From: Luca G Date: Wed, 31 Jan 2024 23:50:56 +0100 Subject: [PATCH] further doc --- docs/source/files/assignments/project.rst | 91 ++++------------------- 1 file changed, 15 insertions(+), 76 deletions(-) diff --git a/docs/source/files/assignments/project.rst b/docs/source/files/assignments/project.rst index 2c0ee1c0..730e81c4 100644 --- a/docs/source/files/assignments/project.rst +++ b/docs/source/files/assignments/project.rst @@ -4,8 +4,8 @@ In the project phase we decided to implement a userfriendly Gui. The aim is to make the usage of our Tsunami solver as easy and interactive as possible. -GUI -=========== +GUI (Client-side) +================== .. image:: ../../_static/assets/task-10-Gui_help.png @@ -28,85 +28,24 @@ After selecting the simulation has to be recompiled with the according button be The last tab contains further actions to interact with the simulation. First, the simulation can be started or killed here. Also files for the bathymetry and displacement can be chosen. As an addition, the user can get data like the heigth from the simulation. +Server-side +============= +Libraries +============== Communicator -============================= +************** -For communication between simulation and the gui Luca-Philipp introduced a communication library. -The **Communicator.cpp** library can be used to easily create a client-server TCP connection and handle its communication and logging. +For communication between simulation and the GUI we implemented a communication library. +The **Communicator.hpp** library can be used to easily create a client-server TCP connection and handle its communication and logging. -**communicator_api** +Communicator API +****************** -Since all communication happens using text over TCP, we had to implement a structure that both server and client can adhere to -in order to guarantee correct communication. For this, we decided to send all data in JSON format. Furthermore, each message -follows a strict pattern. It consists of 3 parts: the TYPE which provides information on the nature of the message, -the KEY which is a unique identifier for each message, and ARGS containing other message data (such as parameters) in JSON format. - -.. code:: cpp - - enum MessagePart - { - TYPE, - KEY, - ARGS - }; - - enum MessageType - { - SERVER_CALL, - FUNCTION_CALL, - OTHER, - SERVER_RESPONSE - }; - - struct Message - { - MessageType type = MessageType::OTHER; - std::string key = "NONE"; - json args = ""; - }; - -It also implements various functions to convert from and to json format, such as ``messageToJson()``, ``messageToJsonString()`` -and ``jsonToMessage()``. - -**Communicator.hpp** - -The library provides functions to start server and client and to send messages to each other. -Transmitted data is logged and can be retrieved via ``getLog()``. -Describing the detailed code here would be too extensive and not necessary, as this library -is rather just a tool for us to develop the actually interesting code. - -**Communication example** - -``communicator_api.h`` - -.. code:: cpp - - inline const Message START_SIMULATION = {MessageType::SERVER_CALL, "start_simulation"}; - -Client-side usage: - -.. code:: cpp - - xlpmg::Communicator m_communicator; - m_communicator.startClient(IPADDRESS, PORT) - - [...] - - xlpmg::Message startSimMsg = xlpmg::START_SIMULATION; - m_communicator.sendToServer(messageToJsonString(startSimMsg)); - -Server-side usage: - -.. code:: cpp - - xlpmg::Communicator m_communicator; - m_communicator.startServer(m_PORT); - - // listen for key +(**File: communicator_api.h**) +Since all communication happens using text over TCP, we had to implement a structure that both server and client can adhere to +in order to guarantee correct communication. For this, we decided to send all data in JSON format and a ``Message`` struct. -Server -============ -TODO \ No newline at end of file +.. note:: For further information, see :ref:`ns-lib` \ No newline at end of file