From 5ccf2327415637730d96d7520bc680301ba96e52 Mon Sep 17 00:00:00 2001 From: deva Date: Wed, 21 Apr 2010 08:41:22 +0000 Subject: Make extensive error handling in libartefact interface. --- server/src/queryhandlerpentominos.cc | 56 ++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 21 deletions(-) (limited to 'server/src') diff --git a/server/src/queryhandlerpentominos.cc b/server/src/queryhandlerpentominos.cc index a8d6c07..c5450b3 100644 --- a/server/src/queryhandlerpentominos.cc +++ b/server/src/queryhandlerpentominos.cc @@ -72,36 +72,50 @@ static QueryResult node2result(atf_result_node_t *node, time_t timestamp) QueryResult QueryHandlerPentominos::exec(Query &query) { - atf_transaction_t* atft = atf_new_transaction(atfc, cpr.c_str()); + atf_transaction_t* atft = NULL; + atf_reply_t *reply = NULL; + atf_result_t *result = NULL; + atf_result_node_t *root = NULL; + atf_status_t status; + time_t timestamp; + atf_id id; - atf_id id = atf_add_query(atft, query.attributes["class"].c_str(), - FILTER_LATEST, USE_NONE, 0, 0); + QueryResult rroot; + rroot.timestamp = timestamp; + rroot.source = "pentominos"; - atf_reply_t *reply = atf_commit(atft); + atft = atf_new_transaction(atfc, cpr.c_str()); + if(!atft) goto aaarg; - if(atf_get_num_results(reply, id) != 1) { - // ... error ... - } + id = atf_add_query(atft, query.attributes["class"].c_str(), + FILTER_LATEST, USE_NONE, 0, 0); + if(!atft) goto aaarg; - atf_result_t *result = atf_get_result(reply, id, 0); + reply = atf_commit(atft); + if(!reply) goto aaarg; - atf_status_t status = atf_get_result_status(result, NULL, 0); - if(status != ATF_STATUS_OK) { return QueryResult(); } - - time_t timestamp = atf_get_result_timestamp(result); + if(atf_get_num_results(reply, id) != 1) goto aaarg; - atf_result_node_t *root = atf_get_result_node(result); + result = atf_get_result(reply, id, 0); + if(!result) goto aaarg; - QueryResult rroot; - rroot.timestamp = timestamp; - rroot.source = "pentominos"; + status = atf_get_result_status(result, NULL, 0); + if(status != ATF_STATUS_OK) goto aaarg; + + timestamp = atf_get_result_timestamp(result); - QueryResult qresult = node2result(root, timestamp); - if(root) rroot.groups[query.attributes["class"]] = qresult; + root = atf_get_result_node(result); + if(!root) goto aaarg; + + { + QueryResult qresult = node2result(root, timestamp); + rroot.groups[query.attributes["class"]] = qresult; + } - atf_free_result_node(root); - atf_free_reply(reply); - atf_free_transaction(atft); + aaarg: + if(root) atf_free_result_node(root); + if(reply) atf_free_reply(reply); + if(atft) atf_free_transaction(atft); return rroot; } -- cgit v1.2.3