client-cpp  0.7.0
EventManager.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 EVENTMANAGER_HPP_
18 #define EVENTMANAGER_HPP_
19 
20 
21 #include <set>
22 #include <list>
23 
24 #include <cstdint>
25 #include <memory>
26 
27 #include "kaa/KaaDefaults.hpp"
28 #include "kaa/KaaThread.hpp"
29 #include "kaa/gen/EndpointGen.hpp"
36 
37 namespace kaa {
38 
41  , public IEventDataProcessor
42  , public AbstractTransactable<std::list<Event> >
43 {
44 public:
46  : currentEventIndex_(0),eventTransport_(nullptr)
47  , status_(status)
48  {
49  }
50 
51  virtual void registerEventFamily(IEventFamily* eventFamily);
52 
53  virtual void produceEvent(const std::string& fqn
54  , const std::vector<std::uint8_t>& data
55  , const std::string& target
56  , TransactionIdPtr trxId);
57 
58  virtual void onEventsReceived(const EventSyncResponse::events_t& events);
59  virtual void onEventListenersReceived(const EventSyncResponse::eventListenersResponses_t& listeners);
60 
61  virtual std::map<std::int32_t, Event> releasePendingEvents();
62  virtual bool hasPendingEvents() const;
63 
64  virtual std::map<std::int32_t, std::list<std::string> > getPendingListenerRequests();
65  virtual bool hasPendingListenerRequests() const;
66 
67  virtual std::int32_t findEventListeners(const std::list<std::string>& eventFQNs, IFetchEventListenersPtr listener);
68 
69  virtual void setTransport(EventTransport *transport);
70 
72  {
74  }
75 
76  virtual void commit(TransactionIdPtr trxId);
77 
78  virtual void rollback(TransactionIdPtr trxId)
79  {
81  }
82 private:
83  struct EventListenersInfo {
84  std::list<std::string> eventFQNs_;
85  IFetchEventListenersPtr listener_;
86  };
87 
88  void onEventFromServer(const std::string& eventClassFQN
89  , const std::vector<std::uint8_t>& data
90  , const std::string& source);
91 
92  void generateUniqueRequestId(std::string& requstId);
93 private:
94  std::set<IEventFamily*> eventFamilies_;
95  std::map<std::int32_t, Event> pendingEvents_;
96  KAA_MUTEX_MUTABLE_DECLARE(pendingEventsGuard_);
97 
98  std::int32_t currentEventIndex_;
99 
100  EventTransport * eventTransport_;
102 
103  std::map<std::int32_t/*request id*/, std::shared_ptr<EventListenersInfo> > eventListenersRequests_;
104  KAA_MUTEX_MUTABLE_DECLARE(eventListenersGuard_);
105 };
106 
107 } /* namespace kaa */
108 
109 #endif /* EVENTMANAGER_HPP_ */
virtual void setTransport(EventTransport *transport)
virtual std::map< std::int32_t, std::list< std::string > > getPendingListenerRequests()
virtual bool hasPendingListenerRequests() const
virtual void produceEvent(const std::string &fqn, const std::vector< std::uint8_t > &data, const std::string &target, TransactionIdPtr trxId)
std::shared_ptr< TransactionId > TransactionIdPtr
virtual void commit(TransactionIdPtr trxId)
std::shared_ptr< IKaaClientStateStorage > IKaaClientStateStoragePtr
virtual std::map< std::int32_t, Event > releasePendingEvents()
EventManager(IKaaClientStateStoragePtr status)
virtual void registerEventFamily(IEventFamily *eventFamily)
virtual void onEventsReceived(const EventSyncResponse::events_t &events)
virtual std::int32_t findEventListeners(const std::list< std::string > &eventFQNs, IFetchEventListenersPtr listener)
virtual TransactionIdPtr beginTransaction()
virtual void rollback(TransactionIdPtr trxId)
virtual TransactionIdPtr beginTransaction()
std::shared_ptr< IFetchEventListeners > IFetchEventListenersPtr
virtual bool hasPendingEvents() const
virtual void rollback(TransactionIdPtr trxId)
virtual void onEventListenersReceived(const EventSyncResponse::eventListenersResponses_t &listeners)