* requestUri must be a char array of size CA_MAX_URI_LENGTH
*/
static int FormCanonicalPresenceUri(const CAEndpoint_t *endpoint, char *resourceUri,
- char *presenceUri)
+ char *presenceUri, bool isMulticast)
{
VERIFY_NON_NULL(endpoint , FATAL, OC_STACK_INVALID_PARAM);
VERIFY_NON_NULL(resourceUri, FATAL, OC_STACK_INVALID_PARAM);
VERIFY_NON_NULL(presenceUri, FATAL, OC_STACK_INVALID_PARAM);
- CAEndpoint_t *ep = (CAEndpoint_t *)endpoint;
+ if (isMulticast)
+ {
+ OIC_LOG(DEBUG, TAG, "Make Multicast Presence URI");
+ return snprintf(presenceUri, CA_MAX_URI_LENGTH, "%s", OC_RSRVD_PRESENCE_URI);
+ }
+ CAEndpoint_t *ep = (CAEndpoint_t *)endpoint;
if (ep->adapter == CA_ADAPTER_IP)
{
if ((ep->flags & CA_IPV6) && !(ep->flags & CA_IPV4))
return OC_STACK_ERROR;
}
- // check for unicast presence
- uriLen = FormCanonicalPresenceUri(endpoint, OC_RSRVD_PRESENCE_URI, presenceUri);
- if (uriLen < 0 || (size_t)uriLen >= sizeof (presenceUri))
- {
- return OC_STACK_INVALID_URI;
- }
-
- cbNode = GetClientCB(NULL, 0, NULL, presenceUri);
- if (cbNode)
- {
- presenceSubscribe = 1;
- }
- else
- {
- // check for multiicast presence
- CAEndpoint_t ep = { .adapter = endpoint->adapter,
- .flags = endpoint->flags };
-
- uriLen = FormCanonicalPresenceUri(&ep, OC_RSRVD_PRESENCE_URI, presenceUri);
-
- cbNode = GetClientCB(NULL, 0, NULL, presenceUri);
- if (cbNode)
- {
- multicastPresenceSubscribe = 1;
- }
- }
-
- if (!presenceSubscribe && !multicastPresenceSubscribe)
- {
- OIC_LOG(ERROR, TAG, "Received a presence notification, but no callback, ignoring");
- goto exit;
- }
-
response.payload = NULL;
response.result = OC_STACK_OK;
maxAge = ((OCPresencePayload*)response.payload)->maxAge;
}
+ // check for unicast presence
+ uriLen = FormCanonicalPresenceUri(endpoint, OC_RSRVD_PRESENCE_URI, presenceUri,
+ responseInfo->isMulticast);
+ if (uriLen < 0 || (size_t)uriLen >= sizeof (presenceUri))
+ {
+ return OC_STACK_INVALID_URI;
+ }
+ OIC_LOG(ERROR, TAG, "check for unicast presence");
+ cbNode = GetClientCB(NULL, 0, NULL, presenceUri);
+ if (cbNode)
+ {
+ presenceSubscribe = 1;
+ }
+ else
+ {
+ // check for multicast presence
+ OIC_LOG(ERROR, TAG, "check for multicast presence");
+ cbNode = GetClientCB(NULL, 0, NULL, OC_RSRVD_PRESENCE_URI);
+ if (cbNode)
+ {
+ multicastPresenceSubscribe = 1;
+ }
+ }
+
+ if (!presenceSubscribe && !multicastPresenceSubscribe)
+ {
+ OIC_LOG(ERROR, TAG, "Received a presence notification, but no callback, ignoring");
+ goto exit;
+ }
+
if (presenceSubscribe)
{
if(cbNode->sequenceNumber == response.sequenceNumber)
// presence node now owns uri
}
+
+
// Ensure that a filter is actually applied.
if(resourceTypeName && cbNode->filterResourceType)
{
+ OIC_LOG_V(INFO, TAG, "find resource type : %s", resourceTypeName);
if(!findResourceType(cbNode->filterResourceType, resourceTypeName))
{
goto exit;
}
}
}
+ OIC_LOG(INFO, TAG, "Callback for presence");
cbResult = cbNode->callBack(cbNode->context, cbNode->handle, &response);
}
static OCStackResult OCPreparePresence(CAEndpoint_t *endpoint,
- char *resourceUri, char **requestUri)
+ char *resourceUri,
+ char **requestUri,
+ bool isMulticast)
{
char uri[CA_MAX_URI_LENGTH];
- FormCanonicalPresenceUri(endpoint, resourceUri, uri);
+ FormCanonicalPresenceUri(endpoint, resourceUri, uri, isMulticast);
*requestUri = OICStrdup(uri);
if (!*requestUri)
flags = (OCTransportFlags)(connectivityType & CT_MASK_FLAGS);
result = ParseRequestUri(requestUri, adapter, flags, &devAddr, &resourceUri, &resourceType);
-
if (result != OC_STACK_OK)
{
OIC_LOG_V(DEBUG, TAG, "Unable to parse uri: %s", requestUri);
break;
case OC_REST_DISCOVER:
qos = OC_LOW_QOS;
+#ifdef WITH_PRESENCE
+ case OC_REST_PRESENCE:
+#endif
if (destination || devAddr)
{
requestInfo.isMulticast = false;
destination = &tmpDevAddr;
requestInfo.isMulticast = true;
}
- // CA_DISCOVER will become GET and isMulticast
- requestInfo.method = CA_GET;
- break;
-#ifdef WITH_PRESENCE
- case OC_REST_PRESENCE:
- // Replacing method type with GET because "presence"
- // is a stack layer only implementation.
+ // OC_REST_DISCOVER: CA_DISCOVER will become GET and isMulticast.
+ // OC_REST_PRESENCE: Since "presence" is a stack layer only implementation.
+ // replacing method type with GET.
requestInfo.method = CA_GET;
break;
-#endif
default:
result = OC_STACK_INVALID_METHOD;
goto exit;
if (method == OC_REST_PRESENCE)
{
char *presenceUri = NULL;
- result = OCPreparePresence(&endpoint, resourceUri, &presenceUri);
+ result = OCPreparePresence(&endpoint, resourceUri, &presenceUri,
+ requestInfo.isMulticast);
if (OC_STACK_OK != result)
{
goto exit;
OCResourceType * rtPointer = resourceTypeList;
while(resourceTypeName && rtPointer)
{
+ OIC_LOG_V(DEBUG, TAG, "current resourceType : %s", rtPointer->resourcetypename);
if(rtPointer->resourcetypename &&
strcmp(resourceTypeName, (const char *)
(rtPointer->resourcetypename)) == 0)
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,
- multicastPresenceURI.str(), connectivityType, presenceHandler);
+ "",
+ connectivityType,
+ presenceHandler);
if(result == OC_STACK_OK)
{
}
else if(TEST_CASE == TEST_MULTICAST_PRESENCE_WITH_FILTER)
{
- result = OCPlatform::subscribePresence(presenceHandle, multicastPresenceURI.str(), "core.light",
- connectivityType, &presenceHandler);
+ result = OCPlatform::subscribePresence(presenceHandle,
+ "", "core.light",
+ connectivityType,
+ &presenceHandler);
if(result == OC_STACK_OK)
{
std::cout << "Subscribed to multicast presence with resource type";
}
else if(TEST_CASE == TEST_MULTICAST_PRESENCE_WITH_FILTERS)
{
- result = OCPlatform::subscribePresence(presenceHandle, multicastPresenceURI.str(), "core.light",
- connectivityType, &presenceHandler);
+ result = OCPlatform::subscribePresence(presenceHandle,
+ "", "core.light",
+ connectivityType,
+ &presenceHandler);
if(result == OC_STACK_OK)
{
std::cout << "Subscribed to multicast presence with resource type";
}
std::cout << "\"core.light\"." << std::endl;
- result = OCPlatform::subscribePresence(presenceHandle, multicastPresenceURI.str(), "core.fan",
- connectivityType, &presenceHandler);
+ result = OCPlatform::subscribePresence(presenceHandle,
+ "", "core.fan",
+ connectivityType,
+ &presenceHandler);
if(result == OC_STACK_OK)
{
std::cout<< "Subscribed to multicast presence with resource type";