1 /******************************************************************
3 * Copyright 2014 Samsung Electronics All Rights Reserved.
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 ******************************************************************/
20 #include "ResourceFinder.h"
22 SSMRESULT CResourceFinder::finalConstruct()
24 SSMRESULT res = SSM_E_FAIL;
26 SSM_CLEANUP_ASSERT(CreateGlobalInstance(OID_ITasker, (IBase **)&m_pTasker));
27 SSM_CLEANUP_ASSERT(CreateGlobalInstance(OID_IResourceConnectivity,
28 (IBase **)&m_pResourceConnectivity));
30 m_pResourceFinderEvent = NULL;
31 m_pPlatform = (OC::OCPlatform *)m_pResourceConnectivity->getPlatform();
37 void CResourceFinder::finalRelease()
41 SSMRESULT CResourceFinder::registerResourceFinderEvent(IN IResourceFinderEvent *pEvent)
43 m_pResourceFinderEvent = pEvent;
47 void CResourceFinder::onResourceFound(std::shared_ptr<OC::OCResource> resource)
51 int *pMessage = new int[2];
52 pMessage[0] = RESOURCE_DISCOVER_REQUESTPROFILE;
53 pMessage[1] = (int)new std::shared_ptr<OC::OCResource>(resource);
55 m_pTasker->addTask(this, pMessage);
59 SSMRESULT CResourceFinder::startResourceFinder()
61 //m_pPlatform->findResource("", "oc/core/service/SoftSensorManager/SoftSensor",
62 m_pPlatform->findResource("", "coap://224.0.1.187/oc/core?rt=SoftSensorManager.Sensor",
63 std::bind(&CResourceFinder::onResourceFound, this, std::placeholders::_1));
68 SSMRESULT CResourceFinder::startObserveResource(IN ISSMResource *pSensor, IN IEvent *pEvent)
70 return m_mapResourceHandler[pSensor->name]->startObserve(pEvent);
73 SSMRESULT CResourceFinder::stopObserveResource(IN ISSMResource *pSensor)
75 return m_mapResourceHandler[pSensor->name]->stopObserve();
78 void CResourceFinder::onExecute(IN void *pArg)
80 SSMRESULT res = SSM_E_FAIL;
81 OC::QueryParamsMap queryParams;
82 OICResourceHandler *pResourceHandler = NULL;
83 int *pMessage = (int *)pArg;
84 std::shared_ptr<OC::OCResource> *pResource = NULL;
88 case RESOURCE_DISCOVER_REQUESTPROFILE:
89 pResource = (std::shared_ptr<OC::OCResource> *)pMessage[1];
90 pResourceHandler = new OICResourceHandler();
91 SSM_CLEANUP_ASSERT(pResourceHandler->initHandler(*pResource, this));
92 m_mapResourceHandler[pResource->get()->host() + pResource->get()->uri()] = pResourceHandler;
93 pResource->get()->get(queryParams, std::bind(&OICResourceHandler::onGetResourceProfile,
94 pResourceHandler, std::placeholders::_1, std::placeholders::_2));
97 case RESOURCE_DISCOVER_SETUP_RESOURCE:
98 m_pResourceFinderEvent->onResourceFound((ISSMResource *)pMessage[1]);
106 void CResourceFinder::onTerminate(IN void *pArg)
108 std::shared_ptr<OC::OCResource> *pResource = NULL;
109 int *pMessage = (int *)pArg;
113 case RESOURCE_DISCOVER_REQUESTPROFILE:
114 pResource = (std::shared_ptr<OC::OCResource> *)pMessage[1];
118 case RESOURCE_DISCOVER_SETUP_RESOURCE: