Commit c3bd09b2 authored by Micha Mueller's avatar Micha Mueller
Browse files

WIP: Fill new C-API functions with live (not yet tested)

parent a60c8812
......@@ -174,7 +174,7 @@ DCDB_C_RESULT dcdbQuerySumMultipleThreaded(
/*****************************************************************************/
/**
* @brief Construct a new DCDB::Connection object.
* @brief Construct a new DCDB::Connection object and connect it to database.
*
* @param hostname Hostname of database node
* @param port TCP port to use for connecting to the database node
......@@ -207,10 +207,11 @@ DCDB_C_RESULT disconnectFromDatabase(DCDB::Connection* conn);
*
* @param conn Database connection, required to access the database.
*
* @return Pointer to the new JobDataStore object.
* @return Pointer to the new JobDataStore object, or NULL if an error
* occurred.
*
* @details
* Construct a new JobDataStore object via < b>new< \b>. Always succeeds. The
* Construct a new JobDataStore object via < b>new< \b>. The
* given Connection object must already be connected to the database,
* otherwise later JobDataStore operations will fail.
*/
......
......@@ -436,14 +436,30 @@ DCDB_C_RESULT dcdbQuerySumMultipleThreaded(
}
Connection* connectToDatabase(const char* hostname, uint16_t port) {
return NULL;
Connection* conn = new Connection(hostname, port);
if (!conn->connect()) {
delete conn;
return NULL;
}
//dcdbConn->initSchema();
return conn;
}
DCDB_C_RESULT disconnectFromDatabase(Connection* conn) {
if (conn) {
conn->disconnect();
delete conn;
}
return DCDB_C_OK;
}
JobDataStore* constructJobDataStore(Connection* conn) {
if (conn) {
return new JobDataStore(conn);
}
return NULL;
}
......@@ -451,9 +467,28 @@ DCDB_C_RESULT insertJobIntoDatabase(JobDataStore* jds, JobId jid,
UserId uid, uint64_t startTs,
uint64_t endTs, const char ** nodes,
unsigned nodeSize) {
JobData jdata;
jdata.jobId = jid;
jdata.userId = uid;
jdata.startTime = startTs;
jdata.endTime = endTs;
for(unsigned i = 0; i < nodeSize; i++) {
jdata.nodes.push_back(nodes[i]);
}
JDError ret = jds->insertJob(jdata);
if (ret == JD_OK) {
return DCDB_C_OK;
} else if (ret == JD_BADPARAMS) {
return DCDB_C_BADPARAMS;
}
return DCDB_C_UNKNOWN;
}
DCDB_C_RESULT destructJobDataStore(JobDataStore* jds) {
if (jds) {
delete jds;
}
return DCDB_C_OK;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment