Fix for prevent tool reported defects. 93/2593/7
authorHarish Kumara Marappa <h.marappa@samsung.com>
Fri, 18 Sep 2015 18:43:35 +0000 (00:13 +0530)
committerMadan Lanka <lanka.madan@samsung.com>
Sat, 19 Sep 2015 08:25:48 +0000 (08:25 +0000)
Change details:
1. Prevent issues fix.
2. Removal of white spaces from Java files.
3. Simulator tool UI changes.
4. Fix for issues observed during regression testing.

Change-Id: I4141541587421bc3de7ee321e8124a0444f37dd5
Signed-off-by: Harish Kumara Marappa <h.marappa@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2593
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
60 files changed:
service/simulator/examples/client-controller/client_controller.cpp
service/simulator/examples/server/service_provider.cpp
service/simulator/inc/simulator_error_codes.h
service/simulator/inc/simulator_manager.h
service/simulator/inc/simulator_resource_model.h
service/simulator/inc/simulator_resource_server.h
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/manager/ResourceManager.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/AttributeView.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ResourceManager.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Constants.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Utility.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/ResourceManagerView.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/DeleteResourceWizard.java
service/simulator/java/jni/resource_attributes_jni.cpp
service/simulator/java/jni/simulator_manager_jni.cpp
service/simulator/java/jni/simulator_manager_jni.h
service/simulator/java/jni/simulator_remote_resource_jni.cpp
service/simulator/java/jni/simulator_remote_resource_jni.h
service/simulator/java/jni/simulator_resource_jni_util.cpp
service/simulator/java/jni/simulator_resource_model_jni.cpp
service/simulator/java/jni/simulator_resource_server_jni.cpp
service/simulator/java/sdk/src/org/oic/simulator/DeviceInfo.java
service/simulator/java/sdk/src/org/oic/simulator/IAutomation.java
service/simulator/java/sdk/src/org/oic/simulator/IDeviceInfo.java
service/simulator/java/sdk/src/org/oic/simulator/IPlatformInfo.java
service/simulator/java/sdk/src/org/oic/simulator/PlatformInfo.java
service/simulator/java/sdk/src/org/oic/simulator/ResourceAttribute.java
service/simulator/java/sdk/src/org/oic/simulator/SimulatorManager.java
service/simulator/java/sdk/src/org/oic/simulator/SimulatorManagerNativeInterface.java
service/simulator/java/sdk/src/org/oic/simulator/SimulatorResourceModel.java
service/simulator/java/sdk/src/org/oic/simulator/SimulatorResult.java
service/simulator/java/sdk/src/org/oic/simulator/clientcontroller/IGetListener.java
service/simulator/java/sdk/src/org/oic/simulator/clientcontroller/IObserveListener.java
service/simulator/java/sdk/src/org/oic/simulator/clientcontroller/IPostListener.java
service/simulator/java/sdk/src/org/oic/simulator/clientcontroller/IPutListener.java
service/simulator/java/sdk/src/org/oic/simulator/clientcontroller/IVerificationListener.java
service/simulator/java/sdk/src/org/oic/simulator/clientcontroller/SimulatorConnectivityType.java
service/simulator/java/sdk/src/org/oic/simulator/clientcontroller/SimulatorRemoteResource.java
service/simulator/java/sdk/src/org/oic/simulator/clientcontroller/SimulatorVerificationType.java
service/simulator/java/sdk/src/org/oic/simulator/serviceprovider/IObserver.java
service/simulator/java/sdk/src/org/oic/simulator/serviceprovider/ObserverInfo.java
service/simulator/java/sdk/src/org/oic/simulator/serviceprovider/SimulatorResourceServer.java
service/simulator/src/client-controller/attribute_generator.cpp
service/simulator/src/client-controller/attribute_generator.h
service/simulator/src/client-controller/post_request_generator.cpp
service/simulator/src/client-controller/put_request_generator.cpp
service/simulator/src/client-controller/query_param_generator.cpp
service/simulator/src/client-controller/request_sender.cpp
service/simulator/src/client-controller/simulator_remote_resource_impl.cpp
service/simulator/src/common/request_model_builder.cpp
service/simulator/src/common/response_model.cpp
service/simulator/src/common/simulator_resource_model.cpp
service/simulator/src/service-provider/resource_update_automation.cpp
service/simulator/src/service-provider/resource_update_automation.h
service/simulator/src/service-provider/resource_update_automation_mngr.cpp
service/simulator/src/service-provider/simulator_resource_creator.cpp
service/simulator/src/service-provider/simulator_resource_server.cpp
service/simulator/src/service-provider/simulator_resource_server_impl.cpp
service/simulator/src/service-provider/simulator_resource_server_impl.h
service/simulator/src/simulator_manager.cpp

index ff9556c..18df736 100644 (file)
@@ -114,7 +114,7 @@ class ClientController
             for (auto & resourceEntry : m_resList)
             {
                 std::cout << index++ << ": " << (resourceEntry.second)->getURI() << "[" <<
-                (resourceEntry.second)->getHost()  << "]" << std::endl;
+                          (resourceEntry.second)->getHost()  << "]" << std::endl;
                 ids.push_back((resourceEntry.second)->getID());
             }
 
@@ -128,7 +128,7 @@ class ClientController
                 return nullptr;
             }
 
-            return m_resList[ids[choice-1]];
+            return m_resList[ids[choice - 1]];
         }
 
         void findResource()
@@ -147,21 +147,24 @@ class ClientController
                 if (m_resList.end() == m_resList.find(resource->getID()))
                     m_resList[resource->getID()] = resource;
                 else
-                    std::cout << "Resource with UID: "<< resource->getID() << "already exist in the list!"<< std::endl;
+                    std::cout << "Resource with UID: " << resource->getID() << "already exist in the list!" <<
+                              std::endl;
             };
 
             try
             {
-                SimulatorManager::getInstance()->findResources(resourceType, callback);
+                SimulatorManager::getInstance()->findResource(resourceType, callback);
                 std::cout << "SimulatorManager::findResource is successfull" << std::endl;
             }
-            catch(InvalidArgsException &e)
+            catch (InvalidArgsException &e)
             {
-                std::cout << "InvalidArgsException occured [code : " << e.code() << " Detail: " << e.what() << "]" << std::endl;
+                std::cout << "InvalidArgsException occured [code : " << e.code() << " Detail: " << e.what() << "]"
+                          << std::endl;
             }
-            catch(SimulatorException &e)
+            catch (SimulatorException &e)
             {
-                std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " << e.what() << "]" << std::endl;
+                std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " << e.what() << "]" <<
+                          std::endl;
             }
         }
 
@@ -179,12 +182,13 @@ class ClientController
             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->getResourceInterfaces())
                 std::cout << type << " ";
-            std::cout << std::boolalpha << "\nisObservable : " << resource->isObservable() << std::endl;
+            std::cout << std::boolalpha << "\nisObservable : " << resource->isObservable()
+                    << std::noboolalpha << std::endl;
             std::cout << "#############################" << std::endl;
         }
 
@@ -195,10 +199,10 @@ class ClientController
 
             // callback implementaion
             SimulatorRemoteResource::ObserveNotificationCallback callback =
-            [](std::string uid, SimulatorResult errorCode, SimulatorResourceModelSP rep, int seq)
+                [](std::string uid, SimulatorResult errorCode, SimulatorResourceModelSP rep, int seq)
             {
-                std::cout << "\nObserve notificatoin received ###[errorcode:  " << errorCode <<
-                    " seq:  " << seq << "UID: " << uid << "]" << std::endl;
+                std::cout << "\nObserve notification received ###[errorcode:  " << errorCode <<
+                          " seq:  " << seq << "UID: " << uid << "]" << std::endl;
                 std::map<std::string, SimulatorResourceModel::Attribute> attributes = rep->getAttributes();
                 for (auto & attribute : attributes)
                 {
@@ -214,13 +218,15 @@ class ClientController
                 resource->observe(ObserveType::OBSERVE, callback);
                 std::cout << "Observe is successfull!" << std::endl;
             }
-            catch(InvalidArgsException &e)
+            catch (InvalidArgsException &e)
             {
-                std::cout << "InvalidArgsException occured [code : " << e.code() << " Detail: " << e.what() << "]" << std::endl;
+                std::cout << "InvalidArgsException occured [code : " << e.code() << " Detail: "
+                        << e.what() << "]" << std::endl;
             }
-            catch(SimulatorException &e)
+            catch (SimulatorException &e)
             {
-                std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " << e.what() << "]" << std::endl;
+                std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " <<
+                        e.what() << "]" << std::endl;
             }
         }
 
@@ -234,9 +240,10 @@ class ClientController
                 resource->cancelObserve();
                 std::cout << "Cancelling observe is successfull!" << std::endl;
             }
-            catch(SimulatorException &e)
+            catch (SimulatorException &e)
             {
-                std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " << e.what() << "]" << std::endl;
+                std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " <<
+                        e.what() << "]" << std::endl;
             }
         }
 
@@ -247,16 +254,19 @@ class ClientController
 
             // callback implementaion
             SimulatorRemoteResource::ResponseCallback callback =
-            [](std::string uId, SimulatorResult errorCode, SimulatorResourceModelSP rep)
+                [](std::string uId, SimulatorResult errorCode, SimulatorResourceModelSP rep)
             {
-                std::cout << "\nGET Response received ### [errorcode:  " << errorCode << "]" << std::endl;
+                std::cout << "\nGET Response received ### [errorcode:  " << errorCode << "]"
+                        << std::endl;
                 std::cout << "UID is: " << uId << std::endl;
                 std::cout << "Representation is: " << std::endl;
-                std::map<std::string, SimulatorResourceModel::Attribute> attributes = rep->getAttributes();
+                std::map<std::string, SimulatorResourceModel::Attribute> attributes =
+                        rep->getAttributes();
                 for (auto & attribute : attributes)
                 {
                     std::cout << (attribute.second).getName() << " :  {" << std::endl;
-                    std::cout << "value: " << (attribute.second).valueToString().c_str() << std::endl;
+                    std::cout << "value: " << (attribute.second).valueToString().c_str()
+                            << std::endl;
                     std::cout << "}" << std::endl;
                 }
                 std::cout << std::endl;
@@ -267,17 +277,20 @@ class ClientController
                 resource->get(std::map <std::string, std::string>(), callback);
                 std::cout << "GET is successfull!" << std::endl;
             }
-            catch(InvalidArgsException &e)
+            catch (InvalidArgsException &e)
             {
-                std::cout << "InvalidArgsException occured [code : " << e.code() << " Detail: " << e.what() << "]" << std::endl;
+                std::cout << "InvalidArgsException occured [code : " << e.code() << " Detail: "
+                        << e.what() << "]" << std::endl;
             }
-            catch(NoSupportException &e)
+            catch (NoSupportException &e)
             {
-                std::cout << "NoSupportException occured [code : " << e.code() << " Detail: " << e.what() << "]" << std::endl;
+                std::cout << "NoSupportException occured [code : " << e.code() << " Detail: " <<
+                        e.what() << "]" << std::endl;
             }
-            catch(SimulatorException &e)
+            catch (SimulatorException &e)
             {
-                std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " << e.what() << "]" << std::endl;
+                std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " <<
+                        e.what() << "]" << std::endl;
             }
         }
 
@@ -288,16 +301,19 @@ class ClientController
 
             // callback implementaion
             SimulatorRemoteResource::ResponseCallback callback =
-            [](std::string uId, SimulatorResult errorCode, SimulatorResourceModelSP rep)
+                [](std::string uId, SimulatorResult errorCode, SimulatorResourceModelSP rep)
             {
-                std::cout << "\nPUT Response received ![errorcode:  " << errorCode << "]" << std::endl;
+                std::cout << "\nPUT Response received ![errorcode:  " << errorCode << "]"
+                        << std::endl;
                 std::cout << "UID is: " << uId << std::endl;
                 std::cout << "Representation is: " << std::endl;
-                std::map<std::string, SimulatorResourceModel::Attribute> attributes = rep->getAttributes();
+                std::map<std::string, SimulatorResourceModel::Attribute> attributes =
+                        rep->getAttributes();
                 for (auto & attribute : attributes)
                 {
                     std::cout << (attribute.second).getName() << " :  {" << std::endl;
-                    std::cout << "value: " << (attribute.second).valueToString().c_str() << std::endl;
+                    std::cout << "value: " << (attribute.second).valueToString().c_str()
+                            << std::endl;
                     std::cout << "}" << std::endl;
                 }
                 std::cout << std::endl;
@@ -313,17 +329,20 @@ class ClientController
                 resource->put(std::map <std::string, std::string>(), rep, callback);
                 std::cout << "PUT is successfull!" << std::endl;
             }
-            catch(InvalidArgsException &e)
+            catch (InvalidArgsException &e)
             {
-                std::cout << "InvalidArgsException occured [code : " << e.code() << " Detail: " << e.what() << "]" << std::endl;
+                std::cout << "InvalidArgsException occured [code : " << e.code() << " Detail: "
+                        << e.what() << "]" << std::endl;
             }
-            catch(NoSupportException &e)
+            catch (NoSupportException &e)
             {
-                std::cout << "NoSupportException occured [code : " << e.code() << " Detail: " << e.what() << "]" << std::endl;
+                std::cout << "NoSupportException occured [code : " << e.code() << " Detail: " <<
+                        e.what() << "]" << std::endl;
             }
-            catch(SimulatorException &e)
+            catch (SimulatorException &e)
             {
-                std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " << e.what() << "]" << std::endl;
+                std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " <<
+                        e.what() << "]" << std::endl;
             }
         }
 
@@ -334,16 +353,19 @@ class ClientController
 
             // callback implementaion
             SimulatorRemoteResource::ResponseCallback callback =
-            [](std::string uId, SimulatorResult errorCode, SimulatorResourceModelSP rep)
+                [](std::string uId, SimulatorResult errorCode, SimulatorResourceModelSP rep)
             {
-                std::cout << "\nPOST Response received ![errorcode:  " << errorCode << "]" << std::endl;
+                std::cout << "\nPOST Response received ![errorcode:  " << errorCode << "]"
+                        << std::endl;
                 std::cout << "UID is: " << uId << std::endl;
                 std::cout << "Representation is: " << std::endl;
-                std::map<std::string, SimulatorResourceModel::Attribute> attributes = rep->getAttributes();
+                std::map<std::string, SimulatorResourceModel::Attribute> attributes =
+                        rep->getAttributes();
                 for (auto & attribute : attributes)
                 {
                     std::cout << (attribute.second).getName() << " :  {" << std::endl;
-                    std::cout << "value: " << (attribute.second).valueToString().c_str() << std::endl;
+                    std::cout << "value: " << (attribute.second).valueToString().c_str()
+                            << std::endl;
                     std::cout << "}" << std::endl;
                 }
                 std::cout << std::endl;
@@ -359,17 +381,20 @@ class ClientController
                 resource->post(std::map <std::string, std::string>(), rep, callback);
                 std::cout << "POST is successfull!" << std::endl;
             }
-            catch(InvalidArgsException &e)
+            catch (InvalidArgsException &e)
             {
-                std::cout << "InvalidArgsException occured [code : " << e.code() << " Detail: " << e.what() << "]" << std::endl;
+                std::cout << "InvalidArgsException occured [code : " << e.code() << " Detail: "
+                        << e.what() << "]" << std::endl;
             }
-            catch(NoSupportException &e)
+            catch (NoSupportException &e)
             {
-                std::cout << "NoSupportException occured [code : " << e.code() << " Detail: " << e.what() << "]" << std::endl;
+                std::cout << "NoSupportException occured [code : " << e.code() << " Detail: " <<
+                        e.what() << "]" << std::endl;
             }
-            catch(SimulatorException &e)
+            catch (SimulatorException &e)
             {
-                std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " << e.what() << "]" << std::endl;
+                std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " <<
+                        e.what() << "]" << std::endl;
             }
         }
 
@@ -378,28 +403,33 @@ class ClientController
             SimulatorRemoteResourceSP resource = selectResource();
             if (!resource) return;
 
-            SimulatorRemoteResource::StateCallback callback = [] (std::string uid, int sessionId, OperationState state)
+            SimulatorRemoteResource::StateCallback callback = [] (std::string uid, int sessionId,
+                    OperationState state)
             {
-                std::cout << "\nResource verification status received ![id:  " << sessionId << "  State: "
-                << getOperationStateString(state) << " UID: "<< uid << "]" << std::endl;
+                std::cout << "\nResource verification status received ![id:  " << sessionId <<
+                        "  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;
+                std::cout << "startVerification for GET is successfull!id: " << id << std::endl;
             }
-            catch(InvalidArgsException &e)
+            catch (InvalidArgsException &e)
             {
-                std::cout << "InvalidArgsException occured [code : " << e.code() << " Detail: " << e.what() << "]" << std::endl;
+                std::cout << "InvalidArgsException occured [code : " << e.code() << " Detail: "
+                        << e.what() << "]" << std::endl;
             }
-            catch(NoSupportException &e)
+            catch (NoSupportException &e)
             {
-                std::cout << "NoSupportException occured [code : " << e.code() << " Detail: " << e.what() << "]" << std::endl;
+                std::cout << "NoSupportException occured [code : " << e.code() << " Detail: " <<
+                        e.what() << "]" << std::endl;
             }
-            catch(SimulatorException &e)
+            catch (SimulatorException &e)
             {
-                std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " << e.what() << "]" << std::endl;
+                std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " <<
+                        e.what() << "]" << std::endl;
             }
         }
 
@@ -408,28 +438,33 @@ class ClientController
             SimulatorRemoteResourceSP resource = selectResource();
             if (!resource) return;
 
-            SimulatorRemoteResource::StateCallback callback = [] (std::string uid, int sessionId, OperationState state)
+            SimulatorRemoteResource::StateCallback callback = [] (std::string uid, int sessionId,
+                    OperationState state)
             {
-                std::cout << "\nResource verification status received ![id:  " << sessionId << "  State: "
-                << getOperationStateString(state) << " UID: "<< uid << "]" << std::endl;
+                std::cout << "\nResource verification status received ![id:  " << sessionId <<
+                        "  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;
+                std::cout << "startVerification for PUT is successfull!id: " << id << std::endl;
             }
-            catch(InvalidArgsException &e)
+            catch (InvalidArgsException &e)
             {
-                std::cout << "InvalidArgsException occured [code : " << e.code() << " Detail: " << e.what() << "]" << std::endl;
+                std::cout << "InvalidArgsException occured [code : " << e.code() << " Detail: "
+                        << e.what() << "]" << std::endl;
             }
-            catch(NoSupportException &e)
+            catch (NoSupportException &e)
             {
-                std::cout << "NoSupportException occured [code : " << e.code() << " Detail: " << e.what() << "]" << std::endl;
+                std::cout << "NoSupportException occured [code : " << e.code() << " Detail: " <<
+                        e.what() << "]" << std::endl;
             }
-            catch(SimulatorException &e)
+            catch (SimulatorException &e)
             {
-                std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " << e.what() << "]" << std::endl;
+                std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " <<
+                        e.what() << "]" << std::endl;
             }
         }
 
@@ -438,48 +473,60 @@ class ClientController
             SimulatorRemoteResourceSP resource = selectResource();
             if (!resource) return;
 
-            SimulatorRemoteResource::StateCallback callback = [] (std::string uid, int sessionId, OperationState state)
+            SimulatorRemoteResource::StateCallback callback = [] (std::string uid, int sessionId,
+                    OperationState state)
             {
-                std::cout << "\nResource verification status received ![id:  " << sessionId << "  State: "
-                << getOperationStateString(state) << " UID: "<< uid << "]" << std::endl;
+                std::cout << "\nResource verification status received ![id:  " << sessionId <<
+                        "  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;
+                std::cout << "startVerification for POST is successfull!id: " << id << std::endl;
             }
-            catch(InvalidArgsException &e)
+            catch (InvalidArgsException &e)
             {
-                std::cout << "InvalidArgsException occured [code : " << e.code() << " Detail: " << e.what() << "]" << std::endl;
+                std::cout << "InvalidArgsException occured [code : " << e.code() << " Detail: "
+                        << e.what() << "]" << std::endl;
             }
-            catch(NoSupportException &e)
+            catch (NoSupportException &e)
             {
-                std::cout << "NoSupportException occured [code : " << e.code() << " Detail: " << e.what() << "]" << std::endl;
+                std::cout << "NoSupportException occured [code : " << e.code() << " Detail: " <<
+                        e.what() << "]" << std::endl;
             }
-            catch(SimulatorException &e)
+            catch (SimulatorException &e)
             {
-                std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " << e.what() << "]" << std::endl;
+                std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " <<
+                        e.what() << "]" << std::endl;
             }
         }
 
         void configure()
         {
             SimulatorRemoteResourceSP resource = selectResource();
-            if (!resource) return;
+            if (!resource)
+                return;
 
             try
             {
-                resource->configure("../../../../../../../../service/simulator/ramlparser/example/oic.r.light.raml");
+                std::string configPath;
+                std::cout << "Enter the config path: ";
+                std::cin >> configPath;
+
+                resource->configure(configPath);
                 std::cout << "configuration is successfull!" << std::endl;
             }
             catch (InvalidArgsException &e)
             {
-                std::cout << "InvalidArgsException occured [code : " << e.code() << " Detail: " << e.what() << "]" << std::endl;
+                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 << "SimulatorException occured [code : " << e.code() << " Detail: " <<
+                        e.what() << "]" << std::endl;
             }
         }
 
@@ -518,7 +565,7 @@ void setLogger()
     {
         case 1:
             {
-                if (false == SimulatorManager::getInstance()->setDefaultConsoleLogger())
+                if (false == SimulatorManager::getInstance()->setConsoleLogger())
                     std::cout << "Failed to set the default console logger" << std::endl;
             }
             break;
@@ -528,7 +575,7 @@ void setLogger()
                 std::string filePath;
                 std::cout << "Enter the file path (without file name) : ";
                 std::cin >> filePath;
-                if (false == SimulatorManager::getInstance()->setDefaultFileLogger(filePath))
+                if (false == SimulatorManager::getInstance()->setFileLogger(filePath))
                     std::cout << "Failed to set default file logger" << std::endl;
             }
             break;
@@ -563,7 +610,7 @@ int main(void)
                 {
                     try
                     {
-                        SimulatorManager::getInstance()->getDeviceInfo(std::bind([](DeviceInfo &deviceInfo)
+                        SimulatorManager::getInstance()->getDeviceInfo(std::bind([](DeviceInfo & deviceInfo)
                         {
                             std::cout << "###Device Information received...." << std::endl;
                             std::ostringstream out;
@@ -575,13 +622,15 @@ int main(void)
                             std::cout << out.str() << std::endl;
                         }, std::placeholders::_1));
                     }
-                    catch(InvalidArgsException &e)
+                    catch (InvalidArgsException &e)
                     {
-                        std::cout << "InvalidArgsException occured [code : " << e.code() << " Detail: " << e.what() << "]" << std::endl;
+                        std::cout << "InvalidArgsException occured [code : " << e.code() << " Detail: " << e.what() << "]"
+                                  << std::endl;
                     }
-                    catch(SimulatorException &e)
+                    catch (SimulatorException &e)
                     {
-                        std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " << e.what() << "]" << std::endl;
+                        std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " << e.what() << "]" <<
+                                  std::endl;
                     }
                 }
                 break;
@@ -590,7 +639,7 @@ int main(void)
                 {
                     try
                     {
-                        SimulatorManager::getInstance()->getPlatformInfo(std::bind([](PlatformInfo &platformInfo)
+                        SimulatorManager::getInstance()->getPlatformInfo(std::bind([](PlatformInfo & platformInfo)
                         {
                             std::cout << "###Platform Information received...." << std::endl;
                             std::ostringstream out;
@@ -609,13 +658,15 @@ int main(void)
                             std::cout << out.str() << std::endl;
                         }, std::placeholders::_1));
                     }
-                    catch(InvalidArgsException &e)
+                    catch (InvalidArgsException &e)
                     {
-                        std::cout << "InvalidArgsException occured [code : " << e.code() << " Detail: " << e.what() << "]" << std::endl;
+                        std::cout << "InvalidArgsException occured [code : " << e.code()
+                                << " Detail: " << e.what() << "]" << std::endl;
                     }
-                    catch(SimulatorException &e)
+                    catch (SimulatorException &e)
                     {
-                        std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " << e.what() << "]" << std::endl;
+                        std::cout << "SimulatorException occured [code : " << e.code()
+                                << " Detail: " << e.what() << "]" << std::endl;
                     }
                 }
                 break;
index b0a82ec..74e5bd0 100644 (file)
@@ -25,7 +25,8 @@ class AppLogger : public ILogger
     public:
         void write(std::string time, ILogger::Level level, std::string message)
         {
-            std::cout << "[APPLogger] " << time << " " << ILogger::getString(level) << " " << message;
+            std::cout << "[APPLogger] " << time << " " << ILogger::getString(level) << " "
+                    << message;
         }
 };
 std::shared_ptr<AppLogger> gAppLogger(new AppLogger());
@@ -42,7 +43,7 @@ class SimLightResource
                 int choice = -1;
                 std::cout << "Enter your choice: ";
                 std::cin >> choice;
-                if (choice < 0 || choice > 9)
+                if (choice < 0 || choice > 10)
                 {
                     std::cout << "Invaild choice !" << std::endl; continue;
                 }
@@ -112,13 +113,13 @@ class SimLightResource
         void onResourceModelChanged(const std::string &uri,
                                     const SimulatorResourceModel &resModel)
         {
-            std::cout << "[callback] Resource model is changed URI: " << uri.c_str() << " Count : " <<
-                      resModel.size() << std::endl;
+            std::cout << "[callback] Resource model is changed URI: " << uri.c_str()
+                    << " 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;
+                std::cout << attribute.second.getName() << " :  "
+                        << attribute.second.valueToString().c_str() << std::endl;
             }
             std::cout << "########################" << std::endl;
         }
@@ -126,14 +127,27 @@ class SimLightResource
         void simulateResource(std::string &configPath)
         {
             SimulatorResourceServer::ResourceModelChangedCB callback = std::bind(
-                        &SimLightResource::onResourceModelChanged, this, std::placeholders::_1, std::placeholders::_2);
-            SimulatorResourceServerSP resource = SimulatorManager::getInstance()->createResource(configPath,
-                                                  callback);
-            if (NULL == resource.get())
-                std::cout << "Failed to create resource" << std::endl;
-
-            m_resources.push_back(resource);
-            std::cout << "Resource created successfully! URI= " << resource->getURI().c_str() << std::endl;
+                        &SimLightResource::onResourceModelChanged, this, std::placeholders::_1,
+                        std::placeholders::_2);
+
+            try
+            {
+                SimulatorResourceServerSP resource =
+                        SimulatorManager::getInstance()->createResource(configPath, callback);
+                m_resources.push_back(resource);
+                std::cout << "Resource created successfully! URI= " << resource->getURI().c_str()
+                        << std::endl;
+            }
+            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 deleteResource()
@@ -164,6 +178,7 @@ class SimLightResource
                         m_resources.erase(m_resources.begin() + (index - 1));
 
                     } break;
+
                 case 2:
                     {
                         std::string resourceType;
@@ -175,23 +190,37 @@ class SimLightResource
                             break;
                         }
 
-                        SimulatorManager::getInstance()->deleteResources(resourceType);
-                        std::cout << "Resources of type \"" << resourceType << "\"" << " deleted successfully! " <<
-                                  std::endl;
-                        std::vector<SimulatorResourceServerSP>::iterator ite = m_resources.begin();
-                        while (ite != m_resources.end())
+                        try
                         {
-                            if (!resourceType.compare((*ite)->getResourceType()))
+                            SimulatorManager::getInstance()->deleteResource(resourceType);
+                            std::cout << "Resources of type \"" << resourceType << "\"" <<
+                                    " deleted successfully! " << std::endl;
+                            std::vector<SimulatorResourceServerSP>::iterator ite = m_resources.begin();
+                            while (ite != m_resources.end())
                             {
-                                ite = m_resources.erase(ite);
-                                continue;
+                                if (!resourceType.compare((*ite)->getResourceType()))
+                                {
+                                    ite = m_resources.erase(ite);
+                                    continue;
+                                }
+                                ite++;
                             }
-                            ite++;
+                        }
+                        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:
                     {
-                        SimulatorManager::getInstance()->deleteResources();
+                        SimulatorManager::getInstance()->deleteResource();
                         std::cout << "All resources deleted successfully! " << std::endl;
                         m_resources.clear();
                     } break;
@@ -217,7 +246,8 @@ class SimLightResource
                 return;
             }
 
-            std::cout << "Setting the new values from allowed values list to power attribute" << std::endl;
+            std::cout << "Setting the new values from allowed values list to power attribute" <<
+                    std::endl;
             // Update all possible values from allowed values
             for (int index = 0; index < allowedValuesSize; index++)
             {
@@ -233,7 +263,7 @@ class SimLightResource
                 if ((index + 1) < allowedValuesSize)
                 {
                     int choice;
-                    std::cout << "Would you like to continue the attribute values changing process? (1/0): ";
+                    std::cout << "Would you like to change attribute value again ? (1/0): ";
                     std::cin >> choice;
                     if (0 == choice)
                         break;
@@ -262,7 +292,8 @@ class SimLightResource
                 return;
             }
 
-            std::cout << "Setting the new values from allowed values list to intensity attribute" << std::endl;
+            std::cout << "Setting the new values from allowed values list to intensity attribute"
+                    << std::endl;
             // Update all possible values from allowed values
             for (int index = min; index <= max; index++)
             {
@@ -278,7 +309,7 @@ class SimLightResource
                 if ((index + 1) <= max)
                 {
                     int choice;
-                    std::cout << "Would you like to continue the attribute values changing process? (1/0): ";
+                    std::cout << "Would you like to change attribute value again ? (1/0): ";
                     std::cin >> choice;
                     if (0 == choice)
                         break;
@@ -308,7 +339,8 @@ class SimLightResource
 
             // Attributes
             SimulatorResourceModel resModel = resource->getModel();
-            std::map<std::string, SimulatorResourceModel::Attribute> attributes = resModel.getAttributes();
+            std::map<std::string, SimulatorResourceModel::Attribute> attributes =
+                    resModel.getAttributes();
             std::cout << "##### Attributes [" << attributes.size() << "]" << std::endl;
             for (auto & attribute : attributes)
             {
@@ -320,7 +352,7 @@ class SimLightResource
                 std::cout << "max: " << max << std::endl;
                 std::cout << "allowed values : ";
                 std::cout << "[ ";
-                for (auto &value : (attribute.second).allowedValuesToString())
+                for (auto & value : (attribute.second).allowedValuesToString())
                     std::cout << value << " ";
                 std::cout << "]" << std::endl;
                 std::cout << "}" << std::endl << std::endl;
@@ -331,8 +363,8 @@ class SimLightResource
         void onUpdateAutomationCompleted(const std::string &uri,
                                          const int id)
         {
-            std::cout << "Update automation is completed [URI: " << uri.c_str() << "  AutomationID: " <<
-                      id << "] ###" << std::endl;
+            std::cout << "Update automation is completed [URI: " << uri.c_str()
+                    << "  AutomationID: " << id << "] ###" << std::endl;
         }
 
         void automateResourceUpdate()
@@ -351,14 +383,15 @@ class SimLightResource
             try
             {
                 int id = m_resources[index - 1]->startUpdateAutomation(type,
-                                    std::bind(&SimLightResource::onUpdateAutomationCompleted, this, std::placeholders::_1,
-                                    std::placeholders::_2));
+                         std::bind(&SimLightResource::onUpdateAutomationCompleted, this,
+                                 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;
+                std::cout << "SimulatorException occured [code : " << e.code() << " Detail: " <<
+                        e.what() << "]" << std::endl;
             }
         }
 
@@ -370,7 +403,8 @@ class SimLightResource
 
             SimulatorResourceServerSP resource = m_resources[index - 1];
             SimulatorResourceModel resModel = resource->getModel();
-            std::map<std::string, SimulatorResourceModel::Attribute> attributes = resModel.getAttributes();
+            std::map<std::string, SimulatorResourceModel::Attribute> attributes =
+                    resModel.getAttributes();
             int size = 0;
             for (auto & attribute : attributes)
             {
@@ -384,7 +418,8 @@ class SimLightResource
             }
 
             int choice = -1;
-            std::cout << "Select the attribute which you want to automate for updation: " << std::endl;
+            std::cout << "Select the attribute which you want to automate for updation: " <<
+                    std::endl;
             std::cin >> choice;
             if (choice < 0 || choice > size)
             {
@@ -411,19 +446,21 @@ class SimLightResource
             if (1 == choice)
                 type = AutomationType::RECURRENT;
 
-            std::cout << "Requesting attribute automation for " << attributeName.c_str() << std::endl;
+            std::cout << "Requesting attribute automation for " << attributeName.c_str() <<
+                    std::endl;
 
             try
             {
 
                 int id = resource->startUpdateAutomation(attributeName, type,
-                                    std::bind(&SimLightResource::onUpdateAutomationCompleted, this, std::placeholders::_1,
-                                    std::placeholders::_2));
+                         std::bind(&SimLightResource::onUpdateAutomationCompleted, this,
+                                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;
+                std::cout << "SimulatorException occured [Error: " << e.code() << " Details: " <<
+                        e.what() << "]" << std::endl;
             }
         }
 
@@ -446,7 +483,8 @@ class SimLightResource
 
             if (!ids.size())
             {
-                std::cout << "No automation operation is going on this resource right now!" << std::endl;
+                std::cout << "No automation operation is going on this resource right now!" <<
+                        std::endl;
                 return;
             }
 
@@ -459,12 +497,14 @@ class SimLightResource
             resource->stopUpdateAutomation(automationid);
         }
 
-        void onObserverChanged(const std::string &uri, ObservationStatus state, const ObserverInfo &observerInfo)
+        void onObserverChanged(const std::string &uri, ObservationStatus state,
+                               const ObserverInfo &observerInfo)
         {
             std::cout << "[callback] Observer notification received..." << uri.c_str() << std::endl;
             std::ostringstream out;
             out << "ID:  " << (int) observerInfo.id << std::endl;
-            out << " [address: " << observerInfo.address << " port: " << observerInfo.port << "]" << std::endl;
+            out << " [address: " << observerInfo.address << " port: " << observerInfo.port
+                    << "]" << std::endl;
             std::cout << out.str();
         }
 
@@ -486,7 +526,8 @@ class SimLightResource
             std::cout << "##### Number of Observers [" << observersList.size() << "]" << std::endl;
             for (auto & observerInfo : observersList)
             {
-                std::cout << " ID :  " << (int) observerInfo.id << " [address: " << observerInfo.address <<" port: " << observerInfo.port << "]" << std::endl;
+                std::cout << " ID :  " << (int) observerInfo.id << " [address: " <<
+                        observerInfo.address << " port: " << observerInfo.port << "]" << std::endl;
             }
             std::cout << "########################" << std::endl;
         }
@@ -529,7 +570,7 @@ void setLogger()
     {
         case 1:
             {
-                if (false == SimulatorManager::getInstance()->setDefaultConsoleLogger())
+                if (false == SimulatorManager::getInstance()->setConsoleLogger())
                     std::cout << "Failed to set the default console logger" << std::endl;
             } break;
         case 2:
@@ -537,7 +578,7 @@ void setLogger()
                 std::string filePath;
                 std::cout << "Enter the file path (without file name) : ";
                 std::cin >> filePath;
-                if (false == SimulatorManager::getInstance()->setDefaultFileLogger(filePath))
+                if (false == SimulatorManager::getInstance()->setFileLogger(filePath))
                     std::cout << "Failed to set default file logger" << std::endl;
             } break;
         case 3: SimulatorManager::getInstance()->setLogger(gAppLogger);
index ae802f3..fe2b6e1 100644 (file)
@@ -74,6 +74,7 @@ typedef enum
     SIMULATOR_UKNOWN_PROPERTY,
     SIMULATOR_TYPE_MISMATCH,
     SIMULATOR_BAD_VALUE,
+    SIMULATOR_BAD_OBJECT,
     /** Simulator specific error codes - START */
 
     SIMULATOR_ERROR = 255
index 69c2ee0..662ea3e 100644 (file)
@@ -113,7 +113,7 @@ class SimulatorManager
           *
           * NOTE: API would throw @InvalidArgsException when invalid arguments passed
           */
-        void deleteResources(const std::string &resourceType = "");
+        void deleteResource(const std::string &resourceType = "");
 
         /**
          * API for discovering all type of resources.
@@ -125,7 +125,7 @@ class SimulatorManager
          * NOTE: API would throw @InvalidArgsException when invalid arguments passed, and
          * @SimulatorException if any other error occured.
          */
-        void findResources(ResourceFindCallback callback);
+        void findResource(ResourceFindCallback callback);
 
         /**
          * API for discovering resources of a particular resource type.
@@ -138,7 +138,7 @@ class SimulatorManager
          * NOTE: API would throw @InvalidArgsException when invalid arguments passed, and
          * @SimulatorException if any other error occured.
          */
-        void findResources(const std::string &resourceType, ResourceFindCallback callback);
+        void findResource(const std::string &resourceType, ResourceFindCallback callback);
 
         /**
          * API for getting device information from remote device.
@@ -197,7 +197,7 @@ class SimulatorManager
          *         otherwise false.
          *
          */
-        bool setDefaultConsoleLogger();
+        bool setConsoleLogger();
 
         /**
          * API for setting file as logger target.
@@ -208,7 +208,7 @@ class SimulatorManager
          *         otherwise false.
          *
          */
-        bool setDefaultFileLogger(const std::string &path);
+        bool setFileLogger(const std::string &path);
 
     private:
         SimulatorManager();
index d4757e9..fcdfb6b 100644 (file)
@@ -41,9 +41,9 @@ class SimulatorResourceModel
 {
     public:
         SimulatorResourceModel() = default;
-        SimulatorResourceModel(SimulatorResourceModel &&) = default;
         SimulatorResourceModel(const SimulatorResourceModel &) = default;
         SimulatorResourceModel &operator=(const SimulatorResourceModel &) = default;
+        SimulatorResourceModel(SimulatorResourceModel &&) = default;
         SimulatorResourceModel &operator=(SimulatorResourceModel && ) = default;
 
         /**
@@ -60,6 +60,15 @@ class SimulatorResourceModel
                 std::string
                 > ValueVariant;
 
+                enum class ValueType
+                {
+                    UNKNOWN,
+                    INTEGER,
+                    DOUBLE,
+                    BOOLEAN,
+                    STRING
+                };
+
                 Attribute()
                 {
                     m_min = INT_MIN;
@@ -114,12 +123,9 @@ class SimulatorResourceModel
                 /**
                  * API to get attribute's value type.
                  *
-                 * @return type of value.
+                 * @return ValueType enum.
                  */
-                int getValueType() const
-                {
-                    return m_value.which();
-                }
+                ValueType getValueType() const;
 
                 /**
                  * API to set the attribute's value.
@@ -285,11 +291,7 @@ class SimulatorResourceModel
           * @param attr  - Attribute pointer
           *
           */
-        void addAttribute(Attribute &attr)
-        {
-            std::string attrName = attr.getName();
-            m_attributes[attrName] = Attribute(attr);
-        }
+        void addAttribute(const Attribute &attribute);
 
         /**
          * API to set range of attribute value.
index d72d1d0..715e8bb 100644 (file)
@@ -151,6 +151,9 @@ class SimulatorResourceServer
         void updateAttributeValue(const std::string &attrName, const T &value)
         {
             m_resModel.updateAttribute(attrName, value);
+
+            // Notify all the subscribers
+            notifyAll();
         }
 
         /**
index 20e7d6c..c7d225f 100644 (file)
@@ -99,13 +99,17 @@ public class ResourceManager {
     // Map with Server ID as key and the complete object as the value
     private Map<String, RemoteResource>               resourceMap;
     private List<RemoteResource>                      favoriteResources;
-    // TODO: Temporarily maintaining a list of favorite resource URIs.
+    // Maintaining a list of resource URIs for favorite resources feature.
     private List<String>                              favoriteURIList;
 
+    // Maintaining a list of observed resource URIs.
+    private List<String>                              observedResourceURIList;
+
     public ResourceManager() {
         resourceMap = new HashMap<String, RemoteResource>();
         favoriteResources = new ArrayList<RemoteResource>();
         favoriteURIList = new ArrayList<String>();
+        observedResourceURIList = new ArrayList<String>();
         findResourceUIListeners = new ArrayList<IFindResourceUIListener>();
         resourceSelectionChangedUIListeners = new ArrayList<IResourceSelectionChangedUIListener>();
         getUIListeners = new ArrayList<IGetUIListener>();
@@ -147,16 +151,23 @@ public class ResourceManager {
 
                         resource.setResource(resourceN);
 
-                        // Add the resource in local data structure
-                        addResourceDetails(resource);
-
-                        // Add resource to favorite list
                         String uri = resource.getResourceURI();
                         if (null != uri) {
+                            // Add resource to favorite list if it was in
+                            // favorites list during find/refresh operation.
                             if (favoriteURIList.contains(uri)) {
                                 addResourcetoFavorites(resource);
                             }
+                            // Add resource to observed resources list if it was
+                            // in observe list during find/refresh operation.
+                            if (observedResourceURIList.contains(uri)) {
+                                resource.setObserved(true);
+                            }
                         }
+
+                        // Add the resource in local data structure
+                        addResourceDetails(resource);
+
                         // Notify the UI listener
                         newResourceFoundNotification(resource);
 
@@ -557,6 +568,26 @@ public class ResourceManager {
         }
     }
 
+    public void addObservedResourceURI(String resourceURI) {
+        synchronized (observedResourceURIList) {
+            observedResourceURIList.add(resourceURI);
+        }
+    }
+
+    public void removeObservedResourceURI(String resourceURI) {
+        synchronized (observedResourceURIList) {
+            observedResourceURIList.remove(resourceURI);
+        }
+    }
+
+    public boolean isResourceObserved(String resourceURI) {
+        boolean observed = false;
+        synchronized (observedResourceURIList) {
+            observed = observedResourceURIList.contains(resourceURI);
+        }
+        return observed;
+    }
+
     public synchronized RemoteResource getCurrentResourceInSelection() {
         return currentResourceInSelection;
     }
@@ -689,7 +720,7 @@ public class ResourceManager {
                             }
                             /*
                              * Type baseType = attribute.getAttValBaseType();
-                             * 
+                             *
                              * if(baseType == Type.INT) { //int[] values =
                              * attributeN.getAllowedValues();
                              * attribute.setAllowedValues
@@ -926,7 +957,7 @@ public class ResourceManager {
         while (searchItr.hasNext()) {
             rType = searchItr.next();
             try {
-                SimulatorManager.findResources(rType, findResourceListener);
+                SimulatorManager.findResource(rType, findResourceListener);
                 result = true;
             } catch (SimulatorException e) {
                 Activator
@@ -1011,6 +1042,7 @@ public class ResourceManager {
                     if (exist) {
                         // Remove the resource
                         keyItr.remove();
+                        // Remove the resource from favorites list.
                         removeResourceFromFavorites(resource);
                     }
                 }
@@ -1346,8 +1378,11 @@ public class ResourceManager {
             return;
         }
         try {
-            resourceN.observe(SimulatorObserveType.OBSERVE, null,
+            resourceN.startObserve(SimulatorObserveType.OBSERVE, null,
                     observeListener);
+            // Add observed resource URI to show the proper status after every
+            // find/refresh operations.
+            addObservedResourceURI(resource.getResourceURI());
         } catch (SimulatorException e) {
             Activator
                     .getDefault()
@@ -1370,7 +1405,10 @@ public class ResourceManager {
             return;
         }
         try {
-            resourceN.cancelObserve();
+            resourceN.stopObserve();
+            // Remove observed resource URI to show the proper status after
+            // every find/refresh operations.
+            removeObservedResourceURI(resource.getResourceURI());
         } catch (SimulatorException e) {
             Activator
                     .getDefault()
@@ -1464,7 +1502,7 @@ public class ResourceManager {
             return;
         }
         try {
-            resourceN.configureRAMLPath(configFilePath);
+            resourceN.setConfigInfo(configFilePath);
         } catch (SimulatorException e) {
             Activator
                     .getDefault()
index f91a752..255d9f1 100644 (file)
@@ -32,9 +32,9 @@ import oic.simulator.clientcontroller.remoteresource.PutPostAttributeModel;
 import oic.simulator.clientcontroller.remoteresource.RemoteResource;
 import oic.simulator.clientcontroller.remoteresource.RemoteResourceAttribute;
 import oic.simulator.clientcontroller.utils.Constants;
-import oic.simulator.clientcontroller.view.dialogs.VerificationDialog;
 import oic.simulator.clientcontroller.view.dialogs.PostRequestDialog;
 import oic.simulator.clientcontroller.view.dialogs.PutRequestDialog;
+import oic.simulator.clientcontroller.view.dialogs.VerificationDialog;
 
 import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.viewers.IStructuredContentProvider;
@@ -45,10 +45,6 @@ import org.eclipse.jface.viewers.Viewer;
 import org.eclipse.jface.viewers.ViewerCell;
 import org.eclipse.jface.window.Window;
 import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.CTabFolder;
-import org.eclipse.swt.custom.CTabFolder2Adapter;
-import org.eclipse.swt.custom.CTabFolderEvent;
-import org.eclipse.swt.custom.CTabItem;
 import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.graphics.Color;
@@ -59,7 +55,6 @@ import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Group;
 import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.Text;
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.part.ViewPart;
 
@@ -78,12 +73,6 @@ public class AttributeView extends ViewPart {
     private Button                              automateButton;
     private Button                              observeResButton;
 
-    private CTabFolder                          payloadFolder;
-    private CTabItem                            requestPayloadTab;
-    private CTabItem                            responsePayloadTab;
-    private Text                                requestPayloadTxt;
-    private Text                                responsePayloadTxt;
-
     private final String[]                      attTblHeaders  = {
             "Attribute Name", "Attribute Value"               };
     private final Integer[]                     attTblColWidth = { 200, 200 };
@@ -403,8 +392,10 @@ public class AttributeView extends ViewPart {
         gd = new GridData();
         gd.grabExcessHorizontalSpace = true;
         gd.horizontalAlignment = SWT.FILL;
+        gd.grabExcessVerticalSpace = true;
+        gd.verticalAlignment = SWT.FILL;
         gd.horizontalSpan = 2;
-        gd.heightHint = 175;
+        // gd.heightHint = 175;
         attGroup.setLayoutData(gd);
         attGroup.setText("Attributes");
         attGroup.setBackground(color);
@@ -415,8 +406,6 @@ public class AttributeView extends ViewPart {
 
         setupResourceLevelOpsArea(parent);
 
-        setupTabArea(parent);
-
         setUIListeners();
 
         addManagerListeners();
@@ -496,65 +485,6 @@ public class AttributeView extends ViewPart {
         observeResButton.setLayoutData(gd);
     }
 
-    private void setupTabArea(final Composite parent) {
-        GridData gd;
-        payloadFolder = new CTabFolder(parent, SWT.BORDER);
-        gd = new GridData(SWT.FILL, SWT.FILL, true, true);
-        gd.horizontalSpan = 2;
-        payloadFolder.setLayoutData(gd);
-        payloadFolder.setSimple(false);
-        payloadFolder.setUnselectedCloseVisible(false);
-        payloadFolder.setUnselectedImageVisible(false);
-        // payloadFolder.setMaximizeVisible(true);
-        // payloadFolder.setMinimizeVisible(true);
-
-        requestPayloadTab = new CTabItem(payloadFolder, SWT.NULL);
-        requestPayloadTab.setText("Request Payload");
-
-        requestPayloadTxt = new Text(payloadFolder, SWT.MULTI | SWT.V_SCROLL
-                | SWT.H_SCROLL | SWT.READ_ONLY | SWT.WRAP);
-        requestPayloadTab.setControl(requestPayloadTxt);
-
-        responsePayloadTab = new CTabItem(payloadFolder, SWT.NULL);
-        responsePayloadTab.setText("Response Payload");
-
-        responsePayloadTxt = new Text(payloadFolder, SWT.MULTI | SWT.V_SCROLL
-                | SWT.H_SCROLL | SWT.READ_ONLY | SWT.WRAP);
-        responsePayloadTab.setControl(responsePayloadTxt);
-
-        // Add Listeners
-
-        payloadFolder.addCTabFolder2Listener(new CTabFolder2Adapter() {
-            @Override
-            public void minimize(CTabFolderEvent event) {
-                payloadFolder.setMinimized(true);
-                GridData gd = new GridData(SWT.FILL, SWT.FILL, true, false);
-                gd.horizontalSpan = 2;
-                payloadFolder.setLayoutData(gd);
-                parent.layout(true);
-            }
-
-            @Override
-            public void maximize(CTabFolderEvent event) {
-                payloadFolder.setMaximized(true);
-                GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
-                gd.horizontalSpan = 2;
-                payloadFolder.setLayoutData(gd);
-                parent.layout(true);
-            }
-
-            @Override
-            public void restore(CTabFolderEvent event) {
-                payloadFolder.setMaximized(false);
-                payloadFolder.setMinimized(false);
-                GridData gd = new GridData(SWT.FILL, SWT.FILL, true, false);
-                gd.horizontalSpan = 2;
-                payloadFolder.setLayoutData(gd);
-                parent.layout(true);
-            }
-        });
-    }
-
     private void setupAttributeTable(Group attGroup) {
         attTblViewer = new TableViewer(attGroup, SWT.SINGLE | SWT.H_SCROLL
                 | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
index 08a7037..d52a1e2 100644 (file)
@@ -69,6 +69,8 @@ public class ResourceManager {
 
     private Map<String, ArrayList<String>>              orderedResourceUriMap;
 
+    private Map<String, String>                         displayNameMap;
+
     private StandardConfiguration                       stdConfig;
 
     private SimulatorResource                           currentResourceInSelection;
@@ -96,6 +98,7 @@ public class ResourceManager {
     public ResourceManager() {
         resourceMap = new HashMap<String, Map<String, SimulatorResource>>();
         orderedResourceUriMap = new HashMap<String, ArrayList<String>>();
+        displayNameMap = new HashMap<String, String>();
         stdConfig = new StandardConfiguration();
 
         resourceListChangedUIListeners = new ArrayList<IResourceListChangedUIListener>();
@@ -466,6 +469,34 @@ public class ResourceManager {
         return result;
     }
 
+    public void addResourceDisplayName(String displayName, String completeURI) {
+        synchronized (displayNameMap) {
+            displayNameMap.put(displayName, completeURI);
+        }
+    }
+
+    public void removeResourceDisplayName(String displayName) {
+        synchronized (displayNameMap) {
+            displayNameMap.remove(displayName);
+        }
+    }
+
+    public boolean isDisplayName(String displayName) {
+        boolean exist = false;
+        synchronized (displayNameMap) {
+            exist = displayNameMap.containsKey(displayName);
+        }
+        return exist;
+    }
+
+    public String getCompleteUriFromDisplayName(String displayName) {
+        String completeURI = null;
+        synchronized (displayNameMap) {
+            completeURI = displayNameMap.get(displayName);
+        }
+        return completeURI;
+    }
+
     public void createResource(final String configFilePath) {
         new Thread() {
             @Override
@@ -488,12 +519,26 @@ public class ResourceManager {
                 SimulatorResource simulatorResource;
                 simulatorResource = fetchResourceData(resourceServerN);
                 if (null != simulatorResource) {
+                    String uri = simulatorResource.getResourceURI();
                     addResourceToMap(simulatorResource);
                     addResourceUriToOrderedMap(
-                            simulatorResource.getResourceType(),
-                            simulatorResource.getResourceURI());
+                            simulatorResource.getResourceType(), uri);
                     resourceCreatedUINotification();
 
+                    // Form the display URI
+                    String displayName = Utility.uriToDisplayName(uri);
+                    if (null != displayName) {
+                        addResourceDisplayName(displayName, uri);
+                    } else {
+                        Activator
+                                .getDefault()
+                                .getLogManager()
+                                .log(Level.ERROR.ordinal(),
+                                        new Date(),
+                                        "Converting the URI to display format for "
+                                                + uri + "failed!");
+                    }
+
                     // Set the observer for the created resource
                     try {
                         resourceServerN.setObserverCallback(observer);
@@ -543,6 +588,7 @@ public class ResourceManager {
                 resourceTypeMap = new HashMap<String, SimulatorResource>();
                 SimulatorResource resource;
                 String uri;
+                String displayName;
                 for (SimulatorResourceServer resourceServerN : simulatorResourceServers) {
                     resource = fetchResourceData(resourceServerN);
                     if (null != resource) {
@@ -550,6 +596,20 @@ public class ResourceManager {
                         resourceTypeMap.put(uri, resource);
                         addResourceUriToOrderedMap(resource.getResourceType(),
                                 uri);
+
+                        // Form the display URI
+                        displayName = Utility.uriToDisplayName(uri);
+                        if (null != displayName) {
+                            addResourceDisplayName(displayName, uri);
+                        } else {
+                            Activator
+                                    .getDefault()
+                                    .getLogManager()
+                                    .log(Level.ERROR.ordinal(),
+                                            new Date(),
+                                            "Converting the URI to display format for "
+                                                    + uri + "failed!");
+                        }
                     }
                     // Set the observer for the created resource
                     try {
@@ -911,6 +971,12 @@ public class ResourceManager {
                 }
             }
         }
+        // Remove the display name from the map
+        if (null != resourceURI) {
+            String dispName = Utility.uriToDisplayName(resourceURI);
+            if (null != dispName)
+                removeResourceDisplayName(dispName);
+        }
     }
 
     private void resourceCreatedUINotification() {
index 890c076..b444073 100644 (file)
@@ -59,7 +59,6 @@ public class Constants {
     public static final String         START_RESOURCE_AUTOMATION        = "Start Automation";
     public static final String         STOP_RESOURCE_AUTOMATION         = "Stop Automation";
 
-    public static final int            PROPER_RESOURCE_URI_TOKEN_COUNT  = 6;
     public static final int            DISPLAY_RESOURCE_URI_TOKEN_COUNT = 2;
 
     public static final AutomationType DEFAULT_AUTOMATION_TYPE          = AutomationType.NORMAL;
index 06f6ebd..4c053d3 100644 (file)
@@ -30,24 +30,9 @@ public class Utility {
         String result = null;
         if (null != uri) {
             String tokens[] = uri.split(Constants.FORWARD_SLASH);
-            if (Constants.PROPER_RESOURCE_URI_TOKEN_COUNT == tokens.length) {
-                // Proper URI
-                result = tokens[3] + Constants.UNDERSCORE + tokens[5];
-            }
-        }
-        return result;
-    }
-
-    public static String displayNameToUri(String displayName) {
-        String result = null;
-        if (null != displayName) {
-            String tokens[] = displayName.split(Constants.UNDERSCORE);
-            if (Constants.DISPLAY_RESOURCE_URI_TOKEN_COUNT == tokens.length) {
-                // Proper Display Name
-                result = Constants.OIC_PREFIX + Constants.FORWARD_SLASH
-                        + tokens[0] + Constants.FORWARD_SLASH
-                        + Constants.SIMULATOR + Constants.FORWARD_SLASH
-                        + tokens[1];
+            if (null != tokens && tokens.length > 2) {
+                result = tokens[tokens.length - 3] + Constants.UNDERSCORE
+                        + tokens[tokens.length - 1];
             }
         }
         return result;
@@ -85,17 +70,6 @@ public class Utility {
         return fileName;
     }
 
-    public static boolean isUriComplete(String uri) {
-        boolean uriComplete = false;
-        if (null != uri) {
-            String tokens[] = uri.split(Constants.FORWARD_SLASH);
-            if (Constants.PROPER_RESOURCE_URI_TOKEN_COUNT == tokens.length) {
-                uriComplete = true;
-            }
-        }
-        return uriComplete;
-    }
-
     public static String getAutomationStatus(boolean status) {
         if (status) {
             return Constants.ENABLED;
index fb56e5c..a9abf80 100644 (file)
@@ -248,10 +248,15 @@ public class ResourceManagerView extends ViewPart {
                             if (deleteCategory == DeleteCategory.BY_URI) {
                                 String uri = deleteWizard.getDeleteCandidate();
                                 if (null != uri) {
-                                    boolean completeURI = Utility
-                                            .isUriComplete(uri);
-                                    if (!completeURI) {
-                                        uri = Utility.displayNameToUri(uri);
+                                    boolean dispName = Activator.getDefault()
+                                            .getResourceManager()
+                                            .isDisplayName(uri);
+                                    if (dispName) {
+                                        uri = Activator
+                                                .getDefault()
+                                                .getResourceManager()
+                                                .getCompleteUriFromDisplayName(
+                                                        uri);
                                     }
                                     resourceManager.deleteResourceByURI(uri);
                                 }
@@ -279,8 +284,8 @@ public class ResourceManagerView extends ViewPart {
                         TreeItem selectedItem = (TreeItem) e.item;
                         if (null != selectedItem) {
                             String selectedItemText = selectedItem.getText();
-                            selectedItemText = Utility
-                                    .displayNameToUri(selectedItemText);
+                            selectedItemText = resourceManager
+                                    .getCompleteUriFromDisplayName(selectedItemText);
                             // Propagate this selection change event to manager
                             resourceManager
                                     .resourceSelectionChanged(selectedItemText);
@@ -310,8 +315,9 @@ public class ResourceManagerView extends ViewPart {
                                 // automation if any attribute level
                                 // automation is in progress for the
                                 // selected resource
-                                boolean started = resourceManager.isAttributeAutomationStarted(Utility
-                                        .displayNameToUri(selectedItem));
+                                boolean started = resourceManager
+                                        .isAttributeAutomationStarted(resourceManager
+                                                .getCompleteUriFromDisplayName(selectedItem));
                                 if (started) {
                                     MessageDialog
                                             .openInformation(
@@ -322,8 +328,8 @@ public class ResourceManagerView extends ViewPart {
                                                             + "running attribute level automations to start resource level automation.");
                                 } else {
                                     boolean status = resourceManager
-                                            .startResourceAutomationUIRequest(Utility
-                                                    .displayNameToUri(selectedItem));
+                                            .startResourceAutomationUIRequest(resourceManager
+                                                    .getCompleteUriFromDisplayName(selectedItem));
                                     String statusMsg = status ? "Automation started successfully!!!"
                                             : "Automation request failed!!!";
                                     MessageDialog.openInformation(Display
@@ -339,8 +345,8 @@ public class ResourceManagerView extends ViewPart {
                             @Override
                             public void widgetSelected(SelectionEvent e) {
                                 boolean status = resourceManager
-                                        .stopResourceAutomationUIRequest(Utility
-                                                .displayNameToUri(selectedItem));
+                                        .stopResourceAutomationUIRequest(resourceManager
+                                                .getCompleteUriFromDisplayName(selectedItem));
                                 String statusMsg = status ? "Automation stop requested!!!"
                                         : "Automation stop failed.";
                                 MessageDialog.openInformation(Display
@@ -350,9 +356,8 @@ public class ResourceManagerView extends ViewPart {
                         });
 
                         // Set the initial visibility of menu items
-                        boolean status = resourceManager
-                                .isResourceAutomationStarted(Utility
-                                        .displayNameToUri(selectedItem));
+                        boolean status = resourceManager.isResourceAutomationStarted(resourceManager
+                                .getCompleteUriFromDisplayName(selectedItem));
                         startItem.setEnabled(!status);
                         stopItem.setEnabled(status);
                     }
index 980b881..4d079eb 100644 (file)
@@ -20,7 +20,6 @@ import java.net.URL;
 
 import oic.simulator.serviceprovider.Activator;
 import oic.simulator.serviceprovider.resource.DeleteCategory;
-import oic.simulator.serviceprovider.utils.Utility;
 
 import org.eclipse.core.runtime.FileLocator;
 import org.eclipse.core.runtime.IPath;
@@ -62,9 +61,11 @@ public class DeleteResourceWizard extends Wizard {
             // Check whether the uri is in full form or short form
             // If it is in short form, expand it to its full form.
             String uri = page.getDeleteCandidate();
-            boolean uriComplete = Utility.isUriComplete(uri);
-            if (!uriComplete) {
-                uri = Utility.displayNameToUri(uri);
+            boolean dispName = Activator.getDefault().getResourceManager()
+                    .isDisplayName(uri);
+            if (dispName) {
+                uri = Activator.getDefault().getResourceManager()
+                        .getCompleteUriFromDisplayName(uri);
             }
             boolean exist = Activator.getDefault().getResourceManager()
                     .isResourceExist(uri);
index b8db777..0203afa 100644 (file)
@@ -165,7 +165,7 @@ bool JResourceAttributeConverter::setType(JNIEnv *env, jobject &jattributeObj)
         return false;
     }
 
-    int type = m_attribute.getValueType();
+    int type = static_cast<int>(m_attribute.getValueType());
     jobject jtype = env->CallStaticObjectMethod(clsType, midGetType, type);
     if (env->ExceptionCheck())
     {
index bc32389..0cb432e 100644 (file)
@@ -166,7 +166,6 @@ class JNIFoundResourceListener
             }
 
             JniSimulatorRemoteResource *jniSimulatorResource = new JniSimulatorRemoteResource(resource);
-
             if (!jniSimulatorResource)
             {
                 releaseEnv();
@@ -213,6 +212,7 @@ class JNIFoundResourceListener
             env->CallVoidMethod(foundResourceListener, foundResourceMId, simulatorResource);
             if ((env)->ExceptionCheck())
             {
+                delete jniSimulatorResource;
                 releaseEnv();
                 return;
             }
@@ -262,12 +262,11 @@ void onResourceModelChange(jweak jlistenerRef, const std::string &uri,
     }
 
     jobject jModel = JSimulatorResourceModel::toJava(env, reinterpret_cast<jlong>(jniModel));
-
     jstring jUri = env->NewStringUTF(uri.c_str());
-
     env->CallVoidMethod(modelChangeListener, foundModelChangeMId, jUri, jModel);
     if ((env)->ExceptionCheck())
     {
+        delete jniModel;
         releaseEnv();
         return;
     }
@@ -285,14 +284,14 @@ Java_org_oic_simulator_SimulatorManagerNativeInterface_createResource
     if (!configPath)
     {
         throwInvalidArgsException(env, SIMULATOR_INVALID_PARAM,
-                                  "Resource creation failed. Configuration file path is empty!");
+                                  "Configuration file path is empty!");
         return nullptr;
     }
 
     if (!listener)
     {
         throwInvalidArgsException(env, SIMULATOR_INVALID_CALLBACK,
-                                  "Resource creation failed. Resource model change callback not set!");
+                                  "Resource model change callback not set!");
         return nullptr;
     }
 
@@ -350,14 +349,14 @@ Java_org_oic_simulator_SimulatorManagerNativeInterface_createResources
     if (!configPath)
     {
         throwInvalidArgsException(env, SIMULATOR_INVALID_PARAM,
-                                  "Resource(s) creation failed. Configuration file path is empty!");
+                                  "Configuration file path is empty!");
         return nullptr;
     }
 
     if (!listener)
     {
         throwInvalidArgsException(env, SIMULATOR_INVALID_CALLBACK,
-                                  "Resource(s) creation failed. Resource model change callback not set!");
+                                  "Resource model change callback not set!");
         return nullptr;
     }
 
@@ -417,7 +416,7 @@ Java_org_oic_simulator_SimulatorManagerNativeInterface_deleteResource
     if (!jResource)
     {
         throwInvalidArgsException(env, SIMULATOR_INVALID_PARAM,
-                                  "Deletion failed. No resource has been passed!");
+                                  "No resource has been passed!");
         return;
     }
 
@@ -425,8 +424,8 @@ Java_org_oic_simulator_SimulatorManagerNativeInterface_deleteResource
         JniSimulatorResource::getJniSimulatorResourceSP(env, jResource);
     if (!resource)
     {
-        throwInvalidArgsException(env, SIMULATOR_NO_RESOURCE,
-                                  "Deletion failed. Native resource not found!");
+        throwSimulatorException(env, SIMULATOR_BAD_OBJECT,
+                                "Simulator resource not found!");
         return;
     }
 
@@ -458,12 +457,7 @@ Java_org_oic_simulator_SimulatorManagerNativeInterface_deleteResources
 
     try
     {
-        SimulatorManager::getInstance()->deleteResources(type);
-    }
-    catch (InvalidArgsException &e)
-    {
-        throwInvalidArgsException(env, e.code(), e.what());
-        return;
+        SimulatorManager::getInstance()->deleteResource(type);
     }
     catch (...)
     {
@@ -477,34 +471,14 @@ Java_org_oic_simulator_SimulatorManagerNativeInterface_deleteResources
 
 JNIEXPORT void JNICALL
 Java_org_oic_simulator_SimulatorManagerNativeInterface_findResource
-(JNIEnv *env, jobject object, jobject listener)
+(JNIEnv *env, jobject object, jstring jResourceType, jobject jListener)
 {
-    JNIFoundResourceListener *resourceListener = new JNIFoundResourceListener();
-    resourceListener->setJavaFoundResourceListener(env, listener);
-    try
-    {
-        SimulatorManager::getInstance()->findResources(
-            std::bind(&JNIFoundResourceListener::onFoundResource,
-                      resourceListener, std::placeholders::_1));
-    }
-    catch (InvalidArgsException &e)
-    {
-        throwInvalidArgsException(env, e.code(), e.what());
-    }
-    catch (SimulatorException &e)
-    {
-        throwSimulatorException(env, e.code(), e.what());
-    }
-    catch (...)
+    if (!jListener)
     {
-        throwSimulatorException(env, SIMULATOR_ERROR, "Unknown Exception");
+        throwInvalidArgsException(env, SIMULATOR_INVALID_CALLBACK, "Invalid callback!");
+        return;
     }
-}
 
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_SimulatorManagerNativeInterface_findResources
-(JNIEnv *env, jobject object, jstring jResourceType, jobject listener)
-{
     const char *typeCStr = NULL;
     std::string resourceType;
     if (jResourceType)
@@ -514,13 +488,23 @@ Java_org_oic_simulator_SimulatorManagerNativeInterface_findResources
     }
 
     JNIFoundResourceListener *resourceListener = new JNIFoundResourceListener();
-    resourceListener->setJavaFoundResourceListener(env, listener);
+    resourceListener->setJavaFoundResourceListener(env, jListener);
 
     try
     {
-        SimulatorManager::getInstance()->findResources(resourceType,
+        if (!jResourceType)
+        {
+            SimulatorManager::getInstance()->findResource(
                 std::bind(&JNIFoundResourceListener::onFoundResource,
                           resourceListener, std::placeholders::_1));
+        }
+        else
+        {
+            SimulatorManager::getInstance()->findResource(resourceType,
+                    std::bind(&JNIFoundResourceListener::onFoundResource,
+                              resourceListener, std::placeholders::_1));
+        }
+
     }
     catch (InvalidArgsException &e)
     {
@@ -547,8 +531,8 @@ JNIEXPORT void JNICALL
 Java_org_oic_simulator_SimulatorManagerNativeInterface_setLogger
 (JNIEnv *env, jclass object, jobject logger)
 {
-    static std::shared_ptr<ILogger> target(new JNILogger());
-    dynamic_cast<JNILogger *>(target.get())->setJavaLogger(env, logger);
+    static std::shared_ptr<JNILogger> target(new JNILogger());
+    target->setJavaLogger(env, logger);
     SimulatorManager::getInstance()->setLogger(target);
 }
 
index 52d5ada..2a71031 100644 (file)
@@ -45,10 +45,6 @@ Java_org_oic_simulator_SimulatorManagerNativeInterface_deleteResources
 
 JNIEXPORT void JNICALL
 Java_org_oic_simulator_SimulatorManagerNativeInterface_findResource
-(JNIEnv *env, jobject interfaceObject, jobject jListener);
-
-JNIEXPORT void JNICALL
-Java_org_oic_simulator_SimulatorManagerNativeInterface_findResources
 (JNIEnv *env, jobject interfaceObject, jstring jResourceType, jobject jListener);
 
 JNIEXPORT void JNICALL
index 725966a..0b41841 100644 (file)
@@ -91,18 +91,20 @@ class JNIOnObserveListener
                     return;
                 }
 
-                jobject jRepresentation = JSimulatorResourceModel::toJava(env, reinterpret_cast<jlong>(jniModel));
-
+                jobject jRepresentation = JSimulatorResourceModel::toJava(env,
+                        reinterpret_cast<jlong>(jniModel));
                 if (!jRepresentation)
                 {
+                    delete jniModel;
                     releaseEnv();
                     return;
                 }
 
                 jmethodID midL = env->GetMethodID(onObserveCls, "onObserveCompleted",
-                                                  "(Ljava/lang/String;Lorg/oic/simulator/SimulatorResourceModel;I)V");
+                        "(Ljava/lang/String;Lorg/oic/simulator/SimulatorResourceModel;I)V");
                 if (!midL)
                 {
+                    delete jniModel;
                     releaseEnv();
                     return;
                 }
@@ -113,6 +115,7 @@ class JNIOnObserveListener
                                     static_cast<jint>(seqNumber));
                 if (env->ExceptionCheck())
                 {
+                    delete jniModel;
                     releaseEnv();
                 }
             }
@@ -173,9 +176,9 @@ class JNIOnGetListener
                 }
 
                 jobject jRepresentation = JSimulatorResourceModel::toJava(env, reinterpret_cast<jlong>(jniModel));
-
                 if (!jRepresentation)
                 {
+                    delete jniModel;
                     releaseEnv();
                     return;
                 }
@@ -184,15 +187,16 @@ class JNIOnGetListener
                                                   "(Ljava/lang/String;Lorg/oic/simulator/SimulatorResourceModel;)V");
                 if (!midL)
                 {
+                    delete jniModel;
                     releaseEnv();
                     return;
                 }
 
                 jstring jUid = env->NewStringUTF(uId.c_str());
-
                 env->CallVoidMethod(onGetListener, midL, jUid, jRepresentation);
                 if (env->ExceptionCheck())
                 {
+                    delete jniModel;
                     releaseEnv();
                 }
             }
@@ -252,27 +256,29 @@ class JNIOnPutListener
                     return;
                 }
 
-                jobject jRepresentation = JSimulatorResourceModel::toJava(env, reinterpret_cast<jlong>(jniModel));
-
+                jobject jRepresentation = JSimulatorResourceModel::toJava(env,
+                        reinterpret_cast<jlong>(jniModel));
                 if (!jRepresentation)
                 {
+                    delete jniModel;
                     releaseEnv();
                     return;
                 }
 
                 jmethodID midL = env->GetMethodID(onGetCls, "onPutCompleted",
-                                                  "(Ljava/lang/String;Lorg/oic/simulator/SimulatorResourceModel;)V");
+                            "(Ljava/lang/String;Lorg/oic/simulator/SimulatorResourceModel;)V");
                 if (!midL)
                 {
+                    delete jniModel;
                     releaseEnv();
                     return;
                 }
 
                 jstring jUid = env->NewStringUTF(uId.c_str());
-
                 env->CallVoidMethod(onPutListener, midL, jUid, jRepresentation);
                 if (env->ExceptionCheck())
                 {
+                    delete jniModel;
                     releaseEnv();
                 }
             }
@@ -332,18 +338,20 @@ class JNIOnPostListener
                     return;
                 }
 
-                jobject jRepresentation = JSimulatorResourceModel::toJava(env, reinterpret_cast<jlong>(jniModel));
-
+                jobject jRepresentation = JSimulatorResourceModel::toJava(env,
+                        reinterpret_cast<jlong>(jniModel));
                 if (!jRepresentation)
                 {
+                    delete jniModel;
                     releaseEnv();
                     return;
                 }
 
                 jmethodID midL = env->GetMethodID(onGetCls, "onPostCompleted",
-                                                  "(Ljava/lang/String;Lorg/oic/simulator/SimulatorResourceModel;)V");
+                        "(Ljava/lang/String;Lorg/oic/simulator/SimulatorResourceModel;)V");
                 if (!midL)
                 {
+                    delete jniModel;
                     releaseEnv();
                     return;
                 }
@@ -353,6 +361,7 @@ class JNIOnPostListener
                 env->CallVoidMethod(onPostListener, midL, jUid, jRepresentation);
                 if (env->ExceptionCheck())
                 {
+                    delete jniModel;
                     releaseEnv();
                 }
             }
@@ -429,7 +438,7 @@ class JNIOnVerificationListener
 
 
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_observe
+Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_startObserve
 (JNIEnv *env, jobject thiz, jint observeType, jobject jQueryParamsMap, jobject jListener)
 {
     if (!jListener)
@@ -440,9 +449,9 @@ Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_observe
 
     SimulatorRemoteResourceSP resource = JniSimulatorRemoteResource::getResourceHandle(env,
                                          thiz);
-    if (nullptr == resource)
+    if (!resource)
     {
-        throwInvalidArgsException(env, SIMULATOR_NO_RESOURCE, "No resource!");
+        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
         return;
     }
 
@@ -480,14 +489,14 @@ Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_observe
 }
 
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_cancelObserve
+Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_stopObserve
 (JNIEnv *env, jobject thiz)
 {
     SimulatorRemoteResourceSP resource = JniSimulatorRemoteResource::getResourceHandle(env,
                                          thiz);
-    if (nullptr == resource)
+    if (!resource)
     {
-        throwInvalidArgsException(env, SIMULATOR_NO_RESOURCE, "No resource!");
+        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
         return;
     }
 
@@ -518,9 +527,9 @@ Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_get
 
     SimulatorRemoteResourceSP resource = JniSimulatorRemoteResource::getResourceHandle(env,
                                          thiz);
-    if (nullptr == resource)
+    if (!resource)
     {
-        throwInvalidArgsException(env, SIMULATOR_NO_RESOURCE, "No resource!");
+        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
         return;
     }
 
@@ -588,9 +597,9 @@ Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_put
 
     SimulatorRemoteResourceSP resource = JniSimulatorRemoteResource::getResourceHandle(env,
                                          thiz);
-    if (nullptr == resource)
+    if (!resource)
     {
-        throwInvalidArgsException(env, SIMULATOR_NO_RESOURCE, "No resource!");
+        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
         return;
     }
 
@@ -662,9 +671,9 @@ Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_post
 
     SimulatorRemoteResourceSP resource = JniSimulatorRemoteResource::getResourceHandle(env,
                                          thiz);
-    if (nullptr == resource)
+    if (!resource)
     {
-        throwInvalidArgsException(env, SIMULATOR_NO_RESOURCE, "No resource!");
+        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
         return;
     }
 
@@ -724,14 +733,21 @@ Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_post
 }
 
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_configureRAMLPath
+Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_setConfigInfo
 (JNIEnv *env, jobject thiz, jstring jConfigPath)
 {
+    if (!jConfigPath)
+    {
+        throwInvalidArgsException(env, SIMULATOR_INVALID_PARAM,
+                                  "Configuration file path is empty!");
+        return;
+    }
+
     SimulatorRemoteResourceSP resource = JniSimulatorRemoteResource::getResourceHandle(env,
                                          thiz);
-    if (nullptr == resource)
+    if (!resource)
     {
-        throwInvalidArgsException(env, SIMULATOR_NO_RESOURCE, "No resource!");
+        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
         return;
     }
 
@@ -769,17 +785,16 @@ Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_startVerificatio
 {
     if (!jListener)
     {
-        throwInvalidArgsException(env, SIMULATOR_NO_RESOURCE, "No resource!");
-        return -1;
+        throwInvalidArgsException(env, SIMULATOR_INVALID_CALLBACK, "Invalid callback!");
+        return SIMULATOR_INVALID_CALLBACK;
     }
 
-
     SimulatorRemoteResourceSP resource = JniSimulatorRemoteResource::getResourceHandle(env,
                                          thiz);
-    if (nullptr == resource)
+    if (!resource)
     {
-        throwInvalidArgsException(env, SIMULATOR_NO_RESOURCE, "No resource!");
-        return -1;
+        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
+        return SIMULATOR_BAD_OBJECT;
     }
 
     // Convert RequestType
@@ -850,9 +865,9 @@ Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_stopVerification
 {
     SimulatorRemoteResourceSP resource = JniSimulatorRemoteResource::getResourceHandle(env,
                                          thiz);
-    if (nullptr == resource)
+    if (!resource)
     {
-        throwInvalidArgsException(env, SIMULATOR_NO_RESOURCE, "No resource!");
+        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
         return;
     }
 
index bcca0bb..2fd681a 100644 (file)
@@ -39,11 +39,11 @@ extern "C" {
 #endif
 
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_observe
+Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_startObserve
 (JNIEnv *env, jobject thiz, jint observeType, jobject jQueryParamsMap, jobject jListener);
 
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_cancelObserve
+Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_stopObserve
 (JNIEnv *env, jobject thiz);
 
 JNIEXPORT void JNICALL
@@ -62,7 +62,7 @@ Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_post
  jobject jRepresentation, jobject jQueryParamsMap, jobject jListener);
 
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_configureRAMLPath
+Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_setConfigInfo
 (JNIEnv *env, jobject thiz, jstring jConfigPath);
 
 JNIEXPORT jint JNICALL
index 9872a84..de2952b 100644 (file)
@@ -171,7 +171,6 @@ jobject convertHashMapToJavaMap(JNIEnv *env,
 {
     if (observersList.empty())
     {
-        std::cout << "observersList Map is empty";
         return NULL;
     }
 
index a1f86ad..9d67689 100644 (file)
@@ -22,6 +22,7 @@
 #include "simulator_common_jni.h"
 #include "resource_attributes_jni.h"
 #include "simulator_error_codes.h"
+#include "simulator_jni_utils.h"
 
 using namespace std;
 
@@ -41,7 +42,6 @@ bool JSimulatorResourceModel::getResourceModel(JNIEnv *env, jobject thiz,
     JSimulatorResourceModel *resource = GetHandle<JSimulatorResourceModel>(env, thiz);
     if (env->ExceptionCheck())
     {
-        cout << "Exception while converting the nativeHandle to JSimulatorResourceModel" << endl;
         return false;
     }
 
@@ -118,7 +118,8 @@ Java_org_oic_simulator_SimulatorResourceModel_size
     bool result = JSimulatorResourceModel::getResourceModel(env, thiz, resourceModel);
     if (!result)
     {
-        return SIMULATOR_ERROR;
+        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "Resource model not found!");
+        return SIMULATOR_BAD_OBJECT;
     }
 
     return resourceModel.size();
@@ -132,7 +133,8 @@ Java_org_oic_simulator_SimulatorResourceModel_getAttributes
     bool result = JSimulatorResourceModel::getResourceModel(env, thiz, resourceModel);
     if (!result)
     {
-        return NULL;
+        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "Resource model not found!");
+        return nullptr;
     }
 
     map<string, SimulatorResourceModel::Attribute> attributesMap = resourceModel.getAttributes();
@@ -142,7 +144,8 @@ Java_org_oic_simulator_SimulatorResourceModel_getAttributes
     jHashMap = createHashMap(env);
     if (!jHashMap)
     {
-        return NULL;
+        throwSimulatorException(env, SIMULATOR_ERROR, "Java map creation failed!");
+        return nullptr;
     }
 
     for (auto & attributeEntry : attributesMap)
@@ -168,13 +171,15 @@ Java_org_oic_simulator_SimulatorResourceModel_getAttribute
 {
     if (!jAttrName)
     {
-        return NULL;
+        throwInvalidArgsException(env, SIMULATOR_INVALID_PARAM, "Invalid attribute name!");
+        return nullptr;
     }
 
     const char *attrName = env->GetStringUTFChars(jAttrName, NULL);
     if (!attrName)
     {
-        return NULL;
+        throwSimulatorException(env, SIMULATOR_ERROR, "String error!");
+        return nullptr;
     }
 
     SimulatorResourceModel resourceModel;
@@ -182,7 +187,8 @@ Java_org_oic_simulator_SimulatorResourceModel_getAttribute
     if (!result)
     {
         env->ReleaseStringUTFChars(jAttrName, attrName);
-        return NULL;
+        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "Resource model not found!");
+        return nullptr;
     }
 
     SimulatorResourceModel::Attribute attribute;
@@ -190,7 +196,8 @@ Java_org_oic_simulator_SimulatorResourceModel_getAttribute
     if (!found)
     {
         env->ReleaseStringUTFChars(jAttrName, attrName);
-        return NULL;
+        throwInvalidArgsException(env, SIMULATOR_INVALID_PARAM, "Attribute does not exist!");
+        return nullptr;
     }
 
     env->ReleaseStringUTFChars(jAttrName, attrName);
@@ -204,16 +211,24 @@ JNIEXPORT void JNICALL
 Java_org_oic_simulator_SimulatorResourceModel_addAttributeInt
 (JNIEnv *env, jobject thiz, jstring jname, jint jvalue)
 {
+    if (!jname)
+    {
+        throwInvalidArgsException(env, SIMULATOR_INVALID_PARAM, "Invalid attribute name!");
+        return;
+    }
+
     SimulatorResourceModelSP resModelPtr;
     resModelPtr = JSimulatorResourceModel::getResourceModelPtr(env, thiz);
     if (!resModelPtr)
     {
+        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "Resource model not found!");
         return;
     }
 
     const char *nameCstr = env->GetStringUTFChars(jname, NULL);
     if (!nameCstr)
     {
+        throwSimulatorException(env, SIMULATOR_ERROR, "String error!");
         return;
     }
 
@@ -229,16 +244,24 @@ JNIEXPORT void JNICALL
 Java_org_oic_simulator_SimulatorResourceModel_addAttributeDouble
 (JNIEnv *env, jobject thiz, jstring jname, jdouble jvalue)
 {
+    if (!jname)
+    {
+        throwInvalidArgsException(env, SIMULATOR_INVALID_PARAM, "Invalid attribute name!");
+        return;
+    }
+
     SimulatorResourceModelSP resModelPtr;
     resModelPtr = JSimulatorResourceModel::getResourceModelPtr(env, thiz);
     if (!resModelPtr)
     {
+        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "Resource model not found!");
         return;
     }
 
     const char *nameCstr = env->GetStringUTFChars(jname, NULL);
     if (!nameCstr)
     {
+        throwSimulatorException(env, SIMULATOR_ERROR, "String error!");
         return;
     }
 
@@ -254,16 +277,24 @@ JNIEXPORT void JNICALL
 Java_org_oic_simulator_SimulatorResourceModel_addAttributeBoolean
 (JNIEnv *env, jobject thiz, jstring jname, jboolean jvalue)
 {
+    if (!jname)
+    {
+        throwInvalidArgsException(env, SIMULATOR_INVALID_PARAM, "Invalid attribute name!");
+        return;
+    }
+
     SimulatorResourceModelSP resModelPtr;
     resModelPtr = JSimulatorResourceModel::getResourceModelPtr(env, thiz);
     if (!resModelPtr)
     {
+        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "Resource model not found!");
         return;
     }
 
     const char *nameCstr = env->GetStringUTFChars(jname, NULL);
     if (!nameCstr)
     {
+        throwSimulatorException(env, SIMULATOR_ERROR, "String error!");
         return;
     }
 
@@ -279,16 +310,24 @@ JNIEXPORT void JNICALL
 Java_org_oic_simulator_SimulatorResourceModel_addAttributeString
 (JNIEnv *env, jobject thiz, jstring jname, jstring jvalue)
 {
+    if (!jname)
+    {
+        throwInvalidArgsException(env, SIMULATOR_INVALID_PARAM, "Invalid attribute name!");
+        return;
+    }
+
     SimulatorResourceModelSP resModelPtr;
     resModelPtr = JSimulatorResourceModel::getResourceModelPtr(env, thiz);
     if (!resModelPtr)
     {
+        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "Resource model not found!");
         return;
     }
 
     const char *nameCstr = env->GetStringUTFChars(jname, NULL);
     if (!nameCstr)
     {
+        throwSimulatorException(env, SIMULATOR_ERROR, "String error!");
         return;
     }
 
@@ -296,6 +335,7 @@ Java_org_oic_simulator_SimulatorResourceModel_addAttributeString
     if (!valueCstr)
     {
         env->ReleaseStringUTFChars(jname, nameCstr);
+        throwSimulatorException(env, SIMULATOR_ERROR, "String error!");
         return;
     }
 
@@ -315,4 +355,3 @@ Java_org_oic_simulator_SimulatorResourceModel_dispose
     JSimulatorResourceModel *resourceModel = GetHandle<JSimulatorResourceModel>(env, thiz);
     delete resourceModel;
 }
-
index 9b0436a..f8910b6 100644 (file)
@@ -92,7 +92,6 @@ void JniSimulatorResource::setResourceInfo(JNIEnv *env, jobject jobj)
 void onAutomationComplete(jweak jlistenerRef, const std::string &uri,
                           const int automationID)
 {
-    std::cout << "onAutomationComplete JNI entry" << std::endl;
     JNIEnv *env = getEnv();
     if (nullptr == env)
         return;
@@ -138,9 +137,9 @@ Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_getModel
 (JNIEnv *env, jobject object)
 {
     SimulatorResourceServerSP resource = JniSimulatorResource::getJniSimulatorResourceSP(env, object);
-    if (nullptr == resource.get())
+    if (!resource)
     {
-        throwInvalidArgsException(env, SIMULATOR_NO_RESOURCE, "Resource not found!");
+        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
         return nullptr;
     }
 
@@ -162,9 +161,9 @@ Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_addAttributeInteg
 
     SimulatorResourceServerSP resource = JniSimulatorResource::getJniSimulatorResourceSP(env,
                                          jobject);
-    if (nullptr == resource.get())
+    if (!resource)
     {
-        throwInvalidArgsException(env, SIMULATOR_NO_RESOURCE, "Resource not found!");
+        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
         return;
     }
 
@@ -187,9 +186,9 @@ Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_addAttributeDoubl
 
     SimulatorResourceServerSP resource = JniSimulatorResource::getJniSimulatorResourceSP(env,
                                          jobject);
-    if (nullptr == resource.get())
+    if (!resource)
     {
-        throwInvalidArgsException(env, SIMULATOR_NO_RESOURCE, "Resource not found!");
+        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
         return;
     }
 
@@ -212,9 +211,9 @@ Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_addAttributeBoole
 
     SimulatorResourceServerSP resource = JniSimulatorResource::getJniSimulatorResourceSP(env,
                                          jobject);
-    if (nullptr == resource.get())
+    if (!resource)
     {
-        throwInvalidArgsException(env, SIMULATOR_NO_RESOURCE, "Resource not found!");
+        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
         return;
     }
 
@@ -237,9 +236,9 @@ Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_addAttributeStrin
 
     SimulatorResourceServerSP resource = JniSimulatorResource::getJniSimulatorResourceSP(env,
                                          jobject);
-    if (nullptr == resource.get())
+    if (!resource)
     {
-        throwInvalidArgsException(env, SIMULATOR_NO_RESOURCE, "Resource not found!");
+        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
         return;
     }
 
@@ -263,9 +262,9 @@ Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_updateAttributeIn
 
     SimulatorResourceServerSP resource = JniSimulatorResource::getJniSimulatorResourceSP(env,
                                          jobject);
-    if (nullptr == resource.get())
+    if (!resource)
     {
-        throwInvalidArgsException(env, SIMULATOR_NO_RESOURCE, "Resource not found!");
+        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
         return;
     }
 
@@ -285,9 +284,9 @@ Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_updateAttributeDo
 
     SimulatorResourceServerSP resource = JniSimulatorResource::getJniSimulatorResourceSP(env,
                                          jobject);
-    if (nullptr == resource.get())
+    if (!resource)
     {
-        throwInvalidArgsException(env, SIMULATOR_NO_RESOURCE, "Resource not found!");
+        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
         return;
     }
 
@@ -307,9 +306,9 @@ Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_updateAttributeBo
 
     SimulatorResourceServerSP resource = JniSimulatorResource::getJniSimulatorResourceSP(env,
                                          jobject);
-    if (nullptr == resource.get())
+    if (!resource)
     {
-        throwInvalidArgsException(env, SIMULATOR_NO_RESOURCE, "Resource not found!");
+        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
         return;
     }
 
@@ -329,9 +328,9 @@ Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_updateAttributeSt
 
     SimulatorResourceServerSP resource = JniSimulatorResource::getJniSimulatorResourceSP(env,
                                          jobject);
-    if (nullptr == resource.get())
+    if (!resource)
     {
-        throwInvalidArgsException(env, SIMULATOR_NO_RESOURCE, "Resource not found!");
+        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
         return;
     }
 
@@ -352,9 +351,9 @@ Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_updateAttributeFr
     }
 
     SimulatorResourceServerSP resource = JniSimulatorResource::getJniSimulatorResourceSP(env, object);
-    if (resource)
+    if (!resource)
     {
-        throwSimulatorException(env, SIMULATOR_NO_RESOURCE, "Resource not found!");
+        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
         return;
     }
 
@@ -380,9 +379,9 @@ Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_setRange
     }
 
     SimulatorResourceServerSP resource = JniSimulatorResource::getJniSimulatorResourceSP(env, object);
-    if (resource)
+    if (!resource)
     {
-        throwSimulatorException(env, SIMULATOR_NO_RESOURCE, "Resource not found!");
+        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
         return;
     }
 
@@ -408,9 +407,9 @@ Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_setAllowedValuesI
     }
 
     SimulatorResourceServerSP resource = JniSimulatorResource::getJniSimulatorResourceSP(env, object);
-    if (resource)
+    if (!resource)
     {
-        throwSimulatorException(env, SIMULATOR_NO_RESOURCE, "Resource not found!");
+        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
         return;
     }
 
@@ -436,9 +435,9 @@ Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_setAllowedValuesD
     }
 
     SimulatorResourceServerSP resource = JniSimulatorResource::getJniSimulatorResourceSP(env, object);
-    if (resource)
+    if (!resource)
     {
-        throwSimulatorException(env, SIMULATOR_NO_RESOURCE, "Resource not found!");
+        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
         return;
     }
 
@@ -464,9 +463,9 @@ Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_setAllowedValuesS
     }
 
     SimulatorResourceServerSP resource = JniSimulatorResource::getJniSimulatorResourceSP(env, object);
-    if (resource)
+    if (!resource)
     {
-        throwSimulatorException(env, SIMULATOR_NO_RESOURCE, "Resource not found!");
+        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
         return;
     }
 
@@ -488,15 +487,15 @@ Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_startResourceAuto
     SimulatorResourceServerSP resource = JniSimulatorResource::getJniSimulatorResourceSP(env, object);
     if (!resource)
     {
-        throwInvalidArgsException(env, SIMULATOR_NO_RESOURCE, "Resource not found!");
-        return -1;
+        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
+        return SIMULATOR_BAD_OBJECT;
     }
 
     if (!listener)
     {
         throwInvalidArgsException(env, SIMULATOR_INVALID_CALLBACK,
                                   "Start Resource Automation failed! Callback not set");
-        return -1;
+        return SIMULATOR_INVALID_CALLBACK;
     }
 
     jweak jlistenerRef = env->NewWeakGlobalRef(listener);
@@ -537,23 +536,23 @@ Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_startAttributeAut
 (JNIEnv *env, jobject object, jstring attrName, jint automationType, jobject listener)
 {
     SimulatorResourceServerSP resource = JniSimulatorResource::getJniSimulatorResourceSP(env, object);
-    if (nullptr == resource.get())
+    if (!resource)
     {
-        throwInvalidArgsException(env, SIMULATOR_NO_RESOURCE, "Resource not found!");
-        return -1;
+        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
+        return SIMULATOR_BAD_OBJECT;
     }
 
     if (!attrName)
     {
         throwInvalidArgsException(env, SIMULATOR_INVALID_PARAM, "Invalid Attribute name!");
-        return -1;
+        return SIMULATOR_INVALID_PARAM;
     }
 
     if (!listener)
     {
         throwInvalidArgsException(env, SIMULATOR_INVALID_CALLBACK,
                                   "Start Attribute Automation failed! Callback not set");
-        return -1;
+        return SIMULATOR_INVALID_CALLBACK;
     }
 
     jweak jlistenerRef = env->NewWeakGlobalRef(listener);
@@ -599,9 +598,9 @@ Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_stopAutomation
 (JNIEnv *env, jobject object, jint automationId)
 {
     SimulatorResourceServerSP resource = JniSimulatorResource::getJniSimulatorResourceSP(env, object);
-    if (nullptr == resource.get())
+    if (!resource)
     {
-        throwInvalidArgsException(env, SIMULATOR_NO_RESOURCE, "Resource not found!");
+        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
         return;
     }
 
@@ -621,9 +620,9 @@ Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_removeAttribute
 
     SimulatorResourceServerSP resource = JniSimulatorResource::getJniSimulatorResourceSP(env,
                                          jobject);
-    if (nullptr == resource.get())
+    if (!resource)
     {
-        throwInvalidArgsException(env, SIMULATOR_NO_RESOURCE, "Resource not found!");
+        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
         return;
     }
 
@@ -636,9 +635,9 @@ Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_getObserversList
 (JNIEnv *env, jobject object)
 {
     SimulatorResourceServerSP resource = JniSimulatorResource::getJniSimulatorResourceSP(env, object);
-    if (nullptr == resource.get())
+    if (!resource)
     {
-        throwInvalidArgsException(env, SIMULATOR_NO_RESOURCE, "Resource not found!");
+        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
         return nullptr;
     }
 
@@ -724,7 +723,10 @@ Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_setObserverCallba
 (JNIEnv *env, jobject object, jobject jcallback)
 {
     if (!jcallback)
+    {
+        throwInvalidArgsException(env, SIMULATOR_INVALID_CALLBACK, "Callback not set");
         return;
+    }
 
     jweak jlistenerRef = env->NewWeakGlobalRef(jcallback);
     SimulatorResourceServer::ObserverCB callback =  [jlistenerRef](const std::string & uri,
@@ -734,9 +736,9 @@ Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_setObserverCallba
     };
 
     SimulatorResourceServerSP resource = JniSimulatorResource::getJniSimulatorResourceSP(env, object);
-    if (nullptr == resource.get())
+    if (!resource)
     {
-        throwInvalidArgsException(env, SIMULATOR_NO_RESOURCE, "Resource not found!");
+        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
         return;
     }
 
@@ -748,9 +750,9 @@ Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_notifyObserver
 (JNIEnv *env, jobject object, jint jId)
 {
     SimulatorResourceServerSP resource = JniSimulatorResource::getJniSimulatorResourceSP(env, object);
-    if (nullptr == resource.get())
+    if (!resource)
     {
-        throwInvalidArgsException(env, SIMULATOR_NO_RESOURCE, "Resource not found!");
+        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
         return;
     }
 
@@ -773,9 +775,9 @@ Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_notifyAllObserver
 (JNIEnv *env, jobject object)
 {
     SimulatorResourceServerSP resource = JniSimulatorResource::getJniSimulatorResourceSP(env, object);
-    if (nullptr == resource.get())
+    if (!resource)
     {
-        throwInvalidArgsException(env, SIMULATOR_NO_RESOURCE, "Resource not found!");
+        throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
         return;
     }
 
index 090d4b9..49e8e39 100644 (file)
@@ -27,7 +27,7 @@ public class DeviceInfo {
 
     /**
      * This method is for getting the device name.
-     * 
+     *
      * @return Device name.
      */
     public String getName() {
@@ -36,7 +36,7 @@ public class DeviceInfo {
 
     /**
      * This method is for getting the device id.
-     * 
+     *
      * @return Device id.
      */
     public String getID() {
@@ -45,7 +45,7 @@ public class DeviceInfo {
 
     /**
      * This method is for getting device specification version.
-     * 
+     *
      * @return Specification version.
      */
     public String getSpecVersion() {
@@ -54,7 +54,7 @@ public class DeviceInfo {
 
     /**
      * This method is for getting device data model version.
-     * 
+     *
      * @return Device data model version.
      */
     public String getDataModelVersion() {
index e74fbd1..1338fd5 100644 (file)
@@ -22,7 +22,7 @@ package org.oic.simulator;
 public interface IAutomation {
     /**
      * Callback method for receiving automation complete notifications.
-     * 
+     *
      * @param resourceURI
      *            URI of the resource on which the automation has occurred.
      * @param automationId
index 0d4c8a3..cb541ad 100644 (file)
@@ -22,7 +22,7 @@ package org.oic.simulator;
 public interface IDeviceInfo {
     /**
      * Callback method which provides remote device information.
-     * 
+     *
      * @param devInfo
      *            {@link DeviceInfo} object holding the device information.
      */
index 9d948ce..120ec01 100644 (file)
@@ -22,7 +22,7 @@ package org.oic.simulator;
 public interface IPlatformInfo {
     /**
      * Callback method which provides remote device platform information.
-     * 
+     *
      * @param platformInfo
      *            {@link PlatformInfo} object holding the platform information.
      */
index 2b97e13..7956e92 100644 (file)
@@ -35,7 +35,7 @@ public class PlatformInfo {
 
     /**
      * This method is for getting platform id.
-     * 
+     *
      * @return Platform id.
      */
     public String getPlatformID() {
@@ -44,7 +44,7 @@ public class PlatformInfo {
 
     /**
      * This method is for setting platform id.
-     * 
+     *
      * @param mPlatformId
      *            Platform identifier.
      */
@@ -54,7 +54,7 @@ public class PlatformInfo {
 
     /**
      * This method is for getting manufacturer name.
-     * 
+     *
      * @return Manufacturer name.
      */
     public String getManufacturerName() {
@@ -63,7 +63,7 @@ public class PlatformInfo {
 
     /**
      * This method is for setting manufacturer name.
-     * 
+     *
      * @param m_manufacturerName
      *            Manufacturer name.
      */
@@ -73,7 +73,7 @@ public class PlatformInfo {
 
     /**
      * This method is for getting manufacturer URL.
-     * 
+     *
      * @return Manufacturer URL.
      */
     public String getManufacturerUrl() {
@@ -82,7 +82,7 @@ public class PlatformInfo {
 
     /**
      * This method is for setting manufacturer URL.
-     * 
+     *
      * @param m_manufacturerUrl
      *            Manufacturer URL.
      */
@@ -92,7 +92,7 @@ public class PlatformInfo {
 
     /**
      * This method is for getting model number.
-     * 
+     *
      * @return Model number.
      */
     public String getModelNumber() {
@@ -101,7 +101,7 @@ public class PlatformInfo {
 
     /**
      * This method is for setting model number.
-     * 
+     *
      * @param m_modelNumber
      *            Model number.
      */
@@ -111,7 +111,7 @@ public class PlatformInfo {
 
     /**
      * This method is for getting date of manufacture.
-     * 
+     *
      * @return Date of manufacture.
      */
     public String getDateOfManufacture() {
@@ -120,7 +120,7 @@ public class PlatformInfo {
 
     /**
      * This method is for setting date of manufacture.
-     * 
+     *
      * @param m_dateOfManufacture
      *            Date of manufacture.
      */
@@ -130,7 +130,7 @@ public class PlatformInfo {
 
     /**
      * This method is for getting platform version.
-     * 
+     *
      * @return Platform version.
      */
     public String getPlatformVersion() {
@@ -139,7 +139,7 @@ public class PlatformInfo {
 
     /**
      * This method is for setting platform version.
-     * 
+     *
      * @param m_platformVersion
      *            Platform version.
      */
@@ -149,7 +149,7 @@ public class PlatformInfo {
 
     /**
      * This method is for getting operating system version.
-     * 
+     *
      * @return Operation system version.
      */
     public String getOperationSystemVersion() {
@@ -158,7 +158,7 @@ public class PlatformInfo {
 
     /**
      * This method is for setting operating system version.
-     * 
+     *
      * @param m_operationSystemVersion
      *            Operation system version.
      */
@@ -168,7 +168,7 @@ public class PlatformInfo {
 
     /**
      * This method is for getting hardware version.
-     * 
+     *
      * @return Hardware version.
      */
     public String getHardwareVersion() {
@@ -177,7 +177,7 @@ public class PlatformInfo {
 
     /**
      * This method is for setting hardware version.
-     * 
+     *
      * @param m_hardwareVersion
      *            Hardware version.
      */
@@ -187,7 +187,7 @@ public class PlatformInfo {
 
     /**
      * This method is for getting firmware version.
-     * 
+     *
      * @return Firmware version.
      */
     public String getFirmwareVersion() {
@@ -196,7 +196,7 @@ public class PlatformInfo {
 
     /**
      * This method is for setting firmware version.
-     * 
+     *
      * @param m_firmwareVersion
      *            Firmware version.
      */
@@ -206,7 +206,7 @@ public class PlatformInfo {
 
     /**
      * This method is for getting support link URL.
-     * 
+     *
      * @return URL of support link.
      */
     public String getSupportUrl() {
@@ -215,7 +215,7 @@ public class PlatformInfo {
 
     /**
      * This method is for setting support link URL.
-     * 
+     *
      * @param m_supportUrl
      *            URL of support link.
      */
@@ -225,7 +225,7 @@ public class PlatformInfo {
 
     /**
      * This method is for getting system time.
-     * 
+     *
      * @return System time.
      */
     public String getSystemTime() {
@@ -234,7 +234,7 @@ public class PlatformInfo {
 
     /**
      * This method is for setting system time.
-     * 
+     *
      * @param m_systemTime
      *            System time.
      */
index 9f39fc5..0822e76 100644 (file)
@@ -25,7 +25,7 @@ public class ResourceAttribute {
      * Type of attribute value.
      */
     public enum Type {
-        INT, DOUBLE, BOOL, STRING;
+        UNKNOWN, INT, DOUBLE, BOOL, STRING;
 
         private static Type[] m_cvalues = Type.values();
 
index a70d4ce..d9f502c 100644 (file)
@@ -35,10 +35,10 @@ public class SimulatorManager {
      * @param listener
      *            Listener for receiving notifications whenever there is a
      *            change in the resource model.
-     * 
+     *
      * @return {@link SimulatorResourceServer} - Created resource on success,
      *         otherwise null.
-     * 
+     *
      * @throws InvalidArgsException
      *             Thrown if the input parameters are empty.
      * @throws SimulatorException
@@ -64,10 +64,10 @@ public class SimulatorManager {
      * @param listener
      *            Listener for receiving notifications whenever there is a
      *            change in the resource model.
-     * 
+     *
      * @return Returns an array of {@link SimulatorResourceServer} objects one
      *         for each created resource on success, otherwise null.
-     * 
+     *
      * @throws InvalidArgsException
      *             Thrown if the input parameters are empty.
      * @throws SimulatorException
@@ -122,15 +122,15 @@ public class SimulatorManager {
      *
      * @param listener
      *            Interface to receive the discovered remote resources.
-     * 
+     *
      * @throws InvalidArgsException
      *             Thrown if the input parameter is empty.
      * @throws SimulatorException
      *             Thrown for other errors.
      */
-    public static void findResources(IFindResourceListener listener)
+    public static void findResource(IFindResourceListener listener)
             throws InvalidArgsException, SimulatorException {
-        SimulatorManagerNativeInterface.findResources(null, listener);
+        SimulatorManagerNativeInterface.findResource(null, listener);
     }
 
     /**
@@ -141,13 +141,13 @@ public class SimulatorManager {
      *            Required resource type
      * @param listener
      *            Interface to receive the discovered remote resources.
-     * 
+     *
      * @throws InvalidArgsException
      *             Thrown if the input parameter is empty.
      * @throws SimulatorException
      *             Thrown for other errors.
      */
-    public static void findResources(String resourceType,
+    public static void findResource(String resourceType,
             IFindResourceListener listener) throws InvalidArgsException,
             SimulatorException {
         if (null == resourceType || resourceType.isEmpty()) {
@@ -155,7 +155,7 @@ public class SimulatorManager {
                     SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
                     "Resource type is empty");
         }
-        SimulatorManagerNativeInterface.findResources(resourceType, listener);
+        SimulatorManagerNativeInterface.findResource(resourceType, listener);
     }
 
     /**
@@ -170,7 +170,7 @@ public class SimulatorManager {
 
     /**
      * API to set the device information.
-     * 
+     *
      * @param deviceInfo
      *            Device information.
      */
@@ -179,8 +179,9 @@ public class SimulatorManager {
     }
 
     /**
-     * API to get the device information asynchronously via the listener.
-     * 
+     * API to get the device information asynchronously via callback
+     * using {@link IDeviceInfo}.
+     *
      * @param listener
      *            Interface for receiving the device information.
      */
@@ -190,7 +191,7 @@ public class SimulatorManager {
 
     /**
      * API to set the platform information.
-     * 
+     *
      * @param platformInfo
      *            {@link PlatformInfo} - Platform information.
      */
@@ -199,8 +200,9 @@ public class SimulatorManager {
     }
 
     /**
-     * API to get the platform information asynchronously via the listener.
-     * 
+     * API to get the platform information asynchronously via callback
+     * using {@link IPlatformInfo}..
+     *
      * @param listener
      *            Interface for receiving the platform information.
      */
index 42da05c..5fd2185 100644 (file)
@@ -37,7 +37,7 @@ class SimulatorManagerNativeInterface {
      *
      * @return {@link SimulatorResourceServer} object on success, otherwise
      *         null.
-     * 
+     *
      * @throws InvalidArgsException
      *             Thrown if the input parameters are empty.
      * @throws SimulatorException
@@ -76,7 +76,7 @@ class SimulatorManagerNativeInterface {
      * @param resource
      *            {@link SimulatorResourceServer} object of the resource to be
      *            deleted.
-     * 
+     *
      * @throws InvalidArgsException
      *             Thrown if the input parameter is empty.
      * @throws SimulatorException
@@ -90,14 +90,14 @@ class SimulatorManagerNativeInterface {
      *
      * @param resourceType
      *            Type of the resource.
-     * 
+     *
      * @throws InvalidArgsException
      *             Thrown if the input parameter is empty.
      * @throws SimulatorException
      *             Thrown for other errors.
      */
     public static native void deleteResources(String resourceType)
-            throws InvalidArgsException, SimulatorException;
+            throws SimulatorException;
 
     /**
      * Native function for discovering resources.
@@ -106,20 +106,20 @@ class SimulatorManagerNativeInterface {
      *            required resource type
      * @param listener
      *            Interface to receive the discovered remote resources.
-     * 
+     *
      * @throws InvalidArgsException
      *             Thrown if the input parameter is empty.
      * @throws SimulatorException
      *             Thrown for other errors.
      */
-    public static native void findResources(String resourceType,
+    public static native void findResource(String resourceType,
             IFindResourceListener listener) throws InvalidArgsException,
             SimulatorException;
 
     /**
      * Native function to set the logger listener for receiving the log messages
      * from native layer.
-     * 
+     *
      * @param logger
      *            Interface to receive log.
      */
@@ -127,7 +127,7 @@ class SimulatorManagerNativeInterface {
 
     /**
      * Native function to set the device information.
-     * 
+     *
      * @param deviceInfo
      *            Device information.
      */
@@ -136,7 +136,7 @@ class SimulatorManagerNativeInterface {
     /**
      * Native function to get the device information asynchronously via the
      * listener.
-     * 
+     *
      * @param listener
      *            Interface for receiving the device information.
      */
@@ -144,7 +144,7 @@ class SimulatorManagerNativeInterface {
 
     /**
      * Native function to set the platform information.
-     * 
+     *
      * @param platformInfo
      *            Platform information.
      */
@@ -153,7 +153,7 @@ class SimulatorManagerNativeInterface {
     /**
      * Native function to get the platform information asynchronously via the
      * listener.
-     * 
+     *
      * @param listener
      *            Interface for receiving the platform information.
      */
index 4b89502..4186c6e 100644 (file)
@@ -35,8 +35,8 @@ public class SimulatorResourceModel {
     }
 
     /**
-     * Method for adding an attribute whose value is of type int.
-     * 
+     * API to add an attribute of type integer.
+     *
      * @param name
      *            Name of the attribute
      * @param value
@@ -53,8 +53,8 @@ public class SimulatorResourceModel {
             throws InvalidArgsException, SimulatorException;
 
     /**
-     * Method for adding an attribute whose value is of type double.
-     * 
+     * API to add an attribute of type double.
+     *
      * @param name
      *            Name of the attribute
      * @param value
@@ -71,8 +71,8 @@ public class SimulatorResourceModel {
             throws InvalidArgsException, SimulatorException;
 
     /**
-     * Method for adding an attribute whose value is of type boolean.
-     * 
+     * API to add an attribute of type boolean.
+     *
      * @param name
      *            Name of the attribute
      * @param value
@@ -89,8 +89,8 @@ public class SimulatorResourceModel {
             throws InvalidArgsException, SimulatorException;
 
     /**
-     * Method for adding an attribute whose value is of type string.
-     * 
+     * API to add an attribute of type string.
+     *
      * @param name
      *            Name of the attribute
      * @param value
@@ -107,10 +107,10 @@ public class SimulatorResourceModel {
             throws InvalidArgsException, SimulatorException;
 
     /**
-     * Method for getting the number of attributes this model comprised of.
+     * API to get number of attributes for this model.
      *
      * @return Number of attributes.
-     * 
+     *
      * @throws SimulatorException
      *             This exception will be thrown either if the resource model is
      *             not found or for some general errors.
@@ -118,11 +118,11 @@ public class SimulatorResourceModel {
     public native int size() throws SimulatorException;
 
     /**
-     * Method for getting all attributes.
+     * API for getting all attributes.
      *
      * @return Map of attributes with attribute name as the key and its
      *         corresponding {@link ResourceAttribute} object as the value.
-     * 
+     *
      * @throws SimulatorException
      *             This exception will be thrown either if the resource model is
      *             not found or for some general errors.
@@ -131,22 +131,22 @@ public class SimulatorResourceModel {
             throws SimulatorException;
 
     /**
-     * Method for getting a specific attribute by its name.
+     * API to get attribute by its name.
      *
-     * @param attrName
+     * @param name
      *            Name of the attribute
      *
      * @return An object of {@link ResourceAttribute}.
-     * 
+     *
      * @throws InvalidArgsException
      *             This exception will be thrown if the attribute does not
      *             exist.
-     * 
+     *
      * @throws SimulatorException
      *             This exception will be thrown either if the resource model is
      *             not found or for some general errors.
      */
-    public native ResourceAttribute getAttribute(String attrName)
+    public native ResourceAttribute getAttribute(String name)
             throws InvalidArgsException, SimulatorException;
 
     private SimulatorResourceModel(long nativeHandle) {
index 62d1c4c..8e4b9eb 100644 (file)
@@ -139,7 +139,7 @@ public enum SimulatorResult {
             result = SimulatorResult.values()[29];
         else if (ordinal == 46)
             result = SimulatorResult.values()[30];
-                
+
         else if (ordinal == 128)
             result = SimulatorResult.values()[31];
         else if (ordinal == 129)
@@ -155,7 +155,7 @@ public enum SimulatorResult {
             result = SimulatorResult.values()[36];
         else if (ordinal == 134 || ordinal == 50)
             result = SimulatorResult.values()[37];
-        
+
         else if (ordinal == 135 || ordinal == 51)
             result = SimulatorResult.values()[38];
         else if (ordinal == 136 || ordinal == 52)
@@ -164,7 +164,7 @@ public enum SimulatorResult {
             result = SimulatorResult.values()[40];
         else if (ordinal == 138 || ordinal == 54)
             result = SimulatorResult.values()[41];
-        
+
         else
             result = SimulatorResult.values()[42];
         return result;
index 3436a3d..db3e63c 100644 (file)
@@ -27,7 +27,7 @@ public interface IGetListener {
     /**
      * This method will be called when response from the remote resource for GET
      * request arrives.
-     * 
+     *
      * @param uId
      *            Unique Id of the resource.
      * @param representation
@@ -37,7 +37,7 @@ public interface IGetListener {
 
     /**
      * Called when there is an error in GET request.
-     * 
+     *
      * @param ex
      *            Error information.
      */
index f09feaf..30ed0fb 100644 (file)
@@ -28,7 +28,7 @@ public interface IObserveListener {
     /**
      * This method will be called when there is a change in the resource model
      * of the remote resource.
-     * 
+     *
      * @param uId
      *            Unique Id of the resource.
      * @param representation
@@ -41,7 +41,7 @@ public interface IObserveListener {
 
     /**
      * Called when there is an error in observe request.
-     * 
+     *
      * @param ex
      *            Error information.
      */
index 5f4cbe0..9949ac9 100644 (file)
@@ -27,7 +27,7 @@ public interface IPostListener {
     /**
      * This method will be called when response from the remote resource for
      * POST request arrives.
-     * 
+     *
      * @param uId
      *            Unique Id of the resource.
      * @param representation
@@ -38,7 +38,7 @@ public interface IPostListener {
 
     /**
      * Called when there is an error in POST request.
-     * 
+     *
      * @param ex
      *            Error information.
      */
index c44b917..91a44d9 100644 (file)
@@ -27,7 +27,7 @@ public interface IPutListener {
     /**
      * This method will be called when response from the remote resource for PUT
      * request arrives.
-     * 
+     *
      * @param uId
      *            Unique Id of the resource.
      * @param representation
@@ -37,9 +37,10 @@ public interface IPutListener {
 
     /**
      * Called when there is an error in PUT request.
-     * 
+     *
      * @param ex
      *            Error information.
      */
     public void onPutFailed(Throwable ex);
 }
+
index 1114f6b..e69cdd6 100644 (file)
@@ -24,7 +24,7 @@ package org.oic.simulator.clientcontroller;
 public interface IVerificationListener {
     /**
      * Called when the verification request is accepted and started.
-     * 
+     *
      * @param uId
      *            Unique Id of the resource.
      * @param id
@@ -34,7 +34,7 @@ public interface IVerificationListener {
 
     /**
      * Called when the verification is stopped before its completion.
-     * 
+     *
      * @param uId
      *            Unique Id of the resource.
      * @param id
@@ -44,11 +44,11 @@ public interface IVerificationListener {
 
     /**
      * Called when the verification is done.
-     * 
+     *
      * @param uId
      *            Unique Id of the resource.
      * @param id
      *            Verification Id.
      */
     public void onVerificationCompleted(String uId, int id);
-}
\ No newline at end of file
+}
index 94eb195..a751acb 100644 (file)
@@ -86,7 +86,7 @@ public enum SimulatorConnectivityType {
     /**
      * Method to get the {@link SimulatorConnectivityType} from an integer
      * value.
-     * 
+     *
      * @param value
      *            Integral value of {@link SimulatorConnectivityType}.
      * @return {@link SimulatorConnectivityType} corresponding to the given
index cfa9d78..b0b7ee2 100644 (file)
@@ -37,8 +37,8 @@ public class SimulatorRemoteResource {
     }
 
     /**
-     * Method to get the URI for this resource.
-     * 
+     * API to get the URI for this resource.
+     *
      * @return Resource URI
      */
     public String getUri() {
@@ -46,8 +46,8 @@ public class SimulatorRemoteResource {
     }
 
     /**
-     * Method to get the observe capability of this resource.
-     * 
+     * API to get the observe policy of this resource.
+     *
      * @return True if the resource is observable, otherwise false.
      */
     public boolean getIsObservable() {
@@ -55,8 +55,8 @@ public class SimulatorRemoteResource {
     }
 
     /**
-     * Method to get the connectivity type for this resource.
-     * 
+     * API to get the connectivity type for this resource.
+     *
      * @return Connectivity type.
      */
     public SimulatorConnectivityType getConnectivityType() {
@@ -64,8 +64,8 @@ public class SimulatorRemoteResource {
     }
 
     /**
-     * Method to get the list of resource types.
-     * 
+     * API to get the list of resource types.
+     *
      * @return List of resource types.
      */
     public LinkedList<String> getResourceTypes() {
@@ -73,8 +73,8 @@ public class SimulatorRemoteResource {
     }
 
     /**
-     * Method to get the list of resource interfaces.
-     * 
+     * API to get the list of resource interfaces.
+     *
      * @return List of resource interfaces.
      */
     public LinkedList<String> getResourceInterfaces() {
@@ -82,9 +82,8 @@ public class SimulatorRemoteResource {
     }
 
     /**
-     * Method to get a string representation of the host address of the remote
-     * resource.
-     * 
+     * API to get host address and port information of the resource.
+     *
      * @return Host address.
      */
     public String getHost() {
@@ -92,8 +91,8 @@ public class SimulatorRemoteResource {
     }
 
     /**
-     * Method to get a unique Id for the resource.
-     * 
+     * API to get a unique Id of the resource .
+     *
      * @return Unique ID.
      */
     public String getId() {
@@ -101,8 +100,8 @@ public class SimulatorRemoteResource {
     }
 
     /**
-     * Method to set observation on the remote resource.
-     * 
+     * API to start observing the resource.
+     *
      * @param observeType
      *            Allows the client to specify how it wants to observe.
      * @param queryParamsMap
@@ -111,39 +110,40 @@ public class SimulatorRemoteResource {
      *            The handler method which will be invoked with a map of
      *            attribute names and values whenever there is a change in
      *            resource model of the remote resource.
-     * 
+     *
      * @throws InvalidArgsException
      *             This exception will be thrown if any parameter has invalid
      *             values.
      * @throws SimulatorException
      *             This exception will be thrown for other errors.
      */
-    public native void observe(SimulatorObserveType observeType,
+    public native void startObserve(SimulatorObserveType observeType,
             Map<String, String> queryParamsMap,
             IObserveListener onObserveListener) throws InvalidArgsException,
             SimulatorException;
 
     /**
-     * Method to cancel the observation on the resource.
-     * 
+     * API to stop observing the resource.
+     *
      * @throws InvalidArgsException
      *             This exception will be thrown if the native remote resource
      *             object is unavailable.
      * @throws SimulatorException
      *             This exception will be thrown for other errors.
      */
-    public native void cancelObserve() throws InvalidArgsException,
+    public native void stopObserve() throws InvalidArgsException,
             SimulatorException;
 
     /**
-     * Method to get the attributes of a resource.
-     * 
+     * API to send GET request to the resource. Response will be notified
+     * asynchronously via callback set for {@link IGetListener}.
+     *
      * @param queryParamsMap
      *            Map which can have the query parameter name and value.
      * @param onGetListener
      *            Event handler which will be invoked with the response for GET
      *            request with a map of attribute name and values.
-     * 
+     *
      * @throws InvalidArgsException
      *             This exception will be thrown if any parameter has invalid
      *             values.
@@ -160,8 +160,9 @@ public class SimulatorRemoteResource {
     }
 
     /**
-     * Method to get the attributes of a resource.
-     * 
+     * API to send GET request to the resource. Response will be notified
+     * asynchronously via callback set for {@link IGetListener}.
+     *
      * @param resourceInterface
      *            Interface type of the resource to operate on.
      * @param queryParamsMap
@@ -169,7 +170,7 @@ public class SimulatorRemoteResource {
      * @param onGetListener
      *            Event handler which will be invoked with the response for GET
      *            request with a map of attribute name and values.
-     * 
+     *
      * @throws InvalidArgsException
      *             This exception will be thrown if any parameter has invalid
      *             values.
@@ -184,8 +185,9 @@ public class SimulatorRemoteResource {
             throws InvalidArgsException, NoSupportException, SimulatorException;
 
     /**
-     * Method to set the representation of a resource (via PUT)
-     * 
+     * API to send PUT request to the resource. Response will be notified
+     * asynchronously via callback set for {@link IPutListener}.
+     *
      * @param representation
      *            {@link SimulatorResourceModel} holding the representation of
      *            the resource.
@@ -194,7 +196,7 @@ public class SimulatorRemoteResource {
      * @param onPutListener
      *            Event handler which will be invoked with the response for PUT
      *            request with a map of attribute name and values.
-     * 
+     *
      * @throws InvalidArgsException
      *             This exception will be thrown if any parameter has invalid
      *             value.
@@ -211,8 +213,9 @@ public class SimulatorRemoteResource {
     }
 
     /**
-     * Method to set the representation of a resource (via PUT).
-     * 
+     * API to send PUT request to the resource. Response will be notified
+     * asynchronously via callback set for {@link IPutListener}.
+     *
      * @param resourceInterface
      *            Interface type of the resource to operate on.
      * @param representation
@@ -223,7 +226,7 @@ public class SimulatorRemoteResource {
      * @param onPutListener
      *            Event handler which will be invoked with the response for PUT
      *            request with a map of attribute name and values.
-     * 
+     *
      * @throws InvalidArgsException
      *             This exception will be thrown if any parameter has invalid
      *             value.
@@ -239,8 +242,9 @@ public class SimulatorRemoteResource {
             throws InvalidArgsException, NoSupportException, SimulatorException;
 
     /**
-     * Method to POST on a resource.
-     * 
+     * API to send POST request to the resource. Response will be notified
+     * asynchronously via callback set for {@link IPostListener}.
+     *
      * @param representation
      *            {@link SimulatorResourceModel} holding the representation of
      *            the resource
@@ -249,7 +253,7 @@ public class SimulatorRemoteResource {
      * @param onPostListener
      *            Event handler which will be invoked with the response for POST
      *            request with a map of attribute name and values.
-     * 
+     *
      * @throws InvalidArgsException
      *             This exception will be thrown if any parameter has invalid
      *             value.
@@ -266,8 +270,9 @@ public class SimulatorRemoteResource {
     }
 
     /**
-     * Method to POST on a resource.
-     * 
+     * API to send POST request to the resource. Response will be notified
+     * asynchronously via callback set for {@link IPostListener}.
+     *
      * @param resourceInterface
      *            Interface type of the resource to operate on.
      * @param representation
@@ -278,7 +283,7 @@ public class SimulatorRemoteResource {
      * @param onPostListener
      *            Event handler which will be invoked with the response for POST
      *            request with a map of attribute name and values.
-     * 
+     *
      * @throws InvalidArgsException
      *             This exception will be thrown if any parameter has invalid
      *             value.
@@ -294,30 +299,33 @@ public class SimulatorRemoteResource {
             throws InvalidArgsException, NoSupportException, SimulatorException;
 
     /**
-     * Method to set the RAML file path from application
-     * 
-     * @param ramlPath
-     *            RAML configuration file path
-     * 
+     * API to provide remote resource configure information,
+     * which is required for using automation feature.
+     *
+     * @param path
+     *            Path to RAML file.
+     *
      * @throws InvalidArgsException
      *             Thrown if the RAML configuration file path is invalid.
      * @throws SimulatorException
      *             Thrown for other errors.
      */
-    public native void configureRAMLPath(String ramlPath)
+    public native void setConfigInfo(String path)
             throws InvalidArgsException, SimulatorException;
 
     /**
-     * Method to start verification of a resource using automation.
-     * 
+     * API to send multiple requests for the resource, based on
+     * the configure file provided from {@link setConfigInfo}.
+     * This verifies response received as well.
+     *
      * @param requestType
      *            Request type to verify.
      * @param onVerifyListener
      *            This event handler will be invoked with the current status of
      *            the automation.
-     * 
+     *
      * @return Automation ID.
-     * 
+     *
      * @throws InvalidArgsException
      *             This exception will be thrown if any parameter has invalid
      *             value.
@@ -337,17 +345,12 @@ public class SimulatorRemoteResource {
         return startVerification(requestType.ordinal(), onVerifyListener);
     }
 
-    private native int startVerification(int requestType,
-            IVerificationListener onVerifyListener)
-            throws InvalidArgsException, NoSupportException,
-            OperationInProgressException, SimulatorException;
-
     /**
-     * Method to stop verification of a resource previously started.
-     * 
+     * API to stop sending requests which has been started using {@link setConfigInfo}.
+     *
      * @param id
      *            Automation ID.
-     * 
+     *
      * @throws InvalidArgsException
      *             Thrown if the automation ID is invalid.
      * @throws NoSupportException
@@ -358,6 +361,11 @@ public class SimulatorRemoteResource {
     public native void stopVerification(int id) throws InvalidArgsException,
             NoSupportException, SimulatorException;
 
+    private native int startVerification(int requestType,
+            IVerificationListener onVerifyListener)
+            throws InvalidArgsException, NoSupportException,
+            OperationInProgressException, SimulatorException;
+
     @Override
     protected void finalize() throws Throwable {
         super.finalize();
index 7c5e2b1..ccb0c36 100644 (file)
@@ -35,7 +35,7 @@ public enum SimulatorVerificationType {
     /**
      * Method to get the {@link SimulatorVerificationType} from an integer
      * value.
-     * 
+     *
      * @param value
      *            Integral value of {@link SimulatorVerificationType}.
      * @return {@link SimulatorVerificationType} corresponding to the given
index 11750ce..0dceda2 100644 (file)
@@ -23,7 +23,7 @@ public interface IObserver {
     /**
      * This callback method will be called when a new observer is added or an
      * existing observer is removed.
-     * 
+     *
      * @param resourceURI
      *            URI of the resource.
      * @param state
index e082f80..1672abc 100644 (file)
@@ -33,7 +33,7 @@ public class ObserverInfo {
 
     /**
      * This method is used to return the observer's id.
-     * 
+     *
      * @return Observer's Id.
      */
     public int getId() {
@@ -42,7 +42,7 @@ public class ObserverInfo {
 
     /**
      * This method is used to return the observer's address.
-     * 
+     *
      * @return Observer's device address.
      */
     public String getAddress() {
@@ -51,7 +51,7 @@ public class ObserverInfo {
 
     /**
      * This method is used to return the observer's port number.
-     * 
+     *
      * @return Observer's port number.
      */
     public int getPort() {
index a352e4c..78cc281 100644 (file)
@@ -79,41 +79,26 @@ public class SimulatorResourceServer {
         return interfaceType;
     }
 
-    @Override
-    protected void finalize() throws Throwable {
-        try {
-            dispose();
-        } catch(Throwable t){
-            throw t;
-        } finally{
-            System.out.println("Calling finalize of Super Class");
-            super.finalize();
-        }
-    }
-
-    /**
-     * Native function to get the {@link SimulatorResourceModel} of the
-     * corresponding resource.
+   /**
+     * API to get the {@link SimulatorResourceModel} of the
+     * simulated resource.
      *
      * @return {@link SimulatorResourceModel} object on success, otherwise null.
-     * 
-     * @throws InvalidArgsException
-     *             This exception will be thrown if the native resource object
-     *             is invalid. values.
+     *
      * @throws SimulatorException
-     *             This exception will be thrown for other errors.
+     *             This exception will be thrown if simulated resource is not proper.
      */
     public native SimulatorResourceModel getModel()
-            throws InvalidArgsException, SimulatorException;
+            throws SimulatorException;
 
     /**
-     * Native function to add an attribute whose value is of type int.
+     * API to add an attribute whose value is of type int.
      *
      * @param key
      *            Name of the attribute.
      * @param value
      *            Initial value of the attribute.
-     * 
+     *
      * @throws InvalidArgsException
      *             This exception will be thrown if any parameter has invalid
      *             values.
@@ -124,13 +109,13 @@ public class SimulatorResourceServer {
             throws InvalidArgsException, SimulatorException;
 
     /**
-     * Native function to add an attribute whose value is of type double.
+     * API to  add an attribute whose value is of type double.
      *
      * @param key
      *            Name of the attribute.
      * @param value
      *            Initial value of the attribute.
-     * 
+     *
      * @throws InvalidArgsException
      *             This exception will be thrown if any parameter has invalid
      *             values.
@@ -141,13 +126,13 @@ public class SimulatorResourceServer {
             throws InvalidArgsException, SimulatorException;
 
     /**
-     * Native function to add an attribute whose value is of type boolean.
+     * API to  add an attribute whose value is of type boolean.
      *
      * @param key
      *            Name of the attribute.
      * @param value
      *            Initial value of the attribute.
-     * 
+     *
      * @throws InvalidArgsException
      *             This exception will be thrown if any parameter has invalid
      *             values.
@@ -158,13 +143,13 @@ public class SimulatorResourceServer {
             throws InvalidArgsException, SimulatorException;
 
     /**
-     * Native function to add an attribute whose value is of type String.
+     * API to  add an attribute whose value is of type String.
      *
      * @param key
      *            Name of the attribute.
      * @param value
      *            Initial value of the attribute.
-     * 
+     *
      * @throws InvalidArgsException
      *             This exception will be thrown if any parameter has invalid
      *             values.
@@ -175,14 +160,14 @@ public class SimulatorResourceServer {
             throws InvalidArgsException, SimulatorException;
 
     /**
-     * Native function to update the value of an attribute whose value is of
+     * API to  update the value of an attribute whose value is of
      * type int.
      *
      * @param key
      *            Name of the attribute.
      * @param value
      *            New value of the attribute.
-     * 
+     *
      * @throws InvalidArgsException
      *             This exception will be thrown if any parameter has invalid
      *             values.
@@ -193,14 +178,14 @@ public class SimulatorResourceServer {
             throws InvalidArgsException, SimulatorException;
 
     /**
-     * Native function to update the value of an attribute whose value is of
+     * API to  update the value of an attribute whose value is of
      * type double.
      *
      * @param key
      *            Name of the attribute.
      * @param value
      *            New value of the attribute.
-     * 
+     *
      * @throws InvalidArgsException
      *             This exception will be thrown if any parameter has invalid
      *             values.
@@ -211,14 +196,14 @@ public class SimulatorResourceServer {
             throws InvalidArgsException, SimulatorException;
 
     /**
-     * Native function to update the value of an attribute whose value is of
+     * API to  update the value of an attribute whose value is of
      * type boolean.
      *
      * @param key
      *            Name of the attribute.
      * @param value
      *            New value of the attribute.
-     * 
+     *
      * @throws InvalidArgsException
      *             This exception will be thrown if any parameter has invalid
      *             values.
@@ -229,14 +214,14 @@ public class SimulatorResourceServer {
             throws InvalidArgsException, SimulatorException;
 
     /**
-     * Native function to update the value of an attribute whose value is of
+     * API to  update the value of an attribute whose value is of
      * type String.
      *
      * @param key
      *            Name of the attribute.
      * @param value
      *            New value of the attribute.
-     * 
+     *
      * @throws InvalidArgsException
      *             This exception will be thrown if any parameter has invalid
      *             values.
@@ -247,52 +232,52 @@ public class SimulatorResourceServer {
             throws InvalidArgsException, SimulatorException;
 
     /**
-     * Native function to automatically update the value of an attribute from
+     * API to update the value of an attribute from
      * its allowed values.
      *
-     * @param attrName
+     * @param key
      *            Name of the attribute.
      * @param index
      *            Index of the value in the allowed values.
-     * 
+     *
      * @throws InvalidArgsException
      *             This exception will be thrown if any parameter has invalid
      *             values.
      * @throws SimulatorException
      *             This exception will be thrown for other errors.
      */
-    public native void updateAttributeFromAllowedValues(String attrName,
+    public native void updateAttributeFromAllowedValues(String key,
             int index) throws InvalidArgsException, SimulatorException;
 
     /**
-     * Native function to set the range of allowed values. This function is
-     * intended to be used for integral type attributes.
+     * API to  set the range of allowed values. This function is
+     * intended to be used for integer type attributes.
      *
-     * @param attrName
+     * @param key
      *            Name of the attribute.
      * @param min
      *            Minimum value in the range.
      * @param max
      *            Maximum value in the range.
-     * 
+     *
      * @throws InvalidArgsException
      *             This exception will be thrown if any parameter has invalid
      *             values.
      * @throws SimulatorException
      *             This exception will be thrown for other errors.
      */
-    public native void setRange(String attrName, int min, int max)
+    public native void setRange(String key, int min, int max)
             throws InvalidArgsException, SimulatorException;
 
     /**
-     * Native function to set the allowed values of attribute whose value is of
+     * API to  set the allowed values of attribute whose value is of
      * type int.
      *
      * @param key
      *            Name of the attribute.
      * @param allowedValues
      *            Allowed values of the attribute.
-     * 
+     *
      * @throws InvalidArgsException
      *             This exception will be thrown if any parameter has invalid
      *             values.
@@ -304,14 +289,14 @@ public class SimulatorResourceServer {
             SimulatorException;
 
     /**
-     * Native function to set the allowed values of attribute whose value is of
+     * API to  set the allowed values of attribute whose value is of
      * type double.
      *
      * @param key
      *            Name of the attribute.
      * @param allowedValues
      *            Allowed values of the attribute.
-     * 
+     *
      * @throws InvalidArgsException
      *             This exception will be thrown if any parameter has invalid
      *             values.
@@ -323,14 +308,14 @@ public class SimulatorResourceServer {
             SimulatorException;
 
     /**
-     * Native function to set the allowed values of attribute whose value is of
+     * API to  set the allowed values of attribute whose value is of
      * type String.
      *
      * @param key
      *            Name of the attribute.
      * @param allowedValues
      *            Allowed values of the attribute.
-     * 
+     *
      * @throws InvalidArgsException
      *             This exception will be thrown if any parameter has invalid
      *             values.
@@ -342,7 +327,7 @@ public class SimulatorResourceServer {
             SimulatorException;
 
     /**
-     * Native function to start the resource level automation. This automation
+     * API to  start the resource level automation. This automation
      * involves automatically updating all the possible values for all the
      * attributes sequentially.
      *
@@ -353,7 +338,7 @@ public class SimulatorResourceServer {
      *            Listener to be notified when automation ends.
      *
      * @return Automation ID using which the automation can be stopped.
-     * 
+     *
      * @throws InvalidArgsException
      *             This exception will be thrown if any parameter has invalid
      *             values.
@@ -366,12 +351,8 @@ public class SimulatorResourceServer {
         return startResourceAutomation(typeOfAutomation.getValue(), listener);
     }
 
-    private native int startResourceAutomation(int typeOfAutomation,
-            IAutomation listener) throws InvalidArgsException,
-            SimulatorException;
-
     /**
-     * Native function to start the attribute level automation. This automation
+     * API to  start the attribute level automation. This automation
      * involves automatically updating all the possible values for a given
      * attribute sequentially.
      *
@@ -384,7 +365,7 @@ public class SimulatorResourceServer {
      *            Listener to be notified when automation ends.
      *
      * @return Automation ID using which the automation can be stopped.
-     * 
+     *
      * @throws InvalidArgsException
      *             This exception will be thrown if any parameter has invalid
      *             values.
@@ -398,31 +379,24 @@ public class SimulatorResourceServer {
                 listener);
     }
 
-    private native int startAttributeAutomation(String attrName,
-            int typeOfAutomation, IAutomation listener)
-            throws InvalidArgsException, SimulatorException;
-
     /**
-     * Native function to stop the automation.
+     * API to  stop the automation based on automation id.
      *
      * @param automationId
      *            Using which a specific automation can be stopped.
-     * 
-     * @throws InvalidArgsException
-     *             This exception will be thrown if the native resource object
-     *             does not exist.
+     *
      * @throws SimulatorException
      *             This exception will be thrown for other errors.
      */
     public native void stopAutomation(int automationId)
-            throws InvalidArgsException, SimulatorException;
+            throws SimulatorException;
 
     /**
-     * Native function to remove an attribute from the resource model.
+     * API to remove an attribute from the simulated resource.
      *
      * @param key
      *            Name of the attribute to be deleted.
-     * 
+     *
      * @throws InvalidArgsException
      *             This exception will be thrown either if the parameter has
      *             invalid value or the native resource object does not exist.
@@ -433,10 +407,10 @@ public class SimulatorResourceServer {
             SimulatorException;
 
     /**
-     * Native function to get the details of a list of observers.
-     * 
+     * API to get observers  information.
+     *
      * @return An array of {@link ObserverInfo} objects.
-     * 
+     *
      * @throws InvalidArgsException
      *             This exception will be thrown if the native resource object
      *             does not exist.
@@ -447,11 +421,11 @@ public class SimulatorResourceServer {
             throws InvalidArgsException, SimulatorException;
 
     /**
-     * Native function to set callback to receive the clients information who are started or stopped observing the simulated resource.
-     * 
+     * API to set callback to receive notifications when observer is added/removed.
+     *
      * @param observer
      *            Listener to be notified when clients start/stop observing.
-     * 
+     *
      * @throws InvalidArgsException
      *             This exception will be thrown either if the parameter has
      *             invalid value or the native resource object does not exist.
@@ -462,11 +436,11 @@ public class SimulatorResourceServer {
             throws InvalidArgsException, SimulatorException;
 
     /**
-     * Native function which sends notification to a specific observer.
-     * 
+     * API to notify simulated resource's state to a specific observer.
+     *
      * @param id
      *            Observer's Id.
-     * 
+     *
      * @throws InvalidArgsException
      *             This exception will be thrown if the native resource object
      *             does not exist.
@@ -477,8 +451,8 @@ public class SimulatorResourceServer {
             SimulatorException;
 
     /**
-     * Native function which sends notification to all observers.
-     * 
+     * API to notify simualted resource's state to all observers.
+     *
      * @throws InvalidArgsException
      *             This exception will be thrown if the native resource object
      *             does not exist.
@@ -488,9 +462,25 @@ public class SimulatorResourceServer {
     public native void notifyAllObservers() throws InvalidArgsException,
             SimulatorException;
 
-    /**
-     * Native function to release the memory allocated to the native object for
-     * SimulatorResourceServer.
-     */
+    private native int startResourceAutomation(int typeOfAutomation,
+            IAutomation listener) throws InvalidArgsException,
+            SimulatorException;
+
+    private native int startAttributeAutomation(String attrName,
+        int typeOfAutomation, IAutomation listener)
+        throws InvalidArgsException, SimulatorException;
+
+    @Override
+    protected void finalize() throws Throwable {
+        try {
+            dispose();
+        } catch(Throwable t){
+            throw t;
+        } finally{
+            System.out.println("Calling finalize of Super Class");
+            super.finalize();
+        }
+    }
+
     private native void dispose();
 }
index 7cd3290..5943264 100644 (file)
 #include "attribute_generator.h"
 
 AttributeGenerator::AttributeGenerator(SimulatorResourceModel::Attribute &attribute)
+    :   m_name(attribute.getName()),
+        m_min(INT_MIN),
+        m_max(INT_MAX),
+        m_rangeIndex(-1),
+        m_nextAllowedValueIndex(0),
+        m_prevAllowedValueIndex(0),
+        m_hasRange(false),
+        m_hasAllowedValue(false)
 {
-    m_name.assign(attribute.getName());
-    m_type = attribute.getValueType();
-
-    if (!attribute.getValueType())
-        attribute.getRange(m_min, m_max);
-    if (m_max > 0)
+    if (attribute.getValueType() ==
+        SimulatorResourceModel::Attribute::ValueType::INTEGER)
     {
-        m_hasRange = true;
+        attribute.getRange(m_min, m_max);
+        if (INT_MIN != m_min && INT_MAX != m_max)
+        {
+            m_hasRange = true;
+            m_rangeIndex = m_min;
+        }
     }
-
-    if (!m_type)
-        m_rangeIndex = m_min;
-
-    m_allowedValues = attribute.getAllowedValues();
-    if (0 != m_allowedValues.size())
+    else
     {
-        m_hasAllowedValue = true;
+        m_allowedValues = attribute.getAllowedValues();
+        if (0 != m_allowedValues.size())
+        {
+            m_hasAllowedValue = true;
+        }
+        m_prevAllowedValueIndex = m_allowedValues.size();
     }
-    m_nextAllowedValueIndex = 0;
-    m_prevAllowedValueIndex = m_allowedValues.size();
-}
-
-AttributeGenerator::~AttributeGenerator()
-{
-    m_rangeIndex = 0;
-    m_min = 0;
-    m_max = 0;
-    m_nextAllowedValueIndex = 0;
-    m_prevAllowedValueIndex = 0;
-    m_type = 0;
 }
 
 bool AttributeGenerator::hasNext()
 {
-    if (m_hasRange && m_rangeIndex <= m_max && !m_type)
+    if (m_hasRange && m_rangeIndex <= m_max)
     {
         return true;
     }
@@ -69,72 +66,39 @@ bool AttributeGenerator::hasNext()
     return false;
 }
 
-AttributeSP AttributeGenerator::next()
+bool AttributeGenerator::next(SimulatorResourceModel::Attribute &attribute)
 {
-    AttributeSP attr = std::make_shared<SimulatorResourceModel::Attribute>(m_name);
+    attribute.setName(m_name);
 
-    if (!attr)
-        return nullptr;
-
-    if (m_hasRange && !m_type)
+    if (m_hasRange)
     {
-        attr->setName(m_name);
-        attr->setValue(m_rangeIndex++);
-        return attr;
+        attribute.setValue(m_rangeIndex++);
+        return true;
     }
-
-    if (m_hasAllowedValue)
+    else if (m_hasAllowedValue)
     {
-        switch (m_type)
-        {
-            case 1:
-                {
-                    attr->setValue(m_allowedValues[m_nextAllowedValueIndex++]);
-                }
-                break;
-
-            case 3:
-                {
-                    attr->setValue(m_allowedValues[m_nextAllowedValueIndex++]);
-                }
-                break;
-        }
-
-        return attr;
+        attribute.setValue(m_allowedValues[m_nextAllowedValueIndex++]);
+        return true;
     }
+
+    return false;
 }
 
-AttributeSP AttributeGenerator::previous()
+bool AttributeGenerator::previous(SimulatorResourceModel::Attribute &attribute)
 {
-    AttributeSP attr = std::make_shared<SimulatorResourceModel::Attribute>(m_name);
+    attribute.setName(m_name);
 
-    if (!attr)
-        return nullptr;
-
-    if (m_hasRange && !m_type)
+    if (m_hasRange)
     {
-        attr->setValue(m_rangeIndex - 1);
-        return attr;
+        attribute.setValue(m_rangeIndex - 1);
+        return true;
     }
-
-    if (m_hasAllowedValue)
+    else if (m_hasAllowedValue)
     {
-        switch (m_type)
-        {
-            case 1:
-                {
-                    attr->setValue(m_allowedValues[m_prevAllowedValueIndex - 1]);
-                }
-                break;
-
-            case 3:
-                {
-                    attr->setValue(m_allowedValues[m_prevAllowedValueIndex - 1]);
-                }
-                break;
-        }
-
-        return attr;
+        attribute.setValue(m_allowedValues[m_prevAllowedValueIndex - 1]);
+        return true;
     }
+
+    return false;
 }
 
index a2b3281..3f66372 100644 (file)
@@ -29,16 +29,16 @@ class AttributeGenerator
 {
     public:
         AttributeGenerator(SimulatorResourceModel::Attribute &attribute);
-        ~AttributeGenerator();
         bool hasNext();
-        AttributeSP next();
-        AttributeSP previous();
+        bool next(SimulatorResourceModel::Attribute &attribute);
+        bool previous(SimulatorResourceModel::Attribute &attribute);
+        void reset();
 
     private:
         std::string m_name;
-        int m_type;
-        int m_max;
+        SimulatorResourceModel::Attribute::ValueType m_type;
         int m_min;
+        int m_max;
         int m_rangeIndex;
         int m_nextAllowedValueIndex;
         int m_prevAllowedValueIndex;
index 47a676d..b8c8ebb 100644 (file)
@@ -76,14 +76,15 @@ void POSTRequestGenerator::SendAllRequests()
     OC_LOG(DEBUG, TAG, "Sending OP_START event");
     m_callback(m_id, OP_START);
 
-    std::map<std::string, SimulatorResourceModel::Attribute> attributes = m_rep->getAttributes();
-    if (!attributes.size())
-        return;
+    // Create attribute generator for value manipulation
+    std::vector<AttributeGenerator> attributeGenList;
+    for (auto &attributeElement : m_rep->getAttributes())
+        attributeGenList.push_back(AttributeGenerator(attributeElement.second));
 
-    std::vector<std::shared_ptr<AttributeGenerator>> attributeGenList;
-    for (auto & attribute : attributes)
+    if (!attributeGenList.size())
     {
-        attributeGenList.push_back(std::make_shared<AttributeGenerator>(attribute.second));
+        OC_LOG(ERROR, TAG, "Zero attribute found from resource model!");
+        return;
     }
 
     do
@@ -95,35 +96,17 @@ void POSTRequestGenerator::SendAllRequests()
 
             for (auto & attributeGen : attributeGenList)
             {
-                while (attributeGen->hasNext())
+                while (attributeGen.hasNext())
                 {
-                    SimulatorResourceModelSP repModel = std::make_shared<SimulatorResourceModel>();
-                    AttributeSP attr = attributeGen->next();
-                    int type = attr->getValueType();
-
-                    switch (type)
-                    {
-                        case 0:
-                            {
-                                int attributeValue = attr->getValue<int>();
-                                std::string attributeName = attr->getName();
-                                repModel->addAttribute(attributeName, attributeValue);
-                            }
-                            break;
-
-                        case 3:
-                            {
-                                std::string attributeValue = attr->getValue<std::string>();
-                                std::string attributeName = attr->getName();
-                                repModel->addAttribute(attributeName, attributeValue);
-                            }
-                            break;
-                    }
+                    SimulatorResourceModelSP repModel(new SimulatorResourceModel);
+                    SimulatorResourceModel::Attribute attribute;
+                    if (true == attributeGen.next(attribute))
+                        repModel->addAttribute(attribute);
 
                     // Send the request
                     m_requestSender->sendRequest(queryParam, repModel,
-                                                 std::bind(&POSTRequestGenerator::onResponseReceived,
-                                                           this, std::placeholders::_1, std::placeholders::_2), true);
+                            std::bind(&POSTRequestGenerator::onResponseReceived,
+                            this, std::placeholders::_1, std::placeholders::_2), true);
 
                     m_requestCnt++;
                 }
index 029f115..3c8d63b 100644 (file)
@@ -75,17 +75,19 @@ void PUTRequestGenerator::SendAllRequests()
     OC_LOG(DEBUG, TAG, "Sending OP_START event");
     m_callback(m_id, OP_START);
 
-    bool hasNext = false;
-    std::map<std::string, SimulatorResourceModel::Attribute> attributes = m_rep->getAttributes();
-    if (!attributes.size())
-        return;
+    // Create attribute generator for value manipulation
+    std::vector<AttributeGenerator> attributeGenList;
+    for (auto &attributeElement : m_rep->getAttributes())
+        attributeGenList.push_back(AttributeGenerator(attributeElement.second));
 
-    std::vector<std::shared_ptr<AttributeGenerator>> attributeGenList;
-    for (auto & attribute : attributes)
+    if (!attributeGenList.size())
     {
-        attributeGenList.push_back(std::make_shared<AttributeGenerator>(attribute.second));
+        OC_LOG(ERROR, TAG, "Zero attribute found from resource model!");
+        return;
     }
 
+    bool hasNext = false;
+
     do
     {
         if (!m_stopRequested)
@@ -95,43 +97,22 @@ void PUTRequestGenerator::SendAllRequests()
 
             while (true)
             {
-                SimulatorResourceModelSP repModel = std::make_shared<SimulatorResourceModel>();
-
+                SimulatorResourceModelSP repModel(new SimulatorResourceModel);
                 for (auto & attributeGen : attributeGenList)
                 {
-                    if (attributeGen->hasNext())
+                    if (attributeGen.hasNext())
                     {
-                        AttributeSP attr = attributeGen->next();
-                        int type = attr->getValueType();
-                        if (!type)
-                        {
-                            int attributeValue = attr->getValue<int>();
-                            std::string attributeName = attr->getName();
-                            repModel->addAttribute(attributeName, attributeValue);
-                        }
-                        else
-                        {
-                            std::string attributeValue = attr->getValue<std::string>();
-                            std::string attributeName = attr->getName();
-                            repModel->addAttribute(attr->getName(), attributeValue);
-                        }
+                        SimulatorResourceModel::Attribute attribute;
+                        if (true == attributeGen.next(attribute))
+                            repModel->addAttribute(attribute);
 
                         hasNext = true;
                     }
                     else
                     {
-                        AttributeSP attr = attributeGen->previous();
-                        int type = attr->getValueType();
-                        if (!type)
-                        {
-                            int attributeValue = attr->getValue<int>();
-                            repModel->addAttribute(attr->getName(), attributeValue);
-                        }
-                        else
-                        {
-                            std::string attributeValue = attr->getValue<std::string>();
-                            repModel->addAttribute(attr->getName(), attributeValue);
-                        }
+                        SimulatorResourceModel::Attribute attribute;
+                        if (true == attributeGen.previous(attribute))
+                            repModel->addAttribute(attribute);
                     }
                 }
 
@@ -139,8 +120,8 @@ void PUTRequestGenerator::SendAllRequests()
                 {
                     // Send the request
                     m_requestSender->sendRequest(queryParam, repModel,
-                                                 std::bind(&PUTRequestGenerator::onResponseReceived, this,
-                                                           std::placeholders::_1, std::placeholders::_2), true);
+                            std::bind(&PUTRequestGenerator::onResponseReceived, this,
+                            std::placeholders::_1, std::placeholders::_2), true);
 
                     m_requestCnt++;
                     hasNext = false;
index 2d0e890..1e51e7e 100644 (file)
@@ -55,7 +55,7 @@ std::map<std::string, std::string> QPGenerator::next()
     for (auto ele : m_qpDetails)
         queryParams[ele.key] = ele.values[ele.index];
 
-    for (int index = m_qpDetails.size(); index >= 0; index--)
+    for (int index = m_qpDetails.size() - 1; index >= 0; index--)
     {
         m_qpDetails[index].index++;
         if (m_qpDetails[index].index >= m_qpDetails[index].values.size()) // Boundary check
index 1e2ca62..4e5ba75 100644 (file)
@@ -127,7 +127,7 @@ OCStackResult PUTRequestSender::send(OC::QueryParamsMap &queryParams,
                                      SimulatorResourceModelSP &repModel, OC::GetCallback callback)
 {
     OC::OCRepresentation ocRep;
-    if (!repModel)
+    if (repModel)
     {
         ocRep = repModel->getOCRepresentation();
     }
@@ -143,7 +143,7 @@ OCStackResult POSTRequestSender::send(OC::QueryParamsMap &queryParams,
                                       SimulatorResourceModelSP &repModel, OC::GetCallback callback)
 {
     OC::OCRepresentation ocRep;
-    if (!repModel)
+    if (repModel)
         ocRep = repModel->getOCRepresentation();
 
     SIM_LOG(ILogger::INFO, "Sending POST request..." << "\n" << getRequestString(queryParams, ocRep));
index 9805a81..9de0782 100644 (file)
@@ -286,7 +286,7 @@ int SimulatorRemoteResourceImpl::startVerification(RequestType type,
         throw NoSupportException("Resource is not configured with RAML!");
     }
 
-    if (m_requestModelList.end() != m_requestModelList.find(type))
+    if (m_requestModelList.end() == m_requestModelList.find(type))
         throw NoSupportException("Resource does not support this request type!");
 
     // Local callback for handling progress sate callback
@@ -302,8 +302,8 @@ int SimulatorRemoteResourceImpl::startVerification(RequestType type,
             if (m_getRequestSender)
             {
                 return m_autoRequestGenMngr->startOnGET(m_getRequestSender,
-                                                        m_requestModelList[RequestType::RQ_TYPE_GET]->getQueryParams(),
-                                                        localCallback);
+                                    m_requestModelList[RequestType::RQ_TYPE_GET]->getQueryParams(),
+                                    localCallback);
             }
             break;
 
@@ -311,9 +311,9 @@ int SimulatorRemoteResourceImpl::startVerification(RequestType type,
             if (m_putRequestSender)
             {
                 return m_autoRequestGenMngr->startOnPUT(m_putRequestSender,
-                                                        m_requestModelList[RequestType::RQ_TYPE_PUT]->getQueryParams(),
-                                                        m_requestModelList[RequestType::RQ_TYPE_PUT]->getRepSchema(),
-                                                        localCallback);
+                                    m_requestModelList[RequestType::RQ_TYPE_PUT]->getQueryParams(),
+                                    m_requestModelList[RequestType::RQ_TYPE_PUT]->getRepSchema(),
+                                    localCallback);
             }
             break;
 
@@ -321,9 +321,9 @@ int SimulatorRemoteResourceImpl::startVerification(RequestType type,
             if (m_postRequestSender)
             {
                 return m_autoRequestGenMngr->startOnPOST(m_putRequestSender,
-                        m_requestModelList[RequestType::RQ_TYPE_PUT]->getQueryParams(),
-                        m_requestModelList[RequestType::RQ_TYPE_PUT]->getRepSchema(),
-                        localCallback);
+                                    m_requestModelList[RequestType::RQ_TYPE_POST]->getQueryParams(),
+                                    m_requestModelList[RequestType::RQ_TYPE_POST]->getRepSchema(),
+                                    localCallback);
             }
             break;
 
@@ -387,7 +387,7 @@ void SimulatorRemoteResourceImpl::configure(std::shared_ptr<RAML::Raml> &raml)
         m_postRequestSender->setRequestModel(m_requestModelList[RequestType::RQ_TYPE_POST]);
     }
 
-    if (m_autoRequestGenMngr)
+    if (!m_autoRequestGenMngr)
     {
         m_autoRequestGenMngr = std::make_shared<AutoRequestGenMngr>();
     }
index c3adf51..9a20021 100644 (file)
@@ -44,7 +44,7 @@ std::map<RequestType, RequestModelSP> RequestModelBuilder::build(const std::stri
         for (auto  & action :  (resource.second)->getActions())
         {
             RequestModelSP requestModel = createRequestModel(action.second);
-            if (!requestModel)
+            if (requestModel)
                 modelList[requestModel->type()] = requestModel;
         }
     }
@@ -67,7 +67,7 @@ RequestModelSP RequestModelBuilder::createRequestModel(const RAML::ActionPtr &ac
         return nullptr;
     }
 
-    // Construcut RequestModel
+    // Construct RequestModel
     RequestModelSP requestModel(new RequestModel(getRequestType(actionType)));
 
     // Get the allowed query parameters of the request
@@ -111,6 +111,10 @@ ResponseModelSP RequestModelBuilder::createResponseModel(int code,
 SimulatorResourceModelSP RequestModelBuilder::createRepSchema(const RAML::RequestResponseBodyPtr
         &rep)
 {
+    if (!rep)
+    {
+        return nullptr;
+    }
     RAML::SchemaPtr schema = rep->getSchema();
     if (!schema)
     {
@@ -124,13 +128,17 @@ SimulatorResourceModelSP RequestModelBuilder::createRepSchema(const RAML::Reques
     SimulatorResourceModelSP repSchema = std::make_shared<SimulatorResourceModel>();
     for (auto & propertyEntry : properties->getProperties())
     {
+        std::string propName = propertyEntry.second->getName();
+        if ("rt" == propName || "resourceType" == propName || "if" == propName
+            || "p" == propName || "n" == propName || "id" == propName)
+            continue;
+
         int valueType = propertyEntry.second->getValueType();
         switch (valueType)
         {
             case 0: // Integer
                 {
                     // Add the attribute with value
-                    std::cout << "[createRepresentationSchema] Adding Attribute of type int" << std::endl;
                     repSchema->addAttribute(propertyEntry.second->getName(), propertyEntry.second->getValue<int>());
 
                     // Set the range
@@ -143,7 +151,6 @@ SimulatorResourceModelSP RequestModelBuilder::createRepSchema(const RAML::Reques
             case 1: // Double
                 {
                     // Add the attribute with value
-                    std::cout << "[createRepresentationSchema] Adding Attribute of type double" << std::endl;
                     repSchema->addAttribute(propertyEntry.second->getName(), propertyEntry.second->getValue<double>());
 
                     std::vector<SimulatorResourceModel::Attribute::ValueVariant> propValues =
@@ -166,7 +173,6 @@ SimulatorResourceModelSP RequestModelBuilder::createRepSchema(const RAML::Reques
             case 2: // Boolean
                 {
                     // Add the attribute with value
-                    std::cout << "[createRepresentationSchema] Adding Attribute of type boolean" << std::endl;
                     repSchema->addAttribute(propertyEntry.second->getName(), propertyEntry.second->getValue<bool>());
                 }
                 break;
@@ -174,7 +180,6 @@ SimulatorResourceModelSP RequestModelBuilder::createRepSchema(const RAML::Reques
             case 3: // String
                 {
                     // Add the attribute with value
-                    std::cout << "[createRepresentationSchema] Adding Attribute of type string" << std::endl;
                     repSchema->addAttribute(propertyEntry.second->getName(),
                                             propertyEntry.second->getValue<std::string>());
 
index 213cf4b..8398a18 100644 (file)
@@ -37,10 +37,9 @@ SimulatorResult ResponseModel::verifyResponse(const OC::OCRepresentation &rep)
             return SIMULATOR_UKNOWN_PROPERTY;
         }
 
-        int type = attribute.getValueType();
-        switch (type)
+        switch (attribute.getValueType())
         {
-            case 0: // Integer
+            case SimulatorResourceModel::Attribute::ValueType::INTEGER : // Integer
                 {
                     SimulatorResult result = validateAttributeInteger(attribute, ocAttribute);
                     if (SIMULATOR_OK != result)
@@ -50,7 +49,7 @@ SimulatorResult ResponseModel::verifyResponse(const OC::OCRepresentation &rep)
                 }
                 break;
 
-            case 1: // Double
+            case SimulatorResourceModel::Attribute::ValueType::DOUBLE : // Double
                 {
                     SimulatorResult result = validateAttributeDouble(attribute, ocAttribute);
                     if (SIMULATOR_OK != result)
@@ -60,7 +59,7 @@ SimulatorResult ResponseModel::verifyResponse(const OC::OCRepresentation &rep)
                 }
                 break;
 
-            case 2: // String
+            case SimulatorResourceModel::Attribute::ValueType::STRING : // String
                 {
                     SimulatorResult result = validateAttributeString(attribute, ocAttribute);
                     if (SIMULATOR_OK != result)
index 9445b11..417bb84 100644 (file)
 #include <sstream>
 #include <boost/lexical_cast.hpp>
 
+template <typename T>
+struct TypeConverter
+{
+    constexpr static SimulatorResourceModel::Attribute::ValueType type =
+            SimulatorResourceModel::Attribute::ValueType::UNKNOWN;
+};
+
+template <>
+struct TypeConverter<int>
+{
+    constexpr static SimulatorResourceModel::Attribute::ValueType type =
+            SimulatorResourceModel::Attribute::ValueType::INTEGER;
+};
+
+template <>
+struct TypeConverter<double>
+{
+    constexpr static SimulatorResourceModel::Attribute::ValueType type =
+            SimulatorResourceModel::Attribute::ValueType::DOUBLE;
+};
+
+template <>
+struct TypeConverter<bool>
+{
+    constexpr static SimulatorResourceModel::Attribute::ValueType type =
+            SimulatorResourceModel::Attribute::ValueType::BOOLEAN;
+};
+
+template <>
+struct TypeConverter<std::string>
+{
+    constexpr static SimulatorResourceModel::Attribute::ValueType type =
+            SimulatorResourceModel::Attribute::ValueType::STRING;
+};
+
+class attribute_type_visitor : public boost::static_visitor<
+        SimulatorResourceModel::Attribute::ValueType>
+{
+    public:
+        template <typename T>
+        result_type operator ()(const T &)
+        {
+            return TypeConverter<T>::type;
+        }
+};
+
 class to_string_visitor : public boost::static_visitor<std::string>
 {
     public:
         template <typename T>
         result_type operator ()(const T &value)
         {
-            return boost::lexical_cast<std::string>(value);
+            try
+            {
+                return boost::lexical_cast<std::string>(value);
+            }
+            catch (const boost::bad_lexical_cast &e)
+            {
+                return "";
+            }
         }
 };
 
@@ -167,6 +220,12 @@ void SimulatorResourceModel::Attribute::setFromAllowedValue(unsigned int index)
     m_value = m_allowedValues.at(index);
 }
 
+SimulatorResourceModel::Attribute::ValueType SimulatorResourceModel::Attribute::getValueType() const
+{
+    attribute_type_visitor typeVisitor;
+    return boost::apply_visitor(typeVisitor, m_value);
+}
+
 std::string SimulatorResourceModel::Attribute::valueToString() const
 {
     to_string_visitor visitor;
@@ -222,6 +281,15 @@ const
     return m_attributes;
 }
 
+void SimulatorResourceModel::addAttribute(const SimulatorResourceModel::Attribute &attribute)
+{
+    if (!attribute.getName().empty() &&
+        m_attributes.end() == m_attributes.find(attribute.getName()))
+    {
+        m_attributes[attribute.getName()] = attribute;
+    }
+}
+
 void SimulatorResourceModel::setRange(const std::string &attrName, const int min, const int max)
 {
     if (m_attributes.end() != m_attributes.find(attrName))
index b162cdd..c66711a 100644 (file)
@@ -39,7 +39,8 @@ AttributeUpdateAutomation::AttributeUpdateAutomation(int id, SimulatorResourceSe
         m_stopRequested(false),
         m_updateInterval(interval),
         m_callback(callback),
-        m_finishedCallback(finishedCallback) {}
+        m_finishedCallback(finishedCallback),
+        m_thread(nullptr) {}
 
 void AttributeUpdateAutomation::start()
 {
@@ -64,7 +65,8 @@ void AttributeUpdateAutomation::start()
 void AttributeUpdateAutomation::stop()
 {
     m_stopRequested = true;
-    m_thread->join();
+    if (m_thread)
+        m_thread->join();
 }
 
 void AttributeUpdateAutomation::updateAttribute()
@@ -75,7 +77,7 @@ void AttributeUpdateAutomation::updateAttribute()
         {
             setAttributeValue();
         }
-        catch(SimulatorException &e)
+        catch (SimulatorException &e)
         {
             break;
         }
@@ -100,32 +102,35 @@ void AttributeUpdateAutomation::updateAttribute()
 
 void AttributeUpdateAutomation::setAttributeValue()
 {
-    if (0 == m_attribute.getValueType()) // For integer type values
+    SimulatorResourceServerImpl *resourceImpl =
+        dynamic_cast<SimulatorResourceServerImpl *>(m_resource);
+    if (!resourceImpl)
+        return;
+
+    if (SimulatorResourceModel::Attribute::ValueType::INTEGER ==
+            m_attribute.getValueType()) // For integer type values
     {
         int min;
         int max;
-        SimulatorResourceServerImpl *resourceImpl;
-        resourceImpl = dynamic_cast<SimulatorResourceServerImpl *>(m_resource);
+
         m_attribute.getRange(min, max);
         for (int value = min; value <= max; value++)
         {
             if (m_stopRequested)
                 break;
-            m_resource->updateAttributeValue(m_attribute.getName(), value);
-            resourceImpl->resourceModified();
+            resourceImpl->updateAttributeValue(m_attribute.getName(), value);
+            resourceImpl->notifyApp();
             SLEEP_FOR(m_updateInterval);
         }
     }
     else
     {
-        SimulatorResourceServerImpl *resourceImpl;
-        resourceImpl = dynamic_cast<SimulatorResourceServerImpl *>(m_resource);
         for (int index = 0; index < m_attribute.getAllowedValuesSize(); index++)
         {
             if (m_stopRequested)
                 break;
-            m_resource->updateFromAllowedValues(m_attribute.getName(), index);
-            resourceImpl->resourceModified();
+            resourceImpl->updateFromAllowedValues(m_attribute.getName(), index);
+            resourceImpl->notifyApp();
             SLEEP_FOR(m_updateInterval);
         }
     }
index 8a5f1d2..ba80911 100644 (file)
@@ -44,12 +44,12 @@ class AttributeUpdateAutomation
         std::string m_attrName;
         AutomationType m_type;
         int m_id;
-        std::thread *m_thread;
         bool m_stopRequested;
         int m_updateInterval;
         SimulatorResourceModel::Attribute m_attribute;
         updateCompleteCallback m_callback;
         std::function<void (const int)> m_finishedCallback;
+        std::thread *m_thread;
 };
 
 typedef std::shared_ptr<AttributeUpdateAutomation> AttributeUpdateAutomationSP;
@@ -72,7 +72,6 @@ class ResourceUpdateAutomation
         SimulatorResourceServer *m_resource;
         AutomationType m_type;
         int m_id;
-        std::thread *m_thread;
         int m_updateInterval;
         SimulatorResourceModel m_resModel;
         std::map<int, AttributeUpdateAutomationSP> m_attrUpdationList;
index e0f6c63..1567f4f 100644 (file)
@@ -45,7 +45,7 @@ int UpdateAutomationMngr::startResourceAutomation(SimulatorResourceServer *resou
     resourceAutomation->start();
 
     OC_LOG_V(DEBUG, TAG, "Resource automation successfully started [id: %d]", m_id);
-    SIM_LOG(ILogger::INFO, "Resource automation successfully started : " << m_id);
+    SIM_LOG(ILogger::INFO, "Resource automation successfully started [ id: " << m_id << " ]");
 
     m_resourceUpdationList[m_id] = resourceAutomation;
     return m_id++;
@@ -70,8 +70,9 @@ int UpdateAutomationMngr::startAttributeAutomation(SimulatorResourceServer *reso
 
     OC_LOG_V(DEBUG, TAG, "Attribute automation successfully started [name: %s, id: %d]",
              attrName.c_str(), m_id);
-    SIM_LOG(ILogger::INFO, "Automation for " << attrName << " attribute has successfully started : " <<
-            m_id);
+    SIM_LOG(ILogger::INFO, "Automation for " << attrName << " attribute has successfully started [ id: "
+            <<
+            m_id << " ]");
 
     m_attrUpdationList[m_id] = attributeAutomation;
     return m_id++;
index 1bd372e..f7992b1 100644 (file)
 #include "simulator_resource_creator.h"
 #include "simulator_logger.h"
 #include <RamlParser.h>
-#include <boost/lexical_cast.hpp>
+#include "logger.h"
 
-using namespace RAML;
+#define TAG "SIM_RESOURCE_CREATOR"
 
 unsigned int SimulatorResourceCreator::s_id;
 SimulatorResourceServerImplSP SimulatorResourceCreator::createResource(
     const std::string &configPath)
 {
-    RamlParser *ramlParser = new RamlParser(configPath);
-    RamlPtr raml = ramlParser->getRamlPtr();
-    for (auto  resourceElement : raml->getResources())
+    RAML::RamlPtr raml;
+
+    try
+    {
+        RAML::RamlParser *ramlParser = new RAML::RamlParser(configPath);
+        raml = ramlParser->getRamlPtr();
+    }
+    catch (RAML::RamlException &e)
+    {
+        OC_LOG_V(ERROR, TAG, "RAML Exception occured! [%s]", e.what());
+        throw;
+    }
+
+    std::map<std::string, RAML::RamlResourcePtr> ramlResources = raml->getResources();
+    RAML::RamlResourcePtr ramlResource;
+    if (0 == ramlResources.size() || (ramlResource = ramlResources.begin()->second) == nullptr)
     {
-        SimulatorResourceServerImplSP resource(new SimulatorResourceServerImpl());
-        resource->setName(resourceElement.first);
-        resource->setURI(resourceElement.second->getResourceUri());
+        OC_LOG(ERROR, TAG, "Zero resources detected from RAML!");
+        return nullptr;
+    }
 
-        // TODO: Currently setting only baseline interface.
-        resource->setInterfaceType(OC::DEFAULT_INTERFACE);
-        // TODO: Need to modify based on the spec for observable property
-        resource->setObservable(true);
+    if (ramlResource)
+    {
+        SimulatorResourceServerImplSP simResource(new SimulatorResourceServerImpl());
+        simResource->setName(ramlResource->getDisplayName());
+        simResource->setURI(ramlResource->getResourceUri());
 
-        for (auto  action :  resourceElement.second->getActions())
+        // Get the resource representation schema from GET response body
+        RAML::ActionPtr action = ramlResource->getAction(RAML::ActionType::GET);
+        if (!action)
         {
-            for (auto  response :  action.second->getResponses())
+            OC_LOG(ERROR, TAG, "Failed to create resource representation schema as it does not"
+                    "posess the GET request!");
+            return nullptr;
+        }
+
+        RAML::ResponsePtr getResponse = action->getResponse("200");
+        if (!getResponse)
+        {
+            OC_LOG(ERROR, TAG, "Resource does not provide valid GET response!");
+            return nullptr;
+        }
+
+        RAML::RequestResponseBodyPtr responseBody = getResponse->getResponseBody("application/json");
+        if (responseBody)
+        {
+            RAML::JsonSchemaPtr resourceProperties = responseBody->getSchema()->getProperties();
+            for ( auto &propertyElement : resourceProperties->getProperties())
             {
-                for (auto bdy :  response.second->getResponseBody())
+                if (!propertyElement.second)
+                    continue;
+
+                std::string propName = propertyElement.second->getName();
+                if ("rt" == propName || "resourceType" == propName)
                 {
-                    auto resourceProperties = bdy.second->getSchema()->getProperties();
-
-                    for ( auto property : resourceProperties->getProperties() )
-                    {
-                        std::string propName = property.second->getName();
-
-                        if (propName == "rt")
-                        {
-                            resource->setResourceType(property.second->getValueString());
-                            continue;
-                        }
-
-                        // Include more property names if required based on spec support.
-                        if (propName == "if" || propName == "p" || propName == "n" || propName == "id")
-                            continue;
-
-                        SimulatorResourceModel::Attribute *attr = new SimulatorResourceModel::Attribute(propName);
-
-                        int type = property.second->getValueType();
-                        switch (type)
-                        {
-                            case 0: // Integer
-                                {
-                                    int attributeValue = property.second->getValueInt();
-                                    attr->setValue(attributeValue);
-                                }
-                                break;
-
-                            case 3: // String
-                                {
-                                    std::string attributeValue = property.second->getValueString();
-                                    attr->setValue(attributeValue);
-                                }
-                                break;
-                        }
-
-                        attr->setUpdateFrequencyTime(property.second->getUpdateFrequencyTime());
-
-                        int min = 0, max = 0, multipleof = 0;
-                        property.second->getRange(min, max, multipleof);
-                        attr->setRange(min, max);
-
-                        if (property.second->getAllowedValuesSize() > 0)
-                            attr->setAllowedValues(property.second->getAllowedValues());
-
-                        resource->addAttribute(*attr);
-                    }
-
-                    resource->setURI(constructURI(resource->getURI()));
-                    return resource;
+                    simResource->setResourceType(propertyElement.second->getValueString());
+                    continue;
                 }
+                else if ("if" == propName)
+                {
+                    simResource->setInterfaceType(propertyElement.second->getValueString());
+                    continue;
+                }
+                else if ("p" == propName || "n" == propName || "id" == propName)
+                {
+                    continue;
+                }
+
+                // Build representation attribute
+                SimulatorResourceModel::Attribute attribute(propName);
+                switch (propertyElement.second->getValueType())
+                {
+                    case 0: // Integer
+                        attribute.setValue(propertyElement.second->getValue<int>());
+                        break;
+
+                    case 1: // Double
+                        attribute.setValue(propertyElement.second->getValue<double>());
+                        break;
+
+                    case 2: // Boolean
+                        attribute.setValue(propertyElement.second->getValue<bool>());
+                        break;
+
+                    case 3: // String
+                        attribute.setValue(propertyElement.second->getValue<std::string>());
+                        break;
+                }
+
+                // Set attriute update frequency interval
+                attribute.setUpdateFrequencyTime(propertyElement.second->getUpdateFrequencyTime());
+
+                // Set range/supported values set
+                int min = 0, max = 0, multipleof = 0;
+                propertyElement.second->getRange(min, max, multipleof);
+                attribute.setRange(min, max);
+
+                if (propertyElement.second->getAllowedValuesSize() > 0)
+                    attribute.setAllowedValues(propertyElement.second->getAllowedValues());
+
+                simResource->addAttribute(attribute);
             }
         }
+
+        simResource->setURI(constructURI(simResource->getURI()));
+        return simResource;
     }
 
     return nullptr;
index b2f9638..a4ae6a7 100644 (file)
@@ -63,6 +63,9 @@ void SimulatorResourceServer::updateFromAllowedValues(const std::string &attrNam
         unsigned int index)
 {
     m_resModel.updateAttributeFromAllowedValues(attrName, index);
+
+    // Notify all the subscribers
+    notifyAll();
 }
 
 void SimulatorResourceServer::removeAttribute(const std::string &attrName)
index 6fbd060..229e7d6 100644 (file)
@@ -26,9 +26,9 @@
 #define TAG "SIM_RESOURCE_SERVER"
 
 SimulatorResourceServerImpl::SimulatorResourceServerImpl()
-    : m_resourceHandle(NULL)
+    :   m_resourceHandle(NULL)
 {
-    m_property = static_cast<OCResourceProperty>(OC_DISCOVERABLE);
+    m_property = static_cast<OCResourceProperty>(OC_DISCOVERABLE | OC_OBSERVABLE);
     m_interfaceType.assign(OC::DEFAULT_INTERFACE);
 }
 
@@ -237,6 +237,15 @@ void SimulatorResourceServerImpl::stop()
     m_resourceHandle = nullptr;
 }
 
+void SimulatorResourceServerImpl::notifyApp()
+{
+    // Notify the application callback
+    if (m_callback)
+    {
+        m_callback(m_uri, m_resModel);
+    }
+}
+
 OC::OCRepresentation SimulatorResourceServerImpl::getOCRepresentation()
 {
     return m_resModel.getOCRepresentation();
index b0aea93..471ed9c 100644 (file)
@@ -67,12 +67,13 @@ class SimulatorResourceServerImpl : public SimulatorResourceServer
 
         void stop();
 
-        void resourceModified();
+        void notifyApp();
 
     private:
         OC::OCRepresentation getOCRepresentation();
         bool modifyResourceModel(OC::OCRepresentation &ocRep);
         OCEntityHandlerResult entityHandler(std::shared_ptr<OC::OCResourceRequest> request);
+        void resourceModified();
 
         ResourceModelChangedCB m_callback;
         ObserverCB m_observeCallback;
index 09e70c4..38e5269 100644 (file)
@@ -69,17 +69,17 @@ void SimulatorManager::deleteResource(
     ResourceManager::getInstance()->deleteResource(resource);
 }
 
-void SimulatorManager::deleteResources(const std::string &resourceType)
+void SimulatorManager::deleteResource(const std::string &resourceType)
 {
     ResourceManager::getInstance()->deleteResources(resourceType);
 }
 
-void SimulatorManager::findResources(ResourceFindCallback callback)
+void SimulatorManager::findResource(ResourceFindCallback callback)
 {
     SimulatorClient::getInstance()->findResources(callback);
 }
 
-void SimulatorManager::findResources(const std::string &resourceType,
+void SimulatorManager::findResource(const std::string &resourceType,
                                      ResourceFindCallback callback)
 {
     SimulatorClient::getInstance()->findResources(resourceType, callback);
@@ -187,12 +187,12 @@ void SimulatorManager::setLogger(const std::shared_ptr<ILogger> &logger)
     simLogger().setCustomTarget(logger);
 }
 
-bool SimulatorManager::setDefaultConsoleLogger()
+bool SimulatorManager::setConsoleLogger()
 {
     return simLogger().setDefaultConsoleTarget();
 }
 
-bool SimulatorManager::setDefaultFileLogger(const std::string &path)
+bool SimulatorManager::setFileLogger(const std::string &path)
 {
     return simLogger().setDefaultFileTarget(path);
 }
\ No newline at end of file