@@ -14,7 +14,8 @@ namespace nativeapi {
14
14
// want to listen for broadcasts.
15
15
class BroadcastReceiver {
16
16
public:
17
- virtual void OnBroadcastReceived (const std::string& message) = 0;
17
+ virtual void OnBroadcastReceived (const std::string& topic,
18
+ const std::string& message) = 0;
18
19
};
19
20
20
21
// BroadcastCenter is a singleton that manages all broadcasts on the system.
@@ -23,17 +24,16 @@ class BroadcastCenter {
23
24
BroadcastCenter ();
24
25
virtual ~BroadcastCenter ();
25
26
27
+ // Send a broadcast message to all receivers of a given topic
28
+ void SendBroadcast (const std::string& topic, const std::string& message);
29
+
26
30
// Register a receiver to the broadcast center
27
31
void RegisterReceiver (const std::string& topic, BroadcastReceiver* receiver);
28
32
29
33
// Unregister a receiver from the broadcast center
30
34
void UnregisterReceiver (const std::string& topic,
31
35
BroadcastReceiver* receiver);
32
36
33
- // Notify all receivers of a given topic
34
- void NotifyReceivers (const std::string& topic,
35
- std::function<void (BroadcastReceiver*)> callback);
36
-
37
37
private:
38
38
std::vector<BroadcastReceiver*> receivers_;
39
39
};
@@ -43,14 +43,17 @@ class BroadcastCenter {
43
43
class BroadcastEventHandler : public BroadcastReceiver {
44
44
public:
45
45
// Constructor that takes callbacks for broadcast events
46
- BroadcastEventHandler (std::function<void (const std::string& message)>
47
- onBroadcastReceivedCallback);
46
+ BroadcastEventHandler (
47
+ std::function<void (const std::string& topic, const std::string& message)>
48
+ onBroadcastReceivedCallback);
48
49
49
50
// Implementation of OnBroadcastReceive from BroadcastReceiver interface
50
- void OnBroadcastReceived (const std::string& message) override ;
51
+ void OnBroadcastReceived (const std::string& topic,
52
+ const std::string& message) override ;
51
53
52
54
private:
53
- std::function<void (const std::string&)> onBroadcastReceivedCallback_;
55
+ std::function<void (const std::string& topic, const std::string& message)>
56
+ onBroadcastReceivedCallback_;
54
57
};
55
58
56
59
} // namespace nativeapi
0 commit comments