Class for the client thread. More...
#include <ClientThread.hpp>
Public Member Functions | |
ClientThread (QObject *parent=nullptr) | |
Construct a new Client Thread:: Client Thread object. | |
~ClientThread () | |
Destructor for the ClientThread class. | |
void | runClient (int argc, char *argv[]) |
Run the client by initializing the Ice communicator and connecting to the server. | |
void | setJoystickValue (bool value) |
Set the joystick value on the server. | |
bool | getJoystickValue () |
Get the joystick value from the server. | |
void | setRunning (bool value) |
Sets the running flag of the client thread. | |
Private Attributes | |
Ice::CommunicatorPtr | communicator |
Ice::ObjectPrx | base |
Data::CarDataPrx | carData |
std::thread | clientThread |
bool | running = true |
bool | connected = false |
std::mutex | mtx |
std::condition_variable | cv |
Class for the client thread.
Definition at line 31 of file ClientThread.hpp.
|
explicit |
Construct a new Client Thread:: Client Thread object.
parent |
Definition at line 23 of file ClientThread.cpp.
ClientThread::~ClientThread | ( | ) |
Destructor for the ClientThread class.
Shuts down and destroys the Ice communicator if it is initialized, ensuring a clean termination of client-server communication.
Definition at line 31 of file ClientThread.cpp.
bool ClientThread::getJoystickValue | ( | ) |
Get the joystick value from the server.
This method gets the joystick value from the server by calling the getJoystickValue method on the carData proxy. It first waits until the client is connected to the server and then checks if the carData proxy is valid. If the proxy is valid, it calls the method and returns the joystick value, otherwise it returns false and prints an error message.
Definition at line 119 of file ClientThread.cpp.
void ClientThread::runClient | ( | int | argc, |
char * | argv[] ) |
Run the client by initializing the Ice communicator and connecting to the server.
argc | The number of command-line arguments. |
argv | The array of command-line arguments. |
This method initializes the Ice communicator using the given argc and argv and connects to the server by specifying the proxy endpoint. The carData proxy is then cast to the correct type (carDataPrx). The connected flag is set to true once the connection is established and the main thread is notified via a condition variable. The client then enters a loop where it waits for requests and processes them. The loop is exited when the running flag is set to false and the communicator is gracefully shutdown.
Definition at line 49 of file ClientThread.cpp.
void ClientThread::setJoystickValue | ( | bool | value | ) |
Set the joystick value on the server.
value | The new value to set the joystick to. |
This method sets the joystick value on the server by calling the setJoystickValue method on the carData proxy. It first waits until the client is connected to the server and then checks if the carData proxy is valid. If the proxy is valid, it calls the method, otherwise it prints an error message.
Definition at line 93 of file ClientThread.cpp.
void ClientThread::setRunning | ( | bool | value | ) |
Sets the running flag of the client thread.
This method sets the running flag of the client thread, which controls whether the client is connected to the server or not. This flag is used to stop the client thread gracefully when requested.
value | The new value for the running flag. |
Definition at line 146 of file ClientThread.cpp.
|
private |
Definition at line 37 of file ClientThread.hpp.
|
private |
Definition at line 38 of file ClientThread.hpp.
|
private |
Definition at line 39 of file ClientThread.hpp.
|
private |
Definition at line 36 of file ClientThread.hpp.
|
private |
Definition at line 41 of file ClientThread.hpp.
|
private |
Definition at line 43 of file ClientThread.hpp.
|
private |
Definition at line 42 of file ClientThread.hpp.
|
private |
Definition at line 40 of file ClientThread.hpp.