From 06a7e5285b3d8cdf736ccf28c8bb0fde8767c5fb Mon Sep 17 00:00:00 2001 From: HyunJun Kim Date: Wed, 15 Apr 2015 17:37:56 +0900 Subject: [PATCH] Update sample and Group for CA. We cannot use OC_ALL. So we call the findResource API twice using OC_ETHERNET and OC_WIFI. Change-Id: I303c56e7f15c36da3ee0519f9f9a00c092a83928 Signed-off-by: HyunJun Kim Reviewed-on: https://gerrit.iotivity.org/gerrit/728 Tested-by: jenkins-iotivity Reviewed-by: Uze Choi --- .../sampleapp/linux/groupsyncaction/group.cpp | 17 +++++++++------ .../sampleapp/linux/groupsyncaction/phone.cpp | 4 +++- service/things-manager/sdk/src/GroupManager.cpp | 25 ++++++++++++++++------ .../sdk/src/GroupSynchronization.cpp | 14 ++++++------ 4 files changed, 39 insertions(+), 21 deletions(-) diff --git a/service/things-manager/sampleapp/linux/groupsyncaction/group.cpp b/service/things-manager/sampleapp/linux/groupsyncaction/group.cpp index 8965c4b..45c1ced 100644 --- a/service/things-manager/sampleapp/linux/groupsyncaction/group.cpp +++ b/service/things-manager/sampleapp/linux/groupsyncaction/group.cpp @@ -75,7 +75,6 @@ void onFindResource(std::shared_ptr< OCResource > resource) int main(int argc, char* argv[]) { - // Create PlatformConfig object PlatformConfig cfg { OC::ServiceType::InProc, OC::ModeType::Both/*OC::ModeType::Server*/, "0.0.0.0", 0, @@ -113,8 +112,12 @@ int main(int argc, char* argv[]) } else if (selectedMenu == 11) { + ostringstream query; + query << OC_WELL_KNOWN_QUERY << "?rt=core.musicplayer"; + + cout << query.str() << endl; result = OCPlatform::findResource("", - "coap://224.0.1.187/oc/core?rt=core.musicplayer", + query.str(), OC_ETHERNET, onFindResource); @@ -134,12 +137,14 @@ int main(int argc, char* argv[]) } else if (selectedMenu == 12) { - result = OCPlatform::findResource("", - "coap://224.0.1.187/oc/core?rt=core.speaker", + ostringstream query; + query << OC_WELL_KNOWN_QUERY << "?rt=core.speaker"; + result = OCPlatform::findResource("", + query.str(), OC_ETHERNET, onFindResource); - - result = OCPlatform::findResource("", + + result = OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=core.speaker", OC_WIFI, onFindResource); diff --git a/service/things-manager/sampleapp/linux/groupsyncaction/phone.cpp b/service/things-manager/sampleapp/linux/groupsyncaction/phone.cpp index 177399d..d3729a9 100644 --- a/service/things-manager/sampleapp/linux/groupsyncaction/phone.cpp +++ b/service/things-manager/sampleapp/linux/groupsyncaction/phone.cpp @@ -249,7 +249,9 @@ int main(int argc, char* argv[]) std::string resourceInterface = DEFAULT_INTERFACE; result = OCPlatform::registerResource(gPhoneResourceHandle, resourceURi, - resourceTypeName, resourceInterface, NULL, OC_DISCOVERABLE | OC_OBSERVABLE); + resourceTypeName, resourceInterface, + NULL, OC_DISCOVERABLE | OC_OBSERVABLE); + if (OC_STACK_OK == result) { cout << "To register phone resource was successful\n"; diff --git a/service/things-manager/sdk/src/GroupManager.cpp b/service/things-manager/sdk/src/GroupManager.cpp index 091621a..30720f0 100755 --- a/service/things-manager/sdk/src/GroupManager.cpp +++ b/service/things-manager/sdk/src/GroupManager.cpp @@ -227,19 +227,19 @@ OCStackResult GroupManager::findCandidateResources( query.append("?rt="); query.append(resourceTypes.at(i)); - OCPlatform::findResource("", + OCPlatform::findResource("", query, OC_ETHERNET, std::function < void(std::shared_ptr < OCResource > resource) > (std::bind(&GroupManager::onFoundResource, this, std::placeholders::_1, waitsec))); - // OCPlatform::findResource("", - // query, - // OC_WIFI, - // std::function < void(std::shared_ptr < OCResource > resource) - // > (std::bind(&GroupManager::onFoundResource, this, std::placeholders::_1, - // waitsec))); + OCPlatform::findResource("", + query, + OC_WIFI, + std::function < void(std::shared_ptr < OCResource > resource) + > (std::bind(&GroupManager::onFoundResource, this, std::placeholders::_1, + waitsec))); } if (waitsec >= 0) @@ -374,6 +374,17 @@ void GroupManager::checkCollectionRepresentation(const OCRepresentation& rep, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, hostAddress, oit->getUri()))); + result = OCPlatform::subscribePresence(presenceHandle, hostAddress, + // resourceType, + resourceTypes.front(), + OC_WIFI, + std::function< + void(OCStackResult result, const unsigned int nonce, + const std::string& hostAddress) >( + std::bind(&GroupManager::collectionPresenceHandler, this, + std::placeholders::_1, std::placeholders::_2, + std::placeholders::_3, hostAddress, oit->getUri()))); + if (result == OC_STACK_OK) { presenceCallbacks.insert(std::make_pair(oit->getUri(), callback)); diff --git a/service/things-manager/sdk/src/GroupSynchronization.cpp b/service/things-manager/sdk/src/GroupSynchronization.cpp index ca6819f..bfae87f 100644 --- a/service/things-manager/sdk/src/GroupSynchronization.cpp +++ b/service/things-manager/sdk/src/GroupSynchronization.cpp @@ -83,9 +83,9 @@ namespace OIC OC_ETHERNET, std::bind(&GroupSynchronization::onFindGroup, this, std::placeholders::_1)); - // OCPlatform::findResource("", query, - // OC_WIFI, - // std::bind(&GroupSynchronization::onFindGroup, this, std::placeholders::_1)); + OCPlatform::findResource("", query, + OC_WIFI, + std::bind(&GroupSynchronization::onFindGroup, this, std::placeholders::_1)); } bIsFinding = true; @@ -708,10 +708,10 @@ OCStackResult GroupSynchronization::leaveGroup( std::bind(&GroupSynchronization::onFindResource, this, std::placeholders::_1)); - // OCPlatform::findResource("", resourceName, - // OC_WIFI, - // std::bind(&GroupSynchronization::onFindResource, this, - // std::placeholders::_1)); + OCPlatform::findResource("", resourceName, + OC_WIFI, + std::bind(&GroupSynchronization::onFindResource, this, + std::placeholders::_1)); return OC_EH_SLOW; } -- 2.7.4