1 /*
   2  * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 #ifndef SHARE_VM_LOGGING_LOGTAGSET_HPP
  25 #define SHARE_VM_LOGGING_LOGTAGSET_HPP
  26 #include "logging/logDecorators.hpp"
  27 #include "logging/logLevel.hpp"
  28 #include "logging/logOutputList.hpp"
  29 #include "logging/logTag.hpp"
  30 #include "utilities/globalDefinitions.hpp"
  31 
  32 // The tagset represents a combination of tags that occur in a log call somewhere.
  33 // Tagsets are created automatically by the LogTagSetMappings and should never be
  34 // instantiated directly somewhere else.
  35 class LogTagSet {
  36  private:
  37   static LogTagSet* _list;
  38   static size_t     _ntagsets;
  39 
  40   LogTagSet* const  _next;
  41   size_t            _ntags;
  42   LogTagType        _tag[LogTag::MaxTags];
  43 
  44   LogOutputList     _output_list;
  45   LogDecorators     _decorators;
  46 
  47   // Keep constructor private to prevent incorrect instantiations of this class.
  48   // Only LogTagSetMappings can create/contain instances of this class.
  49   LogTagSet(LogTagType t0, LogTagType t1, LogTagType t2, LogTagType t3, LogTagType t4);
  50 
  51   template <LogTagType T0, LogTagType T1, LogTagType T2, LogTagType T3, LogTagType T4>
  52   friend class LogTagSetMapping;
  53 
  54  public:
  55   static LogTagSet* first() {
  56     return _list;
  57   }
  58 
  59   LogTagSet* next() {
  60     return _next;
  61   }
  62 
  63   size_t ntags() const {
  64     return _ntags;
  65   }
  66 
  67   bool contains(LogTagType tag) const {
  68     for (size_t i = 0; _tag[i] != LogTag::__NO_TAG; i++) {
  69       if (tag == _tag[i]) {
  70         return true;
  71       }
  72     }
  73     return false;
  74   }
  75 
  76   void set_output_level(LogOutput* output, LogLevelType level) {
  77     _output_list.set_output_level(output, level);
  78   }
  79 
  80   // Refresh the decorators for this tagset to contain the decorators for all
  81   // of its current outputs combined with the given decorators.
  82   void update_decorators(const LogDecorators& decorator);
  83 
  84   int label(char *buf, size_t len);
  85   bool has_output(const LogOutput* output);
  86   bool is_level(LogLevelType level);
  87   void log(LogLevelType level, const char* msg);
  88 };
  89 
  90 template <LogTagType T0, LogTagType T1 = LogTag::__NO_TAG, LogTagType T2 = LogTag::__NO_TAG, LogTagType T3 = LogTag::__NO_TAG, LogTagType T4 = LogTag::__NO_TAG>
  91 class LogTagSetMapping {
  92 private:
  93   static LogTagSet _tagset;
  94 
  95 public:
  96   static LogTagSet& tagset() {
  97     return _tagset;
  98   }
  99 };
 100 
 101 template <LogTagType T0, LogTagType T1, LogTagType T2, LogTagType T3, LogTagType T4>
 102 LogTagSet LogTagSetMapping<T0, T1, T2, T3, T4>::_tagset(T0, T1, T2, T3, T4);
 103 
 104 #endif