Hotwheels-Cluster 1.2
Creation of Cluster APP for SEA:ME project.
 
Loading...
Searching...
No Matches
ClientThread Class Reference

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
 

Detailed Description

Class for the client thread.

Definition at line 31 of file ClientThread.hpp.

Constructor & Destructor Documentation

◆ ClientThread()

ClientThread::ClientThread ( QObject * parent = nullptr)
explicit

Construct a new Client Thread:: Client Thread object.

Parameters
parent

Definition at line 23 of file ClientThread.cpp.

◆ ~ClientThread()

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.

Member Function Documentation

◆ getJoystickValue()

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.

Returns
The current value of the joystick.

Definition at line 119 of file ClientThread.cpp.

◆ runClient()

void ClientThread::runClient ( int argc,
char * argv[] )

Run the client by initializing the Ice communicator and connecting to the server.

Parameters
argcThe number of command-line arguments.
argvThe 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.

◆ setJoystickValue()

void ClientThread::setJoystickValue ( bool value)

Set the joystick value on the server.

Parameters
valueThe 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.

◆ setRunning()

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.

Parameters
valueThe new value for the running flag.

Definition at line 146 of file ClientThread.cpp.

Field Documentation

◆ base

Ice::ObjectPrx ClientThread::base
private

Definition at line 37 of file ClientThread.hpp.

◆ carData

Data::CarDataPrx ClientThread::carData
private

Definition at line 38 of file ClientThread.hpp.

◆ clientThread

std::thread ClientThread::clientThread
private

Definition at line 39 of file ClientThread.hpp.

◆ communicator

Ice::CommunicatorPtr ClientThread::communicator
private

Definition at line 36 of file ClientThread.hpp.

◆ connected

bool ClientThread::connected = false
private

Definition at line 41 of file ClientThread.hpp.

◆ cv

std::condition_variable ClientThread::cv
private

Definition at line 43 of file ClientThread.hpp.

◆ mtx

std::mutex ClientThread::mtx
private

Definition at line 42 of file ClientThread.hpp.

◆ running

bool ClientThread::running = true
private

Definition at line 40 of file ClientThread.hpp.


The documentation for this class was generated from the following files: