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/session/custom/session.cxx | 5 +++-- common/transaction/callback/driver.cxx | 33 +++++++++++++++++++++++++-------- common/transaction/callback/test.std | 2 ++ 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/common/session/custom/session.cxx b/common/session/custom/session.cxx index 0009d79..d82ab3d 100644 --- a/common/session/custom/session.cxx +++ b/common/session/custom/session.cxx @@ -22,7 +22,7 @@ session:: // Unregister from transaction. // if (tran_ != 0) - tran_->unregister (this); + tran_->callback_unregister (this); assert (current == this); current = 0; @@ -44,7 +44,8 @@ flush (odb::database& db) if (flushed) { tran_ = &odb::transaction::current (); - tran_->register_ (&mark, this, odb::transaction::event_all, 0, &tran_); + tran_->callback_register ( + &mark, this, odb::transaction::event_all, 0, &tran_); } } 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