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
namespace pvAccess {

static ChannelProviderRegistry::shared_pointer ChannelProviderRegistry;

static Mutex channelProviderMutex;

typedef std::map<string, ChannelProviderFactory::shared_pointer> ChannelProviderFactoryMap;
static ChannelProviderFactoryMap channelProviders;


class ChannelProviderRegistryImpl : public ChannelProviderRegistry {
    public:

    ChannelProvider::shared_pointer getProvider(std::string const & _providerName) {
        
        // TODO remove, here for backward compatibility 
        const string providerName = (_providerName == "pvAccess") ? "pva" : _providerName;
            
        Lock guard(channelProviderMutex);
        ChannelProviderFactoryMap::const_iterator iter = channelProviders.find(providerName);
        if (iter != channelProviders.end())
            return iter->second->sharedInstance();
        else
            return ChannelProvider::shared_pointer();
    }

    ChannelProvider::shared_pointer createProvider(std::string const & _providerName) {

        // TODO remove, here for backward compatibility 
        const string providerName = (_providerName == "pvAccess") ? "pva" : _providerName;
            
        Lock guard(channelProviderMutex);
        ChannelProviderFactoryMap::const_iterator iter = channelProviders.find(providerName);
        if (iter != channelProviders.end())
            return iter->second->newInstance();
        else
            return ChannelProvider::shared_pointer();
    }

    std::auto_ptr<stringVector_t> getProviderNames() {
        Lock guard(channelProviderMutex);
        std::auto_ptr<stringVector_t> providers(new stringVector_t());
        for (ChannelProviderFactoryMap::const_iterator i = channelProviders.begin();
            i != channelProviders.end(); i++)
            providers->push_back(i->first);

        return providers;
    }
};

ChannelProviderRegistry::shared_pointer getChannelProviderRegistry() {
    static Mutex mutex;
    Lock guard(mutex);

    if(ChannelProviderRegistry.get()==0){
        ChannelProviderRegistry.reset(new ChannelProviderRegistryImpl());
    }
    return ChannelProviderRegistry;
}

void registerChannelProviderFactory(ChannelProviderFactory::shared_pointer const & channelProviderFactory) {
    Lock guard(channelProviderMutex);
    channelProviders[channelProviderFactory->getFactoryName()] = channelProviderFactory;
}

void unregisterChannelProviderFactory(ChannelProviderFactory::shared_pointer const & channelProviderFactory) {
    Lock guard(channelProviderMutex);
    channelProviders.erase(channelProviderFactory->getFactoryName());
}

}}
Ejemplo n.º 3
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;
}