Handle race condition and mutex issues.
[platform/upstream/iotivity.git] / resource / include / InProcServerWrapper.h
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 #ifndef OC_IN_PROC_SERVER_WRAPPER_H_
22 #define OC_IN_PROC_SERVER_WRAPPER_H_
23
24 #include <thread>
25 #include <mutex>
26
27 #include <IServerWrapper.h>
28 #ifdef WITH_PROCESS_EVENT
29 #include "ocevent.h"
30 #endif
31
32 namespace OC
33 {
34     class InProcServerWrapper : public IServerWrapper
35     {
36     public:
37         InProcServerWrapper(
38             std::weak_ptr<std::recursive_mutex> csdkLock,
39             PlatformConfig cfg);
40         virtual ~InProcServerWrapper();
41
42         virtual OCStackResult registerResource(
43                     OCResourceHandle& resourceHandle,
44                     std::string& resourceURI,
45                     const std::string& resourceTypeName,
46                     const std::string& resourceInterface,
47                     EntityHandler& entityHandler,
48                     uint8_t resourceProperty);
49
50         virtual OCStackResult registerDeviceInfo(
51                     const OCDeviceInfo deviceInfo);
52
53         virtual OCStackResult registerPlatformInfo(
54                     const OCPlatformInfo PlatformInfo);
55
56         virtual OCStackResult unregisterResource(
57                     const OCResourceHandle& resourceHandle);
58
59         virtual OCStackResult bindTypeToResource(
60                     const OCResourceHandle& resourceHandle,
61                     const std::string& resourceTypeName);
62
63         virtual OCStackResult resetResourceTypes(
64                     const OCResourceHandle& resourceHandle,
65                     const std::string& newResourceType);
66
67         virtual OCStackResult bindInterfaceToResource(
68                     const OCResourceHandle& resourceHandle,
69                     const std::string& resourceInterface);
70
71         virtual OCStackResult resetResourceInterfaces(
72                     const OCResourceHandle& resourceHandle,
73                     const std::string& newResourceInterface);
74
75         virtual OCStackResult startPresence(const unsigned int seconds);
76
77         virtual OCStackResult stopPresence();
78
79         virtual OCStackResult notifyAllObservers(
80                     OCResourceHandle resourceHandle,
81                     QualityOfService QoS);
82
83         virtual OCStackResult notifyListOfObservers(
84                     OCResourceHandle resourceHandle,
85                     ObservationIds& observationIds,
86                     const std::shared_ptr<OCResourceResponse> pResponse,
87                     QualityOfService QoS);
88
89         virtual OCStackResult setDefaultDeviceEntityHandler(EntityHandler entityHandler);
90
91         virtual OCStackResult sendResponse(const std::shared_ptr<OCResourceResponse> pResponse);
92
93         virtual OCStackResult setPropertyValue(OCPayloadType type, const std::string& tag, const std::string& value);
94         virtual OCStackResult getPropertyValue(OCPayloadType type, const std::string& tag, std::string& value);
95
96         virtual OCStackResult stop();
97
98         virtual OCStackResult start();
99     private:
100         void processFunc();
101         std::thread m_processThread;
102         bool m_threadRun;
103         std::weak_ptr<std::recursive_mutex> m_csdkLock;
104         PlatformConfig  m_cfg;
105 #ifdef WITH_PROCESS_EVENT
106         oc_event m_processEvent;
107 #endif
108     };
109 }
110
111 #endif