X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=service%2Fsimulator%2Fexamples%2Fserver%2Fservice_provider.cpp;h=3cb3c138c428951b30a3d08403b9f75bc2a23d6f;hb=3e9402ad71cb3e93266a77796f44d17bab9853fd;hp=28512a8e72c4fcd4bceb3710d162d6ec72d3ec70;hpb=17c68b2fd1e74586f85e552eeab4e32dc121f8a0;p=platform%2Fupstream%2Fiotivity.git diff --git a/service/simulator/examples/server/service_provider.cpp b/service/simulator/examples/server/service_provider.cpp index 28512a8..3cb3c13 100644 --- a/service/simulator/examples/server/service_provider.cpp +++ b/service/simulator/examples/server/service_provider.cpp @@ -26,7 +26,7 @@ class AppLogger : public ILogger void write(std::string time, ILogger::Level level, std::string message) { std::cout << "[APPLogger] " << time << " " << ILogger::getString(level) << " " - << message; + << message; } }; std::shared_ptr gAppLogger(new AppLogger()); @@ -34,7 +34,7 @@ std::shared_ptr gAppLogger(new AppLogger()); class SimLightResource { public: - void startTest(std::string &configPath) + void startTest() { printMenu(); bool cont = true; @@ -50,19 +50,9 @@ class SimLightResource 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; @@ -124,17 +114,17 @@ class SimLightResource 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, @@ -142,21 +132,24 @@ class SimLightResource 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; } } @@ -204,7 +197,7 @@ class SimLightResource { SimulatorManager::getInstance()->deleteResource(resourceType); std::cout << "Resources of type \"" << resourceType << "\"" << - " deleted successfully! " << std::endl; + " deleted successfully! " << std::endl; std::vector::iterator ite = m_resources.begin(); while (ite != m_resources.end()) { @@ -219,12 +212,12 @@ class SimLightResource 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; @@ -257,7 +250,7 @@ class SimLightResource } 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++) { @@ -303,7 +296,7 @@ class SimLightResource } 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++) { @@ -350,7 +343,7 @@ class SimLightResource // Attributes SimulatorResourceModel resModel = resource->getModel(); std::map attributes = - resModel.getAttributes(); + resModel.getAttributes(); std::cout << "##### Attributes [" << attributes.size() << "]" << std::endl; for (auto & attribute : attributes) { @@ -374,7 +367,7 @@ class SimLightResource const int id) { std::cout << "Update automation is completed [URI: " << uri.c_str() - << " AutomationID: " << id << "] ###" << std::endl; + << " AutomationID: " << id << "] ###" << std::endl; } void automateResourceUpdate() @@ -392,16 +385,16 @@ class SimLightResource 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; } } @@ -414,7 +407,7 @@ class SimLightResource SimulatorResourceServerSP resource = m_resources[index - 1]; SimulatorResourceModel resModel = resource->getModel(); std::map attributes = - resModel.getAttributes(); + resModel.getAttributes(); int size = 0; for (auto & attribute : attributes) { @@ -429,7 +422,7 @@ class SimLightResource 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) { @@ -457,20 +450,20 @@ class SimLightResource 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; } } @@ -494,7 +487,7 @@ class SimLightResource if (!ids.size()) { std::cout << "No automation operation is going on this resource right now!" << - std::endl; + std::endl; return; } @@ -514,7 +507,7 @@ class SimLightResource 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(); } @@ -537,7 +530,7 @@ class SimLightResource 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; } @@ -553,12 +546,6 @@ void printMainMenu() 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; } @@ -597,17 +584,6 @@ void setLogger() int main(int argc, char *argv[]) { - std::string configPath = ""; - - if (argc == 2) - { - char *value = argv[1]; - configPath.append(value); - } - else - { - configPath = ""; - } SimLightResource lightResource; printMainMenu(); @@ -624,7 +600,7 @@ int main(int argc, char *argv[]) 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;