Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
scanline_status.h
Go to the documentation of this file.
1 /*
2  * Copyright 2013 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http:///www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 #ifndef PAGESPEED_KERNEL_IMAGE_SCANLINE_STATUS_H_
20 #define PAGESPEED_KERNEL_IMAGE_SCANLINE_STATUS_H_
21 
22 #include <cstdarg>
26 
27 namespace pagespeed {
28 
29 namespace image_compression {
30 
31 #if defined(PAGESPEED_SCANLINE_STATUS) || \
32  defined(PAGESPEED_SCANLINE_STATUS_SOURCE) || \
33  defined(PAGESPEED_SCANLINE_STATUS_ENUM_NAME) || \
34  defined(PAGESPEED_SCANLINE_STATUS_ENUM_STRING)
35 #error "Preprocessor macro collision."
36 #endif
37 
38 #define PAGESPEED_SCANLINE_STATUS(_X) \
39  _X(SCANLINE_STATUS_UNINITIALIZED), \
40  _X(SCANLINE_STATUS_SUCCESS), \
41  _X(SCANLINE_STATUS_UNSUPPORTED_FORMAT), \
42  _X(SCANLINE_STATUS_UNSUPPORTED_FEATURE), \
43  _X(SCANLINE_STATUS_PARSE_ERROR), \
44  _X(SCANLINE_STATUS_MEMORY_ERROR), \
45  _X(SCANLINE_STATUS_INTERNAL_ERROR), \
46  _X(SCANLINE_STATUS_TIMEOUT_ERROR), \
47  _X(SCANLINE_STATUS_INVOCATION_ERROR), \
48  \
49  _X(NUM_SCANLINE_STATUS)
50 
53 #define PAGESPEED_SCANLINE_STATUS_SOURCE(_X) \
54  _X(SCANLINE_UNKNOWN), \
55  _X(SCANLINE_PNGREADER), \
56  _X(SCANLINE_PNGREADERRAW), \
57  _X(SCANLINE_GIFREADER), \
58  _X(SCANLINE_GIFREADERRAW), \
59  _X(SCANLINE_JPEGREADER), \
60  _X(SCANLINE_WEBPREADER), \
61  _X(SCANLINE_RESIZER), \
62  _X(SCANLINE_PNGWRITER), \
63  _X(SCANLINE_JPEGWRITER), \
64  _X(SCANLINE_WEBPWRITER), \
65  _X(SCANLINE_UTIL), \
66  _X(SCANLINE_PIXEL_FORMAT_OPTIMIZER), \
67  _X(FRAME_TO_SCANLINE_READER_ADAPTER), \
68  _X(FRAME_TO_SCANLINE_WRITER_ADAPTER), \
69  _X(SCANLINE_TO_FRAME_READER_ADAPTER), \
70  _X(SCANLINE_TO_FRAME_WRITER_ADAPTER), \
71  _X(FRAME_GIFREADER), \
72  _X(FRAME_WEBPWRITER), \
73  _X(FRAME_PADDING_READER), \
74  \
75  _X(NUM_SCANLINE_SOURCE)
76 
77 #define PAGESPEED_SCANLINE_STATUS_ENUM_NAME(_Y) _Y
78 #define PAGESPEED_SCANLINE_STATUS_ENUM_STRING(_Y) #_Y
79 
80 enum ScanlineStatusType {
81  PAGESPEED_SCANLINE_STATUS(PAGESPEED_SCANLINE_STATUS_ENUM_NAME)
82 };
83 
84 enum ScanlineStatusSource {
85  PAGESPEED_SCANLINE_STATUS_SOURCE(PAGESPEED_SCANLINE_STATUS_ENUM_NAME)
86 };
87 
94  public:
95  ScanlineStatus() : type_(SCANLINE_STATUS_SUCCESS),
96  source_(SCANLINE_UNKNOWN),
97  details_() {}
98 
99  ScanlineStatus(ScanlineStatusType type,
100  ScanlineStatusSource source,
101  const GoogleString& details)
102  : type_(type),
103  source_(source),
104  details_(details) {}
105 
106  explicit ScanlineStatus(ScanlineStatusType type)
107  : type_(type),
108  source_(SCANLINE_UNKNOWN),
109  details_() {}
110 
114  static ScanlineStatus New(ScanlineStatusType type,
115  ScanlineStatusSource source,
116  const char* details,
117  ...) INSTAWEB_PRINTF_FORMAT(3, 4) {
118  va_list args;
119  GoogleString detail_list;
122  va_start(args, details);
123  StringAppendV(&detail_list, details, args);
124  va_end(args);
125  return ScanlineStatus(type, source, detail_list);
126  };
127 
128  bool Success() const { return (type_ == SCANLINE_STATUS_SUCCESS); }
129  ScanlineStatusType type() const { return type_; }
130  ScanlineStatusSource source() const { return source_; }
131  const GoogleString& details() const { return details_; }
132 
133  const char* TypeStr() const {
134  static const char* const kScanlineStatusTypeNames[] = {
135  PAGESPEED_SCANLINE_STATUS(PAGESPEED_SCANLINE_STATUS_ENUM_STRING)
136  };
137  return kScanlineStatusTypeNames[type_];
138  }
139 
140  const char* SourceStr() const {
141  static const char* const kScanlineStatusSourceNames[] = {
142  PAGESPEED_SCANLINE_STATUS_SOURCE(PAGESPEED_SCANLINE_STATUS_ENUM_STRING)
143  };
144  return kScanlineStatusSourceNames[source_];
145  }
146 
147  const GoogleString ToString() const {
148  return GoogleString(SourceStr()) + "/" + TypeStr() + " " + details();
149  }
150 
153  bool ComesFromReader() const {
154  switch (source_) {
155  case SCANLINE_PNGREADER:
156  case SCANLINE_PNGREADERRAW:
157  case SCANLINE_GIFREADER:
158  case SCANLINE_GIFREADERRAW:
159  case SCANLINE_JPEGREADER:
160  case SCANLINE_WEBPREADER:
161  case FRAME_TO_SCANLINE_READER_ADAPTER:
162  case SCANLINE_TO_FRAME_READER_ADAPTER:
163  case FRAME_GIFREADER:
164  case FRAME_PADDING_READER:
165  return true;
166  default:
167  return false;
168  }
169  return false;
170  }
171 
172  private:
173  ScanlineStatusType type_;
174  ScanlineStatusSource source_;
175  GoogleString details_;
176 
179 };
180 
181 #undef PAGESPEED_SCANLINE_STATUS_ENUM_STRING
182 #undef PAGESPEED_SCANLINE_STATUS_ENUM_NAME
183 #undef PAGESPEED_SCANLINE_STATUS_SOURCE
184 #undef PAGESPEED_SCANLINE_STATUS
185 
189 #define PS_LOGGED_STATUS(_LOGGER, _HANDLER, _TYPE, _SOURCE, ...) \
190  (_LOGGER(_HANDLER, #_SOURCE "/" #_TYPE " " __VA_ARGS__), \
191  ScanlineStatus::New(_TYPE, _SOURCE, __VA_ARGS__))
192 
193 }
194 
195 }
196 
197 #endif
Definition: scanline_status.h:93
bool ComesFromReader() const
Definition: scanline_status.h:153
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
static ScanlineStatus New(ScanlineStatusType type, ScanlineStatusSource source, const char *details,...) INSTAWEB_PRINTF_FORMAT(3
#define PAGESPEED_SCANLINE_STATUS_SOURCE(_X)
Definition: scanline_status.h:53
#define INSTAWEB_PRINTF_FORMAT(x, y)
< Not GCC
Definition: printf_format.h:34