Imported Upstream version 1.0.0
[platform/upstream/iotivity.git] / resource / examples / simpleclient.cpp
index bb7620c..e43618a 100644 (file)
@@ -59,13 +59,22 @@ int observe_count()
     return ++oc;
 }
 
-void onObserve(const HeaderOptions headerOptions, const OCRepresentation& rep,
+void onObserve(const HeaderOptions /*headerOptions*/, const OCRepresentation& rep,
                     const int& eCode, const int& sequenceNumber)
 {
     try
     {
-        if(eCode == OC_STACK_OK)
+        if(eCode == OC_STACK_OK && sequenceNumber != OC_OBSERVE_NO_OPTION)
         {
+            if(sequenceNumber == OC_OBSERVE_REGISTER)
+            {
+                std::cout << "Observe registration action is successful" << std::endl;
+            }
+            else if(sequenceNumber == OC_OBSERVE_DEREGISTER)
+            {
+                std::cout << "Observe De-registration action is successful" << std::endl;
+            }
+
             std::cout << "OBSERVE RESULT:"<<std::endl;
             std::cout << "\tSequenceNumber: "<< sequenceNumber << std::endl;
             rep.getValue("state", mylight.m_state);
@@ -76,7 +85,7 @@ void onObserve(const HeaderOptions headerOptions, const OCRepresentation& rep,
             std::cout << "\tpower: " << mylight.m_power << std::endl;
             std::cout << "\tname: " << mylight.m_name << std::endl;
 
-            if(observe_count() > 10)
+            if(observe_count() == 11)
             {
                 std::cout<<"Cancelling Observe..."<<std::endl;
                 OCStackResult result = curResource->cancelObserve();
@@ -89,8 +98,15 @@ void onObserve(const HeaderOptions headerOptions, const OCRepresentation& rep,
         }
         else
         {
-            std::cout << "onObserve Response error: " << eCode << std::endl;
-            std::exit(-1);
+            if(sequenceNumber == OC_OBSERVE_NO_OPTION)
+            {
+                std::cout << "Observe registration or de-registration action is failed" << std::endl;
+            }
+            else
+            {
+                std::cout << "onObserve Response error: " << eCode << std::endl;
+                std::exit(-1);
+            }
         }
     }
     catch(std::exception& e)
@@ -100,7 +116,8 @@ void onObserve(const HeaderOptions headerOptions, const OCRepresentation& rep,
 
 }
 
-void onPost2(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode)
+void onPost2(const HeaderOptions& /*headerOptions*/,
+        const OCRepresentation& rep, const int eCode)
 {
     try
     {
@@ -145,7 +162,8 @@ void onPost2(const HeaderOptions& headerOptions, const OCRepresentation& rep, co
 
 }
 
-void onPost(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode)
+void onPost(const HeaderOptions& /*headerOptions*/,
+        const OCRepresentation& rep, const int eCode)
 {
     try
     {
@@ -214,7 +232,7 @@ void postLightRepresentation(std::shared_ptr<OCResource> resource)
 }
 
 // callback handler on PUT request
-void onPut(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode)
+void onPut(const HeaderOptions& /*headerOptions*/, const OCRepresentation& rep, const int eCode)
 {
     try
     {
@@ -265,7 +283,7 @@ void putLightRepresentation(std::shared_ptr<OCResource> resource)
 }
 
 // Callback handler on GET request
-void onGet(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode)
+void onGet(const HeaderOptions& /*headerOptions*/, const OCRepresentation& rep, const int eCode)
 {
     try
     {
@@ -412,7 +430,7 @@ void checkObserverValue(int value)
     }
 }
 
-static FILE* client_open(const char *path, const char *mode)
+static FILE* client_open(const char* /*path*/, const char *mode)
 {
     return fopen("./oic_svr_db_client.json", mode);
 }