PMDA++  0.4.4
Header-only C++ library for writing PCP PMDAs
instance_domain.hpp
Go to the documentation of this file.
1 // Copyright Paul Colby 2013 - 2015.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE.md or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
5 
6 /**
7  * @file
8  * @brief Defines the pcp::instance_domain class.
9  */
10 
11 #ifndef __PCP_CPP_INSTANCE_DOMAIN_HPP__
12 #define __PCP_CPP_INSTANCE_DOMAIN_HPP__
13 
14 #include "config.hpp"
15 #include "types.hpp"
16 
17 #include <map>
18 
19 PCP_CPP_BEGIN_NAMESPACE
20 
21 namespace pcp {
22 
23 /**
24  * @brief Basic instance domain information.
25  */
26 struct instance_info {
27  std::string instance_name; ///< Instance domain name.
28  std::string short_description; ///< Instance domain short description.
29  std::string verbose_description; ///< Instance domain verbose description.
30 };
31 
32 /**
33  * @brief Performance metric instance domain.
34  */
35 class instance_domain : public std::map<instance_id_type, const instance_info> {
36 
37 public:
38 
39  /**
40  * @brief [Default] Constructor
41  *
42  * @param domain_id User-defined ID for this instance domain.
43  *
44  * @see set_domain_id
45  */
46  explicit instance_domain(domain_id_type domain_id = PM_INDOM_NULL)
47  : domain_id(domain_id),
48  pm_instance_domain(PM_INDOM_NULL)
49  {
50 
51  }
52 
53  /**
54  * @brief Get this instance domain's user-defined ID.
55  *
56  * @return This instance domain's user-defined ID.
57  *
58  * @see set_domain_id
59  */
61  {
62  return domain_id;
63  }
64 
65  /**
66  * @brief Get this instance domain's PCP-modifed ID.
67  *
68  * This function is used to track the instance ID as modifed by PCP's
69  * pmdaInit function. This is essentially the same as the ID returned by
70  * get_domain_id, with a number of higher bits set to PCP-internal values.
71  *
72  * This can be necessary for passing this instance domain's ID to some other
73  * PCP built-in functions.
74  *
75  * @return This instance domain's PCP-modified ID.
76  *
77  * @see set_pm_instance_domain
78  * @see pmdaInit
79  */
80  pmInDom get_pm_instance_domain() const
81  {
82  return pm_instance_domain;
83  }
84 
85  /**
86  * @brief Set this instance domain's user-defined ID.
87  *
88  * @param id The domiain ID to set.
89  */
91  {
92  domain_id = id;
93  }
94 
95  /**
96  * @brief Set this instance domain's PCP-modified ID.
97  *
98  * This function is normally used by the pcp::pmda class to update the
99  * domain ID after invoking pmdaInit.
100  *
101  * @param domain The domiain ID to set.
102  */
103  void set_pm_instance_domain(const pmInDom domain)
104  {
105  pm_instance_domain = domain;
106  }
107 
108  /**
109  * @brief Functor for setting this instance's domain ID.
110  *
111  * This functor is equivalent to the set_domain_id function, but allows for
112  * convenient functor chaining.
113  *
114  * @param domain_id ID for the instance domain.
115  *
116  * @return A reference to this instance domain.
117  */
119  {
120  set_domain_id(domain_id);
121  set_pm_instance_domain(PM_INDOM_NULL);
122  return *this;
123  }
124 
125  /**
126  * @brief Instance insertion functor.
127  *
128  * This functor allows for convenient insertion of instances into this
129  * domain.
130  *
131  * @param instance_id ID for the instance to insert.
132  * @param info Basic instance information.
133  *
134  * @return A reference to this instance domain.
135  */
137  const instance_info &info)
138  {
139  insert(value_type(instance_id, info));
140  return *this;
141  }
142 
143  /**
144  * @brief Instance insertion functor.
145  *
146  * This functor allows for convenient insertion of instances into this
147  * domain.
148  *
149  * @param instance_id ID for the instance to insert.
150  * @param instance_name Name of the instance to insert.
151  * @param short_description Short description of the instance to insert.
152  * @param verbose_description Verbose description of the instance to insert.
153  *
154  * @return A reference to this instance domain.
155  */
157  const std::string &instance_name,
158  const std::string &short_description = std::string(),
159  const std::string &verbose_description = std::string())
160  {
161  instance_info info;
165  insert(value_type(instance_id, info));
166  return *this;
167  }
168 
169  /**
170  * @brief Operator for implicit cast to pmInDom.
171  *
172  * This operator allows this object to be used wherever PCP functions
173  * require a pmInDom instance. It is equivalent to calling the
174  * get_pm_instance_domain function.
175  *
176  * @return This instance's PCP-modified ID.
177  */
178  inline operator pmInDom() const
179  {
180  return pm_instance_domain;
181  }
182 
183 private:
184  domain_id_type domain_id; ///< User-defined ID for this instance.
185  pmInDom pm_instance_domain; ///< PCP modified ID for this instance.
186 };
187 
188 } // pcp namespace.
189 
190 PCP_CPP_END_NAMESPACE
191 
192 #endif
unsigned int instance_id_type
https://github.com/pcolby/pcp-pmda-cpp/issues/11
Definition: types.hpp:25
Basic instance domain information.
Definition: atom.hpp:20
instance_domain & operator()(const instance_id_type instance_id, const instance_info &info)
Instance insertion functor.
pmInDom get_pm_instance_domain() const
Get this instance domain&#39;s PCP-modifed ID.
Sets up common PMDA++ library macros.
Declares various types used throughout the PMDA++ library.
std::string instance_name
Instance domain name.
Performance metric instance domain.
void set_pm_instance_domain(const pmInDom domain)
Set this instance domain&#39;s PCP-modified ID.
std::string verbose_description
Instance domain verbose description.
instance_domain & operator()(const instance_id_type instance_id, const std::string &instance_name, const std::string &short_description=std::string(), const std::string &verbose_description=std::string())
Instance insertion functor.
instance_domain(domain_id_type domain_id=PM_INDOM_NULL)
[Default] Constructor
std::string short_description
Instance domain short description.
uint_fast16_t domain_id_type
__pmID_int::cluster (9-bits); pmdaIndom::it_indom
Definition: types.hpp:24
void set_domain_id(const domain_id_type id)
Set this instance domain&#39;s user-defined ID.
instance_domain & operator()(const domain_id_type domain_id)
Functor for setting this instance&#39;s domain ID.
domain_id_type get_domain_id() const
Get this instance domain&#39;s user-defined ID.