OCStackApplicationResult obsReqCB(void* ctx, OCDoHandle handle,
                                  OCClientResponse * clientResponse)
{
    if (ctx == (void*)DEFAULT_CONTEXT_VALUE)
    {
        OIC_LOG(INFO, TAG, "Callback Context for OBS query recvd successfully");
    }

    if (clientResponse)
    {
        OIC_LOG_V(INFO, TAG, "StackResult: %s",  getResult(clientResponse->result));
        OIC_LOG_V(INFO, TAG, "SEQUENCE NUMBER: %d", clientResponse->sequenceNumber);
        OIC_LOG_V(INFO, TAG, "Callback Context for OBSERVE notification recvd successfully %d",
                gNumObserveNotifies);
        OIC_LOG_PAYLOAD(INFO, clientResponse->payload);
        OIC_LOG(INFO, TAG, ("=============> Obs Response"));
        gNumObserveNotifies++;
        if (gNumObserveNotifies > 15) //large number to test observing in DELETE case.
        {
            if (TestCase == TEST_OBS_REQ_NON || TestCase == TEST_OBS_REQ_CON)
            {
                OIC_LOG(ERROR, TAG, "Cancelling with LOW QOS");
                if (OCCancel (handle, OC_LOW_QOS, NULL, 0) != OC_STACK_OK)
                {
                    OIC_LOG(ERROR, TAG, "Observe cancel error");
                }
                return OC_STACK_DELETE_TRANSACTION;
            }
            else if (TestCase == TEST_OBS_REQ_NON_CANCEL_IMM)
            {
                OIC_LOG(ERROR, TAG, "Cancelling with HIGH QOS");
                if (OCCancel (handle, OC_HIGH_QOS, NULL, 0) != OC_STACK_OK)
                {
                    OIC_LOG(ERROR, TAG, "Observe cancel error");
                }
            }
        }
        if (clientResponse->sequenceNumber == OC_OBSERVE_REGISTER)
        {
            OIC_LOG(INFO, TAG, "This also serves as a registration confirmation");
        }
        else if (clientResponse->sequenceNumber == OC_OBSERVE_DEREGISTER)
        {
            OIC_LOG(INFO, TAG, "This also serves as a deregistration confirmation");
            return OC_STACK_DELETE_TRANSACTION;
        }
        else if (clientResponse->sequenceNumber == OC_OBSERVE_NO_OPTION)
        {
            OIC_LOG(INFO, TAG, "This also tells you that registration/deregistration failed");
            return OC_STACK_DELETE_TRANSACTION;
        }
    }
    else
    {
        OIC_LOG_V(INFO, TAG, "obsReqCB received Null clientResponse");
    }
    return OC_STACK_KEEP_TRANSACTION;
}
OCStackApplicationResult obsReqCB(void* ctx, OCDoHandle handle, OCClientResponse * clientResponse)
{
    if(!clientResponse)
    {
        OIC_LOG_V(INFO, TAG, "obsReqCB received NULL response");
    }
    if(ctx == (void*)DEFAULT_CONTEXT_VALUE)
    {
        OIC_LOG(INFO, TAG, "Callback Context recvd successfully");
    }
    OIC_LOG_V(INFO, TAG, "StackResult: %s",  getResult(clientResponse->result));
    OIC_LOG_V(INFO, TAG, "SEQUENCE NUMBER: %d", clientResponse->sequenceNumber);
    OIC_LOG_V(INFO, TAG, "OBSERVE notification %d recvd", gNumObserveNotifies);
    OIC_LOG_PAYLOAD(INFO, clientResponse->payload);

    gNumObserveNotifies++;
    if (gNumObserveNotifies == maxNotification)
    {
        if (OCCancel (gObserveDoHandle, OC_LOW_QOS, NULL, 0) != OC_STACK_OK)
        {
            OIC_LOG(ERROR, TAG, "Observe cancel error");
        }
        return OC_STACK_DELETE_TRANSACTION;
    }
    if (gNumObserveNotifies == 1 && TEST_CASE == TEST_OBS_REQ_NON_CANCEL_IMM)
    {
        if (OCCancel (gObserveDoHandle, OC_HIGH_QOS, NULL, 0) != OC_STACK_OK)
        {
            OIC_LOG(ERROR, TAG, "Observe cancel error");
        }
    }
    if(clientResponse->sequenceNumber == OC_OBSERVE_REGISTER)
    {
        OIC_LOG(INFO, TAG, "Registration confirmed");
    }
    else if(clientResponse->sequenceNumber == OC_OBSERVE_DEREGISTER)
    {
        OIC_LOG(INFO, TAG, "de-registration confirmed");
        return OC_STACK_DELETE_TRANSACTION;
    }
    else if(clientResponse->sequenceNumber == OC_OBSERVE_NO_OPTION)
    {
        OIC_LOG(INFO, TAG, "Registration/deregistration failed");
        return OC_STACK_DELETE_TRANSACTION;
    }

    SET_BUT_NOT_USED(handle);
    return OC_STACK_KEEP_TRANSACTION;
}
Beispiel #3
0
OCStackApplicationResult getReqCB(void* ctx, OCDoHandle /*handle*/,
                                  OCClientResponse * clientResponse)
{
    OIC_LOG_V(INFO, TAG, "StackResult: %s",
            getResult(clientResponse->result));
    if(ctx == (void*)DEFAULT_CONTEXT_VALUE)
    {
        OIC_LOG_V(INFO, TAG, "SEQUENCE NUMBER: %d", clientResponse->sequenceNumber);
        if(clientResponse->sequenceNumber == 0)
        {
            OIC_LOG_V(INFO, TAG, "Callback Context for GET query recvd successfully");
            OIC_LOG_PAYLOAD(INFO, clientResponse->payload);
        }
        else
        {
            OIC_LOG_V(INFO, TAG, "Callback Context for Get recvd successfully %d",
                    gNumObserveNotifies);
            OIC_LOG_PAYLOAD(INFO, clientResponse->payload);;
            gNumObserveNotifies++;
            if (gNumObserveNotifies == 3)
            {
                if (OCCancel (gObserveDoHandle, OC_LOW_QOS, NULL, 0) != OC_STACK_OK)
                {
                    OIC_LOG(ERROR, TAG, "Observe cancel error");
                }
            }
        }
    }
    if(TestType == TEST_PUT_DEFAULT || TestType == TEST_PUT_BATCH || TestType == TEST_PUT_LINK_LIST)
    {
        InitPutRequest(clientResponse);
    }
    return OC_STACK_KEEP_TRANSACTION;
}
OCStackApplicationResult presenceCB(void* ctx, OCDoHandle /*handle*/,
                                    OCClientResponse * clientResponse)
{
    if (ctx == (void*) DEFAULT_CONTEXT_VALUE)
    {
        OIC_LOG(INFO, TAG, "Callback Context for Presence recvd successfully");
    }

    if (clientResponse)
    {
        OIC_LOG_V(INFO, TAG, "StackResult: %s", getResult(clientResponse->result));
        OIC_LOG_V(INFO, TAG, "Callback Context for Presence notification recvd successfully %d",
                gNumPresenceNotifies);
        OIC_LOG_PAYLOAD(INFO, clientResponse->payload);
        OIC_LOG(INFO, TAG, ("=============> Presence Response"));
        gNumPresenceNotifies++;
        if (gNumPresenceNotifies == 20)
        {
            if (OCCancel(gPresenceHandle, OC_LOW_QOS, NULL, 0) != OC_STACK_OK)
            {
                OIC_LOG(ERROR, TAG, "Presence cancel error");
            }
            return OC_STACK_DELETE_TRANSACTION;
        }
    }
    else
    {
        OIC_LOG_V(INFO, TAG, "presenceCB received Null clientResponse");
    }
    return OC_STACK_KEEP_TRANSACTION;
}
    OCStackResult InProcClientWrapper::CancelObserveResource(
            OCDoHandle handle,
            const std::string& host, // unused
            const std::string& uri,  // unused
            const HeaderOptions& headerOptions,
            QualityOfService QoS)
    {
        OCStackResult result;
        auto cLock = m_csdkLock.lock();

        if(cLock)
        {
            std::lock_guard<std::recursive_mutex> lock(*cLock);
            OCHeaderOption options[MAX_HEADER_OPTIONS];

            result = OCCancel(handle,
                    static_cast<OCQualityOfService>(QoS),
                    assembleHeaderOptions(options, headerOptions),
                    headerOptions.size());
        }
        else
        {
            result = OC_STACK_ERROR;
        }

        return result;
    }
OCStackApplicationResult presenceCB(void* ctx,
        OCDoHandle handle, OCClientResponse * clientResponse)
{
    if(ctx == (void*)DEFAULT_CONTEXT_VALUE)
    {
        OIC_LOG(INFO, TAG, "Callback Context recvd successfully");
    }

    if (clientResponse)
    {
        OIC_LOG_V(INFO, TAG, "StackResult: %s", getResult(clientResponse->result));
        OIC_LOG_V(INFO, TAG, "NONCE NUMBER: %u", clientResponse->sequenceNumber);
        OIC_LOG_V(INFO, TAG, "PRESENCE notification %d recvd", gNumPresenceNotifies);
        OIC_LOG_PAYLOAD(INFO, clientResponse->payload);

        gNumPresenceNotifies++;
        if (gNumPresenceNotifies == maxNotification)
        {
            if (OCCancel(gPresenceHandle, OC_LOW_QOS, NULL, 0) != OC_STACK_OK)
            {
                OIC_LOG(ERROR, TAG, "Presence cancel error");
            }
            return OC_STACK_DELETE_TRANSACTION;
        }
    }
    else
    {
        OIC_LOG_V(INFO, TAG, "presenceCB received Null clientResponse");
    }
    SET_BUT_NOT_USED(handle);
    return OC_STACK_KEEP_TRANSACTION;
}
    OCStackResult InProcClientWrapper::UnsubscribePresence(OCDoHandle handle)
    {
        OCStackResult result;
        auto cLock = m_csdkLock.lock();

        if(cLock)
        {
            std::lock_guard<std::recursive_mutex> lock(*cLock);
            result = OCCancel(handle, OC_LOW_QOS, NULL, 0);
        }
        else
        {
            result = OC_STACK_ERROR;
        }

        return result;
    }