@@ -14,7 +14,8 @@ namespace nativeapi {
1414// want to listen for broadcasts.
1515class BroadcastReceiver {
1616 public:
17- virtual void OnBroadcastReceived (const std::string& message) = 0;
17+ virtual void OnBroadcastReceived (const std::string& topic,
18+ const std::string& message) = 0;
1819};
1920
2021// BroadcastCenter is a singleton that manages all broadcasts on the system.
@@ -23,17 +24,16 @@ class BroadcastCenter {
2324 BroadcastCenter ();
2425 virtual ~BroadcastCenter ();
2526
27+ // Send a broadcast message to all receivers of a given topic
28+ void SendBroadcast (const std::string& topic, const std::string& message);
29+
2630 // Register a receiver to the broadcast center
2731 void RegisterReceiver (const std::string& topic, BroadcastReceiver* receiver);
2832
2933 // Unregister a receiver from the broadcast center
3034 void UnregisterReceiver (const std::string& topic,
3135 BroadcastReceiver* receiver);
3236
33- // Notify all receivers of a given topic
34- void NotifyReceivers (const std::string& topic,
35- std::function<void (BroadcastReceiver*)> callback);
36-
3737 private:
3838 std::vector<BroadcastReceiver*> receivers_;
3939};
@@ -43,14 +43,17 @@ class BroadcastCenter {
4343class BroadcastEventHandler : public BroadcastReceiver {
4444 public:
4545 // 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);
4849
4950 // 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 ;
5153
5254 private:
53- std::function<void (const std::string&)> onBroadcastReceivedCallback_;
55+ std::function<void (const std::string& topic, const std::string& message)>
56+ onBroadcastReceivedCallback_;
5457};
5558
5659} // namespace nativeapi
0 commit comments