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 "DevicePresence.h"
23 DevicePresence::DevicePresence(PrimitiveResource & pResource, BrokerCB _cb)
25 address = pResource.getHost();
26 pSubscribeRequestCB = std::bind(&DevicePresence::subscribeCB, this,
27 std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
29 presenceResourceList = new std::list<ResourcePresence *>();
30 addPresenceResource(pResource, _cb);
32 OC::OCPlatform::subscribePresence(presenceHandle, address,
33 BROKER_TRANSPORT, pSubscribeRequestCB);
36 DevicePresence::~DevicePresence()
38 // TODO Auto-generated destructor stub
39 OC::OCPlatform::unsubscribePresence(presenceHandle);
40 presenceResourceList->clear();
41 delete presenceResourceList;
44 void DevicePresence::addPresenceResource(PrimitiveResource & pResource, BrokerCB _cb)
46 ResourcePresence * newPresenceResource = new ResourcePresence(pResource, _cb);
47 presenceResourceList->push_back(newPresenceResource);
50 ResourcePresence * DevicePresence::findPresenceResource(PrimitiveResource & pResource, BrokerCB _cb)
52 ResourcePresence * retResource = NULL;
53 if (presenceResourceList->empty() || pResource.isEmpty())
59 std::list<ResourcePresence *>::iterator it;
61 ResourcePresence * temp = new ResourcePresence(pResource, _cb);
62 it = std::find(presenceResourceList->begin(), presenceResourceList->end(), temp);
65 if(it == presenceResourceList->end())
78 void DevicePresence::subscribeCB(OCStackResult ret,
79 const unsigned int seq, const std::string& msg)