Simulator:Fix for static analyzer reported issues 01/21501/6
authorHarry <h.marappa@samsung.com>
Tue, 4 Jul 2017 16:33:18 +0000 (22:03 +0530)
committerUze Choi <uzchoi@samsung.com>
Thu, 28 Sep 2017 08:51:25 +0000 (08:51 +0000)
1. Removal of unused variables.
2. Using Map.empty() than Map.size() for optimization.
3. New API simulator_remote_resource::observe added to accept
   query parameters.

Change-Id: I3e8a4ebf3d03694f4f075a5345f1343d9ea453f8
Signed-off-by: Harry <h.marappa@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/21237
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Senthil Kumar G S <senthil.gs@samsung.com>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
(cherry picked from commit 543d59f964c8b16db34897a4440b74fb9b83a2f3)

service/simulator/examples/client/simulator_client.cpp
service/simulator/inc/simulator_remote_resource.h
service/simulator/java/jni/simulator_remote_resource_jni.cpp
service/simulator/java/jni/simulator_resource_jni.cpp
service/simulator/ramlparser/raml/model/Raml.cpp
service/simulator/ramlparser/raml/model/RamlResource.cpp
service/simulator/ramlparser/raml/model/RamlResource.h
service/simulator/ramlparser/raml/model/RequestResponseBody.h
service/simulator/src/client/simulator_remote_resource_impl.cpp
service/simulator/src/client/simulator_remote_resource_impl.h
service/simulator/src/common/simulator_utils.cpp

index 229de74..869bd6f 100644 (file)
@@ -107,7 +107,7 @@ class ClientController
         SimulatorRemoteResourceSP selectResource()
         {
             std::lock_guard<std::recursive_mutex> lock(m_mutex);
-            if (0 == m_resList.size())
+            if (m_resList.empty())
             {
                 std::cout << "No resources!" << std::endl;
                 return nullptr;
index 84da19a..44769c7 100644 (file)
@@ -141,6 +141,18 @@ class SimulatorRemoteResource : private UnCopyable
          */
         virtual void observe(ObserveType type, ObserveNotificationCallback callback) = 0;
 
+        /**
+         * API to send observe request to remote resource.
+         *
+         * @param type - Observe request type.
+         * @param queryParametersMap - Query parameters.
+         * @param callback - callback for receiving notifications from remote resource
+         * asynchronously.
+         */
+        virtual void observe(ObserveType type,
+                  const std::map<std::string, std::string> &queryParams,
+                  ObserveNotificationCallback callback) = 0;
+
         /**
          * API to send cancel observe request to remote resource.
          *
index f033f2c..477e877 100644 (file)
@@ -436,7 +436,7 @@ Java_org_oic_simulator_client_SimulatorRemoteResource_nativeStartObserve
         }, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3,
         std::placeholders::_4, JniListenerHolder::create(env, jListener));
 
-        resource->observe(ObserveType::OBSERVE, callback);
+        resource->observe(ObserveType::OBSERVE, queryParams, callback);
     }
     catch (InvalidArgsException &e)
     {
index ca6094f..2adfd65 100644 (file)
@@ -54,7 +54,7 @@ static jobject createObserverInfo(JNIEnv *env, const ObserverInfo &observerInfo)
 }
 
 static jobject createObserverInfoVector(JNIEnv *env,
-                                        const std::vector<ObserverInfo> observersList)
+                                        const std::vector<ObserverInfo> &observersList)
 {
     jobject vectorObject = JniVector(env).toJava();
     if (!vectorObject)
index d7dc0c4..d455a5a 100644 (file)
@@ -197,7 +197,6 @@ namespace RAML
                         for ( YAML::const_iterator tt = (*iit).begin(); tt != (*iit).end(); ++tt )\r
                         {\r
                             std::string key = READ_NODE_AS_STRING(tt->first);\r
-                            std::pair<std::string, Schema> schema;\r
 \r
                             IncludeResolver::FileType fileType = m_includeResolver->getFileType(tt->second);\r
                             if ((fileType == IncludeResolver::FileType::JSON) ||\r
index ecee418..1474796 100644 (file)
@@ -115,7 +115,8 @@ namespace RAML
     {\r
         return (m_parentUri + m_relativeUri);\r
     }\r
-    void RamlResource::readResource(const std::string resourceKey, const YAML::Node &yamlNode,\r
+\r
+    void RamlResource::readResource(const std::string &resourceKey, const YAML::Node &yamlNode,\r
                                     const std::string &parentUri)\r
     {\r
         m_relativeUri = resourceKey;\r
index 1b4d748..c49ade9 100644 (file)
@@ -221,14 +221,14 @@ namespace RAML
                    * @param parentUri - Uri of the Parent to form the Absolute Uri\r
                    *\r
                    */\r
-            RamlResource(const std::string resourceKey, const YAML::Node &yamlNode ,\r
+            RamlResource(const std::string &resourceKey, const YAML::Node &yamlNode ,\r
                          const IncludeResolverPtr &includeResolver,\r
                          const std::string &parentUri) : m_includeResolver(includeResolver)\r
             {\r
                 readResource(resourceKey, yamlNode, parentUri);\r
             }\r
         private:\r
-            void readResource(const std::string resourceKey, const YAML::Node &yamlNode,\r
+            void readResource(const std::string &resourceKey, const YAML::Node &yamlNode,\r
                               const std::string &parentUri);\r
         private:\r
             std::string m_displayName;\r
index 929f915..0e0e80d 100644 (file)
@@ -112,7 +112,7 @@ namespace RAML
                    * @param type - type of request response body\r
                    *\r
                    */\r
-            RequestResponseBody(const std::string type) : m_type(type), m_schema(NULL),\r
+            RequestResponseBody(const std::string &type) : m_type(type), m_schema(NULL),\r
                 m_includeResolver(NULL) {}\r
 \r
             /**\r
@@ -123,7 +123,7 @@ namespace RAML
                    * @param includeResolver - Reference to IncludeResolver for reading external files\r
                    *\r
                    */\r
-            RequestResponseBody(const std::string type, const YAML::Node &yamlNode,\r
+            RequestResponseBody(const std::string &type, const YAML::Node &yamlNode,\r
                                 const IncludeResolverPtr &includeResolver): m_schema(NULL),\r
                 m_includeResolver(includeResolver)\r
             { readRequestResponseBody(type, yamlNode); }\r
index 5523695..aacc6b0 100644 (file)
@@ -115,6 +115,14 @@ bool SimulatorRemoteResourceImpl::isObservable() const
 
 void SimulatorRemoteResourceImpl::observe(ObserveType type,
         ObserveNotificationCallback callback)
+{
+    std::map<std::string, std::string> queryParams;
+    return observe(type, queryParams, callback);
+}
+
+void SimulatorRemoteResourceImpl::observe(ObserveType type,
+        const std::map<std::string, std::string> &queryParams,
+        ObserveNotificationCallback callback)
 {
     VALIDATE_CALLBACK(callback)
 
@@ -145,7 +153,7 @@ void SimulatorRemoteResourceImpl::observe(ObserveType type,
 
     try
     {
-        OCStackResult ocResult = m_ocResource->observe(observeType, OC::QueryParamsMap(), observeCallback);
+        OCStackResult ocResult = m_ocResource->observe(observeType, queryParams, observeCallback);
         if (OC_STACK_OK != ocResult)
             throw SimulatorException(static_cast<SimulatorResult>(ocResult), OC::OCException::reason(ocResult));
 
index 2e75ab0..4169c01 100644 (file)
@@ -49,6 +49,8 @@ class SimulatorRemoteResourceImpl : public SimulatorRemoteResource
         bool isObservable() const;
 
         void observe(ObserveType type, ObserveNotificationCallback callback);
+        void observe(ObserveType type, const std::map<std::string, std::string> &queryParams,
+                     ObserveNotificationCallback callback);
         void cancelObserve();
 
         void get(const GetResponseCallback &callback);
index 070e1f2..618fda7 100644 (file)
@@ -131,7 +131,7 @@ std::string getRequestString(const std::map<std::string, std::string> &queryPara
                              const OC::OCRepresentation &rep)
 {
     std::ostringstream requestString;
-    if (queryParams.size() > 0)
+    if (!queryParams.empty())
     {
         requestString << "qp: ";
         for (auto &qp : queryParams)
@@ -146,7 +146,7 @@ std::string getRequestString(const std::map<std::string, std::string> &queryPara
 std::string getRequestString(const std::map<std::string, std::string> &queryParams)
 {
     std::ostringstream requestString;
-    if (queryParams.size() > 0)
+    if (!queryParams.empty())
     {
         requestString << "qp: ";
         for (auto &qp : queryParams)