forked from mavlink-router/mavlink-router
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logendpoint.h
63 lines (52 loc) · 1.76 KB
/
logendpoint.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
* This file is part of the MAVLink Router project
*
* Copyright (C) 2017 Intel Corporation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <assert.h>
#include <dirent.h>
#include "endpoint.h"
#include "timeout.h"
#define LOG_ENDPOINT_SYSTEM_ID 2
#define LOG_ENDPOINT_TARGET_SYSTEM_ID 1
class LogEndpoint : public Endpoint {
public:
LogEndpoint(const char *logs_dir)
: Endpoint{"BinLog", false}
, _logs_dir{logs_dir}
{
assert(_logs_dir);
}
virtual bool start();
virtual void stop();
protected:
const char *_logs_dir;
const int _target_system_id = LOG_ENDPOINT_TARGET_SYSTEM_ID;
int _file = -1;
Timeout *_logging_start_timeout = nullptr;
Timeout *_alive_check_timeout = nullptr;
uint32_t _timeout_write_total = 0;
virtual const char *_get_logfile_extension() = 0;
void _send_msg(const mavlink_message_t *msg, int target_sysid);
void _remove_start_timeout();
bool _start_alive_timeout();
virtual bool _start_timeout() = 0;
virtual bool _alive_timeout();
private:
int _get_file(const char *extension, char *filename_result, size_t filename_size);
uint32_t _get_prefix(DIR *dir);
DIR *_open_or_create_dir(const char *name);
};