1 /** @file
2 
3   Public Rec defines and types
4 
5   @section license License
6 
7   Licensed to the Apache Software Foundation (ASF) under one
8   or more contributor license agreements.  See the NOTICE file
9   distributed with this work for additional information
10   regarding copyright ownership.  The ASF licenses this file
11   to you under the Apache License, Version 2.0 (the
12   "License"); you may not use this file except in compliance
13   with the License.  You may obtain a copy of the License at
14 
15       http://www.apache.org/licenses/LICENSE-2.0
16 
17   Unless required by applicable law or agreed to in writing, software
18   distributed under the License is distributed on an "AS IS" BASIS,
19   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20   See the License for the specific language governing permissions and
21   limitations under the License.
22  */
23 
24 #pragma once
25 
26 #include "tscore/ink_mutex.h"
27 #include "tscore/ink_rwlock.h"
28 #include "I_RecMutex.h"
29 
30 //-------------------------------------------------------------------------
31 // Error Values
32 //-------------------------------------------------------------------------
33 enum RecErrT {
34   REC_ERR_FAIL = -1,
35   REC_ERR_OKAY = 0,
36 };
37 
38 //-------------------------------------------------------------------------
39 // Types
40 //-------------------------------------------------------------------------
41 #define RecStringNull nullptr
42 
43 typedef int64_t RecInt;
44 typedef float RecFloat;
45 typedef char *RecString;
46 typedef const char *RecStringConst;
47 typedef int64_t RecCounter;
48 typedef int8_t RecByte;
49 typedef bool RecBool;
50 
51 enum RecT {
52   RECT_NULL    = 0x00,
53   RECT_CONFIG  = 0x01,
54   RECT_PROCESS = 0x02,
55   RECT_NODE    = 0x04,
56   RECT_LOCAL   = 0x10,
57   RECT_PLUGIN  = 0x20,
58   RECT_ALL     = 0x3F
59 };
60 
61 enum RecDataT {
62   RECD_NULL = 0,
63   RECD_INT,
64   RECD_FLOAT,
65   RECD_STRING,
66   RECD_COUNTER,
67 
68   RECD_MAX
69 };
70 
71 enum RecPersistT {
72   RECP_NULL,
73   RECP_PERSISTENT,
74   RECP_NON_PERSISTENT,
75 };
76 
77 // RECP_NULL should never be used by callers of RecRegisterStat*(). You have to decide
78 // whether to persist stats or not. The template goop below make sure that passing RECP_NULL
79 // is a very ugly compile-time error.
80 
81 namespace rec
82 {
83 namespace detail
84 {
85   template <RecPersistT> struct is_valid_persistence;
86 
87   template <> struct is_valid_persistence<RECP_PERSISTENT> {
88     static const RecPersistT value = RECP_PERSISTENT;
89   };
90 
91   template <> struct is_valid_persistence<RECP_NON_PERSISTENT> {
92     static const RecPersistT value = RECP_NON_PERSISTENT;
93   };
94 } // namespace detail
95 } // namespace rec
96 
97 #define REC_PERSISTENCE_TYPE(P) rec::detail::is_valid_persistence<P>::value
98 
99 enum RecUpdateT {
100   RECU_NULL,       // default: don't know the behavior
101   RECU_DYNAMIC,    // config can be updated dynamically w/ "traffic_ctl config reload"
102   RECU_RESTART_TS, // config requires TS to be restarted to take effect
103   RECU_RESTART_TM, // config requires TM/TS to be restarted to take effect
104 };
105 
106 enum RecCheckT {
107   RECC_NULL, // default: no check type defined
108   RECC_STR,  // config is a string
109   RECC_INT,  // config is an integer with a range
110   RECC_IP    // config is an ip address
111 };
112 
113 /// The source of the value.
114 /// @internal @c REC_SOURCE_NULL is useful for a return value, I don't see using it in the actual data.
115 /// @internal If this is changed, TSMgmtSource in apidefs.h.in must also be changed.
116 enum RecSourceT {
117   REC_SOURCE_NULL,     ///< No source / value not set.
118   REC_SOURCE_DEFAULT,  ///< Built in default.
119   REC_SOURCE_PLUGIN,   ///< Plugin supplied default.
120   REC_SOURCE_EXPLICIT, ///< Set by administrator (config file, external API, etc.)
121   REC_SOURCE_ENV       ///< Process environment variable.
122 };
123 
124 enum RecModeT {
125   RECM_NULL,
126   RECM_CLIENT,
127   RECM_SERVER,
128   RECM_STAND_ALONE,
129 };
130 
131 enum RecAccessT {
132   RECA_NULL,
133   RECA_NO_ACCESS,
134   RECA_READ_ONLY,
135 };
136 
137 //-------------------------------------------------------------------------
138 // Data Union
139 //-------------------------------------------------------------------------
140 union RecData {
141   RecInt rec_int;
142   RecFloat rec_float;
143   RecString rec_string;
144   RecCounter rec_counter;
145 };
146 
147 //-------------------------------------------------------------------------
148 // RawStat Structures
149 //-------------------------------------------------------------------------
150 struct RecRawStat {
151   int64_t sum;
152   int64_t count;
153   // XXX - these will waste some space because they are only needed for the globals
154   // this is a fix for bug TS-162, so I am trying to do as few code changes as
155   // possible, this should be revisited -bcall
156   int64_t last_sum;   // value from the last global sync
157   int64_t last_count; // value from the last global sync
158   uint32_t version;
159 };
160 
161 // WARNING!  It's advised that developers do not modify the contents of
162 // the RecRawStatBlock.  ^_^
163 struct RecRawStatBlock {
164   off_t ethr_stat_offset; // thread local raw-stat storage
165   RecRawStat **global;    // global raw-stat storage (ptr to RecRecord)
166   int num_stats;          // number of stats in this block
167   int max_stats;          // maximum number of stats for this block
168   ink_mutex mutex;
169 };
170 
171 //-------------------------------------------------------------------------
172 // RecCore Callback Types
173 //-------------------------------------------------------------------------
174 typedef int (*RecConfigUpdateCb)(const char *name, RecDataT data_type, RecData data, void *cookie);
175 typedef int (*RecStatUpdateFunc)(const char *name, RecDataT data_type, RecData *data, RecRawStatBlock *rsb, int id, void *cookie);
176 typedef int (*RecRawStatSyncCb)(const char *name, RecDataT data_type, RecData *data, RecRawStatBlock *rsb, int id);
177