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; }
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; }