summaryrefslogtreecommitdiff
path: root/src/CommonAPI/CallInfo.cpp
blob: 189e9d868f5965a0800e2653084de1b713f1eeca (plain)
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
// Copyright (C) 2015-2020 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include <CommonAPI/CallInfo.hpp>
#include <CommonAPI/Runtime.hpp>

namespace CommonAPI {

CallInfo::CallInfo()
        : CallInfo(DEFAULT_SEND_TIMEOUT_MS, 0) {
}

CallInfo::CallInfo(Timeout_t _timeout)
        : CallInfo(_timeout, 0) {
}

CallInfo::CallInfo(const CallInfo &_other)
        : CallInfo(_other.timeout_, _other.sender_) {
}

CallInfo::CallInfo(Timeout_t _timeout, Sender_t _sender)
        : timeout_(_timeout), sender_(_sender) {

    Timeout_t defaultCallTimeout = Runtime::get()->getDefaultCallTimeout();
    const char *env = std::getenv("COMMONAPI_OVERRIDE_GLOBAL_CALL_TIMEOUT");

    if ((_timeout == DEFAULT_SEND_TIMEOUT_MS) && defaultCallTimeout) {
        timeout_ = defaultCallTimeout;
    }
    if (env) {
        Timeout_t globalCallTimeout = std::stoi(env);
        if (0 <= globalCallTimeout || globalCallTimeout == -1) {
            timeout_ = globalCallTimeout;
        }
    }
}

} // namespace CommonAPI