client-cpp  0.7.0
NotificationManager.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2014 CyberVision, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef DEFAULTNOTIFICATONMANAGER_HPP_
18 #define DEFAULTNOTIFICATONMANAGER_HPP_
19 
20 #include "kaa/KaaDefaults.hpp"
21 
22 #include "kaa/KaaThread.hpp"
23 
24 #include <memory>
25 #include <string>
26 #include <unordered_map>
27 #include <unordered_set>
28 
29 #include "kaa/gen/EndpointGen.hpp"
36 
38 
39 namespace kaa {
40 
42 public:
44 
47  virtual Topics getTopics();
48 
49  virtual void addNotificationListener(INotificationListener& listener);
50  virtual void addNotificationListener(const std::string& topidId, INotificationListener& listener);
51  virtual void removeNotificationListener(INotificationListener& listener);
52  virtual void removeNotificationListener(const std::string& topidId, INotificationListener& listener);
53 
54  virtual void subscribeToTopic(const std::string& id, bool forceSync = true);
55  virtual void subscribeToTopics(const std::list<std::string>& idList, bool forceSync = true);
56  virtual void unsubscribeFromTopic(const std::string& id, bool forceSync = true);
57  virtual void unsubscribeFromTopics(const std::list<std::string>& idList, bool forceSync = true);
58  virtual void sync();
59 
60  virtual void topicsListUpdated(const Topics& topics);
61  virtual void notificationReceived(const Notifications& notifications);
62 
63  void setTransport(std::shared_ptr<NotificationTransport> transport);
64 
65 private:
66  void updateSubscriptionInfo(const std::string& id, SubscriptionCommandType type);
67  void updateSubscriptionInfo(const SubscriptionCommands& newSubscriptions);
68 
69  const Topic& findTopic(const std::string& id);
70 
71  void notifyTopicUpdateSubscribers(const Topics& topics);
72  void notifyMandatoryNotificationSubscribers(const std::string& id, const KaaNotification& notification);
73  bool notifyOptionalNotificationSubscribers(const std::string& id, const KaaNotification& notification);
74 
75 private:
76  std::shared_ptr<NotificationTransport> transport_;
77  IKaaClientStateStoragePtr clientStatus_;
78 
79  std::unordered_map<std::string/*Topic ID*/, Topic> topics_;
80  KAA_MUTEX_DECLARE(topicsGuard_);
81 
82  typedef KaaObservable<void(const std::string& topicId, const KaaNotification& notification)
84  typedef std::shared_ptr<NotificationObservable> NotificationObservablePtr;
85 
87  NotificationObservable mandatoryListeners_;
88  std::unordered_map<std::string/*Topic ID*/, NotificationObservable> optionalListeners_;
89  KAA_MUTEX_DECLARE(optionalListenersGuard_);
90 
91  SubscriptionCommands subscriptions_;
92  KAA_MUTEX_DECLARE(subscriptionsGuard_);
93 };
94 
95 } /* namespace kaa */
96 
97 #endif /* DEFAULTNOTIFICATONMANAGER_HPP_ */
The listener which receives updates on available topics.
virtual void sync()
Sends subscription request(s) to the Operations server.
virtual void addNotificationListener(INotificationListener &listener)
Adds the listener which receives notifications on all available topics.
The public interface to topic subscription and notification delivery subsystems.
virtual void notificationReceived(const Notifications &notifications)
virtual Topics getTopics()
Retrieves the list of available topics.
NotificationManager(IKaaClientStateStoragePtr status)
void setTransport(std::shared_ptr< NotificationTransport > transport)
virtual void subscribeToTopics(const std::list< std::string > &idList, bool forceSync=true)
Subscribes to the specified list of optional topics to receive notifications on those topics...
virtual void topicsListUpdated(const Topics &topics)
virtual void addTopicListListener(INotificationTopicListListener &listener)
Adds the listener which receives updates on the list of available topics.
The listener which receives notifications on the specified topic.
std::shared_ptr< IKaaClientStateStorage > IKaaClientStateStoragePtr
virtual void removeNotificationListener(INotificationListener &listener)
Removes the listener which receives notifications on all available topics.
virtual void unsubscribeFromTopics(const std::list< std::string > &idList, bool forceSync=true)
Unsubscribes from the specified list of optional topics to stop receiving notifications on those topi...
std::list< SubscriptionCommand > SubscriptionCommands
virtual void removeTopicListListener(INotificationTopicListListener &listener)
Removes listener which receives updates on the list of available topics.
virtual void subscribeToTopic(const std::string &id, bool forceSync=true)
Subscribes to the specified optional topic to receive notifications on that topic.
virtual void unsubscribeFromTopic(const std::string &id, bool forceSync=true)
Unsubscribes from the specified optional topic to stop receiving notifications on that topic...