2016-09-13 18:54:26 -07:00
|
|
|
#ifndef DB_H
|
|
|
|
#define DB_H
|
|
|
|
|
2016-11-18 19:57:51 -08:00
|
|
|
#include "common.h"
|
2016-09-13 18:54:26 -07:00
|
|
|
#include "event_loop.h"
|
|
|
|
|
2016-10-29 15:22:33 -07:00
|
|
|
typedef struct db_handle db_handle;
|
2016-09-13 18:54:26 -07:00
|
|
|
|
2016-11-18 19:57:51 -08:00
|
|
|
/**
|
|
|
|
* Connect to the global system store.
|
|
|
|
*
|
|
|
|
* @param db_address The hostname to use to connect to the database.
|
|
|
|
* @param db_port The port to use to connect to the database.
|
|
|
|
* @param client_type The type of this client.
|
|
|
|
* @param client_addr The hostname of the client that is connecting. If not
|
|
|
|
* relevant, set this to the empty string.
|
|
|
|
* @param client_port The port of the client that is connecting. If not
|
|
|
|
* relevant, set this to -1.
|
|
|
|
* @return This returns a handle to the database, which must be freed with
|
|
|
|
* db_disconnect after use.
|
|
|
|
*/
|
|
|
|
|
2016-09-25 21:52:06 -07:00
|
|
|
db_handle *db_connect(const char *db_address,
|
|
|
|
int db_port,
|
|
|
|
const char *client_type,
|
|
|
|
const char *client_addr,
|
|
|
|
int client_port);
|
2016-09-13 18:54:26 -07:00
|
|
|
|
2016-11-18 19:57:51 -08:00
|
|
|
/**
|
|
|
|
* Attach global system store connection to an event loop. Callbacks from
|
|
|
|
* queries to the global system store will trigger events in the event loop.
|
|
|
|
*
|
|
|
|
* @param db The database in question.
|
|
|
|
* @param loop The event loop to attach to.
|
|
|
|
* @return Void.
|
|
|
|
*/
|
2016-09-25 21:52:06 -07:00
|
|
|
void db_attach(db_handle *db, event_loop *loop);
|
2016-09-13 18:54:26 -07:00
|
|
|
|
2016-11-18 19:57:51 -08:00
|
|
|
/**
|
|
|
|
* Disconnect from the global system store.
|
|
|
|
*
|
|
|
|
* @param db The database connection to close and clean up.
|
|
|
|
* @return Void.
|
|
|
|
*/
|
2016-09-25 21:52:06 -07:00
|
|
|
void db_disconnect(db_handle *db);
|
2016-09-13 18:54:26 -07:00
|
|
|
|
2016-10-18 15:12:41 -07:00
|
|
|
/**
|
2016-11-18 19:57:51 -08:00
|
|
|
* Returns the db client ID.
|
2016-10-18 15:12:41 -07:00
|
|
|
*
|
|
|
|
* @param db The handle to the database.
|
2016-11-18 19:57:51 -08:00
|
|
|
* @returns int The db client ID for this connection to the database.
|
2016-10-18 15:12:41 -07:00
|
|
|
*/
|
2016-11-18 19:57:51 -08:00
|
|
|
db_client_id get_db_client_id(db_handle *db);
|
2016-10-18 15:12:41 -07:00
|
|
|
|
2016-09-13 18:54:26 -07:00
|
|
|
#endif
|