| 1 | // ========================================================= // |
|---|
| 2 | // // |
|---|
| 3 | // File : app.cxx // |
|---|
| 4 | // Purpose : code specific to arb GUI apps using DB // |
|---|
| 5 | // // |
|---|
| 6 | // Coded by Ralf Westram (coder@reallysoft.de) in Dec 25 // |
|---|
| 7 | // http://www.arb-home.de/ // |
|---|
| 8 | // // |
|---|
| 9 | // ========================================================= // |
|---|
| 10 | |
|---|
| 11 | #include "app.hxx" |
|---|
| 12 | #include <macros.hxx> |
|---|
| 13 | #include <aw_root.hxx> |
|---|
| 14 | #include <arbdbt.h> |
|---|
| 15 | |
|---|
| 16 | #include <list> |
|---|
| 17 | #include <algorithm> |
|---|
| 18 | |
|---|
| 19 | using namespace std; |
|---|
| 20 | |
|---|
| 21 | static list<ArbDisconnectCallback> callbacks; |
|---|
| 22 | |
|---|
| 23 | void ARB_atdisconnect_callback(const ArbDisconnectCallback& cb) { |
|---|
| 24 | // Make sure the passed callback may be called multiple times. |
|---|
| 25 | // |
|---|
| 26 | // Callbacks added via this function are called once for each used arb database, |
|---|
| 27 | // ie. they might be called multiple times, if multiple databases are opened |
|---|
| 28 | // (e.g. in ARB_MERGE or when using import). |
|---|
| 29 | // |
|---|
| 30 | // The 'gb_main' passed to these callbacks will never be NULp, and the callback |
|---|
| 31 | // will never be called multiple times with the same 'gb_main'. |
|---|
| 32 | // |
|---|
| 33 | // Identical callbacks are added only once. |
|---|
| 34 | |
|---|
| 35 | if (find(callbacks.begin(), callbacks.end(), cb) == callbacks.end()) { |
|---|
| 36 | callbacks.push_front(cb); |
|---|
| 37 | } |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | void ARB_disconnect_from_db(AW_root *aw_root, GBDATA*& gb_main_ref) { |
|---|
| 41 | // disconnect arb application from database: |
|---|
| 42 | // |
|---|
| 43 | // - shutdown database server |
|---|
| 44 | // - deny further usage of passed pointer 'gb_main_ref' |
|---|
| 45 | // (which should be the global database pointer, i.e. GLOBAL.gb_main or similar in case of the main database). |
|---|
| 46 | // - unlink awars which are bound to database |
|---|
| 47 | // - close the database |
|---|
| 48 | // |
|---|
| 49 | // After disconnecting from the main database you should exit ASAP. |
|---|
| 50 | // After disconnecting from other databases, your program may continue. |
|---|
| 51 | // The latter happens when using the importer. |
|---|
| 52 | |
|---|
| 53 | if (gb_main_ref) { |
|---|
| 54 | shutdown_macro_recording_via_database(aw_root, gb_main_ref); |
|---|
| 55 | |
|---|
| 56 | GBCMS_shutdown(gb_main_ref); // shutdown DB server (if any) |
|---|
| 57 | |
|---|
| 58 | GBDATA *gb_main = gb_main_ref; |
|---|
| 59 | gb_main_ref = NULp; // avoid further usage |
|---|
| 60 | |
|---|
| 61 | arb_assert(aw_root); |
|---|
| 62 | aw_root->unlink_awars_from_DB(gb_main); |
|---|
| 63 | |
|---|
| 64 | // call disconnect callbacks for passed database: |
|---|
| 65 | for (list<ArbDisconnectCallback>::const_iterator cb = callbacks.begin(); cb != callbacks.end(); ++cb) { |
|---|
| 66 | (*cb)(aw_root, gb_main); |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | GB_close(gb_main); |
|---|
| 70 | } |
|---|
| 71 | } |
|---|
| 72 | |
|---|