Imported Upstream version 1.0.0
[platform/upstream/iotivity.git] / service / resource-encapsulation / src / resourceBroker / include / DevicePresence.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 RB_DEVICEPRESENCE_H_
22 #define RB_DEVICEPRESENCE_H_
23
24 #include <list>
25 #include <string>
26 #include <atomic>
27
28 #include "BrokerTypes.h"
29 #include "ResourcePresence.h"
30 #include "PresenceSubscriber.h"
31 #include "ExpiryTimer.h"
32
33 namespace OIC
34 {
35     namespace Service
36     {
37         class DevicePresence
38         {
39         public:
40             typedef long long TimerID;
41
42             DevicePresence();
43             ~DevicePresence();
44
45             void initializeDevicePresence(PrimitiveResourcePtr pResource);
46
47             void addPresenceResource(ResourcePresence * rPresence);
48             void removePresenceResource(ResourcePresence * rPresence);
49
50             bool isEmptyResourcePresence() const;
51             const std::string getAddress() const;
52             DEVICE_STATE getDeviceState() const noexcept;
53
54         private:
55             std::list<ResourcePresence * > resourcePresenceList;
56
57             std::string address;
58             std::atomic_int state;
59             std::atomic_bool isRunningTimeOut;
60
61             std::mutex timeoutMutex;
62             std::condition_variable condition;
63
64             ExpiryTimer presenceTimer;
65             TimerID presenceTimerHandle;
66             TimerCB pTimeoutCB;
67             SubscribeCB pSubscribeRequestCB;
68             PresenceSubscriber presenceSubscriber;
69
70             void changeAllPresenceMode(BROKER_MODE mode);
71             void subscribeCB(OCStackResult ret,const unsigned int seq, const std::string& Hostaddress);
72             void timeOutCB(TimerID id);
73
74             void setDeviceState(DEVICE_STATE);
75         };
76     } // namespace Service
77 } // namespace OIC
78
79 #endif /* RB_DEVICEPRESENCE_H_ */