Imported Upstream version 1.0.0
[platform/upstream/iotivity.git] / service / resource-container / examples / BMISensorBundle / src / inputSensors / HeightSensorApp / include / HeightSensorApp.h
1 //******************************************************************
2 //
3 // Copyright 2015 Samsung Electronics 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 #ifndef HEIGHTSENSORAPP_H_
22 #define HEIGHTSENSORAPP_H_
23
24 #include <functional>
25 #include <pthread.h>
26 #include "OCPlatform.h"
27 #include "OCApi.h"
28
29 #include <string>
30 #include <cstdlib>
31
32
33 #define COAP_IP                 "0.0.0.0"
34 #define COAP_PORT               0
35 #define COAP_MODE               OC::ModeType::Server
36 #define COAP_SRVTYPE            OC::ServiceType::InProc
37
38 #define RESOURCE_TYPE_NAME          "oic.r.sensor.height"
39
40 //  testing case
41 #define INTERVAL_FOR_CHECK          4   // seconds
42 #define INTERVAL_FOR_MEASUREMENT    3   // seconds
43 #define INIT_VAL                    1   // default value
44 #define DIFF_VAL                    0.02   // default value
45
46
47 class HeightResource
48 {
49     public:
50         // Access this property from a TB client
51         double m_height;
52         std::string m_resourceUri;
53         std::vector<std::string> m_resourceTypes;
54         std::vector<std::string> m_resourceInterfaces;
55         OCResourceHandle m_resourceHandle;
56         OC::OCRepresentation m_resourceRep;
57         OC::ObservationIds m_interestedObservers;
58
59     public:
60         // Constructor
61         HeightResource() : m_height(INIT_VAL), m_resourceHandle(0)
62         {
63             m_resourceUri = "/Thing_HeightSensor";
64             m_resourceTypes.push_back(RESOURCE_TYPE_NAME);
65             m_resourceInterfaces.push_back(OC::DEFAULT_INTERFACE);
66
67             printf("Running thing as %s\n", m_resourceUri.c_str());
68             m_resourceRep.setUri(m_resourceUri);
69             m_resourceRep.setResourceTypes(m_resourceTypes);
70             m_resourceRep.setResourceInterfaces(m_resourceInterfaces);
71         }
72
73         ~HeightResource()
74         {
75         }
76
77         void registerResource();
78
79         OCResourceHandle getHandle();
80
81         void setResourceRepresentation(OC::OCRepresentation &rep);
82
83         OC::OCRepresentation getResourceRepresentation();
84 };
85
86 #endif /* THINGRESOURCESERVER_H_ */