boost::int32_t PublishingService::RequestSubscription(
        const std::string &subscriptionName,
        boost::uint32_t subToPubPingIntervalMs,
        boost::uint32_t & pubToSubPingIntervalMs)
    {
        PublisherPtr publisherPtr;
        std::string publisherName = subscriptionName;
        Lock lock(mPublishersMutex);
        Publishers::iterator iter = mPublishers.find(publisherName);
        if (iter != mPublishers.end())
        {
            PublisherWeakPtr publisherWeakPtr = iter->second;
            publisherPtr = publisherWeakPtr.lock();
        }
        lock.unlock();
        if (publisherPtr)
        {
            RcfSession & rcfSession = getTlsRcfSession();

            if (publisherPtr->mParms.mOnSubscriberConnect)
            {
                bool allowSubscriber = publisherPtr->mParms.mOnSubscriberConnect(rcfSession, subscriptionName);
                if (!allowSubscriber)
                {
                    return RcfError_AccessDenied;
                }
            }

            rcfSession.setPingIntervalMs(subToPubPingIntervalMs);

            ServerTransportEx &serverTransport = dynamic_cast<ServerTransportEx &>(
                rcfSession.getNetworkSession().getServerTransport());

            ClientTransportAutoPtrPtr clientTransportAutoPtrPtr( new ClientTransportAutoPtr(
                serverTransport.createClientTransport( rcfSession.shared_from_this() )));

            (*clientTransportAutoPtrPtr)->setRcfSession(
                rcfSession.shared_from_this());

            if ( publisherPtr->mParms.mOnSubscriberDisconnect )
            {
                rcfSession.setOnDestroyCallback( boost::bind(
                    publisherPtr->mParms.mOnSubscriberDisconnect,
                    _1,
                    publisherName));
            }

            rcfSession.setPingTimestamp();

            rcfSession.addOnWriteCompletedCallback( boost::bind(
                &PublishingService::addSubscriberTransport,
                this,
                _1,
                publisherName,
                clientTransportAutoPtrPtr) );
        }  
        pubToSubPingIntervalMs = mPingIntervalMs;
        return publisherPtr ? RcfError_Ok : RcfError_UnknownPublisher;
    }
 // remotely accessible
 boost::int32_t SessionObjectFactoryService::CreateSessionObject(
     const std::string &objectName)
 {
     StubFactoryPtr stubFactoryPtr( getStubFactory( objectName));
     if (stubFactoryPtr.get())
     {
         RcfClientPtr rcfClientPtr( stubFactoryPtr->makeServerStub());
         getTlsRcfSession().setDefaultStubEntryPtr(
             StubEntryPtr( new StubEntry(rcfClientPtr)));
         return RcfError_Ok;
     }
     return RcfError_ObjectFactoryNotFound;
 }
    // remotely accessible
    boost::int32_t ObjectFactoryService::CreateObject(
        const std::string &objectName,
        Token &token)
    {
        RCF_LOG_3()(objectName);

        {
            Lock lock(mCleanupThresholdMutex);
            if (!mLazyStarted)
            {
                mTaskEntries[0].start();
                mLazyStarted = true;
            }
        }

        // TODO: seems unnecessary to be triggering a sweep here
        std::size_t nAvail = mTokenFactory->getAvailableTokenCount();
        std::size_t nTotal = mTokenFactory->getTokenSpace().size();
        float used = float(nTotal - nAvail) / float(nTotal);
        if (used > mCleanupThreshold)
        {
            Lock lock(mCleanupThresholdMutex);
            mCleanupThresholdCondition.notify_all(lock);
        }

        boost::int32_t ret = RcfError_Ok;

        StubFactoryPtr stubFactoryPtr( getStubFactory( objectName));
        if (stubFactoryPtr.get())
        {
            RcfClientPtr rcfClientPtr( stubFactoryPtr->makeServerStub());
            StubEntryPtr stubEntryPtr( new StubEntry(rcfClientPtr));

            ret = addObject(TokenMappedPtr(stubEntryPtr), token);
            
            if (ret == RcfError_Ok)
            {
                getTlsRcfSession().setCachedStubEntryPtr(stubEntryPtr);

                RCF_LOG_3()(objectName)(token) << "Dynamically bound object created.";
            }
        }
        else
        {
            ret = RcfError_ObjectFactoryNotFound;
        }

        return ret;
    }
 // remotely accessible
 boost::int32_t SessionObjectFactoryService::DeleteSessionObject()
 {
     getTlsRcfSession().setDefaultStubEntryPtr(StubEntryPtr());
     return RcfError_Ok;
 }
Example #5
0
 RcfSession & getCurrentRcfSession()
 {
     return getTlsRcfSession();
 }