• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

LogField.h

Go to the documentation of this file.
00001 /** @file
00002 
00003   A brief file description
00004 
00005   @section license License
00006 
00007   Licensed to the Apache Software Foundation (ASF) under one
00008   or more contributor license agreements.  See the NOTICE file
00009   distributed with this work for additional information
00010   regarding copyright ownership.  The ASF licenses this file
00011   to you under the Apache License, Version 2.0 (the
00012   "License"); you may not use this file except in compliance
00013   with the License.  You may obtain a copy of the License at
00014 
00015       http://www.apache.org/licenses/LICENSE-2.0
00016 
00017   Unless required by applicable law or agreed to in writing, software
00018   distributed under the License is distributed on an "AS IS" BASIS,
00019   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020   See the License for the specific language governing permissions and
00021   limitations under the License.
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   // Initialize LogSlice by slice notation,
00048   // the str looks like: "xxx[0:30]".
00049   //
00050   LogSlice(char *str);
00051 
00052   //
00053   // Convert slice notation to target string's offset,
00054   // return the available length belongs to this slice.
00055   //
00056   // Use the offset and return value, we can locate the
00057   // string content indicated by this slice.
00058   //
00059   int toStrOffset(int strlen, int *offset);
00060 };
00061 
00062 
00063 /*-------------------------------------------------------------------------
00064   LogField
00065 
00066   This class represents a field that can be logged.  To construct a new
00067   field, we need to know its name, its symbol, its datatype, and the
00068   pointer to its LogAccess marshalling routine.  Example:
00069 
00070       LogField ("client_host_ip", "chi", LogField::INT,
00071                 &LogAccess::marshal_client_host_ip);
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, ///< IP Address.
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;   // place data into buffer
00177   UnmarshalFunc m_unmarshal_func;       // create a string of the data
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; // map sINT <--> string
00184   SetFunc m_set_func;
00185 
00186 public:
00187   LINK(LogField, link);
00188   LogSlice m_slice;
00189 
00190 private:
00191 // luis, check where this is used and what it does
00192 //    void init (char *name, char *symbol, Type type);
00193 
00194   // -- member functions that are not allowed --
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   LogFieldList
00204 
00205   This class maintains a list of LogField objects (tah-dah).
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   // -- member functions that are not allowed --
00238   LogFieldList(const LogFieldList & rhs);
00239   LogFieldList & operator=(const LogFieldList & rhs);
00240 };
00241 
00242 /** Base IP address data.
00243     To unpack an IP address, the generic memory is first cast to
00244     this type to get the family. That pointer can then be static_cast
00245     to the appropriate subtype to get the actual address data.
00246 
00247     @note We don't use our own enum for the family. Instead we use
00248     @c AF_INET and @c AF_INET6.
00249 */
00250 struct LogFieldIp {
00251   uint16_t _family; ///< IP address family.
00252 };
00253 /// IPv4 address as log field.
00254 struct LogFieldIp4 : public LogFieldIp {
00255   in_addr_t _addr; ///< IPv4 address.
00256 };
00257 /// IPv6 address as log field.
00258 struct LogFieldIp6 : public LogFieldIp {
00259   in6_addr _addr; ///< IPv6 address.
00260 };
00261 /// Something big enough to hold any of the IP field types.
00262 union LogFieldIpStorage {
00263   LogFieldIp _ip;
00264   LogFieldIp4 _ip4;
00265   LogFieldIp6 _ip6;
00266 };
00267 
00268 #endif

Generated by  doxygen 1.7.1