Ejemplo n.º 1
0
    void update(
            std::string                               table,
            std::vector<boost::optional<const char*>> fields,
            T&                                        values,
            connection&                               db
            )
    {
        std::ostringstream query;
        query << "UPDATE " << table << " SET ";
        auto query_fields = fields;
        query_fields.erase(
                std::remove_if(
                    query_fields.begin(),
                    query_fields.end(),
                    [](const boost::optional<const char*>& field) -> bool {
                        return !field;
                    }
                    ),
                query_fields.end()
                );
        json::serialise(
            query_fields,
            [](const boost::optional<const char*>& field, std::ostream& os) {
                os << field.get() << " = ?";
            },
            ", ",
            query
            );
        // ID field
        query << " WHERE " << T::id_field() << " = " << values.id();

        sqlite3_stmt *stmt = nullptr;
        if( sqlite3_prepare(
                    db.handle(),
                    query.str().c_str(),
                    -1,
                    &stmt,
                    nullptr
                    ) != SQLITE_OK )
        {
            std::cerr << "Query: " << query.str() << std::endl;
            throw std::runtime_error("Preparing SQLite statement for update");
        }
        bind_values(fields, values, stmt);

        int step_ret = sqlite3_step(stmt);
        if( step_ret != SQLITE_OK && step_ret != SQLITE_DONE )
        {
            std::ostringstream oss;
            oss << "Stepping SQLite update " << sqlite3_errmsg(db.handle());
            throw std::runtime_error(oss.str());
        }

        int finalise_ret = sqlite3_finalize(stmt);
        if( finalise_ret != SQLITE_OK && finalise_ret != SQLITE_DONE)
        {
            std::ostringstream oss;
            oss << "SQLite finalise " << sqlite3_errmsg(db.handle());
            throw std::runtime_error(oss.str());
        }
    }
Ejemplo n.º 2
0
 /// If the given `connection` `conn` is connected it gets added to the list of
 /// tracked connections.
 inline void add(connection conn) {
     if(conn.connected()) {
         m_conns.emplace_back(std::move(conn));
     }
 }
Ejemplo n.º 3
0
 inline void swap(connection &conn1, connection &conn2)
 {
   conn1.swap(conn2);
 }
Ejemplo n.º 4
0
int dijkstra(query_simple q, connection& result, simple_stats* st){
	if(q.source_st == q.dest_st) return DIJ_NO_CONN;

	bool* vis = new bool[num_vertices];
	int* d = new int[num_vertices];
	el_conn** p = new el_conn*[num_vertices];
	int* wsk = new int[num_vertices + 1];
	vbox* kop = new vbox[num_vertices + 1];

	fill(vis, vis + num_vertices, false);
	fill(d, d + num_vertices, INF_T);
	fill(wsk, wsk + num_vertices + 1, 0);
	
	d[q.source_st] = q.dep_time;
	p[q.source_st] = NULL;

	Heap* kol = new Heap(kop, wsk);
	kol->push(vbox(-q.dep_time, q.source_st));

	while(!kol->empty()){
		int v = kol->pop();

		st->num_pop ++;
		if(vis[v]) continue;
		st->num_vertices ++;

		vis[v] = true;
		if(v == q.dest_st) break;

		for(vertex::iterator it = graph[v].begin(); it != graph[v].end(); it ++){
			int u = it->first;
			int nr = it->second;

			el_conn* conn = edges[nr].get_after(d[v]);
			if(conn == NULL) continue;

			int nt = conn->arr_time;

			
			if(nt < d[u]){
				d[u] = nt;
				p[u] = conn;
				kol->push(vbox(-nt, u));
				if(kol->size > st->max_heap)
					st->max_heap = kol->size;
			}
		}
	}

	delete kol;

	delete[] vis;
	delete[] wsk;
	delete[] kop;

	if(d[q.dest_st] >= INF_T){
		delete[] d;
		delete[] p;
		return DIJ_NO_CONN;
	}

	int w = q.dest_st;
	
	while(p[w]){
		result.push_back(*p[w]);
		w = p[w]->dep_station;
	}

	result.sort();

	delete[] p;
	delete[] d;
	return DIJ_OK;
}
Ejemplo n.º 5
0
 static context::id id(const connection& c) { return id(c.pn_object()); }
Ejemplo n.º 6
0
    void apply(connection& c) {
        pn_connection_t *pnc = connection_options::pn_connection(c);
        pn_transport_t *pnt = pn_connection_transport(pnc);
        connector *outbound = dynamic_cast<connector*>(
            connection_context::get(c).handler.get());
        bool uninit = (c.state() & endpoint::LOCAL_UNINIT);

        // pnt is NULL between reconnect attempts.
        // Only apply transport options if uninit or outbound with
        // transport not yet configured.
        if (pnt && (uninit || (outbound && !outbound->transport_configured())))
        {
            // SSL
            if (outbound && outbound->address().scheme() == url::AMQPS) {
                pn_ssl_t *ssl = pn_ssl(pnt);
                if (pn_ssl_init(ssl, ssl_client_options.value.pn_domain(), NULL))
                    throw error(MSG("client SSL/TLS initialization error"));
            } else if (!outbound) {
                pn_acceptor_t *pnp = pn_connection_acceptor(pnc);
                if (pnp) {
                    listener_context &lc(listener_context::get(pnp));
                    if (lc.ssl) {
                        pn_ssl_t *ssl = pn_ssl(pnt);
                        if (pn_ssl_init(ssl, ssl_server_options.value.pn_domain(), NULL))
                            throw error(MSG("server SSL/TLS initialization error"));
                    }
                }
            }

            // SASL
            transport t = c.transport();
            if (!sasl_enabled.set || sasl_enabled.value) {
                if (sasl_enabled.set)  // Explicitly set, not just default behaviour.
                    t.sasl();          // Force a sasl instance.  Lazily create one otherwise.
                if (sasl_allow_insecure_mechs.set)
                    t.sasl().allow_insecure_mechs(sasl_allow_insecure_mechs.value);
                if (sasl_allowed_mechs.set)
                    t.sasl().allowed_mechs(sasl_allowed_mechs.value);
                if (sasl_config_name.set)
                    t.sasl().config_name(sasl_config_name.value);
                if (sasl_config_path.set)
                    t.sasl().config_path(sasl_config_path.value);
            }

            if (max_frame_size.set)
                pn_transport_set_max_frame(pnt, max_frame_size.value);
            if (max_channels.set)
                pn_transport_set_channel_max(pnt, max_channels.value);
            if (idle_timeout.set)
                pn_transport_set_idle_timeout(pnt, idle_timeout.value.ms());
        }
        // Only apply connection options if uninit.
        if (uninit) {
            if (reconnect.set && outbound)
                outbound->reconnect_timer(reconnect.value);
            if (container_id.set)
                pn_connection_set_container(pnc, container_id.value.c_str());
            if (link_prefix.set)
                connection_context::get(pnc).link_gen.prefix(link_prefix.value);
        }
    }
Ejemplo n.º 7
0
void handler::on_connection_error(connection &c) { on_error(c.error()); }
Ejemplo n.º 8
0
	dns_requester::dns_requester(connection& aConnection) : whois_requester::requester(aConnection.whois()), iResolver(aConnection.connection_manager().resolver()), iConnection(aConnection)
	{
		iConnection.add_observer(*this);
	}
Ejemplo n.º 9
0
void print_connection( connection const& c ) {

  std::cerr << "Local address: " << c.local() << std::endl ;
  std::cerr << "Peer address: "  << c.peer () << std::endl ;

}