diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2013-02-08 12:55:28 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2013-02-08 12:55:28 +0200 |
commit | 42123e65fab590f5b052f53ad755fba9bded0c24 (patch) | |
tree | e4339f4e0591c26483d34d265e91cf6191288ac8 /common/transaction | |
parent | 261863a5037ba892ec33eb037d77736c8e599369 (diff) |
Add callback_ prefix to transaction callback functions
Also test callback_update().
Diffstat (limited to 'common/transaction')
-rw-r--r-- | common/transaction/callback/driver.cxx | 33 | ||||
-rw-r--r-- | common/transaction/callback/test.std | 2 |
2 files changed, 27 insertions, 8 deletions
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<void*> (i), - transaction::event_all, - i); + t.callback_register (&dummy_func, + reinterpret_cast<void*> (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 |