client-cpp  0.7.4
LogCollector.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2014-2015 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 
21 #include <chrono>
22 #include <memory>
23 #include <unordered_map>
24 
25 #include "kaa/KaaThread.hpp"
26 #include "kaa/log/ILogStorage.hpp"
32 #include "kaa/utils/KaaTimer.hpp"
33 
34 namespace kaa {
35 
36 class IExecutorContext;
37 class LoggingTransport;
39 
40 typedef std::chrono::system_clock clock_t;
41 
42 class TimeoutInfo {
43 
44 public:
45  TimeoutInfo(const std::int32_t& transportAccessPointId, const std::chrono::time_point<clock_t>& timeoutTime)
46  : transportAccessPointId_(transportAccessPointId), timeoutTime_(timeoutTime) {}
47 
48  std::int32_t getTransportAccessPointId() const {
49  return transportAccessPointId_;
50  }
51 
52  std::chrono::time_point<clock_t> getTimeoutTime() const {
53  return timeoutTime_;
54  }
55 
56 private:
57  std::int32_t transportAccessPointId_;
58  std::chrono::time_point<clock_t> timeoutTime_;
59 };
60 
65 public:
66  LogCollector(IKaaChannelManagerPtr manager, IExecutorContext& executorContext, const KaaClientProperties& clientProperties);
67 
68  virtual void addLogRecord(const KaaUserLogRecord& record);
69 
70  virtual void setStorage(ILogStoragePtr storage);
71  virtual void setUploadStrategy(ILogUploadStrategyPtr strategy);
72 
73  virtual std::shared_ptr<LogSyncRequest> getLogUploadRequest();
74  virtual void onLogUploadResponse(const LogSyncResponse& response);
75 
76  void setTransport(LoggingTransport* transport);
77 
78 private:
79  virtual void retryLogUpload();
80  virtual void retryLogUpload(std::size_t delay);
81 
82  virtual void switchAccessPoint();
83 
84  void doSync();
85  void processLogUploadDecision(LogUploadStrategyDecision decision);
86 
87  bool isDeliveryTimeout();
88  void addDeliveryTimeout(std::int32_t requestId);
89  bool removeDeliveryTimeout(std::int32_t requestId);
90 
91  void startTimeoutTimer();
92  void startLogUploadCheckTimer();
93 
94  void processTimeout();
95 
96  void rescheduleTimers();
97 
98  bool isUploadAllowed();
99 
100 private:
101  ILogStoragePtr storage_;
102  KAA_MUTEX_DECLARE(storageGuard_);
103 
104  ILogUploadStrategyPtr uploadStrategy_;
105 
106  LoggingTransport* transport_;
107  KAA_MUTEX_DECLARE(transportGuard_);
108 
109  IKaaChannelManagerPtr channelManager_;
110 
111  std::unordered_map<std::int32_t, TimeoutInfo> timeouts_;
112  std::int32_t timeoutAccessPointId_;
113  KAA_MUTEX_DECLARE(timeoutsGuard_);
114 
115  KaaTimer<void ()> logUploadCheckTimer_;
116  KaaTimer<void ()> scheduledUploadTimer_;
117  KaaTimer<void ()> timeoutTimer_;
118 
119  IExecutorContext& executorContext_;
120 };
121 
122 } // namespace kaa
123 
124 #endif /* LOGCOLLECTOR_HPP_ */
virtual void setStorage(ILogStoragePtr storage)
Sets the new log storage.
void setTransport(LoggingTransport *transport)
virtual void setUploadStrategy(ILogUploadStrategyPtr strategy)
Sets the new log upload strategy.
std::shared_ptr< ILogStorage > ILogStoragePtr
virtual std::shared_ptr< LogSyncRequest > getLogUploadRequest()
LogCollector(IKaaChannelManagerPtr manager, IExecutorContext &executorContext, const KaaClientProperties &clientProperties)
virtual void addLogRecord(const KaaUserLogRecord &record)
Adds a new log record to the log storage.
TimeoutInfo(const std::int32_t &transportAccessPointId, const std::chrono::time_point< clock_t > &timeoutTime)
The public interface to the Kaa log collecting subsystem.
virtual void onLogUploadResponse(const LogSyncResponse &response)
NOTE: THIS FILE IS AUTO-GENERATED. DO NOT EDIT IT MANUALLY.
std::shared_ptr< ILogUploadStrategy > ILogUploadStrategyPtr
std::chrono::system_clock clock_t
LogUploadStrategyDecision
Log upload decisions.
std::chrono::time_point< clock_t > getTimeoutTime() const
std::int32_t getTransportAccessPointId() const