-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathengine_hsm.h
More file actions
107 lines (95 loc) · 3.33 KB
/
engine_hsm.h
File metadata and controls
107 lines (95 loc) · 3.33 KB
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
/*
fdqueens : visualizing SWI-Prolog attributed variables in Qt
Author : Carlo Capelli
E-mail : cc.carlo.cap@gmail.com
Copyright (C): 2013,2014,2015,2016
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef ENGINE_HSM_H
#define ENGINE_HSM_H
#include "SwiPrologEngine.h"
#include <QDebug>
#include <QEvent>
#include <QStateMachine>
#include <QAbstractTransition>
/**
* @brief The query_complete_event struct
* a query has completed
*/
struct query_complete_event : QEvent {
QString q; int i;
query_complete_event(QString q, int i) : QEvent(User), q(q), i(i) {}
};
class query_complete_transition : public QAbstractTransition {
Q_OBJECT
protected:
virtual bool eventTest(QEvent *e) {
return dynamic_cast<query_complete_event*>(e) != 0;
}
virtual void onTransition(QEvent *) {}
};
/**
* @brief The query_result_event struct
* a query give a result
*/
struct query_result_event : QEvent {
QString q; int i;
query_result_event(QString q, int i) : QEvent(User), q(q), i(i) {}
};
class query_result_transition : public QAbstractTransition {
Q_OBJECT
protected:
virtual bool eventTest(QEvent *e) {
return dynamic_cast<query_result_event*>(e) != 0;
}
virtual void onTransition(QEvent *) {}
};
/**
* @brief The query_exception_event struct
* an exception raised from Prolog side
*/
struct query_exception_event : QEvent {
QString q; QString e;
query_exception_event(QString q, QString e) : QEvent(User), q(q), e(e) {}
};
class query_exception_transition : public QAbstractTransition {
Q_OBJECT
protected:
virtual bool eventTest(QEvent *e) {
return dynamic_cast<query_exception_event*>(e) != 0;
}
virtual void onTransition(QEvent *) {}
};
/**
* @brief wrap_engine_events
* route engine events into UX
* @param eng
* query execution engine
* @param contr
* UX controller
*/
inline void wrap_engine_events(SwiPrologEngine *eng, QStateMachine *contr) {
contr->connect(eng, &SwiPrologEngine::query_complete, [contr](QString q, int i) {
qDebug() << "query_complete" << q << i << contr->configuration();
contr->postEvent(new query_complete_event(q, i));
});
contr->connect(eng, &SwiPrologEngine::query_exception, [contr](QString q, QString e) {
qDebug() << "query_exception" << q << e << contr->configuration();
contr->postEvent(new query_exception_event(q, e));
});
contr->connect(eng, &SwiPrologEngine::query_result, [contr](QString q, int i) {
qDebug() << "query_result" << q << i << contr->configuration();
contr->postEvent(new query_result_event(q, i));
});
}
#endif // ENGINE_HSM_H