1 //******************************************************************
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
11 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #include <PresenceSubscriber.h>
23 #include <internal/AssertUtils.h>
25 #include <OCPlatform.h>
32 void subscribePresence(OCDoHandle& handle, const std::string& host,
33 OCConnectivityType connectivityType, SubscribeCallback presenceHandler)
35 using SubscribePresence = OCStackResult (*)(OC::OCPlatform::OCPresenceHandle&,
36 const std::string&, OCConnectivityType, SubscribeCallback);
38 invokeOCFunc(static_cast<SubscribePresence>(OC::OCPlatform::subscribePresence),
39 handle, host, connectivityType, presenceHandler);
42 void subscribePresence(OCDoHandle& handle, const std::string& host,
43 const std::string& resourceType, OCConnectivityType connectivityType,
44 SubscribeCallback presenceHandler)
46 using SubscribePresence = OCStackResult (*)(OC::OCPlatform::OCPresenceHandle&,
47 const std::string&, const std::string&, OCConnectivityType, SubscribeCallback);
49 invokeOCFunc(static_cast<SubscribePresence>(OC::OCPlatform::subscribePresence),
50 handle, host, resourceType, connectivityType, presenceHandler);
53 void unsubscribePresence(OCDoHandle handle)
55 invokeOCFunc(OC::OCPlatform::unsubscribePresence, handle);
59 PresenceSubscriber::PresenceSubscriber() :
64 PresenceSubscriber::PresenceSubscriber(PresenceSubscriber&& from) :
67 std::swap(m_handle, from.m_handle);
70 PresenceSubscriber::PresenceSubscriber(const std::string& host,
71 OCConnectivityType connectivityType, SubscribeCallback presenceHandler) :
74 subscribePresence(m_handle, host, connectivityType, presenceHandler);
77 PresenceSubscriber::PresenceSubscriber(const std::string& host,
78 const std::string& resourceType, OCConnectivityType connectivityType,
79 SubscribeCallback presenceHandler) :
82 subscribePresence(m_handle, host, resourceType, connectivityType, presenceHandler);
85 PresenceSubscriber::~PresenceSubscriber()
99 PresenceSubscriber& PresenceSubscriber::operator=(PresenceSubscriber&& from)
102 std::swap(m_handle, from.m_handle);
106 void PresenceSubscriber::unsubscribe()
108 if (m_handle == nullptr) return;
110 unsubscribePresence(m_handle);
115 bool PresenceSubscriber::isSubscribing() const
117 return m_handle != nullptr;