/**
 * Return the connection resulting from the connection request.
 *
 * \return A pointer to the Connection object.
 */
ConnectionPtr PendingConnection::connection() const
{
    if (!isFinished()) {
        warning() << "PendingConnection::connection called before finished, returning 0";
        return ConnectionPtr();
    } else if (!isValid()) {
        warning() << "PendingConnection::connection called when not valid, returning 0";
        return ConnectionPtr();
    }

    return mPriv->connection;
}
/**
 * Construct a new PendingChannelRequest object that always fails.
 *
 * \param account Account to use.
 * \param errorName The name of a D-Bus error.
 * \param errorMessage The error message.
 */
PendingChannelRequest::PendingChannelRequest(const AccountPtr &account,
        const QString &errorName, const QString &errorMessage)
    : PendingOperation(ConnectionPtr()),
      mPriv(new Private(account->dbusConnection()))
{
    setFinishedWithError(errorName, errorMessage);
}
bool uamc::Instance::connect(std::string const& application_name)
{
    auto mir_connection = mir_connect_sync(NULL, application_name.c_str());

    // mir_connect_sync() always returns a connection object, even in case
    // of a failed connection. We need to release this object in all cases.
    con = ConnectionPtr(mir_connection,
        [](MirConnection *c)
        {
            mir_connection_release(c);
        });

    return mir_connection_is_valid(mir_connection);
}
ConnectionPtr EventDispatcher::addEventListener(const event::Type& evType, ListenerPtr listener)
{
  uint32_t result;
  
  SignalPtr signal = eventType2signal[evType];
  if(!signal)
  {
    signal.reset(new Signal);
    eventType2signal[evType] = signal;
  }
  result = signal->addListener(listener);
  
  return ConnectionPtr(new Connection(evType, result));
}
示例#5
0
///////////////////////////////////////////////////////////////////////////////
/// CConnectionManager::GetConnectionByUUID
/// @description Constructs or retrieves from cache a connection to a specific
///              UUID.
/// @param uuid_: The uuid to construct a connection to
/// @param ios: The ioservice the connection will use.
/// @param dispatch_: The dispatcher the connection will use
/// @pre: None
/// @post: If a connection has been constructed it will be put in the
///        connections table and has been started. If the connection is not
///        constructed there is no change to the connection table.
/// @return A pointer to the connection, or NULL if construction failed for
///         some reason.
///////////////////////////////////////////////////////////////////////////////
ConnectionPtr CConnectionManager::GetConnectionByUUID
    (std::string uuid_, boost::asio::io_service& ios,  CDispatcher &dispatch_)
{
    Logger::Debug << __PRETTY_FUNCTION__ << std::endl;

    ConnectionPtr c_;  
    std::string s_;

    // See if there is a connection in the open connections already
    if(m_connections.count(uuid_))
    {
        if(m_connections[uuid_]->GetSocket().is_open())
        {
            Logger::Notice << "Recycling connection to " << uuid_ << std::endl;
            return m_connections[uuid_];
        }
        else
        {
            Logger::Notice <<" Connection to " << uuid_ << " has gone stale " << std::endl;
            //The socket is not marked as open anymore, we
            //should stop it.
            Stop(m_connections[uuid_]);
        }
    }  

    Logger::Notice << "Making Fresh Connection to " << uuid_ << std::endl;

    // Find the requested host from the list of known hosts
    std::map<std::string, std::string>::iterator mapIt_;
    mapIt_ = m_hostnames.find(uuid_);
    if(mapIt_ == m_hostnames.end())
        return ConnectionPtr();
    s_ = mapIt_->second;

    // Create a new CConnection object for this host	
    c_.reset(new CConnection(ios, *this, dispatch_, uuid_));  
   
    // Initiate the TCP connection
    //XXX Right now, the port is hardcoded  
    boost::asio::ip::udp::resolver resolver(ios);
    boost::asio::ip::udp::resolver::query query( s_, "1870");
    boost::asio::ip::udp::endpoint endpoint = *resolver.resolve( query );
    c_->GetSocket().connect( endpoint ); 

    //Once the connection is built, connection manager gets a call back to register it.    
    PutConnection(uuid_,c_);
    return c_;
}
示例#6
0
ConnectionPtr PeerNode::ConnectBackups()
{
	boost::recursive_mutex::scoped_lock L(m_mutex);
	ConnectionManagerPtr pConnMgr = ConnectionManager::GetConnectionManager();
	ConnectionPtr pConn = ConnectionPtr();
	for(int i = 0; i < m_backups.size(); i++) {
		pConn = pConnMgr->Connect(m_backups[i].m_ipAddress, m_backups[i].m_port);
		if( pConn == NULL ) {
			Log(CONSOLE, L"BackUp Coordinator (port: %d), Not UP!!\n", m_backups[i].m_port);
			continue;
		} else {
			Log(CONSOLE, L"BackUp Coordinator (port: %d), Working!!\n", m_backups[i].m_port);
			this->m_ipAddress = m_backups[i].m_ipAddress;
			this->m_listenPort = m_backups[i].m_port;
			break;
		}
	}
	return pConn;
}
示例#7
0
int LuaTesting::createConnection(lua_State* L) {
    luaL_checkany(L, 1);

    string charName = luaL_checkstring(L, 1);
    lua_pop(L, 1);

    auto con = new ConnectionInstance();
    con->characterName = charName;
    con->characterNameLower = charName;
    con->identified = true;
    con->accountID = 1;
    con->characterID = 2;
    con->closed = true;
    auto conPtr = ConnectionPtr(con);
    ServerState::addConnection(charName, conPtr);

    lua_pushlightuserdata(L, conPtr.get());
    return 1;
}
ConnectionPtr CommunicationClient::bind( const signal_t::slot_type &rhs )
{
	return ConnectionPtr(new boost::signals2::connection(onImageReceived.connect(rhs)));
}
示例#9
0
    ConnectionPtr AsioClient::newConnection(){
        long cid = generateConnectionId();

        return ConnectionPtr(new Connection(cid, ioServicePool_.getIoService(), ioHandlerPtr_, connectionManagerPtr_));
    }
示例#10
0
 static ConnectionPtr create(boost::asio::io_service& ioService, RequestListener requestListener) {
     return ConnectionPtr(new Connection(ioService, requestListener));
 }
示例#11
0
 ConnectionPtr Connection::create(boost::asio::io_service& service)
 {
     return ConnectionPtr(new Connection(service));
 }