Initial merge-commit of the OIC code. Should successfully do discovery for single...
[platform/upstream/iotivity.git] / examples / OCWrapper / testServer.cpp
1 //******************************************************************
2 //
3 // Copyright 2014 Intel Corporation All Rights Reserved.
4 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
5
6
7 #include <WrapperFactory.h>
8 #include <OCApi.h>
9 #include <IServerWrapper.h>
10 #include <IClientWrapper.h>
11 #include <OCReflect.h>
12
13 #include <algorithm>
14 #include <cstring>
15 #include <cstdlib>
16
17 using namespace OC;
18 using namespace OC::OCReflect;
19
20 // Demo of how to generate OCStack stuff:
21 void rep_test()
22 {
23         using OC::OCReflect::property_type;
24         using OC::OCReflect::named_property_binding;
25
26         named_property_binding_vector sigs {
27                named_property_binding("state", property_type::boolean),
28                named_property_binding("power", property_type::integer),
29         };
30
31         using namespace OC::OCReflect::to_OCStack;
32
33         std::vector<std::string> reps { convert(sigs) };
34
35         for(const auto& r : reps)
36             std::cout << r << '\n';
37
38         char **LEDrep = convert(reps);
39
40         std::for_each(LEDrep, LEDrep + length(LEDrep), [](const char *s) { std::cout << s << '\n'; });
41
42
43
44
45     OCEntityHandler entityHandler;
46     OCResourceHandle resourceHandle;
47
48     OCCreateResource(   &resourceHandle, // OCResourceHandle *handl
49                         "core.led", // const char * resourceTypeName
50                         "state:oc.bt.b;power:oc.bt.i", //const char * resourceTypeRepresentation
51                         "core.rw", //const char * resourceInterfaceName
52                         OC_REST_GET | OC_REST_PUT, // uint8_t allowedMethods
53                         "/a/led", // const char * uri
54                         entityHandler, // OCEntityHandler entityHandler
55                         OC_DISCOVERABLE | OC_OBSERVABLE // uint8_t resourceProperties
56                     );
57                                         
58
59
60  release(LEDrep);
61 }
62
63 void testServer()
64 {
65     PlatformConfig cfg;
66     cfg.ipAddress = "192.168.1.5";
67     cfg.port = 8080;
68     cfg.mode = ModeType::Server;
69     cfg.serviceType = ServiceType::InProc;
70
71     IWrapperFactory::Ptr pFactory= std::make_shared<WrapperFactory>();
72
73     IServerWrapper::Ptr pServer = pFactory->CreateServerWrapper(cfg);
74
75     //pServer->bindTo
76 }
77
78 int main()
79 {
80     rep_test();
81         testServer();
82 }