From 42123e65fab590f5b052f53ad755fba9bded0c24 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 8 Feb 2013 12:55:28 +0200 Subject: Add callback_ prefix to transaction callback functions Also test callback_update(). --- common/transaction/callback/driver.cxx | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) (limited to 'common/transaction/callback/driver.cxx') diff --git a/common/transaction/callback/driver.cxx b/common/transaction/callback/driver.cxx index b74df4c..b4c3d85 100644 --- a/common/transaction/callback/driver.cxx +++ b/common/transaction/callback/driver.cxx @@ -27,17 +27,24 @@ struct callback register_ (transaction& t) { t_ = &t; - t.register_ (&func, this, transaction::event_all, v_, &t_); + t.callback_register (&func, this, transaction::event_all, v_, &t_); } void unregister () { cout << " unregister callback " << v_ << endl; - t_->unregister (this); + t_->callback_unregister (this); t_ = 0; } + void + update (unsigned short v) + { + v_ = v; + t_->callback_update (this, transaction::event_all, v_, &t_); + } + private: static void func (unsigned short event, void* key, unsigned long long data) @@ -87,10 +94,10 @@ fill (transaction& t) // 20 is from odb/transaction.hxx. // for (size_t i (0); i < 20; ++i) - t.register_ (&dummy_func, - reinterpret_cast (i), - transaction::event_all, - i); + t.callback_register (&dummy_func, + reinterpret_cast (i), + transaction::event_all, + i); } int @@ -150,7 +157,7 @@ main (int argc, char* argv[]) if (i == 2) fill (t); callback c1 (1, t); c1.unregister (); - t.unregister (&c1); // Test unregistering non-registered key. + t.callback_unregister (&c1); // Test unregistering non-registered key. t.commit (); } @@ -195,13 +202,23 @@ main (int argc, char* argv[]) transaction t (db->begin ()); if (i == 2) fill (t); callback c1 (1, t); - t.register_ (&throw_func, 0); + t.callback_register (&throw_func, 0); callback c2 (2, t); t.commit (); } catch (const failed&) { } + + // Test callback_update(). + // + { + transaction t (db->begin ()); + if (i == 2) fill (t); + callback c (1, t); + c.update (2); + t.commit (); + } } } catch (const odb::exception& e) -- cgit v1.1