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 OC::PlatformConfig cfg(OC::ServiceType::InProc, OC::ModeType::Both,
27 "0.0.0.0", 0, OC::QualityOfService::LowQos);
29 SSM_CLEANUP_ASSERT(CreateGlobalInstance(OID_ITasker, (IBase **)&m_pTasker));
31 OC::OCPlatform::Configure(cfg);
33 m_pResourceFinderEvent = NULL;
39 void CResourceFinder::finalRelease()
43 SSMRESULT CResourceFinder::registerResourceFinderEvent(IN IResourceFinderEvent *pEvent)
45 m_pResourceFinderEvent = pEvent;
49 void CResourceFinder::onResourceFound(std::shared_ptr<OC::OCResource> resource)
53 int *pMessage = new int[2];
54 pMessage[0] = RESOURCE_DISCOVER_REQUESTPROFILE;
55 pMessage[1] = (int)new std::shared_ptr<OC::OCResource>(resource);
57 m_pTasker->addTask(this, pMessage);
61 SSMRESULT CResourceFinder::startResourceFinder()
63 OCStackResult res = OC_STACK_ERROR;
65 res = OC::OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=SoftSensorManager.Sensor",
66 std::bind(&CResourceFinder::onResourceFound, this, std::placeholders::_1));
68 if (res != OC_STACK_OK)
74 SSMRESULT CResourceFinder::startObserveResource(IN ISSMResource *pSensor, IN IEvent *pEvent)
76 return m_mapResourceHandler[pSensor->name]->startObserve(pEvent);
79 SSMRESULT CResourceFinder::stopObserveResource(IN ISSMResource *pSensor)
81 return m_mapResourceHandler[pSensor->name]->stopObserve();
84 void CResourceFinder::onExecute(IN void *pArg)
86 SSMRESULT res = SSM_E_FAIL;
87 OC::QueryParamsMap queryParams;
88 OICResourceHandler *pResourceHandler = NULL;
89 int *pMessage = (int *)pArg;
90 std::shared_ptr<OC::OCResource> *pResource = NULL;
94 case RESOURCE_DISCOVER_REQUESTPROFILE:
95 pResource = (std::shared_ptr<OC::OCResource> *)pMessage[1];
96 pResourceHandler = new OICResourceHandler();
97 SSM_CLEANUP_ASSERT(pResourceHandler->initHandler(*pResource, this));
98 m_mapResourceHandler[pResource->get()->host() + pResource->get()->uri()] = pResourceHandler;
99 pResource->get()->get(queryParams, std::bind(&OICResourceHandler::onGetResourceProfile,
100 pResourceHandler, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
103 case RESOURCE_DISCOVER_SETUP_RESOURCE:
104 m_pResourceFinderEvent->onResourceFound((ISSMResource *)pMessage[1]);
112 void CResourceFinder::onTerminate(IN void *pArg)
114 std::shared_ptr<OC::OCResource> *pResource = NULL;
115 int *pMessage = (int *)pArg;
119 case RESOURCE_DISCOVER_REQUESTPROFILE:
120 pResource = (std::shared_ptr<OC::OCResource> *)pMessage[1];
124 case RESOURCE_DISCOVER_SETUP_RESOURCE: