source: branches/gcc/SL/APP/app.cxx

Last change on this file was 19731, checked in by westram, 3 months ago
File size: 2.6 KB
Line 
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
19using namespace std;
20
21static list<ArbDisconnectCallback> callbacks;
22
23void 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
40void 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
60        arb_assert(aw_root);
61        aw_root->unlink_awars_from_DB(gb_main);
62
63        // call disconnect callbacks for passed database:
64        for (list<ArbDisconnectCallback>::const_iterator cb = callbacks.begin(); cb != callbacks.end(); ++cb) {
65            (*cb)(aw_root, gb_main);
66        }
67
68        gb_main_ref = NULp; // avoid further usage
69        GB_close(gb_main);
70    }
71}
72
Note: See TracBrowser for help on using the repository browser.