iotivity 0.9.0
[platform/upstream/iotivity.git] / service / soft-sensor-manager / SampleApp / linux / THSensorApp / include / ThingResourceServer.h
1 /******************************************************************
2  *
3  * Copyright 2014 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  * ThingResourceServer.h
22  */
23
24 #ifndef THINGRESOURCESERVER_H_
25 #define THINGRESOURCESERVER_H_
26
27 #include <functional>
28 #include <pthread.h>
29 #include "OCPlatform.h"
30 #include "OCApi.h"
31
32 using namespace OC;
33 using namespace std;
34
35 #include <string>
36 #include <cstdlib>
37
38 #define COAP_IP                 "0.0.0.0"
39 #define COAP_PORT               0
40 #define COAP_MODE               ModeType::Server
41 #define COAP_SRVTYPE        ServiceType::InProc
42
43 #define COAP_TYPE_NAME          "SoftSensorManager.Sensor"
44
45 // Forward declaring the entityHandler
46
47 class TemphumidResource
48 {
49     public:
50         /// Access this property from a TB client
51         int m_humid;
52         int m_temp;
53         std::string m_resourceUri;
54         std::vector<std::string> m_resourceTypes;
55         std::vector<std::string> m_resourceInterfaces;
56         OCResourceHandle m_resourceHandle;
57         OCRepresentation m_resourceRep;
58         ObservationIds m_interestedObservers;
59
60     public:
61         /// Constructor
62         TemphumidResource() :
63             m_humid(0), m_temp(0), m_resourceHandle(0)
64         {
65             m_resourceUri = "/Thing_TempHumSensor";
66             m_resourceTypes.push_back(COAP_TYPE_NAME);
67             m_resourceInterfaces.push_back(DEFAULT_INTERFACE);
68
69             printf("Running thing as %s\n", m_resourceUri.c_str());
70             m_resourceRep.setUri(m_resourceUri);
71             m_resourceRep.setResourceTypes(m_resourceTypes);
72             m_resourceRep.setResourceInterfaces(m_resourceInterfaces);
73         }
74
75         ~TemphumidResource()
76         {
77         }
78
79         void registerResource();
80
81         OCResourceHandle getHandle();
82
83         void setResourceRepresentation(OCRepresentation &rep);
84
85         OCRepresentation getResourceRepresentation();
86 };
87
88 #endif /* THINGRESOURCESERVER_H_ */