audit.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2006-2008 The FLWOR Foundation.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  * http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #ifndef ZORBA_AUDIT_H
00018 #define ZORBA_AUDIT_H
00019 
00020 #include <iostream>
00021 #include <vector>
00022 #include <zorba/config.h>
00023 #include <zorba/zorba_string.h>
00024 
00025 namespace zorba {
00026 namespace audit {
00027 
00028   /**
00029     * an identifier for a set of pieces of information that can be audited
00030     * together.
00031     * It is assumed that all instances of PropertyGroup are created statically
00032     * and that they exist while a process exists.
00033     */
00034   class ZORBA_DLL_PUBLIC PropertyGroup {
00035   public:
00036     virtual size_t      pathLength()       const = 0;
00037     virtual const char* getSegment(size_t) const = 0;
00038   };
00039 
00040   /**
00041     * an identifier for a specific piece of information that can be audited.
00042     * It is assumed that all instances of Property are created statically
00043     * and that they exist while a process exists.
00044     */
00045   class ZORBA_DLL_PUBLIC Property {
00046   public:
00047     enum Type {
00048       INT,
00049       STRING
00050     };
00051 
00052     virtual ~Property();
00053 
00054     virtual const PropertyGroup& group() const = 0;
00055     virtual const char*          name()  const = 0;
00056     virtual long                 id()    const = 0;
00057     virtual Type                 type()  const = 0;
00058   };
00059 
00060   class ZORBA_DLL_PUBLIC Observation {
00061   public:
00062     virtual const Property&    property()    const = 0;
00063     virtual const String& stringValue() const = 0;
00064     virtual long long          longValue()   const = 0;
00065   };
00066 
00067   class ZORBA_DLL_PUBLIC Configuration {
00068   public:
00069     static void            getPropertyNames(std::vector<String>&);
00070     static size_t          getPropertyCount();
00071     static const Property& getProperty(size_t i);
00072     static bool            enableProperty(Configuration*, const std::vector<String>&, const String&);
00073 
00074     virtual size_t size() const                                         = 0;
00075     virtual void   enableAudit(size_t i)                                = 0;
00076     virtual void   enableAudit(const String& aPropertyName)        = 0;
00077     virtual bool   auditEnabled(size_t i) const                         = 0;
00078     virtual bool   auditEnabled(const String& aPropertyName) const = 0;
00079 
00080     virtual const Property* getDynamicProperty(const String&) const = 0;
00081 
00082     virtual std::ostream& write(std::ostream&) const = 0;
00083   };
00084 
00085   class ZORBA_DLL_PUBLIC Record {
00086   public:
00087     virtual const PropertyGroup& group() const = 0;
00088 
00089     virtual size_t             size()       const = 0;
00090     virtual const Observation& at(size_t i) const = 0;
00091 
00092     virtual void add(const Property& prop, long long val)          = 0;
00093     virtual void add(const Property& prop, const String& val) = 0;
00094   };
00095 
00096   class ZORBA_DLL_PUBLIC Event {
00097   public:
00098     static Event* get();
00099 
00100     virtual bool audit(const Property&) const = 0;
00101     virtual bool audit(const String&) const = 0;
00102 
00103     virtual const Property* getDynamicProperty(const String&) const = 0;
00104 
00105     virtual Record* createRecord()        = 0;
00106     virtual void    submitRecord(Record*) = 0;
00107 
00108     virtual size_t        size()     const = 0;
00109     virtual const Record* at(size_t) const = 0;
00110 
00111     virtual std::ostream& write(std::ostream&) const = 0;
00112   };
00113 
00114   class ZORBA_DLL_PUBLIC Provider {
00115   public:
00116     virtual Configuration* createConfiguration(size_t = 0)      = 0;
00117     virtual void           destroyConfiguration(Configuration*) = 0;
00118 
00119     virtual Event* createEvent(const Configuration*) = 0;
00120     virtual void   submitEvent(Event*)               = 0;
00121   };
00122 
00123 } /* namespace audit */
00124 } /* namespace zorba */
00125 
00126 inline std::ostream& operator<<(std::ostream& os, const zorba::audit::Configuration& c) {
00127   return c.write(os);
00128 }
00129 
00130 inline std::ostream& operator<<(std::ostream& os, const zorba::audit::Event& e) {
00131   return e.write(os);
00132 }
00133 
00134 #endif
00135 /* vim:set et sw=2 ts=2: */
blog comments powered by Disqus