-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add NetworkOffline for offline environment (#1470)
There are cases where device want to rely on the offline data only or even want to completely avoid network related libs like libcurl and libssl. Relates-To: OLPEDGE-2861 Signed-off-by: Rustam Gamidov <[email protected]>
- Loading branch information
1 parent
2e70b67
commit 98b995a
Showing
6 changed files
with
219 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Copyright (C) 2024 HERE Europe B.V. | ||
# | ||
# 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. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# License-Filename: LICENSE | ||
|
||
|
||
set(OLP_SDK_HTTP_OFFLINE_SOURCES | ||
"${CMAKE_CURRENT_LIST_DIR}/../src/http/offline/NetworkOffline.cpp" | ||
"${CMAKE_CURRENT_LIST_DIR}/../src/http/offline/NetworkOffline.h" | ||
) | ||
|
||
add_definitions(-DOLP_SDK_NETWORK_OFFLINE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright (C) 2024 HERE Europe B.V. | ||
* | ||
* 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. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* License-Filename: LICENSE | ||
*/ | ||
|
||
#include "NetworkOffline.h" | ||
|
||
#include <memory> | ||
|
||
#include "olp/core/http/HttpStatusCode.h" | ||
#include "olp/core/logging/Log.h" | ||
|
||
namespace olp { | ||
namespace http { | ||
|
||
namespace { | ||
|
||
const char* kLogTag = "NetworkOffline"; | ||
|
||
} // anonymous namespace | ||
|
||
NetworkOffline::NetworkOffline() { | ||
OLP_SDK_LOG_TRACE(kLogTag, "Created NetworkOffline with address=" << this); | ||
} | ||
|
||
NetworkOffline::~NetworkOffline() { | ||
OLP_SDK_LOG_TRACE(kLogTag, "Destroyed NetworkOffline object, this=" << this); | ||
} | ||
|
||
SendOutcome NetworkOffline::Send(NetworkRequest request, | ||
std::shared_ptr<std::ostream> payload, | ||
Network::Callback callback, | ||
Network::HeaderCallback header_callback, | ||
Network::DataCallback data_callback) { | ||
OLP_SDK_CORE_UNUSED(payload); | ||
OLP_SDK_CORE_UNUSED(callback); | ||
OLP_SDK_CORE_UNUSED(header_callback); | ||
OLP_SDK_CORE_UNUSED(data_callback); | ||
OLP_SDK_LOG_ERROR( | ||
kLogTag, "Send failed - network is offline, url=" << request.GetUrl()); | ||
return SendOutcome(ErrorCode::OFFLINE_ERROR); | ||
} | ||
|
||
void NetworkOffline::Cancel(RequestId id) { | ||
OLP_SDK_LOG_ERROR(kLogTag, "Cancel failed - network is offline, id=" << id); | ||
return; | ||
} | ||
|
||
} // namespace http | ||
} // namespace olp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright (C) 2024 HERE Europe B.V. | ||
* | ||
* 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. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* License-Filename: LICENSE | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "olp/core/http/Network.h" | ||
#include "olp/core/http/NetworkRequest.h" | ||
|
||
namespace olp { | ||
namespace http { | ||
|
||
/** | ||
* @brief The implementation of Network based on cURL. | ||
*/ | ||
class NetworkOffline : public olp::http::Network, | ||
public std::enable_shared_from_this<NetworkOffline> { | ||
public: | ||
/** | ||
* @brief NetworkOffline constructor. | ||
*/ | ||
NetworkOffline(); | ||
|
||
/** | ||
* @brief ~NetworkOffline destructor. | ||
*/ | ||
~NetworkOffline() override; | ||
|
||
/** | ||
* @brief Not copyable. | ||
*/ | ||
NetworkOffline(const NetworkOffline& other) = delete; | ||
|
||
/** | ||
* @brief Not movable. | ||
*/ | ||
NetworkOffline(NetworkOffline&& other) = delete; | ||
|
||
/** | ||
* @brief Not copy-assignable. | ||
*/ | ||
NetworkOffline& operator=(const NetworkOffline& other) = delete; | ||
|
||
/** | ||
* @brief Not move-assignable. | ||
*/ | ||
NetworkOffline& operator=(NetworkOffline&& other) = delete; | ||
|
||
/** | ||
* @brief Implementation of Send method from Network abstract class. | ||
*/ | ||
SendOutcome Send(NetworkRequest request, Payload payload, Callback callback, | ||
HeaderCallback header_callback = nullptr, | ||
DataCallback data_callback = nullptr) override; | ||
|
||
/** | ||
* @brief Implementation of Cancel method from Network abstract class. | ||
*/ | ||
void Cancel(RequestId id) override; | ||
}; | ||
|
||
} // namespace http | ||
} // namespace olp |