client-cpp  0.0.1-SNAPSHOT
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 
21 
22 #include <boost/thread/mutex.hpp>
23 #include <boost/scoped_ptr.hpp>
28 
29 namespace kaa {
30 
34 class LogCollector : public ILogCollector {
35 public:
36  LogCollector();
37  LogCollector(ILogStorage* storage, ILogStorageStatus* status, ILogUploadConfiguration* configuration, ILogUploadStrategy* strategy);
38 
39  void addLogRecord(const SuperRecord& record) {
40  makeLogRecord(LogRecord(record));
41  }
42 
43  void setStorage(ILogStorage * storage);
44  void setStorageStatus(ILogStorageStatus * status);
45  void setConfiguration(ILogUploadConfiguration * configuration);
46  void setUploadStrategy(ILogUploadStrategy * strategy);
47 
48  LogSyncRequest getLogUploadRequest();
49  void onLogUploadResponse(const LogSyncResponse& response);
50 
51  void setTransport(LoggingTransport *transport);
52 
54 
55 private:
56  void makeLogRecord(const LogRecord& record);
57  void doUpload();
58  void doCleanup();
59 private:
60  typedef boost::mutex mutex_type;
61  typedef boost::unique_lock<mutex_type> lock_type;
62 
63  ILogStorage * storage_;
64  ILogStorageStatus * status_;
65  ILogUploadConfiguration * configuration_;
66  ILogUploadStrategy * strategy_;
67 
68  LoggingTransport* transport_;
69 
70  std::map<std::string, LogSyncRequest> requests_;
71 
72  mutex_type storageGuard_;
73  mutex_type requestsGuard_;
74  bool isUploading_;
75 
76  boost::scoped_ptr<MemoryLogStorage> defaultLogStorage_;
77  boost::scoped_ptr<SizeUploadStrategy> defaultUploadStrategy_;
78  boost::scoped_ptr<DefaultLogUploadConfiguration> defaultConfiguration_;
79 };
80 
81 } // namespace kaa
82 
83 #endif /* LOGCOLLECTOR_HPP_ */
void onLogUploadResponse(const LogSyncResponse &response)
void setConfiguration(ILogUploadConfiguration *configuration)
void setStorage(ILogStorage *storage)
LogSyncRequest getLogUploadRequest()
void setTransport(LoggingTransport *transport)
void addLogRecord(const SuperRecord &record)
void setUploadStrategy(ILogUploadStrategy *strategy)
void setStorageStatus(ILogStorageStatus *status)