00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef LOG_FIELD_H
00027 #define LOG_FIELD_H
00028
00029 #include "libts.h"
00030 #include "LogFieldAliasMap.h"
00031
00032 class LogAccess;
00033
00034 struct LogSlice
00035 {
00036 bool m_enable;
00037 int m_start;
00038 int m_end;
00039
00040 LogSlice() {
00041 m_enable = false;
00042 m_start = 0;
00043 m_end = INT_MAX;
00044 }
00045
00046
00047
00048
00049
00050 LogSlice(char *str);
00051
00052
00053
00054
00055
00056
00057
00058
00059 int toStrOffset(int strlen, int *offset);
00060 };
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074 class LogField
00075 {
00076 public:
00077 typedef int (LogAccess::*MarshalFunc) (char *buf);
00078 typedef int (*UnmarshalFunc) (char **buf, char *dest, int len);
00079 typedef int (*UnmarshalFuncWithSlice) (char **buf, char *dest, int len, LogSlice *slice);
00080 typedef int (*UnmarshalFuncWithMap) (char **buf, char *dest, int len, Ptr<LogFieldAliasMap> map);
00081 typedef void (LogAccess::*SetFunc) (char *buf, int len);
00082
00083
00084 enum Type
00085 {
00086 sINT = 0,
00087 dINT,
00088 STRING,
00089 IP,
00090 N_TYPES
00091 };
00092
00093 enum Container
00094 {
00095 NO_CONTAINER = 0,
00096 CQH,
00097 PSH,
00098 PQH,
00099 SSH,
00100 CSSH,
00101 ECQH,
00102 EPSH,
00103 EPQH,
00104 ESSH,
00105 ECSSH,
00106 ICFG,
00107 SCFG,
00108 RECORD,
00109 N_CONTAINERS
00110 };
00111
00112 enum Aggregate
00113 {
00114 NO_AGGREGATE = 0,
00115 eCOUNT,
00116 eSUM,
00117 eAVG,
00118 eFIRST,
00119 eLAST,
00120 N_AGGREGATES
00121 };
00122
00123 LogField(const char *name, const char *symbol, Type type, MarshalFunc marshal, UnmarshalFunc unmarshal, SetFunc _setFunc=NULL);
00124
00125 LogField(const char *name, const char *symbol, Type type,
00126 MarshalFunc marshal, UnmarshalFuncWithMap unmarshal, Ptr<LogFieldAliasMap> map, SetFunc _setFunc=NULL);
00127
00128 LogField(const char *field, Container container, SetFunc _setFunc=NULL);
00129 LogField(const LogField & rhs);
00130 ~LogField();
00131
00132 unsigned marshal_len(LogAccess * lad);
00133 unsigned marshal(LogAccess * lad, char *buf);
00134 unsigned marshal_agg(char *buf);
00135 unsigned unmarshal(char **buf, char *dest, int len);
00136 void display(FILE * fd = stdout);
00137 bool operator==(LogField & rhs);
00138 void updateField(LogAccess * lad, char* val, int len);
00139
00140 char *name()
00141 {
00142 return m_name;
00143 }
00144 char *symbol()
00145 {
00146 return m_symbol;
00147 }
00148 Type type()
00149 {
00150 return m_type;
00151 }
00152 Ptr<LogFieldAliasMap> map() {
00153 return m_alias_map;
00154 };
00155 Aggregate aggregate()
00156 {
00157 return m_agg_op;
00158 }
00159 bool is_time_field()
00160 {
00161 return m_time_field;
00162 }
00163
00164 void set_aggregate_op(Aggregate agg_op);
00165 void update_aggregate(int64_t val);
00166
00167 static Container valid_container_name(char *name);
00168 static Aggregate valid_aggregate_name(char *name);
00169 static bool fieldlist_contains_aggregates(char *fieldlist);
00170
00171 private:
00172 char *m_name;
00173 char *m_symbol;
00174 Type m_type;
00175 Container m_container;
00176 MarshalFunc m_marshal_func;
00177 UnmarshalFunc m_unmarshal_func;
00178 UnmarshalFuncWithMap m_unmarshal_func_map;
00179 Aggregate m_agg_op;
00180 int64_t m_agg_cnt;
00181 int64_t m_agg_val;
00182 bool m_time_field;
00183 Ptr<LogFieldAliasMap> m_alias_map;
00184 SetFunc m_set_func;
00185
00186 public:
00187 LINK(LogField, link);
00188 LogSlice m_slice;
00189
00190 private:
00191
00192
00193
00194
00195 LogField();
00196 LogField & operator=(const LogField & rhs);
00197 };
00198
00199 extern const char *container_names[];
00200 extern const char *aggregate_names[];
00201
00202
00203
00204
00205
00206
00207
00208 class LogFieldList
00209 {
00210 public:
00211 LogFieldList();
00212 ~LogFieldList();
00213
00214 void clear();
00215 void add(LogField * field, bool copy = true);
00216 LogField *find_by_name(const char *name) const;
00217 LogField *find_by_symbol(const char *symbol) const;
00218 unsigned marshal_len(LogAccess * lad);
00219 unsigned marshal(LogAccess * lad, char *buf);
00220 unsigned marshal_agg(char *buf);
00221
00222 LogField *first() const
00223 {
00224 return m_field_list.head;
00225 }
00226 LogField *next(LogField * here) const
00227 {
00228 return (here->link).next;
00229 }
00230 unsigned count();
00231 void display(FILE * fd = stdout);
00232
00233 private:
00234 unsigned m_marshal_len;
00235 Queue<LogField> m_field_list;
00236
00237
00238 LogFieldList(const LogFieldList & rhs);
00239 LogFieldList & operator=(const LogFieldList & rhs);
00240 };
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250 struct LogFieldIp {
00251 uint16_t _family;
00252 };
00253
00254 struct LogFieldIp4 : public LogFieldIp {
00255 in_addr_t _addr;
00256 };
00257
00258 struct LogFieldIp6 : public LogFieldIp {
00259 in6_addr _addr;
00260 };
00261
00262 union LogFieldIpStorage {
00263 LogFieldIp _ip;
00264 LogFieldIp4 _ip4;
00265 LogFieldIp6 _ip6;
00266 };
00267
00268 #endif