void write(std::string time, ILogger::Level level, std::string message)
{
std::cout << "[APPLogger] " << time << " " << ILogger::getString(level) << " "
- << message;
+ << message;
}
};
std::shared_ptr<AppLogger> gAppLogger(new AppLogger());
class SimLightResource
{
public:
- void startTest(std::string &configPath)
+ void startTest()
{
printMenu();
bool cont = true;
switch (choice)
{
- case 1 : simulateResource(configPath); break;
+ case 1 : simulateResource(); break;
case 2 : displayResource(); break;
- case 3 :
- try
- {
- deleteResource();
- }
- catch (InvalidArgsException &e)
- {
- std::cout << "InvalidArgsException occured [code : " << e.code() <<
- " Detail: " << e.what() << "]" << std::endl;
- }
- break;
+ case 3 : deleteResource(); break;
case 4 : updateAttributePower(); break;
case 5 : updateAttributeIntensity(); break;
case 6 : automateResourceUpdate(); break;
const SimulatorResourceModel &resModel)
{
std::cout << "[callback] Resource model is changed URI: " << uri.c_str()
- << " Count : " << resModel.size() << std::endl;
+ << " Count : " << resModel.size() << std::endl;
std::cout << "#### Modified attributes are ####" << std::endl;
for (auto & attribute : resModel.getAttributes())
{
std::cout << attribute.second.getName() << " : "
- << attribute.second.valueToString().c_str() << std::endl;
+ << attribute.second.valueToString().c_str() << std::endl;
}
std::cout << "########################" << std::endl;
}
- void simulateResource(std::string &configPath)
+ void simulateResource()
{
SimulatorResourceServer::ResourceModelChangedCB callback = std::bind(
&SimLightResource::onResourceModelChanged, this, std::placeholders::_1,
try
{
+ std::string configPath;
+ std::cout << "Enter RAML path: ";
+ std::cin>>configPath;
SimulatorResourceServerSP resource =
- SimulatorManager::getInstance()->createResource(configPath, callback);
+ SimulatorManager::getInstance()->createResource(configPath, callback);
m_resources.push_back(resource);
std::cout << "Resource created successfully! URI= " << resource->getURI().c_str()
- << std::endl;
+ << 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;
}
}
{
SimulatorManager::getInstance()->deleteResource(resourceType);
std::cout << "Resources of type \"" << resourceType << "\"" <<
- " deleted successfully! " << std::endl;
+ " deleted successfully! " << std::endl;
std::vector<SimulatorResourceServerSP>::iterator ite = m_resources.begin();
while (ite != m_resources.end())
{
catch (InvalidArgsException &e)
{
std::cout << "InvalidArgsException occured [code : " << e.code()
- << " Detail: " << e.what() << "]" << std::endl;
+ << " Detail: " << e.what() << "]" << std::endl;
}
catch (SimulatorException &e)
{
std::cout << "SimulatorException occured [code : " << e.code()
- << " Detail: " << e.what() << "]" << std::endl;
+ << " Detail: " << e.what() << "]" << std::endl;
}
} break;
}
std::cout << "Setting the new values from allowed values list to power attribute" <<
- std::endl;
+ std::endl;
// Update all possible values from allowed values
for (int index = 0; index < allowedValuesSize; index++)
{
}
std::cout << "Setting the new values from allowed values list to intensity attribute"
- << std::endl;
+ << std::endl;
// Update all possible values from allowed values
for (int index = min; index <= max; index++)
{
// Attributes
SimulatorResourceModel resModel = resource->getModel();
std::map<std::string, SimulatorResourceModel::Attribute> attributes =
- resModel.getAttributes();
+ resModel.getAttributes();
std::cout << "##### Attributes [" << attributes.size() << "]" << std::endl;
for (auto & attribute : attributes)
{
const int id)
{
std::cout << "Update automation is completed [URI: " << uri.c_str()
- << " AutomationID: " << id << "] ###" << std::endl;
+ << " AutomationID: " << id << "] ###" << std::endl;
}
void automateResourceUpdate()
try
{
- int id = m_resources[index - 1]->startUpdateAutomation(type,
+ int id = m_resources[index - 1]->startUpdateAutomation(type, 500,
std::bind(&SimLightResource::onUpdateAutomationCompleted, this,
- std::placeholders::_1, std::placeholders::_2));
+ std::placeholders::_1, std::placeholders::_2));
std::cout << "startUpdateAutomation() returned succces : " << id << std::endl;
}
catch (SimulatorException &e)
{
std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " <<
- e.what() << "]" << std::endl;
+ e.what() << "]" << std::endl;
}
}
SimulatorResourceServerSP resource = m_resources[index - 1];
SimulatorResourceModel resModel = resource->getModel();
std::map<std::string, SimulatorResourceModel::Attribute> attributes =
- resModel.getAttributes();
+ resModel.getAttributes();
int size = 0;
for (auto & attribute : attributes)
{
int choice = -1;
std::cout << "Select the attribute which you want to automate for updation: " <<
- std::endl;
+ std::endl;
std::cin >> choice;
if (choice < 0 || choice > size)
{
type = AutomationType::RECURRENT;
std::cout << "Requesting attribute automation for " << attributeName.c_str() <<
- std::endl;
+ std::endl;
try
{
- int id = resource->startUpdateAutomation(attributeName, type,
+ int id = resource->startUpdateAutomation(attributeName, type, 500,
std::bind(&SimLightResource::onUpdateAutomationCompleted, this,
- std::placeholders::_1, std::placeholders::_2));
+ std::placeholders::_1, std::placeholders::_2));
std::cout << "startUpdateAutomation() returned succces : " << id << std::endl;
}
catch (SimulatorException &e)
{
std::cout << "SimulatorException occured [Error: " << e.code() << " Details: " <<
- e.what() << "]" << std::endl;
+ e.what() << "]" << std::endl;
}
}
if (!ids.size())
{
std::cout << "No automation operation is going on this resource right now!" <<
- std::endl;
+ std::endl;
return;
}
std::ostringstream out;
out << "ID: " << (int) observerInfo.id << std::endl;
out << " [address: " << observerInfo.address << " port: " << observerInfo.port
- << "]" << std::endl;
+ << "]" << std::endl;
std::cout << out.str();
}
for (auto & observerInfo : observersList)
{
std::cout << " ID : " << (int) observerInfo.id << " [address: " <<
- observerInfo.address << " port: " << observerInfo.port << "]" << std::endl;
+ observerInfo.address << " port: " << observerInfo.port << "]" << std::endl;
}
std::cout << "########################" << std::endl;
}
std::cout << "2. Set Logger" << std::endl;
std::cout << "3. Help" << std::endl;
std::cout << "0. Exit" << std::endl;
- std::cout <<
- "To set the Resource from RAML file, run the service provider with argument of Path of Raml File."
- << std::endl;
- std::cout <<
- "Example: ./simulator-server PATH-TO-RAML-FILE"
- << std::endl;
std::cout << "######################################" << std::endl;
}
int main(int argc, char *argv[])
{
- std::string configPath = "";
-
- if (argc == 2)
- {
- char *value = argv[1];
- configPath.append(value);
- }
- else
- {
- configPath = "";
- }
SimLightResource lightResource;
printMainMenu();
switch (choice)
{
- case 1: lightResource.startTest(configPath);
+ case 1: lightResource.startTest();
std::cout << "Welcome back to main menu !" << std::endl;
break;
case 2: setLogger(); break;