예제 #1
0
    SubscriptionPtr SubscriptionService::onRequestSubscriptionCompleted(
        boost::int32_t                      ret,
        const std::string &                 publisherName,
        RcfClient<I_RequestSubscription> &  client,
        RcfClientPtr                        rcfClientPtr,
        OnSubscriptionDisconnect            onDisconnect,
        boost::uint32_t                     pubToSubPingIntervalMs,
        bool                                pingsEnabled)
    {
        bool ok = (ret == RcfError_Ok);
        if (ok)
        {
            ClientTransportAutoPtr clientTransportAutoPtr(
                client.getClientStub().releaseTransport());

            I_ServerTransport * pTransport = NULL;
            I_ServerTransportEx * pTransportEx = NULL;

            if (clientTransportAutoPtr->isInProcess())
            {
                pTransport = dynamic_cast<I_ServerTransport *>(
                    clientTransportAutoPtr.get());
            }
            else
            {
                pTransport = & mpServer->findTransportCompatibleWith(
                    *clientTransportAutoPtr);
            }

            pTransportEx = dynamic_cast<I_ServerTransportEx *>(pTransport);

            I_ServerTransportEx & serverTransportEx = * pTransportEx; 

            SessionPtr sessionPtr = serverTransportEx.createServerSession(
                clientTransportAutoPtr,
                StubEntryPtr(new StubEntry(rcfClientPtr)),
                true);

            RCF_ASSERT( sessionPtr );

            RcfSessionPtr rcfSessionPtr = sessionPtr;

            rcfSessionPtr->setUserData(client.getClientStub().getUserData());
            rcfSessionPtr->setPingTimestamp();

            std::string publisherUrl;
            EndpointPtr epPtr = client.getClientStub().getEndpoint();
            if (epPtr)
            {
                publisherUrl = epPtr->asString();
            }

            if (    !clientTransportAutoPtr->isInProcess() 
                &&  !clientTransportAutoPtr->isAssociatedWithIoService())
            {
                AsioServerTransport & asioTransport = dynamic_cast<AsioServerTransport &>(
                    mpServer->getServerTransport());

                clientTransportAutoPtr->associateWithIoService(asioTransport.getIoService());
            }

            SubscriptionPtr subscriptionPtr( new Subscription(
                *this,
                clientTransportAutoPtr, 
                rcfSessionPtr, 
                pubToSubPingIntervalMs, 
                publisherUrl,
                publisherName,
                onDisconnect));

            rcfSessionPtr->setOnDestroyCallback( boost::bind(
                &Subscription::onDisconnect,
                SubscriptionWeakPtr(subscriptionPtr),
                _1));

            subscriptionPtr->setWeakThisPtr(subscriptionPtr);

            subscriptionPtr->mPingsEnabled = pingsEnabled;

            Lock lock(mSubscriptionsMutex);
            mSubscriptions.insert(subscriptionPtr);

            return subscriptionPtr;                
        }
        return SubscriptionPtr();
    }
예제 #2
0
    SubscriptionPtr SubscriptionService::onRequestSubscriptionCompleted(
        boost::int32_t                      ret,
        const std::string &                 publisherName,
        ClientStub &                        clientStub,
        RcfClientPtr                        rcfClientPtr,
        OnSubscriptionDisconnect            onDisconnect,
        boost::uint32_t                     pubToSubPingIntervalMs,
        bool                                pingsEnabled)
    {
        if (ret != RcfError_Ok)
        {
            RCF_THROW( Exception( Error(ret) ) );
        }

        ClientTransportAutoPtr clientTransportAutoPtr( 
                clientStub.releaseTransport() );

        ServerTransport * pTransport = NULL;
        ServerTransportEx * pTransportEx = NULL;

        pTransport = & mpServer->findTransportCompatibleWith(
            *clientTransportAutoPtr);

        pTransportEx = dynamic_cast<ServerTransportEx *>(pTransport);

        ServerTransportEx & serverTransportEx = * pTransportEx; 

        SessionPtr sessionPtr = serverTransportEx.createServerSession(
            clientTransportAutoPtr,
            StubEntryPtr(new StubEntry(rcfClientPtr)),
            true);

        RCF_ASSERT( sessionPtr );

        RcfSessionPtr rcfSessionPtr = sessionPtr;

        rcfSessionPtr->setUserData(clientStub.getUserData());
        rcfSessionPtr->setPingTimestamp();

        std::string publisherUrl;
        EndpointPtr epPtr = clientStub.getEndpoint();
        if (epPtr)
        {
            publisherUrl = epPtr->asString();
        }

        //if (!clientTransportAutoPtr->isAssociatedWithIoService())
        //{
        //    AsioServerTransport & asioTransport = dynamic_cast<AsioServerTransport &>(
        //        mpServer->getServerTransport());

        //    clientTransportAutoPtr->associateWithIoService(asioTransport.getIoService());
        //}

        SubscriptionPtr subscriptionPtr( new Subscription(
            *this,
            clientTransportAutoPtr, 
            rcfSessionPtr, 
            pubToSubPingIntervalMs, 
            publisherUrl,
            publisherName,
            onDisconnect));

        rcfSessionPtr->setOnDestroyCallback( boost::bind(
            &Subscription::onDisconnect,
            SubscriptionWeakPtr(subscriptionPtr),
            _1));

        subscriptionPtr->setWeakThisPtr(subscriptionPtr);

        subscriptionPtr->mPingsEnabled = pingsEnabled;

        Lock lock(mSubscriptionsMutex);
        mSubscriptions.insert(subscriptionPtr);

        return subscriptionPtr;                
    }