client-cpp  0.6.3
LogCollector.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 LOGCOLLECTOR_HPP_
18 #define LOGCOLLECTOR_HPP_
19 
20 #include "kaa/KaaDefaults.hpp"
21 
22 #ifdef KAA_USE_LOGGING
23 
25 
26 #include <memory>
27 #include "kaa/KaaThread.hpp"
32 
33 namespace kaa {
34 
38 class LogCollector : public ILogCollector {
39 public:
40  LogCollector();
41  LogCollector(ILogStorage* storage, ILogStorageStatus* status, ILogUploadConfiguration* configuration, ILogUploadStrategy* strategy);
42 
43  void addLogRecord(const SuperRecord& record) {
44  makeLogRecord(LogRecord(record));
45  }
46 
47  void setStorage(ILogStorage * storage);
48  void setStorageStatus(ILogStorageStatus * status);
49  void setConfiguration(ILogUploadConfiguration * configuration);
50  void setUploadStrategy(ILogUploadStrategy * strategy);
51 
52  LogSyncRequest getLogUploadRequest();
53  void onLogUploadResponse(const LogSyncResponse& response);
54 
55  void setTransport(LoggingTransport *transport);
56 
57  ~LogCollector() {}
58 
59 private:
60  void makeLogRecord(const LogRecord& record);
61  void doUpload();
62  void doCleanup();
63 private:
64  ILogStorage * storage_;
65  ILogStorageStatus * status_;
66  ILogUploadConfiguration * configuration_;
67  ILogUploadStrategy * strategy_;
68 
69  LoggingTransport* transport_;
70 
71  std::map<std::int32_t, LogSyncRequest> requests_;
72 
73  KAA_MUTEX_DECLARE(storageGuard_);
74  KAA_MUTEX_DECLARE(requestsGuard_);
75  bool isUploading_;
76 
77  std::unique_ptr<MemoryLogStorage> defaultLogStorage_;
78  std::unique_ptr<SizeUploadStrategy> defaultUploadStrategy_;
79  std::unique_ptr<DefaultLogUploadConfiguration> defaultConfiguration_;
80 };
81 
82 } // namespace kaa
83 
84 #endif
85 
86 #endif /* LOGCOLLECTOR_HPP_ */
#define KAA_MUTEX_DECLARE(name)
Definition: KaaThread.hpp:71