1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
crate::ix!();

//-------------------------------------------[.cpp/bitcoin/src/qt/initexecutor.h]
//-------------------------------------------[.cpp/bitcoin/src/qt/initexecutor.cpp]

/**
  | Class encapsulating Bitcoin Core startup
  | and shutdown.
  | 
  | Allows running startup and shutdown
  | in a different thread from the UI thread.
  |
  */
#[Q_OBJECT]
pub struct InitExecutor {
    base:    QObject,
    node:    Rc<RefCell<dyn NodeInterface>>,
    context: QObject,
    thread:  QThread,
}

impl Drop for InitExecutor {
    fn drop(&mut self) {
        todo!();
        /*
            qDebug() << __func__ << ": Stopping thread";
        m_thread.quit();
        m_thread.wait();
        qDebug() << __func__ << ": Stopped thread";
        */
    }
}

impl InitExecutor {
    
    #[Q_SIGNAL]
    pub fn initialize_result(&mut self, 
        success:  bool,
        tip_info: BlockAndHeaderTipInfo)  {
        
        todo!();
        /*
        
        */
    }
    
    #[Q_SIGNAL]
    pub fn shutdown_result(&mut self)  {
        
        todo!();
        /*
        
        */
    }
    
    #[Q_SIGNAL]
    pub fn runaway_exception(&mut self, message: &String)  {
        
        todo!();
        /*
        
        */
    }

    pub fn new(node: Rc<RefCell<dyn NodeInterface>>) -> Self {
    
        todo!();
        /*
        : q_object(),
        : node(node),

            m_context.moveToThread(&m_thread);
        m_thread.start();
        */
    }
    
    /**
      | Pass fatal exception message to UI thread
      |
      */
    #[Q_SIGNAL]
    pub fn handle_runaway_exception(&mut self, e: *const Exception)  {
        
        todo!();
        /*
            PrintExceptionContinue(e, "Runaway exception");
        Q_EMIT runawayException(QString::fromStdString(m_node.getWarnings().translated));
        */
    }
    
    #[Q_SLOT]
    pub fn initialize(&mut self)  {
        
        todo!();
        /*
            typename gui_util::ObjectInvoke(&m_context, [this] {
            try {
                util::ThreadRename("qt-init");
                qDebug() << "Running initialization in thread";
                typename interfaces::BlockAndHeaderTipInfo tip_info;
                bool rv = m_node.appInitMain(&tip_info);
                Q_EMIT initializeResult(rv, tip_info);
            } catch (const std::exception& e) {
                handleRunawayException(&e);
            } catch (...) {
                handleRunawayException(nullptr);
            }
        });
        */
    }
    
    #[Q_SLOT]
    pub fn shutdown(&mut self)  {
        
        todo!();
        /*
            typename gui_util::ObjectInvoke(&m_context, [this] {
            try {
                qDebug() << "Running Shutdown in thread";
                m_node.appShutdown();
                qDebug() << "Shutdown finished";
                Q_EMIT shutdownResult();
            } catch (const std::exception& e) {
                handleRunawayException(&e);
            } catch (...) {
                handleRunawayException(nullptr);
            }
        });
        */
    }
}