client-cpp  0.7.4
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 
41 class IExecutorContext;
42 
44 public:
46 
49  virtual Topics getTopics();
50 
51  virtual void addNotificationListener(INotificationListener& listener);
52  virtual void addNotificationListener(const std::string& topidId, INotificationListener& listener);
53  virtual void removeNotificationListener(INotificationListener& listener);
54  virtual void removeNotificationListener(const std::string& topidId, INotificationListener& listener);
55 
56  virtual void subscribeToTopic(const std::string& id, bool forceSync = true);
57  virtual void subscribeToTopics(const std::list<std::string>& idList, bool forceSync = true);
58  virtual void unsubscribeFromTopic(const std::string& id, bool forceSync = true);
59  virtual void unsubscribeFromTopics(const std::list<std::string>& idList, bool forceSync = true);
60  virtual void sync();
61 
62  virtual void topicsListUpdated(const Topics& topics);
63  virtual void notificationReceived(const Notifications& notifications);
64 
65  void setTransport(std::shared_ptr<NotificationTransport> transport);
66 
67 private:
68  typedef std::shared_ptr<KaaNotification> KaaNotificationPtr;
69 
70 private:
71  void updateSubscriptionInfo(const std::string& id, SubscriptionCommandType type);
72  void updateSubscriptionInfo(const SubscriptionCommands& newSubscriptions);
73 
74  const Topic& findTopic(const std::string& id);
75 
76  void notifyTopicUpdateSubscribers(const Topics& topics);
77  void notifyMandatoryNotificationSubscribers(const std::string& id, KaaNotificationPtr notification);
78  bool notifyOptionalNotificationSubscribers(const std::string& id, KaaNotificationPtr notification);
79 
80 private:
81  IExecutorContext& executorContext_;
82 
83  std::shared_ptr<NotificationTransport> transport_;
84  IKaaClientStateStoragePtr clientStatus_;
85 
86  std::unordered_map<std::string/*Topic ID*/, Topic> topics_;
87  KAA_MUTEX_DECLARE(topicsGuard_);
88 
89  typedef KaaObservable<void(const std::string& topicId, const KaaNotification& notification)
91  typedef std::shared_ptr<NotificationObservable> NotificationObservablePtr;
92 
94  NotificationObservable mandatoryListeners_;
95  std::unordered_map<std::string/*Topic ID*/, NotificationObservablePtr> optionalListeners_;
96  KAA_MUTEX_DECLARE(optionalListenersGuard_);
97 
98  SubscriptionCommands subscriptions_;
99  KAA_MUTEX_DECLARE(subscriptionsGuard_);
100 };
101 
102 } /* namespace kaa */
103 
104 #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.
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
NotificationManager(IKaaClientStateStoragePtr status, IExecutorContext &executorContext)
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...