#include <octypes.h>
-typedef std::function< void(OCStackResult, const unsigned int, const std::string&) > SubscribeCallback;
-
-class PresenceSubscriber
+namespace OIC
{
-public:
- PresenceSubscriber();
+ namespace Service
+ {
+
+ typedef std::function< void(OCStackResult, const unsigned int, const std::string&) > SubscribeCallback;
+
+ class PresenceSubscriber
+ {
+ public:
+ PresenceSubscriber();
+
+ PresenceSubscriber(PresenceSubscriber&&);
- PresenceSubscriber(PresenceSubscriber&&);
+ /**
+ * @throw PlatformException
+ */
+ PresenceSubscriber(const std::string& host, OCConnectivityType connectivityType,
+ SubscribeCallback presenceHandler);
- /**
- * @throw PlatformException
- */
- PresenceSubscriber(const std::string& host, OCConnectivityType connectivityType,
- SubscribeCallback presenceHandler);
+ /**
+ * @throw PlatformException
+ */
+ PresenceSubscriber(const std::string& host, const std::string& resourceType,
+ OCConnectivityType connectivityType, SubscribeCallback presenceHandler);
- /**
- * @throw PlatformException
- */
- PresenceSubscriber(const std::string& host, const std::string& resourceType,
- OCConnectivityType connectivityType, SubscribeCallback presenceHandler);
+ ~PresenceSubscriber();
- ~PresenceSubscriber();
+ PresenceSubscriber& operator=(PresenceSubscriber&&);
- PresenceSubscriber& operator=(PresenceSubscriber&&);
+ /**
+ * @throw PlatformException
+ */
+ void unsubscribe();
- /**
- * @throw PlatformException
- */
- void unsubscribe();
+ bool isSubscribing() const;
- bool isSubscribing() const;
+ private:
+ OCDoHandle m_handle;
+ };
-private:
- OCDoHandle m_handle;
-};
+ /**
+ * @throw PlatformException
+ */
+ void subscribePresence(OCDoHandle& handle, const std::string& host,
+ OCConnectivityType connectivityType, SubscribeCallback presenceHandler);
-/**
- * @throw PlatformException
- */
-void subscribePresence(OCDoHandle& handle, const std::string& host,
- OCConnectivityType connectivityType, SubscribeCallback presenceHandler);
+ /**
+ * @throw PlatformException
+ */
+ void subscribePresence(OCDoHandle& handle, const std::string& host, const std::string& resourceType,
+ OCConnectivityType connectivityType, SubscribeCallback presenceHandler);
-/**
- * @throw PlatformException
- */
-void subscribePresence(OCDoHandle& handle, const std::string& host, const std::string& resourceType,
- OCConnectivityType connectivityType, SubscribeCallback presenceHandler);
+ void unsubscribePresence(OCDoHandle handle);
-void unsubscribePresence(OCDoHandle handle);
+ }
+}
#endif // __PRESENCESUBSCRIBER_H
#include <PresenceSubscriber.h>
-#include <PrimitiveException.h>
+#include <internal/AssertUtils.h>
#include <OCPlatform.h>
-void subscribePresence(OCDoHandle& handle, const std::string& host,
- OCConnectivityType connectivityType, SubscribeCallback presenceHandler)
+namespace OIC
{
- OCStackResult result = OC::OCPlatform::subscribePresence(handle, host, connectivityType, presenceHandler);
-
- if (result != OC_STACK_OK)
+ namespace Service
{
- throw PlatformException(result);
- }
-}
-void subscribePresence(OCDoHandle& handle, const std::string& host,
- const std::string& resourceType, OCConnectivityType connectivityType,
- SubscribeCallback presenceHandler)
-{
- OCStackResult result = OC::OCPlatform::subscribePresence(handle, host, resourceType,
- connectivityType, presenceHandler);
+ void subscribePresence(OCDoHandle& handle, const std::string& host,
+ OCConnectivityType connectivityType, SubscribeCallback presenceHandler)
+ {
+ OCStackResult result = OC::OCPlatform::subscribePresence(handle, host, connectivityType, presenceHandler);
- if (result != OC_STACK_OK)
- {
- throw PlatformException(result);
- }
-}
+ expectOCStackResultOK(result);
+ }
-void unsubscribePresence(OCDoHandle handle)
-{
- OCStackResult result = OC::OCPlatform::unsubscribePresence(handle);
+ void subscribePresence(OCDoHandle& handle, const std::string& host,
+ const std::string& resourceType, OCConnectivityType connectivityType,
+ SubscribeCallback presenceHandler)
+ {
+ OCStackResult result = OC::OCPlatform::subscribePresence(handle, host, resourceType,
+ connectivityType, presenceHandler);
- if (result != OC_STACK_OK)
- {
- throw PlatformException(result);
- }
-}
+ expectOCStackResultOK(result);
+ }
+ void unsubscribePresence(OCDoHandle handle)
+ {
+ expectOCStackResultOK(OC::OCPlatform::unsubscribePresence(handle));
+ }
-PresenceSubscriber::PresenceSubscriber() :
- m_handle{ nullptr }
-{
-}
-PresenceSubscriber::PresenceSubscriber(PresenceSubscriber&& from) :
- m_handle{ nullptr }
-{
- std::swap(m_handle, from.m_handle);
-}
+ PresenceSubscriber::PresenceSubscriber() :
+ m_handle{ nullptr }
+ {
+ }
-PresenceSubscriber::PresenceSubscriber(const std::string& host,
- OCConnectivityType connectivityType, SubscribeCallback presenceHandler) :
- m_handle{ nullptr }
-{
- subscribePresence(m_handle, host, connectivityType, presenceHandler);
-}
+ PresenceSubscriber::PresenceSubscriber(PresenceSubscriber&& from) :
+ m_handle{ nullptr }
+ {
+ std::swap(m_handle, from.m_handle);
+ }
-PresenceSubscriber::PresenceSubscriber(const std::string& host, const std::string& resourceType,
- OCConnectivityType connectivityType, SubscribeCallback presenceHandler) :
- m_handle{ nullptr }
-{
- subscribePresence(m_handle, host, resourceType, connectivityType, presenceHandler);
-}
+ PresenceSubscriber::PresenceSubscriber(const std::string& host,
+ OCConnectivityType connectivityType, SubscribeCallback presenceHandler) :
+ m_handle{ nullptr }
+ {
+ subscribePresence(m_handle, host, connectivityType, presenceHandler);
+ }
-PresenceSubscriber::~PresenceSubscriber()
-{
- if (m_handle)
- {
- try
+ PresenceSubscriber::PresenceSubscriber(const std::string& host, const std::string& resourceType,
+ OCConnectivityType connectivityType, SubscribeCallback presenceHandler) :
+ m_handle{ nullptr }
{
- unsubscribe();
+ subscribePresence(m_handle, host, resourceType, connectivityType, presenceHandler);
}
- catch (...)
+
+ PresenceSubscriber::~PresenceSubscriber()
{
+ if (m_handle)
+ {
+ try
+ {
+ unsubscribe();
+ }
+ catch (...)
+ {
+ }
+ }
}
- }
-}
-PresenceSubscriber& PresenceSubscriber::operator=(PresenceSubscriber&& from)
-{
- unsubscribe();
- std::swap(m_handle, from.m_handle);
- return *this;
-}
+ PresenceSubscriber& PresenceSubscriber::operator=(PresenceSubscriber&& from)
+ {
+ unsubscribe();
+ std::swap(m_handle, from.m_handle);
+ return *this;
+ }
-void PresenceSubscriber::unsubscribe()
-{
- if (m_handle == nullptr) return;
+ void PresenceSubscriber::unsubscribe()
+ {
+ if (m_handle == nullptr) return;
- unsubscribePresence(m_handle);
+ unsubscribePresence(m_handle);
- m_handle = nullptr;
-}
+ m_handle = nullptr;
+ }
-bool PresenceSubscriber::isSubscribing() const
-{
- return m_handle != nullptr;
+ bool PresenceSubscriber::isSubscribing() const
+ {
+ return m_handle != nullptr;
+ }
+
+ }
}