Commit 54429849 authored by Aleksy Barcz's avatar Aleksy Barcz

draw3: use shared ptrs for DatabaseQuery everywhere

+ raw pointers were bug-prone, especially as there was no standard approach as to where delete them (see: database.cpp)
+ now all pointers to DatabaseQuery are shared_ptrs
+ added reset() in all places where we free a part of query anyway, so that the caller can at least check if the pointer passed to callee is still valid after return
+ added missing base_handler include to dbinquirer and fixed base_handler's includes
parent 3c503bcd
......@@ -53,7 +53,7 @@ void Draw3Base::SetProberAddress(const std::wstring& prefix,
{
}
void Draw3Base::ExtractParameters(DatabaseQuery *query)
void Draw3Base::ExtractParameters(DatabaseQuery::ptr query)
{
DatabaseQuery::ExtractionParameters &pars = query->extraction_parameters;
boost::shared_ptr<SzbExtractor> extr(CreateExtractor());
......@@ -83,26 +83,24 @@ void Draw3Base::ExtractParameters(DatabaseQuery *query)
fclose(output);
}
void Draw3Base::RemoveConfig(DatabaseQuery* query) {
void Draw3Base::RemoveConfig(DatabaseQuery::ptr query) {
RemoveConfig(query->reload_prefix.prefix, true);
DatabaseResponse r(query);
wxPostEvent(m_response_receiver, r);
}
void Draw3Base::RegisterObserver(DatabaseQuery *query) {
delete query;
void Draw3Base::RegisterObserver(DatabaseQuery::ptr query) {
}
void Draw3Base::SetProberAddress(DatabaseQuery* query) {
void Draw3Base::SetProberAddress(DatabaseQuery::ptr query) {
SetProberAddress(query->prefix, query->prober_address.address, query->prober_address.port);
free(query->prober_address.address);
free(query->prober_address.port);
delete query;
query.reset(); // query is in inconsistent state now
}
void Draw3Base::CompileLuaFormula(DatabaseQuery* query) {
void Draw3Base::CompileLuaFormula(DatabaseQuery::ptr query) {
std::wstring error;
bool ret;
......@@ -115,18 +113,17 @@ void Draw3Base::CompileLuaFormula(DatabaseQuery* query) {
wxPostEvent(m_response_receiver, dr);
}
void Draw3Base::NotifyAboutConfigurationChanges(DatabaseQuery* query) {
void Draw3Base::NotifyAboutConfigurationChanges(DatabaseQuery::ptr query) {
NotifyAboutConfigurationChanges();
delete query;
}
void Draw3Base::AddExtraParam(DatabaseQuery *query) {
void Draw3Base::AddExtraParam(DatabaseQuery::ptr query) {
AddExtraParam(query->defined_param.prefix, query->defined_param.p);
free(query->defined_param.prefix);
delete query;
query.reset(); // query is in inconsistent state now
}
void Draw3Base::RemoveExtraParam(DatabaseQuery* query) {
void Draw3Base::RemoveExtraParam(DatabaseQuery::ptr query) {
RemoveExtraParam(query->defined_param.prefix, query->defined_param.p);
}
......@@ -151,7 +148,7 @@ sz4::nanosecond_time_t pair_to_sz4_nanosecond(time_t second, time_t nanosecond)
}
DatabaseQuery* CreateDataQueryPrivate(DrawInfo* di, TParam *param, PeriodType pt, int draw_no);
DatabaseQuery::ptr CreateDataQueryPrivate(DrawInfo* di, TParam *param, PeriodType pt, int draw_no);
std::tr1::tuple<TSzarpConfig*, szb_buffer_t*> SzbaseBase::GetConfigAndBuffer(TParam *param) {
if (param) {
......@@ -231,7 +228,7 @@ SzbExtractor* SzbaseBase::CreateExtractor() {
return new SzbExtractor(ipk_container, szbase);
}
void SzbaseBase::SearchData(DatabaseQuery* query) {
void SzbaseBase::SearchData(DatabaseQuery::ptr query) {
TParam *p = query->param;
TSzarpConfig *cfg = NULL;
szb_buffer_t *szb = NULL;
......@@ -284,7 +281,7 @@ void SzbaseBase::SearchData(DatabaseQuery* query) {
}
void SzbaseBase::GetData(DatabaseQuery* query) {
void SzbaseBase::GetData(DatabaseQuery::ptr query) {
TParam *p = query->param;
TSzarpConfig *cfg = NULL;
szb_buffer_t *szb = NULL;
......@@ -302,7 +299,7 @@ void SzbaseBase::GetData(DatabaseQuery* query) {
std::vector<DatabaseQuery::ValueData::V>::iterator i = vd.vv->begin();
DatabaseQuery *rq = NULL;
DatabaseQuery::ptr rq;
szbase->NextQuery();
......@@ -367,11 +364,9 @@ void SzbaseBase::GetData(DatabaseQuery* query) {
DatabaseResponse dr(rq);
wxPostEvent(m_response_receiver, dr);
}
delete query;
}
void SzbaseBase::ResetBuffer(DatabaseQuery* query) {
void SzbaseBase::ResetBuffer(DatabaseQuery::ptr query) {
TParam *p = query->param;
TSzarpConfig *cfg = NULL;
szb_buffer_t *szb = NULL;
......@@ -382,7 +377,7 @@ void SzbaseBase::ResetBuffer(DatabaseQuery* query) {
szb_reset_buffer(szb);
}
void SzbaseBase::ClearCache(DatabaseQuery* query) {
void SzbaseBase::ClearCache(DatabaseQuery::ptr query) {
TParam *p = query->param;
TSzarpConfig *cfg = NULL;
szb_buffer_t *szb = NULL;
......@@ -504,7 +499,7 @@ SzbExtractor* Sz4Base::CreateExtractor() {
}
void Sz4Base::SearchData(DatabaseQuery* query) {
void Sz4Base::SearchData(DatabaseQuery::ptr query) {
TParam* p = query->param;
DatabaseQuery::SearchData& sd = query->search_data;
......@@ -569,7 +564,7 @@ template<class time_type> void Sz4Base::GetValue(DatabaseQuery::ValueData::V& v,
wsum_to_value(v, wsum, pt, p->GetDataType(), p->GetPrec());
}
void Sz4Base::GetData(DatabaseQuery* query) {
void Sz4Base::GetData(DatabaseQuery::ptr query) {
DatabaseQuery::ValueData &vd = query->value_data;
TParam* p = query->param;
......@@ -577,7 +572,7 @@ void Sz4Base::GetData(DatabaseQuery* query) {
std::vector<DatabaseQuery::ValueData::V>::iterator i = vd.vv->begin();
while (i != vd.vv->end()) {
DatabaseQuery *rq = CreateDataQueryPrivate(query->draw_info, query->param, vd.period_type, query->draw_no);
DatabaseQuery::ptr rq = CreateDataQueryPrivate(query->draw_info, query->param, vd.period_type, query->draw_no);
rq->inquirer_id = query->inquirer_id;
try {
if (pt == PT_HALFSEC || pt == PT_MSEC10)
......@@ -601,15 +596,13 @@ void Sz4Base::GetData(DatabaseQuery* query) {
wxPostEvent(m_response_receiver, dr);
i++;
}
delete query;
}
void Sz4Base::ResetBuffer(DatabaseQuery* query) {
void Sz4Base::ResetBuffer(DatabaseQuery::ptr query) {
}
void Sz4Base::ClearCache(DatabaseQuery* query) {
void Sz4Base::ClearCache(DatabaseQuery::ptr query) {
}
......@@ -621,14 +614,13 @@ std::wstring Sz4Base::GetType() const {
return L"sz4";
}
void Sz4Base::RegisterObserver(DatabaseQuery *query) {
void Sz4Base::RegisterObserver(DatabaseQuery::ptr query) {
base->deregister_observer(
query->observer_registration_parameters.observer,
*query->observer_registration_parameters.params_to_deregister);
base->register_observer(
query->observer_registration_parameters.observer,
*query->observer_registration_parameters.params_to_register);
delete query;
}
......@@ -643,7 +635,7 @@ public:
template<class time_type>
void GetData(std::shared_ptr<DatabaseQuery>);
void SearchData(DatabaseQuery* query);
void SearchData(DatabaseQuery::ptr query);
private:
using sz4_time = Sz4ApiBase::sz4_time;
using RangeOperator = std::function<bool(sz4::nanosecond_time_t)>;
......@@ -767,7 +759,7 @@ auto getMinMaxValueData(DatabaseQuery::ValueData& vd)
}; //anon namespace
void Sz4ApiBase::SearchData(DatabaseQuery* query) {
void Sz4ApiBase::SearchData(DatabaseQuery::ptr query) {
TParam* p = query->param;
DatabaseQuery::SearchData& sd = query->search_data;
......@@ -925,7 +917,7 @@ void Sz4ApiBase::LUAWorker::DoGetData(std::shared_ptr<DatabaseQuery> query)
auto current = sz4_time(itr->time_second, itr->time_nanosecond);
auto sum = GetWeightedSum<time_type>(*query, current, pt);
auto *rq = CreateDataQueryPrivate(query->draw_info, query->param,
auto rq = CreateDataQueryPrivate(query->draw_info, query->param,
query->value_data.period_type, query->draw_no);
rq->inquirer_id = query->inquirer_id;
rq->value_data.vv->push_back(v);
......@@ -980,7 +972,7 @@ auto Sz4ApiBase::LUAWorker::GetWeightedSum(const DatabaseQuery& query,
}
void Sz4ApiBase::LUAWorker::SearchData(DatabaseQuery* query) {
void Sz4ApiBase::LUAWorker::SearchData(DatabaseQuery::ptr query) {
DatabaseQuery::SearchData& sd = query->search_data;
auto end_time = GetEndSearchTime(sd, query->param);
......@@ -1119,7 +1111,7 @@ Sz4ApiBase::LUAWorker::GetLastTime(const std::wstring& prefix, SZARP_PROBE_TYPE
return cb_future.get();
}
template<class time_type> void Sz4ApiBase::DoGetData(DatabaseQuery* query) {
template<class time_type> void Sz4ApiBase::DoGetData(DatabaseQuery::ptr query) {
auto query_ptr = std::shared_ptr<DatabaseQuery>(query);
DatabaseQuery::ValueData &vd = query->value_data;
......@@ -1150,7 +1142,7 @@ template<class time_type> void Sz4ApiBase::DoGetData(DatabaseQuery* query) {
sz4_time s_time = t_start;
for (const auto& sum: sums) {
auto *rq = CreateDataQueryPrivate(query_ptr->draw_info, query_ptr->param,
auto rq = CreateDataQueryPrivate(query_ptr->draw_info, query_ptr->param,
query_ptr->value_data.period_type, query_ptr->draw_no);
rq->inquirer_id = query_ptr->inquirer_id;
rq->value_data.vv->push_back(v);
......@@ -1181,7 +1173,7 @@ template<class time_type> void Sz4ApiBase::DoGetData(DatabaseQuery* query) {
}
}
void Sz4ApiBase::GetData(DatabaseQuery* query) {
void Sz4ApiBase::GetData(DatabaseQuery::ptr query) {
DatabaseQuery::ValueData &vd = query->value_data;
SZARP_PROBE_TYPE pt = PeriodToProbeType(vd.period_type);
if (pt == PT_HALFSEC || pt == PT_MSEC10)
......@@ -1190,12 +1182,12 @@ void Sz4ApiBase::GetData(DatabaseQuery* query) {
DoGetData<sz4::second_time_t>(query);
}
void Sz4ApiBase::ResetBuffer(DatabaseQuery* query) {
void Sz4ApiBase::ResetBuffer(DatabaseQuery::ptr query) {
}
void Sz4ApiBase::ClearCache(DatabaseQuery* query) {
void Sz4ApiBase::ClearCache(DatabaseQuery::ptr query) {
}
......@@ -1216,7 +1208,7 @@ void Sz4ApiBase::ObserverWrapper::operator()() {
obs->param_data_changed(param);
}
void Sz4ApiBase::RegisterObserver(DatabaseQuery* query) {
void Sz4ApiBase::RegisterObserver(DatabaseQuery::ptr query) {
auto observer = query->observer_registration_parameters.observer;
auto& to_dereg = *query->observer_registration_parameters.params_to_deregister;
auto& to_reg = *query->observer_registration_parameters.params_to_register;
......@@ -1245,8 +1237,6 @@ void Sz4ApiBase::RegisterObserver(DatabaseQuery* query) {
std::vector<sz4::param_info>(1 , pi),
[] (const boost::system::error_code&) { /*XXX*/ });
}
delete query;
}
Sz4ApiBase::LUAWorker::~LUAWorker()
......
......@@ -83,12 +83,11 @@ wxDateTime ToWxDateTime(time_t second, time_t nanosecond) {
}
void* QueryExecutor::Entry() {
DatabaseQuery *q = NULL;
DatabaseQuery::ptr q;
std::wstring last_prefix;
while ((q = queue->GetQuery())) {
if(q->type == DatabaseQuery::ADD_BASE_PREFIX) {
base_handler->AddBasePrefix(wxString(q->prefix));
delete q;
continue;
}
if( q->type == DatabaseQuery::REGISTER_OBSERVER ) {
......@@ -102,7 +101,6 @@ void* QueryExecutor::Entry() {
}
catch(MissingBasePrefixException& e) {
sz_log(8, "base prefix missing %s", SC::S2A(q->prefix).c_str() );
delete q;
continue;
}
......@@ -112,7 +110,6 @@ void* QueryExecutor::Entry() {
}
catch(MissingBasePrefixException& e) {
sz_log(8, "base prefix missing %ls", q->defined_param.prefix );
delete q;
continue;
}
base->AddExtraParam(q);
......@@ -121,7 +118,6 @@ void* QueryExecutor::Entry() {
// following query types require a valid base
if (base == nullptr) {
delete q;
continue;
}
switch (q->type) {
......@@ -140,7 +136,6 @@ void* QueryExecutor::Entry() {
case DatabaseQuery::REMOVE_PARAM:
base->RemoveExtraParam(q);
delete q;
break;
case DatabaseQuery::CHECK_CONFIGURATIONS_CHANGE:
......@@ -153,7 +148,6 @@ void* QueryExecutor::Entry() {
case DatabaseQuery::EXTRACT_PARAM_VALUES:
base->ExtractParameters(q);
delete q;
break;
case DatabaseQuery::SEARCH_DATA:
......@@ -166,12 +160,10 @@ void* QueryExecutor::Entry() {
case DatabaseQuery::RESET_BUFFER:
base->ResetBuffer(q);
delete q;
break;
case DatabaseQuery::CLEAR_CACHE:
base->ClearCache(q);
delete q;
break;
case DatabaseQuery::REGISTER_OBSERVER:
......@@ -205,7 +197,7 @@ bool DatabaseQueryQueue::QueryCmp(const QueueEntry& q1, const QueueEntry& q2) {
}
//ranking is in ascending order, so the lower value means higher rank
double DatabaseQueryQueue::FindQueryRanking(DatabaseQuery* q) {
double DatabaseQueryQueue::FindQueryRanking(DatabaseQuery::ptr q) {
double ranking = 0;
......@@ -290,7 +282,7 @@ void DatabaseQueryQueue::ShufflePriorities() {
++i) {
QueueEntry& e = *i;
DatabaseQuery* q = e.query;
auto q = e.query;
e.ranking = FindQueryRanking(q);
}
......@@ -299,7 +291,7 @@ void DatabaseQueryQueue::ShufflePriorities() {
}
void DatabaseQueryQueue::CleanOld(DatabaseQuery *query) {
void DatabaseQueryQueue::CleanOld(DatabaseQuery::ptr query) {
time_t start = query->search_data.start_second;
time_t end = query->search_data.end_second;
......@@ -320,7 +312,7 @@ void DatabaseQueryQueue::CleanOld(DatabaseQuery *query) {
}
}
void DatabaseQueryQueue::Add(DatabaseQuery *query) {
void DatabaseQueryQueue::Add(DatabaseQuery::ptr query) {
QueueEntry entry;
entry.query = query;
entry.ranking = FindQueryRanking(query);
......@@ -336,13 +328,13 @@ void DatabaseQueryQueue::Add(DatabaseQuery *query) {
queue_cv.notify_one();
}
void DatabaseQueryQueue::Add(std::list<DatabaseQuery*> &qlist){
void DatabaseQueryQueue::Add(std::list<DatabaseQuery::ptr> &qlist){
std::list<QueueEntry> querylist;
bool needsort = false;
for(std::list<DatabaseQuery*>::iterator i = qlist.begin(); i != qlist.end(); i++){
for(auto i = qlist.begin(); i != qlist.end(); i++){
QueueEntry entry;
entry.query = *i;
entry.ranking = FindQueryRanking(*i);
......@@ -361,7 +353,7 @@ void DatabaseQueryQueue::Add(std::list<DatabaseQuery*> &qlist){
queue_cv.notify_all();
}
DatabaseQuery* DatabaseQueryQueue::GetQuery() {
DatabaseQuery::ptr DatabaseQueryQueue::GetQuery() {
std::unique_lock<std::mutex> lock(queue_mutex);
while(queue.empty())
......@@ -372,7 +364,7 @@ DatabaseQuery* DatabaseQueryQueue::GetQuery() {
if (std::isnan(qe.ranking))
cant_prioritise_entries -= 1;
DatabaseQuery* dq = qe.query;
auto dq = qe.query;
queue.pop_front();
return dq;
}
......@@ -381,9 +373,9 @@ void DatabaseQueryQueue::SetDatabaseManager(DatabaseManager *manager) {
database_manager = manager;
}
DatabaseQuery* CreateDataQueryPrivate(DrawInfo* di, TParam *param, PeriodType pt, int draw_no) {
DatabaseQuery::ptr CreateDataQueryPrivate(DrawInfo* di, TParam *param, PeriodType pt, int draw_no) {
DatabaseQuery *q = new DatabaseQuery();
auto q = std::make_shared<DatabaseQuery>();
q->type = DatabaseQuery::GET_DATA;
q->draw_info = di;
q->param = param;
......@@ -394,7 +386,7 @@ DatabaseQuery* CreateDataQueryPrivate(DrawInfo* di, TParam *param, PeriodType pt
return q;
}
DatabaseQuery* CreateDataQuery(DrawInfo* di, PeriodType pt, int draw_no) {
DatabaseQuery::ptr CreateDataQuery(DrawInfo* di, PeriodType pt, int draw_no) {
TParam *p;
if (di->IsValid())
p = di->GetParam()->GetIPKParam();
......@@ -405,7 +397,7 @@ DatabaseQuery* CreateDataQuery(DrawInfo* di, PeriodType pt, int draw_no) {
}
DatabaseQuery::ValueData::V& AddTimeToDataQuery(DatabaseQuery *q, const wxDateTime& time) {
DatabaseQuery::ValueData::V& AddTimeToDataQuery(DatabaseQuery::ptr q, const wxDateTime& time) {
DatabaseQuery::ValueData::V v;
ToNanosecondTime(time, v.time_second, v.time_nanosecond);
v.custom_length = 0;
......
......@@ -47,11 +47,10 @@ wxDateTime DBInquirer::GetCurrentTime() {
return wxInvalidDateTime;
}
void DBInquirer::DatabaseResponse(DatabaseQuery *query) {
delete query;
void DBInquirer::DatabaseResponse(DatabaseQuery::ptr query) {
}
void DBInquirer::QueryDatabase(DatabaseQuery *query) {
void DBInquirer::QueryDatabase(DatabaseQuery::ptr query) {
query->inquirer_id = m_inquirer_id;
m_database_manager->QueryDatabase(query);
}
......@@ -60,8 +59,8 @@ void DBInquirer::ChangeObservedParamsRegistration(const std::vector<TParam*> &to
m_database_manager->ChangeObservedParamsRegistration(to_deregister, to_register);
}
void DBInquirer::QueryDatabase(std::list<DatabaseQuery*> &qlist){
for(std::list<DatabaseQuery*>::iterator i = qlist.begin(); i != qlist.end(); i++){
void DBInquirer::QueryDatabase(std::list<DatabaseQuery::ptr> &qlist){
for(auto i = qlist.begin(); i != qlist.end(); i++){
(*i)->inquirer_id = m_inquirer_id;
}
m_database_manager->QueryDatabase(qlist);
......
......@@ -83,14 +83,14 @@ BEGIN_EVENT_TABLE(DatabaseManager, wxEvtHandler)
EVT_COMMAND(wxID_ANY, IKS_CONNECTION_FAILED, DatabaseManager::OnIksConnectionFailed)
END_EVENT_TABLE()
DatabaseResponse::DatabaseResponse(DatabaseQuery *_data) : wxCommandEvent(DATABASE_RESP, wxID_ANY), data(_data)
DatabaseResponse::DatabaseResponse(DatabaseQuery::ptr _data) : wxCommandEvent(DATABASE_RESP, wxID_ANY), data(_data)
{}
wxEvent* DatabaseResponse::Clone() const {
return new DatabaseResponse(*this);
}
DatabaseQuery* DatabaseResponse::GetQuery() {
DatabaseQuery::ptr DatabaseResponse::GetQuery() {
return data;
}
......@@ -129,34 +129,30 @@ DatabaseManager::DatabaseManager(DatabaseQueryQueue *_query_queue, ConfigManager
void DatabaseManager::OnDatabaseResponse(DatabaseResponse &response) {
DatabaseQuery *query = response.GetQuery();
DatabaseQuery::ptr query = response.GetQuery();
CheckAndNotifyAboutError(response);
if (query->type == DatabaseQuery::REMOVE_PARAM) {
ipk_manager->RemoveUserDefined(query->defined_param.prefix, query->defined_param.p);
free(query->defined_param.prefix);
delete query;
query.reset(); // query is in inconsistent state now
} else if (query->type == DatabaseQuery::STARTING_CONFIG_RELOAD) {
std::wstring dbprefix(query->reload_prefix.prefix);
free(query->reload_prefix.prefix);
delete query;
query.reset(); // query is in inconsistent state now
config_manager->ConfigurationReadyForLoad(dbprefix.c_str());
} else {
IHI i = inquirers.find(query->inquirer_id);
if (i == inquirers.end()) {
delete query;
} else {
if (i != inquirers.end()) {
DBInquirer *inquirer = i->second;
inquirer->DatabaseResponse(query);
}
}
}
void DatabaseManager::CheckAndNotifyAboutError(DatabaseResponse &response) {
DatabaseQuery* q = response.GetQuery();
DatabaseQuery::ptr q = response.GetQuery();
if (q->type == DatabaseQuery::GET_DATA) {
for (std::vector<DatabaseQuery::ValueData::V>::iterator i = q->value_data.vv->begin();
......@@ -278,14 +274,13 @@ InquirerId DatabaseManager::GetNextId() {
}
void DatabaseManager::CleanDatabase(DatabaseQuery *query) {
void DatabaseManager::CleanDatabase(DatabaseQuery::ptr query) {
query_queue->CleanOld(query);
}
void DatabaseManager::QueryDatabase(DatabaseQuery *query) {
void DatabaseManager::QueryDatabase(DatabaseQuery::ptr query) {
if (query->draw_info) {
if (reloadingDatabases.Contains(query->draw_info->GetBasePrefix())) {
delete query;
return;
}
}
......@@ -295,15 +290,14 @@ void DatabaseManager::QueryDatabase(DatabaseQuery *query) {
query_queue->Add(query);
}
void DatabaseManager::QueryDatabase(std::list<DatabaseQuery*> & qlist) {
void DatabaseManager::QueryDatabase(std::list<DatabaseQuery::ptr> & qlist) {
std::list<DatabaseQuery *> tmp_queries;
std::list<DatabaseQuery::ptr> tmp_queries;
for(std::list<DatabaseQuery*>::iterator i = qlist.begin(); i != qlist.end(); i++){
for(auto i = qlist.begin(); i != qlist.end(); i++){
if ((*i)->draw_info) {
if (reloadingDatabases.Contains((*i)->draw_info->GetBasePrefix())) {
delete (*i);
continue;
}
}
......@@ -319,7 +313,7 @@ void DatabaseManager::InitiateConfigurationReload(wxString prefix) {
if(!reloadingDatabases.TryAdd(prefix))
return;
DatabaseQuery* query = new DatabaseQuery;
auto query = std::make_shared<DatabaseQuery>();
query->type = DatabaseQuery::STARTING_CONFIG_RELOAD;
query->reload_prefix.prefix = wcsdup(prefix.c_str());
query->draw_info = NULL;
......@@ -341,7 +335,7 @@ void DatabaseManager::AddParams(const std::vector<DefinedParam*>& ddi) {
ipk_manager->AddUserDefined((*i)->GetBasePrefix().wc_str(), (*i)->GetIPKParam());
DatabaseQuery* query = new DatabaseQuery;
auto query = std::make_shared<DatabaseQuery>();
query->type = DatabaseQuery::ADD_PARAM;
query->defined_param.p = (*i)->GetIPKParam();
query->defined_param.prefix = wcsdup((*i)->GetBasePrefix());
......@@ -361,7 +355,7 @@ void DatabaseManager::RemoveParams(const std::vector<DefinedParam*>& ddi) {
wxLogInfo(_T("Removing param with prefix: %s, param: %s"), (*i)->GetBasePrefix().c_str(), (*i)->GetParamName().c_str());
DatabaseQuery* query = new DatabaseQuery;
auto query = std::make_shared<DatabaseQuery>();
query->type = DatabaseQuery::REMOVE_PARAM;
query->defined_param.p = (*i)->GetIPKParam();
query->defined_param.prefix = wcsdup((*i)->GetBasePrefix());
......@@ -383,7 +377,7 @@ void DatabaseManager::SetProbersAddresses(const std::map<wxString, std::pair<wxS
for (std::map<wxString, std::pair<wxString, wxString> >::const_iterator i = addresses.begin();
i != addresses.end();
i++) {
DatabaseQuery* query = new DatabaseQuery;
auto query = std::make_shared<DatabaseQuery>();
query->type = DatabaseQuery::SET_PROBER_ADDRESS;
query->prefix = i->first.c_str();
query->prober_address.address = wcsdup(i->second.first.c_str());
......@@ -393,7 +387,7 @@ void DatabaseManager::SetProbersAddresses(const std::map<wxString, std::pair<wxS
}
void DatabaseManager::ChangeObservedParamsRegistration(const std::vector<TParam*>& to_deregister, const std::vector<TParam*>& to_register) {
DatabaseQuery* query = new DatabaseQuery;
auto query = std::make_shared<DatabaseQuery>();
query->type = DatabaseQuery::REGISTER_OBSERVER;
query->observer_registration_parameters.observer = this;
......@@ -429,7 +423,7 @@ wxString DatabaseManager::GetCurrentPrefix() const
void DatabaseManager::AddBaseHandler(const wxString& prefix)
{
DatabaseQuery* query = new DatabaseQuery;
auto query = std::make_shared<DatabaseQuery>();
query->type = DatabaseQuery::ADD_BASE_PREFIX;
query->prefix = prefix.ToStdWstring();
......
......@@ -204,7 +204,7 @@ bool ShouldFetchNewValue(ValueInfo& vi, bool fetch_present_no_data) {
return vi.state == ValueInfo::PENDING || (vi.state == ValueInfo::PRESENT && !vi.IsData());
}
DatabaseQuery* Draw::GetDataToFetch(bool fetch_present_no_data) {
DatabaseQuery::ptr Draw::GetDataToFetch(bool fetch_present_no_data) {
const DTime& start_time = m_index.GetStartTime();
if (!start_time.IsValid()) {
......@@ -216,7 +216,7 @@ DatabaseQuery* Draw::GetDataToFetch(bool fetch_present_no_data) {
int d = m_values.m_view.Start();
DatabaseQuery* q = nullptr;
DatabaseQuery::ptr q{};
if (m_draw_info == NULL)
return q;
......@@ -385,7 +385,7 @@ DrawsController* Draw::GetDrawsController() {
return m_draws_controller;
}
void Draw::AddData(DatabaseQuery *query, bool &data_within_view, bool &non_fixed) {
void Draw::AddData(DatabaseQuery::ptr query, bool &data_within_view, bool &non_fixed) {
bool stats_updated = false;
non_fixed = false;
......@@ -729,7 +729,7 @@ void ValuesTable::CalculateProbeValue(int index) {
}
void ValuesTable::AddData(DatabaseQuery *q, bool &view_values_changed, bool &stats_updated, bool &non_fixed) {
void ValuesTable::AddData(DatabaseQuery::ptr q, bool &view_values_changed, bool &stats_updated, bool &non_fixed) {
DatabaseQuery::ValueData& vd = q->value_data;
PeriodType pt = vd.period_type;
if (pt != m_draw->GetPeriod() || q->draw_info != m_draw->GetDrawInfo()) {
......
......@@ -1258,7 +1258,7 @@ void DrawFrame::OnExportDataToFile(wxCommandEvent& e) {
if (file.ShowModal() != wxID_OK)
return;
DatabaseQuery* query = new DatabaseQuery();
auto query = std::make_shared<DatabaseQuery>();
query->type = DatabaseQuery::EXTRACT_PARAM_VALUES;
query->extraction_parameters.params = new std::vector<std::wstring>();
......
......@@ -70,9 +70,9 @@ void DrawsController::State::GoToLatestDate() {
void DrawsController::State::NewDataForSelectedDraw() {}
void DrawsController::State::HandleDataResponse(DatabaseQuery*) {}
void DrawsController::State::HandleDataResponse(DatabaseQuery::ptr) {}
void DrawsController::State::HandleSearchResponse(DatabaseQuery*) {}
void DrawsController::State::HandleSearchResponse(DatabaseQuery::ptr) {}
void DrawsController::State::MoveCursorBegin() {}
......@@ -92,7 +92,7 @@ void DrawsController::State::ParamDataChanged(TParam* param) {
if (param != draw->GetDrawInfo()->GetParam()->GetIPKParam())
continue;
DatabaseQuery *q = draw->GetDataToFetch(true);
DatabaseQuery::ptr q = draw->GetDataToFetch(true);
if (q)
m_c->SendQueryToDatabase(q);
}
......@@ -398,7 +398,7 @@ void DrawsController::SearchState::SendSearchQuery(const wxDateTime& start, cons
end.IsValid() ? end.Format().c_str() : none_wstring.c_str(),
direction);
DatabaseQuery *q = new DatabaseQuery();
auto q = std::make_shared<DatabaseQuery>();
q->type = DatabaseQuery::SEARCH_DATA;
q->prefix = m_c->GetCurrentPrefix().ToStdWstring();
q->draw_info = m_c->GetSelectedDraw()->GetDrawInfo();
......@@ -427,7 +427,7 @@ void DrawsController::SearchState::Reset() {
Enter(m_search_time);
}
void DrawsController::SearchState::HandleSearchResponse(DatabaseQuery* query) {
void DrawsController::SearchState::HandleSearchResponse(DatabaseQuery::ptr query) {
DatabaseQuery::SearchData& data = query->search_data;
if (query->q_id != m_search_query_id) {
......@@ -833,7 +833,7 @@ DrawsController::DrawsController(ConfigManager *config_manager, DatabaseManager
m_period_type = PERIOD_T_OTHER;
DatabaseQuery* q = new DatabaseQuery;
auto q = std::make_shared<DatabaseQuery>();
q->type = DatabaseQuery::CHECK_CONFIGURATIONS_CHANGE;
q->draw_info = NULL;
QueryDatabase(q);
......@@ -880,7 +880,7 @@ void DrawsController::SetCurrentTime(const DTime& time) {
m_current_time = time;
}
void DrawsController::SendQueryToDatabase(DatabaseQuery* query) {
void DrawsController::SendQueryToDatabase(DatabaseQuery::ptr query) {
QueryDatabase(query);
}
......@@ -917,7 +917,7 @@ void DrawsController::DisableDisabledDraws() {
}
}
void DrawsController::DatabaseResponse(DatabaseQuery *query) {
void DrawsController::DatabaseResponse(DatabaseQuery::ptr query) {
switch (query->type) {
case DatabaseQuery::SEARCH_DATA:
HandleSearchResponse(query);
......@@ -942,12 +942,11 @@ std::vector<TParam*> DrawsController::GetSubscribedParams() const
return v;
}
void DrawsController::HandleDataResponse(DatabaseQuery *query) {
void DrawsController::HandleDataResponse(DatabaseQuery::ptr query) {
int draw_no = query->draw_no;
if (size_t(draw_no) >= m_draws.size()
|| query->value_data.period_type != GetPeriod()
|| query->draw_info != m_draws[draw_no]->GetDrawInfo()) {
delete query;
return;
}
......@@ -964,8 +963,6 @@ void DrawsController::HandleDataResponse(DatabaseQuery *query) {
m_state->NewDataForSelectedDraw();
m_state->NewValuesAdded(m_draws[draw_no], non_fixed);
delete query;
}