source: trunk/SL/APP/app.cxx

Last change on this file was 19654, checked in by westram, 2 weeks ago
  • reintegrates 'macros' into 'trunk'
    • improves program termination (#867)
      • introduces MacroExitor classes
        • handles confirmation (to quit)
        • waits for macros to finish, then exits w/o confirmation
        • provides specialized termination for different programs via derived classes
          • has been implemented for "normal" arb and merge-tool.
      • introduces ARB_disconnect_from_db
        • generalizes code to terminate all interconnections between GUI, database and macro-ability
        • allow to install atdisconnect-callbacks
          • usable by modules operating on a database; allow to inform module that database will vanish.
        • now used by all arb applications to disconnect from all their database(s), except the properties.
    • fixes some broken behavior
      • merge-tool
        • crashed when quitting via macro
        • wrong restarts, if originally started with arguments,
      • importer
        • failed to record/playback macros
        • crashed in modules operating on the temporary import database
      • database browser
        • crashed on disappearing database
  • adds: log:branches/macros@19620:19653
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        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
Note: See TracBrowser for help on using the repository browser.