EMANE  1.2.1
statisticservice.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 - Adjacent Link LLC, Bridgewater, New Jersey
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * * Neither the name of Adjacent Link LLC nor the names of its
16  * contributors may be used to endorse or promote products derived
17  * from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef EMANESTATISTICSERVICE_HEADER_
34 #define EMANESTATISTICSERVICE_HEADER_
35 
36 #include "emane/types.h"
37 #include "emane/statistic.h"
38 #include "emane/statistictable.h"
39 #include "emane/statisticinfo.h"
42 #include "emane/utils/singleton.h"
43 
44 #include <string>
45 #include <map>
46 #include <vector>
47 #include <memory>
48 
49 
50 namespace EMANE
51 {
52  using StatisticManifest = std::vector<StatisticInfo>;
53 
54  using StatisticTableManifest = std::vector<StatisticTableInfo>;
55 
56  class StatisticService : public Utils::Singleton<StatisticService>
57  {
58  public:
72  void registerStatistic(BuildId buildId,
73  const std::string & sName,
74  Any::Type type,
75  const StatisticProperties & properties,
76  const std::string & sDescription,
77  Statistic * pStatistic);
78 
79 
93  void registerTable(BuildId buildId,
94  const std::string & sName,
95  const StatisticProperties & properties,
96  const std::string & sDescription,
97  StatisticTablePublisher * pStatisticTablePublisher,
98  std::function<void(StatisticTablePublisher *)> clearFunc);
99 
100 
101  std::map<std::string,EMANE::Any>
102  queryStatistic(BuildId, const std::vector<std::string> & names) const;
103 
104  void clearStatistic(BuildId, const std::vector<std::string> & names) const;
105 
106  std::map<std::string,std::pair<StatisticTableLabels,StatisticTableValues>>
107  queryTable(BuildId, const std::vector<std::string> & names) const;
108 
109  void clearTable(BuildId, const std::vector<std::string> & names) const;
110 
112 
114 
115 
116  protected:
117  StatisticService() = default;
118 
119  private:
120  using StatisticStore =
121  std::map<std::string,std::pair<std::unique_ptr<Statistic>,StatisticInfo>>;
122 
123  using BuildIdStatisticStore = std::map<BuildId,StatisticStore>;
124  BuildIdStatisticStore buildIdStatisticStore_;
125 
126  using TableStore =
127  std::map<std::string,std::tuple<std::unique_ptr<StatisticTablePublisher>,
129  std::function<void(StatisticTablePublisher *)>>>;
130 
131  using BuildIdTableStore = std::map<BuildId,TableStore>;
132  BuildIdTableStore buildIdTableStore_;
133  };
134 
136 }
137 
138 #endif // EMANESTATISTICSERVICE_HEADER_
A StatisticTablePublisher produces two dimensional tables of Anys.
void clearStatistic(BuildId, const std::vector< std::string > &names) const
Ensure a class only has one instance, and provide a global point of access to it. ...
Definition: singleton.h:47
Type
Definition: any.h:52
std::vector< StatisticInfo > StatisticManifest
std::vector< StatisticTableInfo > StatisticTableManifest
std::map< std::string, std::pair< StatisticTableLabels, StatisticTableValues > > queryTable(BuildId, const std::vector< std::string > &names) const
StatisticManifest getStatisticManifest(BuildId id) const
Holds name, type, property and description of a Statistic.
Definition: statisticinfo.h:50
void registerStatistic(BuildId buildId, const std::string &sName, Any::Type type, const StatisticProperties &properties, const std::string &sDescription, Statistic *pStatistic)
StatisticTableManifest getTableManifest(BuildId id) const
The Statistic interface is the base class of all statistics. It provided methods to access and clear ...
Definition: statistic.h:48
Holds name, property and description of a StatisticTable.
void registerTable(BuildId buildId, const std::string &sName, const StatisticProperties &properties, const std::string &sDescription, StatisticTablePublisher *pStatisticTablePublisher, std::function< void(StatisticTablePublisher *)> clearFunc)
std::map< std::string, EMANE::Any > queryStatistic(BuildId, const std::vector< std::string > &names) const
void clearTable(BuildId, const std::vector< std::string > &names) const
std::uint32_t BuildId
Definition: types.h:60
Definition: agent.h:43