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 std::string path = resource->host() + resource->uri();
59 m_pTasker->addTask(this, pMessage);
63 SSMRESULT CResourceFinder::startResourceFinder()
65 OCStackResult res = OC_STACK_ERROR;
67 res = OC::OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=SoftSensorManager.Sensor",
68 std::bind(&CResourceFinder::onResourceFound, this, std::placeholders::_1));
70 if (res != OC_STACK_OK)
76 SSMRESULT CResourceFinder::startObserveResource(IN ISSMResource *pSensor, IN IEvent *pEvent)
78 return m_mapResourceHandler[pSensor->name]->startObserve(pEvent);
81 SSMRESULT CResourceFinder::stopObserveResource(IN ISSMResource *pSensor)
83 return m_mapResourceHandler[pSensor->name]->stopObserve();
86 void CResourceFinder::onExecute(IN void *pArg)
88 SSMRESULT res = SSM_E_FAIL;
89 OC::QueryParamsMap queryParams;
90 OICResourceHandler *pResourceHandler = NULL;
91 int *pMessage = (int *)pArg;
92 std::shared_ptr<OC::OCResource> *pResource = NULL;
96 case RESOURCE_DISCOVER_REQUESTPROFILE:
97 pResource = (std::shared_ptr<OC::OCResource> *)pMessage[1];
98 pResourceHandler = new OICResourceHandler();
99 SSM_CLEANUP_ASSERT(pResourceHandler->initHandler(*pResource, this));
100 m_mapResourceHandler[pResource->get()->host() + pResource->get()->uri()] = pResourceHandler;
101 pResource->get()->get(queryParams, std::bind(&OICResourceHandler::onGetResourceProfile,
102 pResourceHandler, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
105 case RESOURCE_DISCOVER_SETUP_RESOURCE:
106 m_pResourceFinderEvent->onResourceFound((ISSMResource *)pMessage[1]);
114 void CResourceFinder::onTerminate(IN void *pArg)
116 std::shared_ptr<OC::OCResource> *pResource = NULL;
117 int *pMessage = (int *)pArg;
121 case RESOURCE_DISCOVER_REQUESTPROFILE:
122 pResource = (std::shared_ptr<OC::OCResource> *)pMessage[1];
126 case RESOURCE_DISCOVER_SETUP_RESOURCE: