From: Mandeep Shetty Date: Tue, 21 Apr 2015 23:19:40 +0000 (-0700) Subject: Fix issue with multicast prescence subscriptions X-Git-Tag: 1.2.0+RC1~1805 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=599d78e819d2264b87d9b407522b6c48e6dbd1be;p=platform%2Fupstream%2Fiotivity.git Fix issue with multicast prescence subscriptions After registering for a multicast presence, the callback handler URI, that is searched for isn't completley formed, so callbacks don't happen. Made uri format consistent across unicast and multicast. Updated C++ sample app presenceclient.cpp for multicast presence cases. Also removed repeat test case in presenceclient.cpp PrintUsage(). Updated 2 files in the service directory for multicast presence cases. Added test in C sample occlient.cpp for a multicast presence subscription. Modified OCPlatform.h::subscribePresence() documentation to inform api users of the expected format. Change-Id: Ic1a262566f605dd0882e563b4ee2d03bd21016be Signed-off-by: Charlie Lenahan Signed-off-by: Mandeep Shetty Reviewed-on: https://gerrit.iotivity.org/gerrit/787 Tested-by: jenkins-iotivity Reviewed-by: Sashi Penta Reviewed-by: Uze Choi Tested-by: Uze Choi --- diff --git a/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp b/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp index ec5f88b..cc473d0 100644 --- a/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp +++ b/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp @@ -95,13 +95,14 @@ static void PrintUsage() "filter"); OC_LOG(INFO, TAG, "-t 14 : Discover Resources and Initiate Nonconfirmable presence with "\ "2 filters"); + OC_LOG(INFO, TAG, "-t 15 : Discover Resources and Initiate Nonconfirmable multicast presence."); #endif - OC_LOG(INFO, TAG, "-t 15 : Discover Resources and Initiate Nonconfirmable Observe Requests "\ + OC_LOG(INFO, TAG, "-t 16 : Discover Resources and Initiate Nonconfirmable Observe Requests "\ "then cancel immediately with High QOS"); - OC_LOG(INFO, TAG, "-t 16 : Discover Resources and Initiate Nonconfirmable Get Request and "\ + OC_LOG(INFO, TAG, "-t 17 : Discover Resources and Initiate Nonconfirmable Get Request and "\ "add vendor specific header options"); - OC_LOG(INFO, TAG, "-t 17 : Discover Devices"); + OC_LOG(INFO, TAG, "-t 18 : Discover Devices"); } OCStackResult InvokeOCDoResource(std::ostringstream &query, @@ -395,6 +396,7 @@ OCStackApplicationResult discoveryReqCB(void* ctx, OCDoHandle handle, case TEST_OBS_PRESENCE: case TEST_OBS_PRESENCE_WITH_FILTER: case TEST_OBS_PRESENCE_WITH_FILTERS: + case TEST_OBS_MULTICAST_PRESENCE: InitPresence(); break; #endif @@ -468,6 +470,17 @@ int InitPresence() presenceCB, NULL, 0); } } + if(TEST_CASE == TEST_OBS_MULTICAST_PRESENCE) + { + if(result == OC_STACK_OK) + { + std::ostringstream multicastPresenceQuery; + multicastPresenceQuery.str(""); + multicastPresenceQuery << "coap://" << OC_MULTICAST_PREFIX << OC_PRESENCE_URI; + result = InvokeOCDoResource(multicastPresenceQuery, OC_REST_PRESENCE, OC_LOW_QOS, + presenceCB, NULL, 0); + } + } return result; } #endif diff --git a/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.h b/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.h index c37ac29..0b2b8b8 100644 --- a/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.h +++ b/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.h @@ -56,6 +56,7 @@ typedef enum { TEST_OBS_PRESENCE, TEST_OBS_PRESENCE_WITH_FILTER, TEST_OBS_PRESENCE_WITH_FILTERS, + TEST_OBS_MULTICAST_PRESENCE, #endif TEST_OBS_REQ_NON_CANCEL_IMM, TEST_GET_REQ_NON_WITH_VENDOR_HEADER_OPTIONS, diff --git a/resource/csdk/stack/src/ocstack.c b/resource/csdk/stack/src/ocstack.c index 39bc5a5..f8b1787 100644 --- a/resource/csdk/stack/src/ocstack.c +++ b/resource/csdk/stack/src/ocstack.c @@ -857,7 +857,8 @@ static OCStackResult HandlePresenceResponse(const CARemoteEndpoint_t* endPoint, } else { - snprintf(fullUri, MAX_URI_LENGTH, "%s%s", OC_MULTICAST_IP, endPoint->resourceUri); + snprintf(fullUri, MAX_URI_LENGTH, "coap://%s:%u%s", OC_MULTICAST_IP, OC_MULTICAST_PORT, + endPoint->resourceUri); cbNode = GetClientCB(NULL, 0, NULL, fullUri); if(cbNode) { diff --git a/resource/examples/presenceclient.cpp b/resource/examples/presenceclient.cpp index 18d1bee..968ffa5 100644 --- a/resource/examples/presenceclient.cpp +++ b/resource/examples/presenceclient.cpp @@ -63,11 +63,6 @@ void printUsage() << std::endl; std::cout << "-t 6 : Discover Resources and Initiate Multicast Presence with two Filters" << std::endl; - std::cout << "-t 4 : Discover Resources and Initiate Multicast Presence" << std::endl; - std::cout << "-t 5 : Discover Resources and Initiate Multicast Presence with Filter" - << std::endl; - std::cout << "-t 6 : Discover Resources and Initiate Multicast Presence with two Filters" - << std::endl; std::cout<<"ConnectivityType: Default WIFI" << std::endl; std::cout << "-c 0 : Send message over ETHERNET interface" << std::endl; std::cout << "-c 1 : Send message over WIFI interface" << std::endl; @@ -279,10 +274,13 @@ int main(int argc, char* argv[]) { OCPlatform::OCPresenceHandle presenceHandle = nullptr; OCStackResult result = OC_STACK_OK; + std::ostringstream multicastPresenceURI; + multicastPresenceURI << "coap://" << OC_MULTICAST_PREFIX; + if(TEST_CASE == TEST_MULTICAST_PRESENCE_NORMAL) { result = OCPlatform::subscribePresence(presenceHandle, - OC_MULTICAST_IP, connectivityType, presenceHandler); + multicastPresenceURI.str(), connectivityType, presenceHandler); if(result == OC_STACK_OK) { @@ -295,7 +293,7 @@ int main(int argc, char* argv[]) { } else if(TEST_CASE == TEST_MULTICAST_PRESENCE_WITH_FILTER) { - result = OCPlatform::subscribePresence(presenceHandle, OC_MULTICAST_IP, "core.light", + result = OCPlatform::subscribePresence(presenceHandle, multicastPresenceURI.str(), "core.light", connectivityType, &presenceHandler); if(result == OC_STACK_OK) { @@ -309,7 +307,7 @@ int main(int argc, char* argv[]) { } else if(TEST_CASE == TEST_MULTICAST_PRESENCE_WITH_FILTERS) { - result = OCPlatform::subscribePresence(presenceHandle, OC_MULTICAST_IP, "core.light", + result = OCPlatform::subscribePresence(presenceHandle, multicastPresenceURI.str(), "core.light", connectivityType, &presenceHandler); if(result == OC_STACK_OK) { @@ -321,7 +319,7 @@ int main(int argc, char* argv[]) { } std::cout << "\"core.light\"." << std::endl; - result = OCPlatform::subscribePresence(presenceHandle, OC_MULTICAST_IP, "core.fan", + result = OCPlatform::subscribePresence(presenceHandle, multicastPresenceURI.str(), "core.fan", connectivityType, &presenceHandler); if(result == OC_STACK_OK) { diff --git a/resource/include/OCPlatform.h b/resource/include/OCPlatform.h index 4d17d9d..d894295 100644 --- a/resource/include/OCPlatform.h +++ b/resource/include/OCPlatform.h @@ -380,6 +380,7 @@ namespace OC * request. It can be used to unsubscribe from these events in the future. * It will be set upon successful return of this method. * @param host - The IP address/addressable name of the server to subscribe to. + * This should be in the format coap://address:port * @param connectivityType - @ref OCConnectivityType type of connectivity indicating the * interface. Example: OC_WIFI, OC_ETHERNET, OC_ALL * @param resourceType - a resource type specified as a filter for subscription callbacks. diff --git a/service/notification-manager/NotificationManager/src/hosting.c b/service/notification-manager/NotificationManager/src/hosting.c index d3cc3b9..e7531b7 100755 --- a/service/notification-manager/NotificationManager/src/hosting.c +++ b/service/notification-manager/NotificationManager/src/hosting.c @@ -351,7 +351,7 @@ OCStackResult OICStartCoordinate() s_mirrorResourceList = createMirrorResourceList(); s_requestHandleList = createRequestHandleList(); - result = requestPresence(OC_DEFAULT_ADDRESS); + result = requestPresence(OC_MULTICAST_PREFIX); if(result != OC_STACK_OK) { return OC_STACK_ERROR; @@ -422,7 +422,7 @@ OCStackResult requestPresence(char *sourceResourceAddress) cbData.cd = NULL; char queryUri[OIC_STRING_MAX_VALUE] = { '\0' }; - sprintf(queryUri, "%s%s", sourceResourceAddress , OC_PRESENCE_URI); + sprintf(queryUri, "coap://%s%s", sourceResourceAddress , OC_PRESENCE_URI); OC_LOG_V(DEBUG, HOSTING_TAG, "initializePresenceForCoordinating Query : %s", queryUri); result = OCDoResource(&handle, OC_REST_PRESENCE, queryUri, 0, 0, OC_ETHERNET, OC_LOW_QOS, &cbData, NULL, 0); diff --git a/service/soft-sensor-manager/SSMCore/src/SensorProcessor/ResourceFinder.cpp b/service/soft-sensor-manager/SSMCore/src/SensorProcessor/ResourceFinder.cpp index 48ba5d0..c44d242 100644 --- a/service/soft-sensor-manager/SSMCore/src/SensorProcessor/ResourceFinder.cpp +++ b/service/soft-sensor-manager/SSMCore/src/SensorProcessor/ResourceFinder.cpp @@ -130,6 +130,9 @@ SSMRESULT CResourceFinder::startResourceFinder() std::ostringstream requestURI; requestURI << OC_WELL_KNOWN_QUERY << "?rt=SSManager.Sensor"; + std::ostringstream multicastPresenceURI; + multicastPresenceURI << "coap://" << OC_MULTICAST_PREFIX; + ret = OC::OCPlatform::findResource("", requestURI.str(), OC_WIFI, std::bind(&CResourceFinder::onResourceFound, this, std::placeholders::_1)); @@ -142,14 +145,14 @@ SSMRESULT CResourceFinder::startResourceFinder() if (ret != OC_STACK_OK) SSM_CLEANUP_ASSERT(SSM_E_FAIL); - ret = OC::OCPlatform::subscribePresence(m_multicastPresenceHandle, OC_MULTICAST_IP, + ret = OC::OCPlatform::subscribePresence(m_multicastPresenceHandle, multicastPresenceURI.str(), "SSManager.Sensor", OC_WIFI, std::bind(&CResourceFinder::presenceHandler, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); if (ret != OC_STACK_OK) SSM_CLEANUP_ASSERT(SSM_E_FAIL); - ret = OC::OCPlatform::subscribePresence(m_multicastPresenceHandle, OC_MULTICAST_IP, + ret = OC::OCPlatform::subscribePresence(m_multicastPresenceHandle, multicastPresenceURI.str(), "SSManager.Sensor", OC_ETHERNET, std::bind(&CResourceFinder::presenceHandler, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));