EMANE  1.0.1
eventservice.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2016 - Adjacent Link LLC, Bridgewater, New Jersey
3  * Copyright (c) 2008-2012 - DRS CenGen, LLC, Columbia, Maryland
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in
14  * the documentation and/or other materials provided with the
15  * distribution.
16  * * Neither the name of DRS CenGen, LLC nor the names of its
17  * contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #ifndef EMANEEVENTSERVICE_HEADER_
35 #define EMANEEVENTSERVICE_HEADER_
36 
37 #include "emane/types.h"
38 #include "emane/componenttypes.h"
40 #include "emane/eventserviceuser.h"
41 #include "emane/event.h"
42 #include "emane/inetaddr.h"
43 #include "emane/serializable.h"
44 #include "emane/utils/singleton.h"
45 #include "multicastsocket.h"
47 
48 #include <map>
49 #include <tuple>
50 #include <atomic>
51 #include <thread>
52 #include <uuid.h>
53 
54 
55 namespace EMANE
56 {
57  class EventService : public Utils::Singleton<EventService>
58  {
59  public:
60  ~EventService();
61 
62  void open(const INETAddr & eventChannelAddress,
63  const std::string & sDevice,
64  int iTTL,
65  bool loopbackEnable,
66  const uuid_t & uuid);
67 
68  void close();
69 
70  void registerEventServiceUser(BuildId buildId,
71  EventServiceUser * pEventServiceUser,
72  NEMId = 0);
73 
74  void registerEvent(BuildId buildId,EventId eventId);
75 
76 
77  void sendEvent(BuildId buildId,
78  NEMId nemId,
79  const Event & event) const;
80 
81  void sendEvent(BuildId buildId,
82  NEMId nemId,
83  EventId eventId,
84  const Serialization & serialization) const;
85 
86 
87  void processEventMessage(NEMId nemId,
88  EventId eventId,
89  const Serialization & serialization,
90  NEMId ignoreNEM = {}) const;
91 
92  void setStatEventCountRowLimit(size_t rows);
93 
94  protected:
95  EventService();
96 
97  private:
98  using EventServiceUserMap = std::map<BuildId, std::pair<NEMId,EventServiceUser *>>;
99 
100  using EventRegistrationMap = std::multimap<EventId, std::tuple<BuildId,NEMId,EventServiceUser *>>;
101 
102  EventRegistrationMap eventRegistrationMap_;
103 
104  EventServiceUserMap eventServiceUserMap_;
105 
106  MulticastSocket mcast_;
107  std::thread thread_;
108 
109  bool bOpen_;
110  bool bCancel_;
111  uuid_t uuid_;
112 
113  mutable EventStatisticPublisher eventStatisticPublisher_;
114  mutable std::atomic<std::uint64_t> u64SequenceNumber_;
115 
116  void process();
117 
118  };
119 
121 }
122 
123 #endif //EMANEEVENTSERVICE_HEADER_
std::string Serialization
Definition: serializable.h:42
EventServiceUser interface.
Event interface is the base for all events.
Definition: event.h:46
Ensure a class only has one instance, and provide a global point of access to it. ...
Definition: singleton.h:47
void sendEvent(BuildId buildId, NEMId nemId, const Event &event) const
std::uint16_t EventId
Definition: types.h:53
void open(const INETAddr &eventChannelAddress, const std::string &sDevice, int iTTL, bool loopbackEnable, const uuid_t &uuid)
Definition: eventservice.cc:92
std::uint16_t NEMId
Definition: types.h:52
void registerEventServiceUser(BuildId buildId, EventServiceUser *pEventServiceUser, NEMId=0)
Definition: eventservice.cc:85
void setStatEventCountRowLimit(size_t rows)
void registerEvent(BuildId buildId, EventId eventId)
Definition: eventservice.cc:67
std::uint32_t BuildId
Definition: types.h:60
Definition: agent.h:43
void processEventMessage(NEMId nemId, EventId eventId, const Serialization &serialization, NEMId ignoreNEM={}) const