void on_nble_gap_connect_evt(const struct nble_gap_connect_evt *ev) { struct bt_conn *conn; BT_DBG("handle %u role %u", ev->conn_handle, ev->role_slave); conn = conn_get(&ev->peer_bda); if (!conn) { BT_ERR("Unable to get bt_conn object"); return; } conn->handle = ev->conn_handle; conn->role = ev->role_slave ? BT_CONN_ROLE_SLAVE : BT_CONN_ROLE_MASTER; conn->interval = ev->conn_values.interval; conn->latency = ev->conn_values.latency; conn->timeout = ev->conn_values.supervision_to; bt_addr_le_copy(&conn->dst, &ev->peer_bda); k_delayed_work_init(&conn->update_work, le_conn_update); conn->state = BT_CONN_CONNECTED; notify_connected(conn); /* * Core 4.2 Vol 3, Part C, 9.3.12.2 * The Peripheral device should not perform a Connection Parameter * Update procedure within 5 s after establishing a connection. */ k_delayed_work_submit(&conn->update_work, conn->role == BT_HCI_ROLE_MASTER ? K_NO_WAIT : CONN_UPDATE_TIMEOUT); }
void Session::on_event(const SessionEvent& event) { switch (event.type) { case SessionEvent::CONNECT: { int port = config_.port(); const Config::ContactPointList& contact_points = config_.contact_points(); for (Config::ContactPointList::const_iterator it = contact_points.begin(), end = contact_points.end(); it != end; ++it) { const std::string& seed = *it; Address address; if (Address::from_string(seed, port, &address)) { add_host(address); } else { pending_resolve_count_++; Resolver::resolve(loop(), seed, port, this, on_resolve); } } if (pending_resolve_count_ == 0) { internal_connect(); } break; } case SessionEvent::NOTIFY_READY: if (pending_pool_count_ > 0) { if (--pending_pool_count_ == 0) { LOG_DEBUG("Session is connected"); notify_connected(); } LOG_DEBUG("Session pending pool count %d", pending_pool_count_); } break; case SessionEvent::NOTIFY_WORKER_CLOSED: if (--pending_workers_count_ == 0) { LOG_DEBUG("Session is disconnected"); control_connection_.close(); close_handles(); } break; case SessionEvent::NOTIFY_UP: control_connection_.on_up(event.address); break; case SessionEvent::NOTIFY_DOWN: control_connection_.on_down(event.address); break; default: assert(false); break; } }
void on_nble_gap_connect_evt(const struct nble_gap_connect_evt *ev) { struct bt_conn *conn; BT_DBG("handle %u role %u", ev->conn_handle, ev->role_slave); conn = conn_new(); if (!conn) { BT_ERR("Unable to create new bt_conn object"); return; } conn->handle = ev->conn_handle; conn->role = ev->role_slave; conn->interval = ev->conn_values.interval; conn->latency = ev->conn_values.latency; conn->timeout = ev->conn_values.supervision_to; bt_addr_le_copy(&conn->dst, &ev->peer_bda); conn->state = BT_CONN_CONNECTED; notify_connected(conn); }
void Session::on_event(const SessionEvent& event) { switch (event.type) { case SessionEvent::CONNECT: { int port = config_.port(); const ContactPointList& contact_points = config_.contact_points(); for (ContactPointList::const_iterator it = contact_points.begin(), end = contact_points.end(); it != end; ++it) { const std::string& seed = *it; Address address; if (Address::from_string(seed, port, &address)) { add_host(address); } else { pending_resolve_count_++; Resolver::resolve(loop(), seed, port, this, on_resolve); } } if (pending_resolve_count_ == 0) { internal_connect(); } break; } case SessionEvent::NOTIFY_READY: if (pending_pool_count_ > 0) { if (--pending_pool_count_ == 0) { LOG_DEBUG("Session is connected"); notify_connected(); } LOG_DEBUG("Session pending pool count %d", pending_pool_count_); } break; case SessionEvent::NOTIFY_KEYSPACE_ERROR: { // Currently, this is only called when the keyspace does not exist // and not for any other keyspace related errors. const CopyOnWritePtr<std::string> keyspace(keyspace_); notify_connect_error(CASS_ERROR_LIB_UNABLE_TO_SET_KEYSPACE, "Keyspace '" + *keyspace + "' does not exist"); break; } case SessionEvent::NOTIFY_WORKER_CLOSED: if (--pending_workers_count_ == 0) { LOG_DEBUG("Session is disconnected"); control_connection_.close(); close_handles(); } break; case SessionEvent::NOTIFY_UP: control_connection_.on_up(event.address); break; case SessionEvent::NOTIFY_DOWN: control_connection_.on_down(event.address); break; default: assert(false); break; } }
void bt_conn_set_state(struct bt_conn *conn, bt_conn_state_t state) { bt_conn_state_t old_state; BT_DBG("%s -> %s", state2str(conn->state), state2str(state)); if (conn->state == state) { BT_WARN("no transition"); return; } old_state = conn->state; conn->state = state; /* Actions needed for exiting the old state */ switch (old_state) { case BT_CONN_DISCONNECTED: /* Take a reference for the first state transition after * bt_conn_add_le() and keep it until reaching DISCONNECTED * again. */ bt_conn_ref(conn); break; case BT_CONN_CONNECT: if (conn->timeout) { fiber_delayed_start_cancel(conn->timeout); conn->timeout = NULL; /* Drop the reference taken by timeout fiber */ bt_conn_unref(conn); } break; default: break; } /* Actions needed for entering the new state */ switch (conn->state) { case BT_CONN_CONNECTED: nano_fifo_init(&conn->tx_queue); fiber_start(conn->stack, sizeof(conn->stack), conn_tx_fiber, (int)bt_conn_ref(conn), 0, 7, 0); bt_l2cap_connected(conn); notify_connected(conn); break; case BT_CONN_DISCONNECTED: /* Notify disconnection and queue a dummy buffer to wake * up and stop the tx fiber for states where it was * running. */ if (old_state == BT_CONN_CONNECTED || old_state == BT_CONN_DISCONNECT) { bt_l2cap_disconnected(conn); notify_disconnected(conn); nano_fifo_put(&conn->tx_queue, net_buf_get(&dummy, 0)); } else if (old_state == BT_CONN_CONNECT) { /* conn->err will be set in this case */ notify_connected(conn); } else if (old_state == BT_CONN_CONNECT_SCAN && conn->err) { /* this indicate LE Create Connection failed */ notify_connected(conn); } /* Release the reference we took for the very first * state transition. */ bt_conn_unref(conn); break; case BT_CONN_CONNECT_SCAN: break; case BT_CONN_CONNECT: /* * Timer is needed only for LE. For other link types controller * will handle connection timeout. */ if (conn->type != BT_CONN_TYPE_LE) { break; } /* Add LE Create Connection timeout */ conn->timeout = fiber_delayed_start(conn->stack, sizeof(conn->stack), timeout_fiber, (int)bt_conn_ref(conn), 0, 7, 0, CONN_TIMEOUT); break; case BT_CONN_DISCONNECT: break; default: BT_WARN("no valid (%u) state was set", state); break; } }
void Session::on_event(const SessionEvent& event) { switch (event.type) { case SessionEvent::CONNECT: { int port = config_.port(); // This needs to be done on the session thread because it could pause // generating a new random seed. if (config_.use_randomized_contact_points()) { random_.reset(new Random()); } MultiResolver<Session*>::Ptr resolver( new MultiResolver<Session*>(this, on_resolve, #if UV_VERSION_MAJOR >= 1 on_resolve_name, #endif on_resolve_done)); const ContactPointList& contact_points = config_.contact_points(); for (ContactPointList::const_iterator it = contact_points.begin(), end = contact_points.end(); it != end; ++it) { const std::string& seed = *it; Address address; if (Address::from_string(seed, port, &address)) { #if UV_VERSION_MAJOR >= 1 if (config_.use_hostname_resolution()) { resolver->resolve_name(loop(), address, config_.resolve_timeout_ms()); } else { #endif add_host(address); #if UV_VERSION_MAJOR >= 1 } #endif } else { resolver->resolve(loop(), seed, port, config_.resolve_timeout_ms()); } } break; } case SessionEvent::NOTIFY_READY: if (pending_pool_count_ > 0) { if (--pending_pool_count_ == 0) { LOG_DEBUG("Session is connected"); notify_connected(); } LOG_DEBUG("Session pending pool count %d", pending_pool_count_); } break; case SessionEvent::NOTIFY_KEYSPACE_ERROR: { // Currently, this is only called when the keyspace does not exist // and not for any other keyspace related errors. notify_connect_error(CASS_ERROR_LIB_UNABLE_TO_SET_KEYSPACE, "Keyspace '" + keyspace() + "' does not exist"); break; } case SessionEvent::NOTIFY_WORKER_CLOSED: if (--pending_workers_count_ == 0) { LOG_DEBUG("Session is disconnected"); control_connection_.close(); close_handles(); } break; case SessionEvent::NOTIFY_UP: control_connection_.on_up(event.address); break; case SessionEvent::NOTIFY_DOWN: control_connection_.on_down(event.address); break; default: assert(false); break; } }