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 +++++++++++++++++++++++++-------- common/transaction/callback/test.std | 2 ++ 2 files changed, 27 insertions(+), 8 deletions(-) (limited to 'common/transaction') 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) diff --git a/common/transaction/callback/test.std b/common/transaction/callback/test.std index f86579b..4298c1e 100644 --- a/common/transaction/callback/test.std +++ b/common/transaction/callback/test.std @@ -15,6 +15,7 @@ test 1/002 callback 3 commit test 1/003 callback 1 commit + callback 2 commit test 2/001 callback 1 commit callback 1 rollback @@ -32,3 +33,4 @@ test 2/002 callback 3 commit test 2/003 callback 1 commit + callback 2 commit -- cgit v1.1