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_IThreadPool, (IBase**)&m_pTaskWorker));
27 SSM_CLEANUP_ASSERT(CreateGlobalInstance(OID_IResourceConnectivity, (IBase**)&m_pResourceConnectivity));
29 m_pResourceFinderEvent = NULL;
30 m_pPlatform = (OC::OCPlatform*)m_pResourceConnectivity->getPlatform();
36 void CResourceFinder::finalRelease()
40 SSMRESULT CResourceFinder::registerResourceFinderEvent(IN IResourceFinderEvent *pEvent)
42 m_pResourceFinderEvent = pEvent;
46 void CResourceFinder::onResourceFound(std::shared_ptr<OC::OCResource> resource)
50 int *pMessage = new int[2];
51 pMessage[0] = RESOURCE_DISCOVER_REQUESTPROFILE;
52 pMessage[1] = (int)new std::shared_ptr<OC::OCResource>(resource);
54 m_pTaskWorker->addTask(this, pMessage);
58 SSMRESULT CResourceFinder::startResourceFinder()
60 //m_pPlatform->findResource("", "oc/core/service/SoftSensorManager/SoftSensor",
61 m_pPlatform->findResource("", "coap://224.0.1.187/oc/core?rt=SoftSensorManager.Sensor",
62 std::bind(&CResourceFinder::onResourceFound, this, std::placeholders::_1));
67 SSMRESULT CResourceFinder::startObserveResource(IN ISSMResource *pSensor, IN IEvent *pEvent)
69 return m_mapResourceHandler[pSensor->name]->startObserve(pEvent);
72 SSMRESULT CResourceFinder::stopObserveResource(IN ISSMResource *pSensor)
74 return m_mapResourceHandler[pSensor->name]->stopObserve();
77 void CResourceFinder::onExecute(IN void* pArg)
79 SSMRESULT res = SSM_E_FAIL;
80 OC::QueryParamsMap queryParams;
81 OICResourceHandler *pResourceHandler = NULL;
82 int *pMessage = (int*)pArg;
83 std::shared_ptr<OC::OCResource> *pResource = NULL;
87 case RESOURCE_DISCOVER_REQUESTPROFILE:
88 pResource = (std::shared_ptr<OC::OCResource>*)pMessage[1];
89 pResourceHandler = new OICResourceHandler();
90 SSM_CLEANUP_ASSERT(pResourceHandler->initHandler(*pResource, this));
91 m_mapResourceHandler[pResource->get()->host() + pResource->get()->uri()] = pResourceHandler;
92 pResource->get()->get(queryParams, std::bind(&OICResourceHandler::onGetResourceProfile,
93 pResourceHandler, std::placeholders::_1, std::placeholders::_2));
96 case RESOURCE_DISCOVER_SETUP_RESOURCE:
97 m_pResourceFinderEvent->onResourceFound((ISSMResource*)pMessage[1]);
105 void CResourceFinder::onTerminate(IN void* pArg)
107 std::shared_ptr<OC::OCResource> *pResource = NULL;
108 int *pMessage = (int*)pArg;
112 case RESOURCE_DISCOVER_REQUESTPROFILE:
113 pResource = (std::shared_ptr<OC::OCResource>*)pMessage[1];
117 case RESOURCE_DISCOVER_SETUP_RESOURCE: