bess
bess

Reputation: 1

how to implement onvif CreatePullPointSubscription operation by gsoap

Referring to onvif core specification: If the subscription is accepted, the response contains a WS-EndpointReference to the instantiated pull point. This WS-Endpoint provides a PullMessages operation, which is used by the client to retrieve Notifications.

But I can't see the codes about instancing pull point, and I don't know how to implement it. Here is my coding.

SOAP_FMAC5 int SOAP_FMAC6 __tev__CreatePullPointSubscription(struct soap* soap, struct _tev__CreatePullPointSubscription *tev__CreatePullPointSubscription, struct _tev__CreatePullPointSubscriptionResponse *tev__CreatePullPointSubscriptionResponse)
{
    tev__CreatePullPointSubscriptionResponse->SubscriptionReference.Address =  (char *)soap_malloc(soap, sizeof(char) * 128);
    strcpy(tev__CreatePullPointSubscriptionResponse->SubscriptionReference.Address, "http://192.168.12.1/Subscription?Idx=0");

    tev__CreatePullPointSubscriptionResponse->wsnt__CurrentTime=time(NULL);
    tev__CreatePullPointSubscriptionResponse->wsnt__TerminationTime=tev__CreatePullPointSubscriptionResponse->wsnt__CurrentTime+60;

    return SOAP_OK;
}

Can anyone brighten me? Thank you in advance.

Upvotes: 0

Views: 1432

Answers (1)

shalm
shalm

Reputation: 1

void CreatePullPointSubscription() {
    struct soap *m_soap = soap_new();
    m_soap->connect_timeout = SOAP_REQUEST_TIMEOUT_IN_SECONDS;
    m_soap->recv_timeout = SOAP_REQUEST_TIMEOUT_IN_SECONDS;
    m_soap->send_timeout = SOAP_REQUEST_TIMEOUT_IN_SECONDS;

    PullPointSubscriptionBindingProxy subscriptionProxy(m_soap);
    subscriptionProxy.soap_endpoint = xAddr;
    if (addCredentialsToCall(m_soap)) {   
        _tev__CreatePullPointSubscription request;
        _tev__CreatePullPointSubscriptionResponse response;
        auto ret = subscriptionProxy.CreatePullPointSubscription(&request, response);
        if (ret != SOAP_OK) {
            soap_stream_fault(m_soap, std::cerr);
        } else {
            auto address = response.SubscriptionReference.Address;
            std::cout << address << std::endl;
            std::cout << "Subscription metadata: " << response.SubscriptionReference.Metadata << std::endl;
            std::cout << "Termination time " << response.wsnt__TerminationTime << std::endl;
            std::cout << "Current time " << response.wsnt__CurrentTime << std::endl;

            std::string uuid = std::string(soap_rand_uuid(m_soap, "urn:uuid:"));
            struct SOAP_ENV__Header header;
            header.wsa5__MessageID = (char *) uuid.c_str();
            header.wsa5__To = response.SubscriptionReference.Address;
            m_soap->header = &header;

                if (addCredentialsToCall(m_soap)) {
                    _tev__PullMessages tev__PullMessages;
                    tev__PullMessages.Timeout = "PT600S";
                    tev__PullMessages.MessageLimit = 100;
                    _tev__PullMessagesResponse tev__PullMessagesResponse;

                    auto ret = subscriptionProxy.PullMessages(&tev__PullMessages, tev__PullMessagesResponse);
                    for (auto msg : tev__PullMessagesResponse.wsnt__NotificationMessage) {
                        std::cout << "\tMessage is :" << msg->Topic->__mixed << std::endl;
                    }

                } else {
                    std::cout << "Couldn't set credentials!!!" << std::endl;
                }
            }
        }
    
        subscriptionProxy.destroy();
}

This worked for me atleast to pull the event initializers.

Upvotes: 0

Related Questions