Imported Upstream version 1.2.0
[platform/upstream/iotivity.git] / resource / examples / threadingsample.cpp
index ff556e2..46cfbec 100644 (file)
@@ -23,6 +23,7 @@
 /// server in a separate thread, and running 2 clients in each thread.
 ///
 
+#include "iotivity_config.h"
 
 #include <memory>
 #include <iostream>
 #include <condition_variable>
 #include <map>
 #include <vector>
+
 #include "OCPlatform.h"
 #include "OCApi.h"
+
+#ifdef HAVE_WINDOWS_H
+#include <windows.h>
+#endif
+
 using namespace OC;
 
+static std::ostringstream requestURI;
 
 struct FooResource
 {
@@ -139,11 +147,7 @@ struct FooResource
             {
                 std::cout <<"\t\trequestFlag : UNSUPPORTED: ";
 
-                if(request->getRequestHandlerFlag()==RequestHandlerFlag::InitFlag)
-                {
-                    std::cout<<"InitFlag"<<std::endl;
-                }
-                else if(request->getRequestHandlerFlag()== RequestHandlerFlag::ObserverFlag)
+                if(request->getRequestHandlerFlag()== RequestHandlerFlag::ObserverFlag)
                 {
                     std::cout<<"ObserverFlag"<<std::endl;
                 }
@@ -158,8 +162,8 @@ struct FooResource
     }
 };
 
-void putResourceInfo(const HeaderOptions& headerOptions,
-        const OCRepresentation rep, const OCRepresentation rep2, const int eCode)
+void putResourceInfo(const HeaderOptions& /*headerOptions*/,
+        const OCRepresentation rep, const OCRepresentation /*rep2*/, const int eCode)
 {
    bool m_isFoo = false;
    int m_barCount = 0;
@@ -188,7 +192,7 @@ void putResourceInfo(const HeaderOptions& headerOptions,
    }
 }
 
-void getResourceInfo(std::shared_ptr<OCResource> resource, const HeaderOptions& headerOptions,
+void getResourceInfo(std::shared_ptr<OCResource> resource, const HeaderOptions& /*headerOptions*/,
             const OCRepresentation rep,
             const int eCode)
 {
@@ -280,9 +284,8 @@ void foundResource1(std::shared_ptr<OCResource> resource)
 void client1()
 {
     std::cout << "in client1\n";
-
-    std::cout<<"result1:" << OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=core.foo",
-            foundResource1)<< std::endl;
+    std::cout<<"result1:" << OCPlatform::findResource("", requestURI.str(),
+            CT_DEFAULT, foundResource1)<< std::endl;
 
     // A condition variable will free the mutex it is given, then do a non-
     // intensive block until 'notify' is called on it.  In this case, since we
@@ -297,10 +300,9 @@ void client1()
 void client2()
 {
     std::cout << "in client2\n";
-
     std::cout<<"result2:" << OCPlatform::findResource("",
-                "coap://224.0.1.187/oc/core?rt=core.foo",
-                foundResource2)<< std::endl;
+                requestURI.str(),
+                CT_DEFAULT, foundResource2)<< std::endl;
 
     // A condition variable will free the mutex it is given, then do a non-
     // intensive block until 'notify' is called on it.  In this case, since we
@@ -331,8 +333,11 @@ void server()
     cv.wait(lock);
 }
 
-int main()
+int main(int /*argc*/, char** /*argv[]*/)
 {
+
+    requestURI << OC_RSRVD_WELL_KNOWN_URI << "?rt=core.foo";
+
     PlatformConfig cfg {
         OC::ServiceType::InProc,
         OC::ModeType::Both,
@@ -382,3 +387,4 @@ int main()
 
     return 0;
 }
+