- bool end = false;
- cout << endl;
- cout << "========================================================" << endl;
- cout << "1. Increase Temperature by 10 degree" << endl;
- cout << "2. Decrease Temperature by 10 degree" << endl;
- cout << "3. Stop the Sensor" << endl;
- cout << "========================================================" << endl;
-
- //user Input for increasing/decreasing the temperature
- cin >> temperatureInput;
- if (std::cin.fail())
- {
- std::cin.clear();
- std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
- std::cout << "Invalid input type, please try again" << std::endl;
- continue;
- }
-
- switch (temperatureInput)
- {
- case 1:
- {
- RCSResourceObject::LockGuard lock(*server);
- ResourceAttributes attrs = server->getAttributes();
-
- attrs[attributeKey] = (server->getAttribute<int>(attributeKey) + 10);
- server->setAttribute(attributeKey, attrs[attributeKey]);
- cout << "\nTemperature increased by 10 degree" << endl;
-
- //getting the current attribute and priniting it on the console
- attrs = server->getAttributes();
- cout << "\nCurrent Temperature : ";
- ResourceAttributes::const_iterator iter = attrs.begin();
- for (unsigned int i = 0; i < attrs.size(); ++i)
- {
- std::cout << iter->value().toString() << std::endl;
- ++iter;
- }
- break;
- }
- case 2:
- {
- RCSResourceObject::LockGuard lock(*server);
- ResourceAttributes attrs = server->getAttributes();
- attrs[attributeKey] = (server->getAttribute<int>(attributeKey) - 10);
- server->setAttribute(attributeKey, attrs[attributeKey]);
- cout << "\nTemperature decreased by 10 degree" << endl;
-
- //getting the current attribute and priniting it on the console
- attrs = server->getAttributes();
- cout << "\nCurrent Temperature : ";
- ResourceAttributes::const_iterator iter = attrs.begin();
- for (unsigned int i = 0; i < attrs.size(); ++i)
- {
- std::cout << iter->value().toString() << std::endl;
- ++iter;
- }
- break;
- }
- case 3:
- {
- cout << "Stopping the Resource" << endl;
- end = true;
- break;
- }
- default:
- {
- cout << "Invalid input. Please try again." << endl;
- break;
- }
- }
- if (end == true)
- {
- break;
- }