File: interface.h

package info (click to toggle)
syncthingtray 2.0.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,124 kB
  • sloc: cpp: 34,081; xml: 1,705; java: 1,258; sh: 97; javascript: 54; makefile: 25
file content (74 lines) | stat: -rw-r--r-- 2,626 bytes parent folder | download
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
64
65
66
67
68
69
70
71
72
73
74
#ifndef LIBSYNCTHING_INTERFACE_H
#define LIBSYNCTHING_INTERFACE_H

#include "./global.h"

#include <chrono>
#include <cstdint>
#include <functional>
#include <string>
#include <type_traits>
#include <vector>

namespace LibSyncthing {

enum class RuntimeFlags : std::uint64_t {
    None = 0,
    Verbose = (1 << 0),
    AllowNewerConfig = (1 << 1),
    ResetDeltaIndexes = (1 << 2),
    EnsureConfigDirExists = (1 << 3),
    EnsureDataDirExists = (1 << 4),
    SkipPortProbing = (1 << 5),
    ExpandPathsFromEnv = (1 << 6),
};

constexpr bool operator&(RuntimeFlags lhs, RuntimeFlags rhs)
{
    return static_cast<std::underlying_type_t<RuntimeFlags>>(lhs) & static_cast<std::underlying_type_t<RuntimeFlags>>(rhs);
}

constexpr RuntimeFlags operator|(RuntimeFlags lhs, RuntimeFlags rhs)
{
    return static_cast<RuntimeFlags>(static_cast<std::underlying_type_t<RuntimeFlags>>(lhs) | static_cast<std::underlying_type_t<RuntimeFlags>>(rhs));
}

struct RuntimeOptions {
    std::string configDir;
    std::string dataDir;
    std::string guiAddress;
    std::string guiApiKey;
    std::string profilerAddress;
    std::chrono::nanoseconds dbMaintenanceInterval = std::chrono::hours(8);
    std::chrono::nanoseconds dbDeleteRetentionInterval = std::chrono::hours(4320);
    RuntimeFlags flags = RuntimeFlags::AllowNewerConfig | RuntimeFlags::EnsureConfigDirExists | RuntimeFlags::EnsureDataDirExists;
};

enum class LogLevel : int {
    Debug = -4,
    Info = 0,
    Default = Info,
    Warning = 4,
    Error = 8,
};
constexpr auto lowestLogLevel = LogLevel::Debug;
constexpr auto highestLogLevel = LogLevel::Error;

using LoggingCallback = std::function<void(LogLevel, const char *message, std::size_t messageSize)>;

LIB_SYNCTHING_EXPORT bool hasLoggingCallback();
LIB_SYNCTHING_EXPORT void setLoggingCallback(const LoggingCallback &callback);
LIB_SYNCTHING_EXPORT void setLoggingCallback(LoggingCallback &&callback);
LIB_SYNCTHING_EXPORT std::int64_t runSyncthing(const RuntimeOptions &options = RuntimeOptions{});
LIB_SYNCTHING_EXPORT bool isSyncthingRunning();
LIB_SYNCTHING_EXPORT std::int64_t stopSyncthing();
LIB_SYNCTHING_EXPORT std::string ownDeviceId();
LIB_SYNCTHING_EXPORT std::string syncthingVersion();
LIB_SYNCTHING_EXPORT std::string longSyncthingVersion();
LIB_SYNCTHING_EXPORT long long runCli(const std::vector<const char *> &arguments);
LIB_SYNCTHING_EXPORT long long runCommand(const std::vector<const char *> &arguments);
LIB_SYNCTHING_EXPORT std::string verify(std::string_view pubKeyPEM, std::string_view signature, std::string_view data);

} // namespace LibSyncthing

#endif // LIBSYNCTHING_INTERFACE_H