Initial merge-commit of the OIC code. Should successfully do discovery for single...
[platform/upstream/iotivity.git] / examples / client / OCClient.cpp
1 //******************************************************************
2 //
3 // Copyright 2014 Intel Corporation All Rights Reserved.
4 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
5
6 // OCClient.cpp : Defines the entry point for the console application.
7 //
8 #include <string>
9
10 #include "OCPlatform.h"
11
12 using namespace OC;
13
14 void foundResource(std::shared_ptr<OCResource> resource){
15
16         try
17         {
18                 // Do some operations with resource object. 
19                 if(resource)
20                 {
21                         std::cout << "URI of the resource: " << resource->uri() << std::endl;
22                         
23                         std::cout << "Host address of the resource: " << resource->host() << std::endl;         
24                 }
25         
26                 else
27                 {
28                         std::cout << "Resource invalid" << std::endl;
29                 }       
30         
31         }
32         catch(OC::OCReflect::reflection_exception& e)
33         {
34                 //log(e.what());
35         }
36         catch(std::exception& e)
37         {
38                 //log(e.what());
39         }
40 }
41
42
43 int main()
44 {
45         // Create PlatformConfig object
46
47         PlatformConfig cfg;
48         cfg.ipAddress = "134.134.161.166";
49         cfg.port = 5683;
50         cfg.mode = ModeType::Client;
51         cfg.serviceType = ServiceType::InProc;
52
53         // Create a OCPlatform instance. 
54         // Note: Platform creation is synchronous call. 
55
56         try
57         {
58                 OCPlatform platform(cfg);
59
60                 // Find all resources
61                 platform.findResource("", "coap://224.0.1.187/oc/core", &foundResource);
62
63                 while(1)
64                 {
65                 }
66
67         }catch(OCException e)
68         {
69                 //log(e.what());
70         }
71
72         return 0;
73 }
74