client-cpp  0.9.0
NotificationManager.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2014-2016 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"
37 
39 
40 namespace kaa {
41 
42 class IExecutorContext;
43 
45 public:
47 
50  virtual Topics getTopics();
51 
52  virtual void addNotificationListener(INotificationListener& listener);
53  virtual void addNotificationListener(std::int64_t topidId, INotificationListener& listener);
54  virtual void removeNotificationListener(INotificationListener& listener);
55  virtual void removeNotificationListener(std::int64_t topidId, INotificationListener& listener);
56 
57  virtual void subscribeToTopic(std::int64_t id, bool forceSync = true);
58  virtual void subscribeToTopics(const std::list<std::int64_t>& idList, bool forceSync = true);
59  virtual void unsubscribeFromTopic(std::int64_t id, bool forceSync = true);
60  virtual void unsubscribeFromTopics(const std::list<std::int64_t>& idList, bool forceSync = true);
61  virtual void sync();
62 
63  virtual void topicsListUpdated(const Topics& topics);
64  virtual void notificationReceived(const Notifications& notifications);
65 
66  void setTransport(std::shared_ptr<NotificationTransport> transport);
67 
68 private:
69  typedef std::shared_ptr<KaaNotification> KaaNotificationPtr;
70 
71 private:
72  void updateSubscriptionInfo(std::int64_t id, SubscriptionCommandType type);
73  void updateSubscriptionInfo(const SubscriptionCommands& newSubscriptions);
74 
75  const Topic& findTopic(std::int64_t id);
76 
77  void notifyTopicUpdateSubscribers(const Topics& topics);
78  void notifyMandatoryNotificationSubscribers(std::int64_t id, KaaNotificationPtr notification);
79  bool notifyOptionalNotificationSubscribers(std::int64_t id, KaaNotificationPtr notification);
80 
81 private:
82  IKaaClientContext &context_;
83 
84  std::shared_ptr<NotificationTransport> transport_;
85  IKaaClientStateStoragePtr clientStatus_;
86 
87  std::unordered_map<std::int64_t/*Topic ID*/, Topic> topics_;
88  KAA_MUTEX_DECLARE(topicsGuard_);
89 
90  typedef KaaObservable<void(std::int64_t topicId, const KaaNotification& notification)
92  typedef std::shared_ptr<NotificationObservable> NotificationObservablePtr;
93 
95  NotificationObservable mandatoryListeners_;
96  std::unordered_map<std::int64_t/*Topic ID*/, NotificationObservablePtr> optionalListeners_;
97  KAA_MUTEX_DECLARE(optionalListenersGuard_);
98 
99  SubscriptionCommands subscriptions_;
100  KAA_MUTEX_DECLARE(subscriptionsGuard_);
101 };
102 
103 } /* namespace kaa */
104 
105 #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.
virtual void unsubscribeFromTopics(const std::list< std::int64_t > &idList, bool forceSync=true)
Unsubscribes from the specified list of optional topics to stop receiving notifications on those topi...
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(IKaaClientContext &context)
void setTransport(std::shared_ptr< NotificationTransport > transport)
virtual void subscribeToTopic(std::int64_t id, bool forceSync=true)
Subscribes to the specified optional topic to receive notifications on that topic.
virtual void subscribeToTopics(const std::list< std::int64_t > &idList, bool forceSync=true)
Subscribes to the specified list of optional topics to receive notifications on those topics...
virtual void unsubscribeFromTopic(std::int64_t id, bool forceSync=true)
Unsubscribes from the specified optional topic to stop receiving notifications on that topic...
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.
std::list< SubscriptionCommand > SubscriptionCommands
virtual void removeTopicListListener(INotificationTopicListListener &listener)
Removes listener which receives updates on the list of available topics.