Ejemplo n.º 1
0
ChannelProviderRegistry::shared_pointer getChannelProviderRegistry() {
    static Mutex mutex;
    Lock guard(mutex);

    if(ChannelProviderRegistry.get()==0){
        ChannelProviderRegistry.reset(new ChannelProviderRegistryImpl());
    }
    return ChannelProviderRegistry;
}
Ejemplo n.º 2
0
void ServerContextImpl::initialize(ChannelProviderRegistry::shared_pointer const & channelProviderRegistry)
{
    Lock guard(_mutex);
    if (!channelProviderRegistry.get())
    {
        THROW_BASE_EXCEPTION("channelProviderRegistry == NULL");
    }

    if (_state == DESTROYED)
    {
        THROW_BASE_EXCEPTION("Context destroyed.");
    }
    else if (_state != NOT_INITIALIZED)
    {
        THROW_BASE_EXCEPTION("Context already initialized.");
    }

    _channelProviderRegistry = channelProviderRegistry;


    // user all providers
    if (_channelProviderNames == PVACCESS_ALL_PROVIDERS)
    {
        _channelProviderNames.resize(0); // VxWorks 5.5 omits clear()

        std::auto_ptr<ChannelProviderRegistry::stringVector_t> names = _channelProviderRegistry->getProviderNames();
        for (ChannelProviderRegistry::stringVector_t::iterator iter = names->begin(); iter != names->end(); iter++)
        {
            ChannelProvider::shared_pointer channelProvider = _channelProviderRegistry->getProvider(*iter);
            if (channelProvider)
            {
                _channelProviders.push_back(channelProvider);

                // compile a list
                if (!_channelProviderNames.empty())
                    _channelProviderNames += ' ';
                _channelProviderNames += *iter;
            }
        }
    }
    else
    {
        // split space separated names
        std::stringstream ss(_channelProviderNames);
        std::string providerName;
        while (std::getline(ss, providerName, ' '))
        {
            ChannelProvider::shared_pointer channelProvider = _channelProviderRegistry->getProvider(providerName);
            if (channelProvider)
                _channelProviders.push_back(channelProvider);
        }
    }

    //_channelProvider = _channelProviderRegistry->getProvider(_channelProviderNames);
    if (_channelProviders.size() == 0)
    {
        std::string msg = "None of the specified channel providers are available: " + _channelProviderNames + ".";
        THROW_BASE_EXCEPTION(msg.c_str());
    }

    internalInitialize();

    _state = INITIALIZED;
}