Hotwheels-Cluster 1.2
Creation of Cluster APP for SEA:ME project.
 
Loading...
Searching...
No Matches
CarDataI.cpp
Go to the documentation of this file.
1
15
16#include "CarDataI.hpp"
17
22namespace Data
23{
24
29 CarDataI::CarDataI(QObject *parent) : QObject(parent) {}
30
37 {
38 if (communicator)
39 {
40 communicator->shutdown();
41 communicator->destroy();
42 }
43 }
44
51 void CarDataI::setJoystickValue(bool newValue, const Ice::Current &)
52 {
53 std::lock_guard<std::mutex> lock(joystick_mutex);
54 joystick_enable = newValue;
55 std::cout << "Joystick value set to: " << joystick_enable << std::endl;
56 }
57
63 bool CarDataI::getJoystickValue(const Ice::Current &)
64 {
65 std::lock_guard<std::mutex> lock(joystick_mutex);
66 return joystick_enable;
67 }
68
78 void CarDataI::setCarTemperatureValue(double newValue, const Ice::Current &)
79 {
80 std::lock_guard<std::mutex> lock(temperature_mutex);
81 car_temperature = newValue;
82 std::cout << "Car temperature value set to: " << car_temperature << std::endl;
83 }
84
92 double CarDataI::getCarTemperatureValue(const Ice::Current &)
93 {
94 std::lock_guard<std::mutex> lock(temperature_mutex);
95 return car_temperature;
96 }
97
109 void CarDataI::runServer(int argc, char **argv)
110 {
111 // Set Ice properties for thread pool size
112 Ice::PropertiesPtr properties = Ice::createProperties();
113 properties->setProperty("Ice.ThreadPool.Server.Size", "10"); // Set min thread pool size to 10
114 properties->setProperty("Ice.ThreadPool.Server.SizeMax", "20"); // Can expand to 20 threads
115
116 // Initialize Ice with the custom properties using InitializationData
117 Ice::InitializationData initData;
118 initData.properties = properties;
119
120 communicator = Ice::initialize(argc, argv, initData);
121 Ice::ObjectAdapterPtr adapter = communicator->createObjectAdapterWithEndpoints(
122 "CarDataAdapter", "tcp -h 127.0.0.1 -p 10000");
123
124 adapter->add(this, Ice::stringToIdentity("carData"));
125 adapter->activate();
126
127 std::cout << "Server is running, press Ctrl+C to stop." << std::endl;
128 communicator->waitForShutdown();
129 }
130
131} // namespace Data
File containing the CarDataI class.
std::mutex joystick_mutex
Definition CarDataI.hpp:44
void setCarTemperatureValue(double newValue, const Ice::Current &) override
Set the car temperature value.
Definition CarDataI.cpp:78
bool joystick_enable
Definition CarDataI.hpp:41
std::mutex temperature_mutex
Definition CarDataI.hpp:45
Ice::CommunicatorPtr communicator
Definition CarDataI.hpp:47
void setJoystickValue(bool newValue, const Ice::Current &) override
Set the joystick value.
Definition CarDataI.cpp:51
~CarDataI()
Destructor for the CarDataI class.
Definition CarDataI.cpp:36
void runServer(int argc, char **argv)
Runs the Ice server.
Definition CarDataI.cpp:109
double car_temperature
Definition CarDataI.hpp:42
CarDataI(QObject *parent=nullptr)
Constructor for the CarDataI class.
Definition CarDataI.cpp:29
double getCarTemperatureValue()
bool getJoystickValue()
Namespace for the car data.