client-cpp  0.0.1-SNAPSHOT
MemoryLogStorage.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2014 CyberVision, 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 
17 #ifndef MEMORYLOGSTORAGE_HPP_
18 #define MEMORYLOGSTORAGE_HPP_
19 
20 #include <list>
21 
22 #include "kaa/log/ILogStorage.hpp"
25 
26 namespace kaa {
27 
34 private:
35  typedef struct __MemoryLogStorage__LogBlock__ {
36  __MemoryLogStorage__LogBlock__(size_t blockSize)
37  : actualSize_(0)
38  , blockSize_(blockSize)
39  , finalized_(false)
40  {
41  }
42 
43  std::string blockId;
45  size_t actualSize_;
46  size_t blockSize_;
47  bool finalized_;
48  } LogBlock;
49 
50 public:
51  MemoryLogStorage(size_t blockSize) : blockSize_(blockSize), occupiedSize_(0) {
52  LogBlock initialBlock(blockSize);
53  initialBlock.actualSize_ = 0;
54  initialBlock.finalized_ = false;
55  logBlocks_.push_back(initialBlock);
56  }
58 
62  void addLogRecord(const LogRecord & record);
63  container_type getRecordBlock(size_t blockSize, const std::string& blockId);
64  void removeRecordBlock(const std::string& blockId);
65  void notifyUploadFailed(const std::string& blockId);
66  void removeOldestRecords(size_t allowedVolume);
67 
71  size_t getConsumedVolume() const;
72  size_t getRecordsCount() const;
73 
74 private:
75  void resize(size_t blockSize);
76 
77 private:
78  size_t blockSize_;
79  size_t occupiedSize_;
80  std::list<LogBlock> logBlocks_;
81 };
82 
83 } // namespace kaa
84 
85 #endif /* MEMORYLOGSTORAGE_HPP_ */
void addLogRecord(const LogRecord &record)
void removeRecordBlock(const std::string &blockId)
void notifyUploadFailed(const std::string &blockId)
std::list< LogRecord > container_type
Definition: ILogStorage.hpp:34
container_type getRecordBlock(size_t blockSize, const std::string &blockId)
size_t getConsumedVolume() const
void removeOldestRecords(size_t allowedVolume)
size_t getRecordsCount() const
MemoryLogStorage(size_t blockSize)