return "OP_UNKNOWN";
}
-std::string getPropertyTypeString(SimulatorResourceModel::AttributeProperty::Type type)
-{
- switch(type)
- {
- case SimulatorResourceModel::AttributeProperty::Type::RANGE:
- return "RANGE";
- case SimulatorResourceModel::AttributeProperty::Type::VALUE_SET:
- return "VALUE_SET";
- default:
- break;
- }
-
- return "UNKNOWN";
-}
-
class AppLogger : public ILogger
{
public:
int choice = -1;
std::cout << "Enter your choice: ";
std::cin >> choice;
- if (choice < 0 || choice > 12)
+ if (choice < 0 || choice > 14)
{
std::cout << "Invaild choice !" << std::endl; continue;
}
case 9: sendAllPUTRequests(); break;
case 10: sendAllPOSTRequests(); break;
case 11: configure(); break;
- case 12: printMenu(); break;
+ case 12: getDeviceInfo(); break;
+ case 13: getPlatformInfo(); break;
+ case 14: printMenu(); break;
case 0: cont = false;
}
}
std::cout << "9. Send All PUT requests" << std::endl;
std::cout << "10. Send All POST requests" << std::endl;
std::cout << "11. Configure (using RAML file)" << std::endl;
- std::cout << "12: Help" << std::endl;
+ std::cout << "12. Get Device Information" << std::endl;
+ std::cout << "13. Get Platform Information" << std::endl;
+ std::cout << "14: Help" << std::endl;
std::cout << "0. Exit" << std::endl;
std::cout << "###################################################" << std::endl;
}
std::lock_guard<std::recursive_mutex> lock(m_mutex);
if (0 == m_resList.size())
{
- std::cout << "No resouces!" << std::endl;
+ std::cout << "No resources!" << std::endl;
return nullptr;
}
int index = 1;
std::vector<std::string> ids;
- for (auto & resourceEntry : m_resList)
+ for (auto &resourceEntry : m_resList)
{
std::cout << index++ << ": " << (resourceEntry.second)->getURI() << "[" <<
(resourceEntry.second)->getHost() << "]" << std::endl;
try
{
SimulatorManager::getInstance()->findResource(resourceType, callback);
- std::cout << "SimulatorManager::findResource is successfull" << std::endl;
+ std::cout << "SimulatorManager::findResource is successful" << std::endl;
+ m_resList.clear();
}
catch (InvalidArgsException &e)
{
std::cout << "Host: " << resource->getHost().c_str() << std::endl;
std::cout << "ID: " << resource->getID().c_str() << std::endl;
std::cout << "Resource Types: ";
- for (auto & type : resource->getResourceTypes())
+ for (auto &type : resource->getResourceTypes())
std::cout << type << " ";
std::cout << "\nInterface Types: ";
- for (auto & type : resource->getResourceInterfaces())
+ for (auto &type : resource->getInterface())
std::cout << type << " ";
std::cout << std::boolalpha << "\nisObservable : " << resource->isObservable()
- << std::noboolalpha << std::endl;
+ << std::noboolalpha << std::endl;
std::cout << "#############################" << std::endl;
}
// callback implementaion
SimulatorRemoteResource::ObserveNotificationCallback callback =
- [](std::string uid, SimulatorResult errorCode, SimulatorResourceModelSP rep, int seq)
+ [](const std::string & uid, SimulatorResult result,
+ const SimulatorResourceModel & rep, int seq)
{
- std::cout << "\nObserve notification received ###[errorcode: " << errorCode <<
- " seq: " << seq << "UID: " << uid << "]" << std::endl;
+ std::cout << "\nObserve notification received ###[errorcode: " << result <<
+ " seq: " << seq << "UID: " << uid << "]" << std::endl;
std::cout << "Representation is: " << std::endl;
- std::cout << rep->toString() << std::endl;
+ std::cout << rep.asString() << std::endl;
};
try
{
resource->observe(ObserveType::OBSERVE, callback);
- std::cout << "Observe is successfull!" << std::endl;
+ std::cout << "Observe is successful!" << std::endl;
}
catch (InvalidArgsException &e)
{
std::cout << "InvalidArgsException occured [code : " << e.code() << " Detail: "
- << e.what() << "]" << std::endl;
+ << e.what() << "]" << std::endl;
}
catch (SimulatorException &e)
{
std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " <<
- e.what() << "]" << std::endl;
+ e.what() << "]" << std::endl;
}
}
try
{
resource->cancelObserve();
- std::cout << "Cancelling observe is successfull!" << std::endl;
+ std::cout << "Cancelling observe is successful!" << std::endl;
}
catch (SimulatorException &e)
{
std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " <<
- e.what() << "]" << std::endl;
+ e.what() << "]" << std::endl;
}
}
// callback implementaion
SimulatorRemoteResource::ResponseCallback callback =
- [](std::string uId, SimulatorResult errorCode, SimulatorResourceModelSP rep)
+ [](const std::string & uid, SimulatorResult result, const SimulatorResourceModel & rep)
{
- std::cout << "\nGET Response received ### [errorcode: " << errorCode << "]"
- << std::endl;
- std::cout << "UID is: " << uId << std::endl;
+ std::cout << "\nGET Response received ### [errorcode: " << result << "]"
+ << std::endl;
+ std::cout << "UID is: " << uid << std::endl;
std::cout << "Representation is: " << std::endl;
- std::cout << rep->toString() << std::endl;
+ std::cout << rep.asString() << std::endl;
};
try
{
resource->get(std::map <std::string, std::string>(), callback);
- std::cout << "GET is successfull!" << std::endl;
+ std::cout << "GET is successful!" << std::endl;
}
catch (InvalidArgsException &e)
{
std::cout << "InvalidArgsException occured [code : " << e.code() << " Detail: "
- << e.what() << "]" << std::endl;
+ << e.what() << "]" << std::endl;
}
catch (NoSupportException &e)
{
std::cout << "NoSupportException occured [code : " << e.code() << " Detail: " <<
- e.what() << "]" << std::endl;
+ e.what() << "]" << std::endl;
}
catch (SimulatorException &e)
{
std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " <<
- e.what() << "]" << std::endl;
+ e.what() << "]" << std::endl;
}
}
// callback implementaion
SimulatorRemoteResource::ResponseCallback callback =
- [](std::string uId, SimulatorResult errorCode, SimulatorResourceModelSP rep)
+ [](const std::string & uid, SimulatorResult result, const SimulatorResourceModel & rep)
{
- std::cout << "\nPUT Response received ![errorcode: " << errorCode << "]"
- << std::endl;
- std::cout << "UID is: " << uId << std::endl;
+ std::cout << "\nPUT Response received ![errorcode: " << result << "]"
+ << std::endl;
+ std::cout << "UID is: " << uid << std::endl;
std::cout << "Representation is: " << std::endl;
- std::cout << rep->toString() << std::endl;
+ std::cout << rep.asString() << std::endl;
};
try
{
- SimulatorResourceModelSP rep = std::make_shared<SimulatorResourceModel>();
- std::string value = "off";
- rep->add("power", value);
- rep->add("intensity", 5);
+ SimulatorResourceModel rep;
+ rep.add("power", false);
+ rep.add("intensity", 15);
- resource->put(std::map <std::string, std::string>(), rep, callback);
- std::cout << "PUT is successfull!" << std::endl;
+ resource->put(rep, callback);
+ std::cout << "PUT is successful!" << std::endl;
}
catch (InvalidArgsException &e)
{
std::cout << "InvalidArgsException occured [code : " << e.code() << " Detail: "
- << e.what() << "]" << std::endl;
+ << e.what() << "]" << std::endl;
}
catch (NoSupportException &e)
{
std::cout << "NoSupportException occured [code : " << e.code() << " Detail: " <<
- e.what() << "]" << std::endl;
+ e.what() << "]" << std::endl;
}
catch (SimulatorException &e)
{
std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " <<
- e.what() << "]" << std::endl;
+ e.what() << "]" << std::endl;
}
}
// callback implementaion
SimulatorRemoteResource::ResponseCallback callback =
- [](std::string uId, SimulatorResult errorCode, SimulatorResourceModelSP rep)
+ [](const std::string & uid, SimulatorResult result, const SimulatorResourceModel & rep)
{
- std::cout << "\nPOST Response received ![errorcode: " << errorCode << "]"
- << std::endl;
- std::cout << "UID is: " << uId << std::endl;
+ std::cout << "\nPOST Response received ![errorcode: " << result << "]"
+ << std::endl;
+ std::cout << "UID is: " << uid << std::endl;
std::cout << "Representation is: " << std::endl;
- std::cout << rep->toString() << std::endl;
+ std::cout << rep.asString() << std::endl;
};
try
{
- SimulatorResourceModelSP rep = std::make_shared<SimulatorResourceModel>();
- std::string value = "on";
- rep->add("power", value);
- rep->add("intensity", 7);
+ SimulatorResourceModel rep;
+ rep.add("power", true);
+ rep.add("intensity", 17);
- resource->post(std::map <std::string, std::string>(), rep, callback);
- std::cout << "POST is successfull!" << std::endl;
+ resource->post(rep, callback);
+ std::cout << "POST is successful!" << std::endl;
}
catch (InvalidArgsException &e)
{
std::cout << "InvalidArgsException occured [code : " << e.code() << " Detail: "
- << e.what() << "]" << std::endl;
+ << e.what() << "]" << std::endl;
}
catch (NoSupportException &e)
{
std::cout << "NoSupportException occured [code : " << e.code() << " Detail: " <<
- e.what() << "]" << std::endl;
+ e.what() << "]" << std::endl;
}
catch (SimulatorException &e)
{
std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " <<
- e.what() << "]" << std::endl;
+ e.what() << "]" << std::endl;
}
}
SimulatorRemoteResourceSP resource = selectResource();
if (!resource) return;
- SimulatorRemoteResource::StateCallback callback = [] (std::string uid, int sessionId,
- OperationState state)
+ SimulatorRemoteResource::AutoRequestGenerationCallback callback =
+ [] (const std::string & uid, int sessionId, OperationState state)
{
std::cout << "\nResource verification status received ![id: " << sessionId <<
- " State: " << getOperationStateString(state) << " UID: " << uid << "]" <<
- std::endl;
+ " State: " << getOperationStateString(state) << " UID: " << uid << "]" <<
+ std::endl;
};
try
{
- int id = resource->startVerification(RequestType::RQ_TYPE_GET, callback);
- std::cout << "startVerification for GET is successfull!id: " << id << std::endl;
+ int id = resource->startAutoRequesting(RequestType::RQ_TYPE_GET, callback);
+ std::cout << "startVerification for GET is successful!id: " << id << std::endl;
}
catch (InvalidArgsException &e)
{
std::cout << "InvalidArgsException occured [code : " << e.code() << " Detail: "
- << e.what() << "]" << std::endl;
+ << e.what() << "]" << std::endl;
}
catch (NoSupportException &e)
{
std::cout << "NoSupportException occured [code : " << e.code() << " Detail: " <<
- e.what() << "]" << std::endl;
+ e.what() << "]" << std::endl;
}
catch (SimulatorException &e)
{
std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " <<
- e.what() << "]" << std::endl;
+ e.what() << "]" << std::endl;
}
}
SimulatorRemoteResourceSP resource = selectResource();
if (!resource) return;
- SimulatorRemoteResource::StateCallback callback = [] (std::string uid, int sessionId,
- OperationState state)
+ SimulatorRemoteResource::AutoRequestGenerationCallback callback =
+ [] (const std::string & uid, int sessionId, OperationState state)
{
std::cout << "\nResource verification status received ![id: " << sessionId <<
- " State: " << getOperationStateString(state) << " UID: " << uid << "]" <<
- std::endl;
+ " State: " << getOperationStateString(state) << " UID: " << uid << "]" <<
+ std::endl;
};
try
{
- int id = resource->startVerification(RequestType::RQ_TYPE_PUT, callback);
- std::cout << "startVerification for PUT is successfull!id: " << id << std::endl;
+ int id = resource->startAutoRequesting(RequestType::RQ_TYPE_PUT, callback);
+ std::cout << "startVerification for PUT is successful!id: " << id << std::endl;
}
catch (InvalidArgsException &e)
{
std::cout << "InvalidArgsException occured [code : " << e.code() << " Detail: "
- << e.what() << "]" << std::endl;
+ << e.what() << "]" << std::endl;
}
catch (NoSupportException &e)
{
std::cout << "NoSupportException occured [code : " << e.code() << " Detail: " <<
- e.what() << "]" << std::endl;
+ e.what() << "]" << std::endl;
}
catch (SimulatorException &e)
{
std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " <<
- e.what() << "]" << std::endl;
+ e.what() << "]" << std::endl;
}
}
SimulatorRemoteResourceSP resource = selectResource();
if (!resource) return;
- SimulatorRemoteResource::StateCallback callback = [] (std::string uid, int sessionId,
- OperationState state)
+ SimulatorRemoteResource::AutoRequestGenerationCallback callback =
+ [] (const std::string & uid, int sessionId, OperationState state)
{
std::cout << "\nResource verification status received ![id: " << sessionId <<
- " State: " << getOperationStateString(state) << " UID: " << uid << "]"
- << std::endl;
+ " State: " << getOperationStateString(state) << " UID: " << uid << "]"
+ << std::endl;
};
try
{
- int id = resource->startVerification(RequestType::RQ_TYPE_POST, callback);
- std::cout << "startVerification for POST is successfull!id: " << id << std::endl;
+ int id = resource->startAutoRequesting(RequestType::RQ_TYPE_POST, callback);
+ std::cout << "startVerification for POST is successful!id: " << id << std::endl;
}
catch (InvalidArgsException &e)
{
std::cout << "InvalidArgsException occured [code : " << e.code() << " Detail: "
- << e.what() << "]" << std::endl;
+ << e.what() << "]" << std::endl;
}
catch (NoSupportException &e)
{
std::cout << "NoSupportException occured [code : " << e.code() << " Detail: " <<
- e.what() << "]" << std::endl;
+ e.what() << "]" << std::endl;
}
catch (SimulatorException &e)
{
std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " <<
- e.what() << "]" << std::endl;
+ e.what() << "]" << std::endl;
}
}
std::cout << "Enter the config path: ";
std::cin >> configPath;
- SimulatorResourceModelSP representation = resource->configure(configPath);
- if (representation)
- {
- std::cout << "configuration is successfull!" << std::endl;
- std::map<std::string, SimulatorResourceModel::Attribute> attributes =
- representation->getAttributes();
- std::cout << "##### Attributes [" << attributes.size() << "]" << std::endl;
- for (auto & attribute : attributes)
- {
- std::cout << (attribute.second).getName() << " : {" << std::endl;
- std::cout << "value: " << (attribute.second).toString() << std::endl;
- SimulatorResourceModel::AttributeProperty prop = (attribute.second).getProperty();
- std::cout << "Supported values given by : " << getPropertyTypeString(prop.type()) << std::endl;
- if (SimulatorResourceModel::AttributeProperty::Type::RANGE == prop.type())
- {
- std::cout << "Min: " << prop.min() << std::endl;
- std::cout << "Max: " << prop.max() << std::endl;
- }
- else if (SimulatorResourceModel::AttributeProperty::Type::VALUE_SET == prop.type())
- {
- std::cout << "Value set: " << prop.valueSetToString() << std::endl;
- }
-
- std::cout << "}" << std::endl << std::endl;
- }
- std::cout << "#############################" << std::endl;
- }
+ resource->configure(configPath);
}
catch (InvalidArgsException &e)
{
std::cout << "InvalidArgsException occured [code : " << e.code() << " Detail: "
- << e.what() << "]" << std::endl;
+ << e.what() << "]" << std::endl;
}
catch (SimulatorException &e)
{
std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " <<
- e.what() << "]" << std::endl;
+ e.what() << "]" << std::endl;
+ }
+ }
+
+ void getDeviceInfo()
+ {
+ SimulatorRemoteResourceSP resource = selectResource();
+ if (!resource)
+ return;
+
+ try
+ {
+ SimulatorManager::getInstance()->getDeviceInfo(resource->getHost(),
+ std::bind([](const std::string & host, DeviceInfo & deviceInfo)
+ {
+ std::cout << "###Device Information received...." << std::endl;
+ std::ostringstream out;
+ out << "Host URI: " << host << std::endl;
+ out << "Device name: " << deviceInfo.getName() << std::endl;
+ out << "Device ID: " << deviceInfo.getID() << std::endl;
+ out << "Device Spec version: " << deviceInfo.getSpecVersion() << std::endl;
+ out << "Device dat model version: " << deviceInfo.getDataModelVersion() << std::endl;
+
+ std::cout << out.str() << std::endl;
+ }, std::placeholders::_1, std::placeholders::_2));
+ }
+ catch (InvalidArgsException &e)
+ {
+ std::cout << "InvalidArgsException occured [code : " << e.code() << " Detail: " << e.what() << "]"
+ << std::endl;
+ }
+ catch (SimulatorException &e)
+ {
+ std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " << e.what() << "]" <<
+ std::endl;
+ }
+ }
+
+ void getPlatformInfo()
+ {
+ SimulatorRemoteResourceSP resource = selectResource();
+ if (!resource)
+ return;
+
+ try
+ {
+ SimulatorManager::getInstance()->getPlatformInfo(resource->getHost(),
+ std::bind([](const std::string & host, PlatformInfo & platformInfo)
+ {
+ std::cout << "###Platform Information received...." << std::endl;
+ std::ostringstream out;
+ out << "Host URI: " << host << std::endl;
+ out << "Platform ID: " << platformInfo.getPlatformID() << std::endl;
+ out << "Platform version: " << platformInfo.getPlatformVersion() << std::endl;
+ out << "Manufacturer name: " << platformInfo.getManufacturerName() << std::endl;
+ out << "Manufacturer url: " << platformInfo.getManufacturerUrl() << std::endl;
+ out << "Modle number: " << platformInfo.getModelNumber() << std::endl;
+ out << "Date of manufacture: " << platformInfo.getDateOfManfacture() << std::endl;
+ out << "Operatio system version: " << platformInfo.getOSVersion() << std::endl;
+ out << "Hardware version: " << platformInfo.getHardwareVersion() << std::endl;
+ out << "Firmware version: " << platformInfo.getFirmwareVersion() << std::endl;
+ out << "Support url: " << platformInfo.getSupportUrl() << std::endl;
+ out << "System time: " << platformInfo.getSystemTime() << std::endl;
+
+ std::cout << out.str() << std::endl;
+ }, std::placeholders::_1, std::placeholders::_2));
+ }
+ catch (InvalidArgsException &e)
+ {
+ std::cout << "InvalidArgsException occured [code : " << e.code()
+ << " Detail: " << e.what() << "]" << std::endl;
+ }
+ catch (SimulatorException &e)
+ {
+ std::cout << "SimulatorException occured [code : " << e.code()
+ << " Detail: " << e.what() << "]" << std::endl;
}
}
{
std::cout << "############### MAIN MENU###############" << std::endl;
std::cout << "1. Client Controller Test" << std::endl;
- std::cout << "2. Get device information" << std::endl;
- std::cout << "3. Get platform information" << std::endl;
- std::cout << "4. Set Logger" << std::endl;
- std::cout << "5. Help" << std::endl;
+ std::cout << "2. Set Logger" << std::endl;
+ std::cout << "3. Help" << std::endl;
std::cout << "0. Exit" << std::endl;
std::cout << "######################################" << std::endl;
}
std::cout << "Welcome back to main menu !" << std::endl;
break;
- case 2:
- {
- try
- {
- SimulatorManager::getInstance()->getDeviceInfo(std::bind([](DeviceInfo & deviceInfo)
- {
- std::cout << "###Device Information received...." << std::endl;
- std::ostringstream out;
- out << "Device name: " << deviceInfo.getName() << std::endl;
- out << "Device ID: " << deviceInfo.getID() << std::endl;
- out << "Device Spec version: " << deviceInfo.getSpecVersion() << std::endl;
- out << "Device dat model version: " << deviceInfo.getDataModelVersion() << std::endl;
-
- std::cout << out.str() << std::endl;
- }, std::placeholders::_1));
- }
- catch (InvalidArgsException &e)
- {
- std::cout << "InvalidArgsException occured [code : " << e.code() << " Detail: " << e.what() << "]"
- << std::endl;
- }
- catch (SimulatorException &e)
- {
- std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " << e.what() << "]" <<
- std::endl;
- }
- }
- break;
-
- case 3:
- {
- try
- {
- SimulatorManager::getInstance()->getPlatformInfo(std::bind([](PlatformInfo & platformInfo)
- {
- std::cout << "###Platform Information received...." << std::endl;
- std::ostringstream out;
- out << "Platform ID: " << platformInfo.getPlatformID() << std::endl;
- out << "Platform version: " << platformInfo.getPlatformVersion() << std::endl;
- out << "Manufacturer name: " << platformInfo.getManufacturerName() << std::endl;
- out << "Manufacturer url: " << platformInfo.getManufacturerUrl() << std::endl;
- out << "Modle number: " << platformInfo.getModelNumber() << std::endl;
- out << "Date of manufacture: " << platformInfo.getDateOfManfacture() << std::endl;
- out << "Operatio system version: " << platformInfo.getOSVersion() << std::endl;
- out << "Hardware version: " << platformInfo.getHardwareVersion() << std::endl;
- out << "Firmware version: " << platformInfo.getFirmwareVersion() << std::endl;
- out << "Support url: " << platformInfo.getSupportUrl() << std::endl;
- out << "System time: " << platformInfo.getSystemTime() << std::endl;
-
- std::cout << out.str() << std::endl;
- }, std::placeholders::_1));
- }
- catch (InvalidArgsException &e)
- {
- std::cout << "InvalidArgsException occured [code : " << e.code()
- << " Detail: " << e.what() << "]" << std::endl;
- }
- catch (SimulatorException &e)
- {
- std::cout << "SimulatorException occured [code : " << e.code()
- << " Detail: " << e.what() << "]" << std::endl;
- }
- }
- break;
-
- case 4: setLogger(); break;
+ case 2: setLogger(); break;
- case 5: printMainMenu(); break;
+ case 3: printMainMenu(); break;
case 0: cont = false;
}