[IOT-2190][Simulator] Replaced all strings with macro values from octypes.h
authorSenthil Kumar G S <senthil.gs@samsung.com>
Wed, 3 May 2017 14:28:10 +0000 (19:58 +0530)
committerUze Choi <uzchoi@samsung.com>
Fri, 5 May 2017 14:11:50 +0000 (14:11 +0000)
Hard-coded device and platform property keys, 'if's, 'rt's, etc are replaced by the
macro constants defined in octypes.h

Change-Id: I1139401793300dada81c2f30cc4a343831d5171f
Signed-off-by: Senthil Kumar G S <senthil.gs@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/19589
Reviewed-by: George Nash <george.nash@intel.com>
Reviewed-by: Harish Marappa <h.marappa@samsung.com>
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Rick Bell <richard.s.bell@intel.com>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/simulator/examples/server/simulator_server.cpp
service/simulator/src/client/simulator_remote_resource_impl.cpp
service/simulator/src/server/simulator_collection_resource_impl.cpp
service/simulator/src/server/simulator_resource_factory.cpp
service/simulator/src/server/simulator_single_resource_impl.cpp
service/simulator/src/simulator_manager.cpp

index 576cc33..fe9ebdd 100644 (file)
@@ -449,8 +449,8 @@ void addInterface()
         return;
 
     SimulatorSingleResourceSP resource = g_singleResources[index - 1];
-    resource->addInterface("oic.if.s");
-    resource->addInterface("oic.if.a");
+    resource->addInterface(OC_RSRVD_INTERFACE_SENSOR);
+    resource->addInterface(OC_RSRVD_INTERFACE_ACTUATOR);
 }
 
 int main(int argc, char *argv[])
index c418b7d..5523695 100644 (file)
@@ -226,9 +226,9 @@ void SimulatorRemoteResourceImpl::get(const std::string &interfaceType,
     VALIDATE_CALLBACK(callback)
 
     std::map<std::string, std::string> queryParamsCpy = queryParams;
-    if (!interfaceType.empty() && queryParamsCpy.end() == queryParamsCpy.find("if"))
+    if (!interfaceType.empty() && queryParamsCpy.end() == queryParamsCpy.find(OC_RSRVD_INTERFACE))
     {
-        queryParamsCpy["if"] = interfaceType;
+        queryParamsCpy[OC_RSRVD_INTERFACE] = interfaceType;
     }
 
     SimulatorResult result = m_getRequestSender.send(queryParamsCpy, std::bind(
@@ -289,9 +289,9 @@ void SimulatorRemoteResourceImpl::put(const std::string &interfaceType,
     VALIDATE_CALLBACK(callback)
 
     std::map<std::string, std::string> queryParamsCpy = queryParams;
-    if (!interfaceType.empty() && queryParamsCpy.end() == queryParamsCpy.find("if"))
+    if (!interfaceType.empty() && queryParamsCpy.end() == queryParamsCpy.find(OC_RSRVD_INTERFACE))
     {
-        queryParamsCpy["if"] = interfaceType;
+        queryParamsCpy[OC_RSRVD_INTERFACE] = interfaceType;
     }
 
     SimulatorResult result = m_putRequestSender.send(queryParamsCpy, representation, std::bind(
@@ -352,9 +352,9 @@ void SimulatorRemoteResourceImpl::post(const std::string &interfaceType,
     VALIDATE_CALLBACK(callback)
 
     std::map<std::string, std::string> queryParamsCpy = queryParams;
-    if (!interfaceType.empty() && queryParamsCpy.end() == queryParamsCpy.find("if"))
+    if (!interfaceType.empty() && queryParamsCpy.end() == queryParamsCpy.find(OC_RSRVD_INTERFACE))
     {
-        queryParamsCpy["if"] = interfaceType;
+        queryParamsCpy[OC_RSRVD_INTERFACE] = interfaceType;
     }
 
     SimulatorResult result = m_postRequestSender.send(queryParamsCpy, representation, std::bind(
index 56c88d9..41c7309 100755 (executable)
@@ -34,7 +34,7 @@ SimulatorCollectionResourceImpl::SimulatorCollectionResourceImpl()
 
     // Add empty vector of OIC Links
     std::vector<SimulatorResourceModel> links;
-    m_resModel.add("links", links);
+    m_resModel.add(OC_RSRVD_LINKS, links);
 
     m_resourceHandle = nullptr;
 }
@@ -411,9 +411,9 @@ OCEntityHandlerResult SimulatorCollectionResourceImpl::handleRequests(
         // Handling interface query parameter "if"
         auto interfaceType = m_interfaces[0];
         auto requestQueryParams = request->getQueryParameters();
-        if (requestQueryParams.end() != requestQueryParams.find("if"))
+        if (requestQueryParams.end() != requestQueryParams.find(OC_RSRVD_INTERFACE))
         {
-            interfaceType = requestQueryParams["if"];
+            interfaceType = requestQueryParams[OC_RSRVD_INTERFACE];
         }
 
         if (!isValidInterface(interfaceType, request->getRequestType()))
@@ -530,13 +530,13 @@ std::shared_ptr<OC::OCResourceResponse> SimulatorCollectionResourceImpl::request
         for (auto &entry : m_childResources)
         {
             OC::OCRepresentation oicLink;
-            oicLink.setValue("href", entry.second->getURI());
-            oicLink.setValue("rt", entry.second->getResourceType());
-            oicLink.setValue("if", entry.second->getInterface()[0]);
+            oicLink.setValue(OC_RSRVD_HREF, entry.second->getURI());
+            oicLink.setValue(OC_RSRVD_RESOURCE_TYPE, entry.second->getResourceType());
+            oicLink.setValue(OC_RSRVD_INTERFACE, entry.second->getInterface()[0]);
             links.push_back(oicLink);
         }
 
-        ocRep.setValue("links", links);
+        ocRep.setValue(OC_RSRVD_LINKS, links);
 
         response = std::make_shared<OC::OCResourceResponse>();
         response->setRequestHandle(request->getRequestHandle());
@@ -576,22 +576,22 @@ void SimulatorCollectionResourceImpl::sendNotification(OC::ObservationIds &obser
 void SimulatorCollectionResourceImpl::addLink(const SimulatorResourceSP &resource)
 {
     std::lock_guard<std::mutex> lock(m_modelLock);
-    if (!m_resModel.contains("links"))
+    if (!m_resModel.contains(OC_RSRVD_LINKS))
         return;
 
     // Create new OIC Link
     SimulatorResourceModel newLink;
-    newLink.add("href", resource->getURI());
-    newLink.add("rt", resource->getResourceType());
-    newLink.add("if", resource->getInterface()[0]);
+    newLink.add(OC_RSRVD_HREF, resource->getURI());
+    newLink.add(OC_RSRVD_RESOURCE_TYPE, resource->getResourceType());
+    newLink.add(OC_RSRVD_INTERFACE, resource->getInterface()[0]);
 
     // Add OIC Link if it is not present
     bool found = false;
     std::vector<SimulatorResourceModel> links =
-        m_resModel.get<std::vector<SimulatorResourceModel>>("links");
+        m_resModel.get<std::vector<SimulatorResourceModel>>(OC_RSRVD_LINKS);
     for (auto &link : links)
     {
-        std::string linkURI = link.get<std::string>("href");
+        std::string linkURI = link.get<std::string>(OC_RSRVD_HREF);
         if (linkURI == resource->getURI())
         {
             found = true;
@@ -602,26 +602,26 @@ void SimulatorCollectionResourceImpl::addLink(const SimulatorResourceSP &resourc
     if (false ==  found)
     {
         links.push_back(newLink);
-        m_resModel.update("links", links);
+        m_resModel.update(OC_RSRVD_LINKS, links);
     }
 }
 
 void SimulatorCollectionResourceImpl::removeLink(std::string uri)
 {
     std::lock_guard<std::mutex> lock(m_modelLock);
-    if (!m_resModel.contains("links"))
+    if (!m_resModel.contains(OC_RSRVD_LINKS))
         return;
 
     // Add OIC Link if it is not present
     std::vector<SimulatorResourceModel> links =
-        m_resModel.get<std::vector<SimulatorResourceModel>>("links");
+        m_resModel.get<std::vector<SimulatorResourceModel>>(OC_RSRVD_LINKS);
     for (size_t i = 0; i < links.size(); i++)
     {
-        std::string linkURI = links[i].get<std::string>("href");
+        std::string linkURI = links[i].get<std::string>(OC_RSRVD_HREF);
         if (linkURI == uri)
         {
             links.erase(links.begin() + i);
-            m_resModel.update("links", links);
+            m_resModel.update(OC_RSRVD_LINKS, links);
             break;
         }
     }
index 061f872..b5f79fd 100644 (file)
@@ -166,10 +166,10 @@ std::shared_ptr<SimulatorResource> SimulatorResourceFactory::buildResource(
     std::string resourceType;\r
 \r
     // Extracting resource type.\r
-    if (resourceModel.contains("rt"))\r
+    if (resourceModel.contains(OC_RSRVD_RESOURCE_TYPE))\r
     {\r
-        resourceType = resourceModel.get<std::string>("rt");\r
-        resourceModel.remove("rt");\r
+        resourceType = resourceModel.get<std::string>(OC_RSRVD_RESOURCE_TYPE);\r
+        resourceModel.remove(OC_RSRVD_RESOURCE_TYPE);\r
     }\r
     else if (resourceModel.contains("resourceType"))\r
     {\r
@@ -179,30 +179,30 @@ std::shared_ptr<SimulatorResource> SimulatorResourceFactory::buildResource(
 \r
     // Extracting interface type.\r
     std::vector<std::string> interfaceTypes;\r
-    if (resourceModel.contains("if"))\r
+    if (resourceModel.contains(OC_RSRVD_INTERFACE))\r
     {\r
-        SimulatorResourceModel::TypeInfo typeInfo = resourceModel.getType("if");\r
+        SimulatorResourceModel::TypeInfo typeInfo = resourceModel.getType(OC_RSRVD_INTERFACE);\r
         if(AttributeValueType::STRING == typeInfo.type())\r
         {\r
-            interfaceTypes.push_back(resourceModel.get<std::string>("if"));\r
+            interfaceTypes.push_back(resourceModel.get<std::string>(OC_RSRVD_INTERFACE));\r
         }\r
         else if(AttributeValueType::VECTOR == typeInfo.type()\r
             && AttributeValueType::STRING == typeInfo.baseType()\r
             && typeInfo.depth() == 1)\r
         {\r
-            interfaceTypes = resourceModel.get<std::vector<std::string>>("if");\r
+            interfaceTypes = resourceModel.get<std::vector<std::string>>(OC_RSRVD_INTERFACE);\r
             if (interfaceTypes.size() > 1)\r
                 interfaceTypes.erase(interfaceTypes.begin()+1, interfaceTypes.end());\r
         }\r
 \r
-        resourceModel.remove("if");\r
+        resourceModel.remove(OC_RSRVD_INTERFACE);\r
     }\r
 \r
     for (auto &requestModel : requestModels)\r
     {\r
         if (requestModel.second)\r
         {\r
-            addInterfaceFromQueryParameter((requestModel.second)->getQueryParams("if"),\r
+            addInterfaceFromQueryParameter((requestModel.second)->getQueryParams(OC_RSRVD_INTERFACE),\r
                 interfaceTypes);\r
         }\r
     }\r
@@ -214,7 +214,7 @@ std::shared_ptr<SimulatorResource> SimulatorResourceFactory::buildResource(
 \r
     // Create simple/collection resource\r
     std::shared_ptr<SimulatorResource> simResource;\r
-    if (resourceModel.contains("links"))\r
+    if (resourceModel.contains(OC_RSRVD_LINKS))\r
     {\r
         std::shared_ptr<SimulatorCollectionResourceImpl> collectionRes(\r
             new SimulatorCollectionResourceImpl());\r
index 44023a3..5ace06a 100755 (executable)
@@ -645,9 +645,9 @@ void SimulatorSingleResourceImpl::notifyAll(const SimulatorResourceModel &resMod
 void SimulatorSingleResourceImpl::setCommonProperties(OC::OCRepresentation &ocResRep)
 {
     std::lock_guard<std::recursive_mutex> lock(m_objectLock);
-    ocResRep.setValue("rt", m_resourceType);
-    ocResRep.setValue("if", m_interfaces);
-    ocResRep.setValue("n", m_name);
+    ocResRep.setValue(OC_RSRVD_RESOURCE_TYPE, m_resourceType);
+    ocResRep.setValue(OC_RSRVD_INTERFACE, m_interfaces);
+    ocResRep.setValue(OC_RSRVD_DEVICE_NAME, m_name);
 }
 
 OCEntityHandlerResult SimulatorSingleResourceImpl::handleRequests(
@@ -766,9 +766,9 @@ OCEntityHandlerResult SimulatorSingleResourceImpl::handleGET(
     // Handling interface query parameter "if"
     auto interfaceType = m_interfaces[0];
     auto requestQueryParams = request->getQueryParameters();
-    if (requestQueryParams.end() != requestQueryParams.find("if"))
+    if (requestQueryParams.end() != requestQueryParams.find(OC_RSRVD_INTERFACE))
     {
-        interfaceType = requestQueryParams["if"];
+        interfaceType = requestQueryParams[OC_RSRVD_INTERFACE];
     }
 
     if (!isValidInterface(interfaceType, "GET"))
@@ -805,9 +805,9 @@ OCEntityHandlerResult SimulatorSingleResourceImpl::handlePUT(
     // Handling interface query parameter "if"
     auto interfaceType = m_interfaces[0];
     auto requestQueryParams = request->getQueryParameters();
-    if (requestQueryParams.end() != requestQueryParams.find("if"))
+    if (requestQueryParams.end() != requestQueryParams.find(OC_RSRVD_INTERFACE))
     {
-        interfaceType = requestQueryParams["if"];
+        interfaceType = requestQueryParams[OC_RSRVD_INTERFACE];
     }
 
     if (!isValidInterface(interfaceType, "PUT"))
@@ -857,9 +857,9 @@ OCEntityHandlerResult SimulatorSingleResourceImpl::handlePOST(
     // Handling interface query parameter "if"
     auto interfaceType = m_interfaces[0];
     auto requestQueryParams = request->getQueryParameters();
-    if (requestQueryParams.end() != requestQueryParams.find("if"))
+    if (requestQueryParams.end() != requestQueryParams.find(OC_RSRVD_INTERFACE))
     {
-        interfaceType = requestQueryParams["if"];
+        interfaceType = requestQueryParams[OC_RSRVD_INTERFACE];
     }
 
     if (!isValidInterface(interfaceType, "POST"))
index 37fd6ea..ee49b05 100644 (file)
@@ -156,10 +156,10 @@ void SimulatorManager::getDeviceInfo(const std::string &host, DeviceInfoCallback
     OC::FindDeviceCallback deviceCallback = std::bind(
             [](const OC::OCRepresentation & rep, const std::string & hostUri, DeviceInfoCallback callback)
     {
-        std::string deviceName = rep.getValue<std::string>("n");
-        std::string deviceID = rep.getValue<std::string>("di");
-        std::string deviceSpecVersion = rep.getValue<std::string>("icv");
-        std::string deviceDMV = rep.getValue<std::string>("dmv");
+        std::string deviceName = rep.getValue<std::string>(OC_RSRVD_DEVICE_NAME);
+        std::string deviceID = rep.getValue<std::string>(OC_RSRVD_DEVICE_ID);
+        std::string deviceSpecVersion = rep.getValue<std::string>(OC_RSRVD_SPEC_VERSION);
+        std::string deviceDMV = rep.getValue<std::string>(OC_RSRVD_DATA_MODEL_VERSION);
 
         DeviceInfo deviceInfo(deviceName, deviceID, deviceSpecVersion, deviceDMV);
         callback(hostUri, deviceInfo);
@@ -169,7 +169,7 @@ void SimulatorManager::getDeviceInfo(const std::string &host, DeviceInfoCallback
                                            OCConnectivityType, OC::FindDeviceCallback);
 
     invokeocplatform(static_cast<GetDeviceInfo>(OC::OCPlatform::getDeviceInfo), host.c_str(),
-                     "/oic/d", CT_DEFAULT, deviceCallback);
+                     OC_RSRVD_DEVICE_URI, CT_DEFAULT, deviceCallback);
 }
 
 void SimulatorManager::setDeviceInfo(const std::string &deviceName)
@@ -205,17 +205,17 @@ void SimulatorManager::getPlatformInfo(const std::string &host, PlatformInfoCall
                 [](const OC::OCRepresentation & rep, const std::string & hostUri, PlatformInfoCallback callback)
     {
         PlatformInfo platformInfo;
-        platformInfo.setPlatformID(rep.getValue<std::string>("pi"));
-        platformInfo.setPlatformVersion(rep.getValue<std::string>("mnpv"));
-        platformInfo.setManufacturerName(rep.getValue<std::string>("mnmn"));
-        platformInfo.setManufacturerUrl(rep.getValue<std::string>("mnml"));
-        platformInfo.setModelNumber(rep.getValue<std::string>("mnmo"));
-        platformInfo.setDateOfManfacture(rep.getValue<std::string>("mndt"));
-        platformInfo.setOSVersion(rep.getValue<std::string>("mnos"));
-        platformInfo.setHardwareVersion(rep.getValue<std::string>("mnhw"));
-        platformInfo.setFirmwareVersion(rep.getValue<std::string>("mnfv"));
-        platformInfo.setSupportUrl(rep.getValue<std::string>("mnsl"));
-        platformInfo.setSystemTime(rep.getValue<std::string>("st"));
+        platformInfo.setPlatformID(rep.getValue<std::string>(OC_RSRVD_PLATFORM_ID));
+        platformInfo.setPlatformVersion(rep.getValue<std::string>(OC_RSRVD_PLATFORM_VERSION));
+        platformInfo.setManufacturerName(rep.getValue<std::string>(OC_RSRVD_MFG_NAME));
+        platformInfo.setManufacturerUrl(rep.getValue<std::string>(OC_RSRVD_MFG_URL));
+        platformInfo.setModelNumber(rep.getValue<std::string>(OC_RSRVD_MODEL_NUM));
+        platformInfo.setDateOfManfacture(rep.getValue<std::string>(OC_RSRVD_MFG_DATE));
+        platformInfo.setOSVersion(rep.getValue<std::string>(OC_RSRVD_OS_VERSION));
+        platformInfo.setHardwareVersion(rep.getValue<std::string>(OC_RSRVD_HARDWARE_VERSION));
+        platformInfo.setFirmwareVersion(rep.getValue<std::string>(OC_RSRVD_FIRMWARE_VERSION));
+        platformInfo.setSupportUrl(rep.getValue<std::string>(OC_RSRVD_SUPPORT_URL));
+        platformInfo.setSystemTime(rep.getValue<std::string>(OC_RSRVD_SYSTEM_TIME));
 
         callback(hostUri, platformInfo);
     }, std::placeholders::_1, host, callback);
@@ -224,7 +224,7 @@ void SimulatorManager::getPlatformInfo(const std::string &host, PlatformInfoCall
             OCConnectivityType, OC::FindPlatformCallback);
 
     invokeocplatform(static_cast<GetPlatformInfo>(OC::OCPlatform::getPlatformInfo), host.c_str(),
-                     "/oic/p", CT_DEFAULT, platformCallback);
+                     OC_RSRVD_PLATFORM_URI, CT_DEFAULT, platformCallback);
 }
 
 void SimulatorManager::setPlatformInfo(PlatformInfo &platformInfo)