void
IceInternal::OutgoingConnectionFactory::setRouterInfo(const RouterInfoPtr& routerInfo)
{
    IceUtil::Monitor<IceUtil::Mutex>::Lock sync(*this);

    if(_destroyed)
    {
        throw CommunicatorDestroyedException(__FILE__, __LINE__);
    }

    assert(routerInfo);

    //
    // Search for connections to the router's client proxy endpoints,
    // and update the object adapter for such connections, so that
    // callbacks from the router can be received over such
    // connections.
    //
    ObjectAdapterPtr adapter = routerInfo->getAdapter();
    vector<EndpointIPtr> endpoints = routerInfo->getClientEndpoints();
    for(vector<EndpointIPtr>::const_iterator p = endpoints.begin(); p != endpoints.end(); ++p)
    {
        EndpointIPtr endpoint = *p;

        //
        // Modify endpoints with overrides.
        //
        if(_instance->defaultsAndOverrides()->overrideTimeout)
        {
            endpoint = endpoint->timeout(_instance->defaultsAndOverrides()->overrideTimeoutValue);
        }

        //
        // The Connection object does not take the compression flag of
        // endpoints into account, but instead gets the information
        // about whether messages should be compressed or not from
        // other sources. In order to allow connection sharing for
        // endpoints that differ in the value of the compression flag
        // only, we always set the compression flag to false here in
        // this connection factory.
        //
        endpoint = endpoint->compress(false);

        for(multimap<ConnectorPtr, ConnectionIPtr>::const_iterator q = _connections.begin();
                q != _connections.end(); ++q)
        {
            if(q->second->endpoint() == endpoint)
            {
                q->second->setAdapter(adapter);
            }
        }
    }
}
示例#2
0
vector<EndpointIPtr>
Ice::ObjectAdapterI::parseEndpoints(const string& str) const
{
    string endpts = str;
    transform(endpts.begin(), endpts.end(), endpts.begin(), ::tolower);

    string::size_type beg;
    string::size_type end = 0;

    vector<EndpointIPtr> endpoints;
    while(end < endpts.length())
    {
        const string delim = " \t\n\r";
        
        beg = endpts.find_first_not_of(delim, end);
        if(beg == string::npos)
        {
            break;
        }

        end = endpts.find(':', beg);
        if(end == string::npos)
        {
            end = endpts.length();
        }
        
        if(end == beg)
        {
            ++end;
            continue;
        }
        
        string s = endpts.substr(beg, end - beg);
        EndpointIPtr endp = _instance->endpointFactoryManager()->create(s);
        if(endp == 0)
        {
            EndpointParseException ex(__FILE__, __LINE__);
            ex.str = s;
            throw ex;
        }
        vector<EndpointIPtr> endps = endp->expand(true);
        endpoints.insert(endpoints.end(), endps.begin(), endps.end());

        ++end;
    }

    return endpoints;
}
示例#3
0
文件: IPEndpointI.cpp 项目: lmtoo/ice
bool
IceInternal::IPEndpointI::equivalent(const EndpointIPtr& endpoint) const
{
    const IPEndpointI* ipEndpointI = dynamic_cast<const IPEndpointI*>(endpoint.get());
    if(!ipEndpointI)
    {
        return false;
    }
    return ipEndpointI->type() == type() && ipEndpointI->_host == _host && ipEndpointI->_port == _port;
}
示例#4
0
bool
IceInternal::WSEndpoint::equivalent(const EndpointIPtr& endpoint) const
{
    const WSEndpoint* wsEndpointI = dynamic_cast<const WSEndpoint*>(endpoint.get());
    if(!wsEndpointI)
    {
        return false;
    }
    return _delegate->equivalent(wsEndpointI->_delegate);
}
示例#5
0
IceBT::AcceptorI::AcceptorI(const EndpointIPtr& endpoint, const InstancePtr& instance, const string& adapterName,
                            const string& addr, const string& uuid, const string& name, int channel) :
    _endpoint(endpoint),
    _instance(instance),
    _adapterName(adapterName),
    _addr(addr),
    _uuid(uuid),
    _name(name),
    _channel(channel)
{
    string s = IceUtilInternal::trim(_addr);
    if(s.empty())
    {
        //
        // If no address was specified, we use the first available BT adapter.
        //
        s = _instance->engine()->getDefaultAdapterAddress();
    }

    s = IceUtilInternal::toUpper(s);

    DeviceAddress da;
    if(!parseDeviceAddress(s, da))
    {
        EndpointParseException ex(__FILE__, __LINE__);
        ex.str = "invalid address value `" + s + "' in endpoint " + endpoint->toString();
        throw ex;
    }
    if(!_instance->engine()->adapterExists(s))
    {
        EndpointParseException ex(__FILE__, __LINE__);
        ex.str = "no device found for `" + s + "' in endpoint " + endpoint->toString();
        throw ex;
    }

    const_cast<string&>(_addr) = s;
}
示例#6
0
EndpointIPtr
IceInternal::EndpointFactoryManager::create(const string& str, bool oaEndpoint) const
{
    vector<string> v;
    bool b = IceUtilInternal::splitString(str, " \t\n\r", v);
    if(!b)
    {
        EndpointParseException ex(__FILE__, __LINE__);
        ex.str = "mismatched quote";
        throw ex;
    }

    if(v.empty())
    {
        EndpointParseException ex(__FILE__, __LINE__);
        ex.str = "value has no non-whitespace characters";
        throw ex;
    }

    string protocol = v.front();
    v.erase(v.begin());

    if(protocol == "default")
    {
        protocol = _instance->defaultsAndOverrides()->defaultProtocol;
    }

    EndpointFactoryPtr factory;
    {
        IceUtil::Mutex::Lock sync(*this); // TODO: Necessary?

        //
        // TODO: Optimize with a map?
        //
        for(vector<EndpointFactoryPtr>::size_type i = 0; i < _factories.size(); i++)
        {
            if(_factories[i]->protocol() == protocol)
            {
                factory = _factories[i];
            }
        }
    }

    if(factory)
    {
#if 1
        EndpointIPtr e = factory->create(v, oaEndpoint);
        if(!v.empty())
        {
            EndpointParseException ex(__FILE__, __LINE__);
            ex.str = "unrecognized argument `" + v.front() + "' in endpoint `" + str + "'";
            throw ex;
        }
        return e;
#else
        // Code below left in place for debugging.

        EndpointIPtr e = factory->create(str.substr(end), oaEndpoint);
        OutputStream bs(_instance.get(), Ice::currentProtocolEncoding);
        e->streamWrite(&bs);
        bs.i = bs.b.begin();
        short type;
        bs.read(type);
        EndpointIPtr ue = new IceInternal::OpaqueEndpointI(type, &bs);
        cerr << "Normal: " << e->toString() << endl;
        cerr << "Opaque: " << ue->toString() << endl;
        return e;
#endif
    }

    //
    // If the stringified endpoint is opaque, create an unknown endpoint,
    // then see whether the type matches one of the known endpoints.
    //
    if(protocol == "opaque")
    {
        EndpointIPtr ue = ICE_MAKE_SHARED(OpaqueEndpointI, v);
        if(!v.empty())
        {
            EndpointParseException ex(__FILE__, __LINE__);
            ex.str = "unrecognized argument `" + v.front() + "' in endpoint `" + str + "'";
            throw ex;
        }
        factory = get(ue->type());
        if(factory)
        {
            //
            // Make a temporary stream, write the opaque endpoint data into the stream,
            // and ask the factory to read the endpoint data from that stream to create
            // the actual endpoint.
            //
            OutputStream bs(_instance.get(), Ice::currentProtocolEncoding);
            bs.write(ue->type());
            ue->streamWrite(&bs);
            InputStream is(bs.instance(), bs.getEncoding(), bs);
            short type;
            is.read(type);
            is.startEncapsulation();
            EndpointIPtr e = factory->read(&is);
            is.endEncapsulation();
            return e;
        }
        return ue; // Endpoint is opaque, but we don't have a factory for its type.
    }

    return 0;
}