forked from benlau/quickios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqisystemdispatcher.h
41 lines (32 loc) · 1.17 KB
/
qisystemdispatcher.h
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
#pragma once
#include <QObject>
#include <QVariantMap>
/// QISystemMessenger provides an simple async messaging interface between C/C++/QML and Objective-C source code.
/**
*/
class QISystemDispatcher : public QObject {
Q_OBJECT
public:
static QISystemDispatcher* instance();
/// Deliver a message
/** If there has a registered listener function , it will return TRUE. Otherwise, it will return FALSE.
*
* After processed by the registered helper, the "received" signal will be emitted
* in next tick of event loop.
*/
Q_INVOKABLE bool dispatch(QString type , QVariantMap message);
/// Register a message listener.
/**
* @brief registerMessageHandler
* @param name
* @return TRUE if it is successfully. If it is already registered, it will return false.
*/
bool addListener(QString name,bool (*func)(QVariantMap&) );
/// Return TRUE if it there has a message helper registered already.
bool hasListener(QString name);
signals:
/// The signal is emitted when a message is received.
void dispatched(QString name , QVariantMap data);
private:
explicit QISystemDispatcher(QObject* parent = 0);
};