Imported Upstream version 0.9.2
[platform/upstream/iotivity.git] / service / resource-encapsulation / src / common / primitiveResource / include / PresenceSubscriber.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 COMMON_PRESENCESUBSCRIBER_H
22 #define COMMON_PRESENCESUBSCRIBER_H
23
24 #include <string>
25 #include <functional>
26
27 #include <octypes.h>
28
29 namespace OIC
30 {
31     namespace Service
32     {
33
34         typedef std::function< void(OCStackResult, const unsigned int, const std::string&) >
35             SubscribeCallback;
36
37         class PresenceSubscriber
38         {
39         public:
40             PresenceSubscriber();
41
42             PresenceSubscriber(PresenceSubscriber&&);
43
44             /**
45              * @throw PlatformException
46              */
47             PresenceSubscriber(const std::string& host, OCConnectivityType connectivityType,
48                     SubscribeCallback presenceHandler);
49
50             /**
51              * @throw PlatformException
52              */
53             PresenceSubscriber(const std::string& host, const std::string& resourceType,
54                     OCConnectivityType connectivityType, SubscribeCallback presenceHandler);
55
56             ~PresenceSubscriber();
57
58             PresenceSubscriber& operator=(PresenceSubscriber&&);
59
60             /**
61              * @throw PlatformException
62              */
63             void unsubscribe();
64
65             bool isSubscribing() const;
66
67         private:
68             OCDoHandle m_handle;
69         };
70
71         /**
72          * @throw PlatformException
73          */
74         void subscribePresence(OCDoHandle& handle, const std::string& host,
75                 OCConnectivityType connectivityType, SubscribeCallback presenceHandler);
76
77         /**
78          * @throw PlatformException
79          */
80         void subscribePresence(OCDoHandle& handle, const std::string& host, const std::string& resourceType,
81                 OCConnectivityType connectivityType, SubscribeCallback presenceHandler);
82
83         void unsubscribePresence(OCDoHandle handle);
84
85     }
86 }
87
88 #endif // COMMON_PRESENCESUBSCRIBER_H