Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
shared_circular_buffer.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011 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_SHAREDMEM_SHARED_CIRCULAR_BUFFER_H_
20 #define PAGESPEED_KERNEL_SHAREDMEM_SHARED_CIRCULAR_BUFFER_H_
21 
27 
28 namespace net_instaweb {
29 
30 class AbstractSharedMem;
31 class AbstractSharedMemSegment;
32 class AbstractMutex;
33 class CircularBuffer;
34 class MessageHandler;
35 
42 
43 class SharedCircularBuffer : public Writer {
44  public:
49  const int buffer_capacity,
50  const GoogleString& filename_prefix,
51  const GoogleString& filename_suffix);
52  virtual ~SharedCircularBuffer();
57  bool InitSegment(bool parent, MessageHandler* handler);
59  void Clear();
61  virtual bool Write(const StringPiece& message, MessageHandler* handler);
62  virtual bool Flush(MessageHandler* message_handler) { return true; }
63 
65  virtual bool Dump(Writer* writer, MessageHandler* handler);
70  void GlobalCleanup(MessageHandler* handler);
71 
72  private:
73  bool InitMutex(MessageHandler* handler);
74  GoogleString SegmentName() const;
75 
78  AbstractSharedMem* shm_runtime_;
80  const int buffer_capacity_;
82  CircularBuffer* buffer_;
83  const GoogleString filename_prefix_;
85  const GoogleString filename_suffix_;
90 
91 
92 };
93 
94 }
95 
96 #endif
bool InitSegment(bool parent, MessageHandler *handler)
SharedCircularBuffer(AbstractSharedMem *shm_runtime, const int buffer_capacity, const GoogleString &filename_prefix, const GoogleString &filename_suffix)
virtual bool Dump(Writer *writer, MessageHandler *handler)
Write content of data in buffer to writer, without clearing the buffer.
Definition: circular_buffer.h:32
GoogleString ToString(MessageHandler *handler)
Return data content as string. This is for test purposes.
Definition: scoped_ptr.h:30
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
Definition: abstract_shared_mem.h:86
void GlobalCleanup(MessageHandler *handler)
Definition: shared_circular_buffer.h:43
virtual bool Write(const StringPiece &message, MessageHandler *handler)
Write content to circular buffer.
Interface for writing bytes to an output stream.
Definition: writer.h:29
Definition: message_handler.h:39
void Clear()
Reset circular buffer.