iotivity 0.9.0
[platform/upstream/iotivity.git] / resource / examples / old_tests / OCWrapper / testServer.cpp
1 //******************************************************************
2 //
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21
22 #include <WrapperFactory.h>
23 #include <OCApi.h>
24 #include <IServerWrapper.h>
25 #include <IClientWrapper.h>
26 #include <OCReflect.h>
27
28 #include <algorithm>
29 #include <cstring>
30 #include <cstdlib>
31
32 using namespace OC;
33 using namespace OC::OCReflect;
34
35 // Demo of how to generate OCStack stuff:
36 void rep_test()
37 {
38         using OC::OCReflect::property_type;
39         using OC::OCReflect::named_property_binding;
40
41         named_property_binding_vector sigs {
42                named_property_binding("state", property_type::boolean),
43                named_property_binding("power", property_type::integer),
44         };
45
46         using namespace OC::OCReflect::OCStack;
47
48         std::vector<std::string> reps { convert(sigs) };
49
50         for(const auto& r : reps)
51             std::cout << r << '\n';
52
53         char **LEDrep = convert(reps);
54
55         std::for_each(LEDrep, LEDrep + length(LEDrep), [](const char *s) { std::cout << s << '\n'; });
56
57
58
59
60     OCEntityHandler entityHandler;
61     OCResourceHandle resourceHandle;
62
63     OCCreateResource(   &resourceHandle, // OCResourceHandle *handl
64                         "core.led", // const char * resourceTypeName
65                         "state:oc.bt.b;power:oc.bt.i", //const char * resourceTypeRepresentation
66                         "core.rw", //const char * resourceInterfaceName
67                         OC_REST_GET | OC_REST_PUT, // uint8_t allowedMethods
68                         "/a/led", // const char * uri
69                         entityHandler, // OCEntityHandler entityHandler
70                         OC_DISCOVERABLE | OC_OBSERVABLE // uint8_t resourceProperties
71                     );
72                                         
73
74
75  release(LEDrep);
76 }
77
78 void testServer()
79 {
80     PlatformConfig cfg;
81     cfg.ipAddress = "192.168.1.5";
82     cfg.port = 8080;
83     cfg.mode = ModeType::Server;
84     cfg.serviceType = ServiceType::InProc;
85
86     IWrapperFactory::Ptr pFactory= std::make_shared<WrapperFactory>();
87
88     IServerWrapper::Ptr pServer = pFactory->CreateServerWrapper(cfg);
89
90     //pServer->bindTo
91 }
92
93 int main()
94 {
95     rep_test();
96         testServer();
97 }