Skip to content

Commit 4bf7b08

Browse files
committed
[out_ptr] switch to P1132 reference implementation
1 parent b758c02 commit 4bf7b08

File tree

6 files changed

+40
-124
lines changed

6 files changed

+40
-124
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ if(UNIX)
146146
list(APPEND MULTIPASS_BACKENDS qemu)
147147
endif()
148148

149+
include(src/cmake/cmake-deps.cmake)
150+
149151
# OpenSSL config
150152
find_package(OpenSSL REQUIRED)
151153

src/cmake/cmake-deps.cmake

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright (C) Canonical, Ltd.
2+
#
3+
# This program is free software: you can redistribute it and/or modify
4+
# it under the terms of the GNU General Public License version 3 as
5+
# published by the Free Software Foundation.
6+
#
7+
# This program is distributed in the hope that it will be useful,
8+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
# GNU General Public License for more details.
11+
#
12+
# You should have received a copy of the GNU General Public License
13+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
14+
15+
include(FetchContent)
16+
17+
# Declare and fetch fmt
18+
FetchContent_Declare(
19+
out_ptr
20+
GIT_REPOSITORY https://github.com/soasis/out_ptr.git
21+
GIT_TAG 02a577edfcf25e2519e380a95c16743b7e5878a1
22+
)
23+
24+
FetchContent_MakeAvailable(out_ptr)

src/platform/backends/hyperv_api/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ if(WIN32)
6060

6161
target_link_libraries(hyperv_api_backend PRIVATE
6262
fmt::fmt-header-only
63+
ztd::out_ptr
6364
utils
6465
computecore.lib
6566
computenetwork.lib

src/platform/backends/hyperv_api/hcn/hyperv_hcn_api_wrapper.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include <hyperv_api/hcn/hyperv_hcn_create_endpoint_params.h>
2121
#include <hyperv_api/hcn/hyperv_hcn_create_network_params.h>
2222
#include <hyperv_api/hcn/hyperv_hcn_wrapper_interface.h>
23-
#include <hyperv_api/util/out_ptr.h>
2423

2524
#include <multipass/exceptions/formatted_exception_base.h>
2625
#include <multipass/logging/log.h>
@@ -36,11 +35,14 @@
3635
// clang-format on
3736

3837
#include <fmt/xchar.h>
38+
#include <ztd/out_ptr.hpp>
3939

4040
#include <cassert>
4141
#include <string>
4242
#include <type_traits>
4343

44+
using ztd::out_ptr::out_ptr;
45+
4446
namespace multipass::hyperv::hcn
4547
{
4648

@@ -156,7 +158,7 @@ OperationResult perform_hcn_operation(const HCNAPITable& api, const FnType& fn,
156158
// HcnClose*) is ErrorRecord, which is a JSON-formatted document emitted by
157159
// the API describing the error happened. Therefore, we can streamline all API
158160
// calls through perform_operation to perform co
159-
const auto result = ResultCode{fn(std::forward<Args>(args)..., util::out_ptr(result_msgbuf, api.CoTaskMemFree))};
161+
const auto result = ResultCode{fn(std::forward<Args>(args)..., out_ptr(result_msgbuf, api.CoTaskMemFree))};
160162

161163
mpl::debug(kLogCategory,
162164
"perform_operation(...) > fn: {}, result: {}",
@@ -187,10 +189,8 @@ UniqueHcnNetwork open_network(const HCNAPITable& api, const std::string& network
187189
mpl::debug(kLogCategory, "open_network(...) > network_guid: {} ", network_guid);
188190

189191
UniqueHcnNetwork network{};
190-
const auto result = perform_hcn_operation(api,
191-
api.OpenNetwork,
192-
guid_from_string(network_guid),
193-
util::out_ptr(network, api.CloseNetwork));
192+
const auto result =
193+
perform_hcn_operation(api, api.OpenNetwork, guid_from_string(network_guid), out_ptr(network, api.CloseNetwork));
194194
if (!result)
195195
{
196196
mpl::error(kLogCategory, "open_network() > HcnOpenNetwork failed with {}!", result.code);
@@ -269,7 +269,7 @@ OperationResult HCNWrapper::create_network(const CreateNetworkParameters& params
269269
api.CreateNetwork,
270270
guid_from_string(params.guid),
271271
network_settings.c_str(),
272-
util::out_ptr(network, api.CloseNetwork));
272+
out_ptr(network, api.CloseNetwork));
273273

274274
if (!result)
275275
{
@@ -330,7 +330,7 @@ OperationResult HCNWrapper::create_endpoint(const CreateEndpointParameters& para
330330
network.get(),
331331
guid_from_string(params.endpoint_guid),
332332
endpoint_settings.c_str(),
333-
util::out_ptr(endpoint, api.CloseEndpoint));
333+
out_ptr(endpoint, api.CloseEndpoint));
334334
return result;
335335
}
336336

src/platform/backends/hyperv_api/hcs/hyperv_hcs_api_wrapper.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include <hyperv_api/hcs/hyperv_hcs_create_compute_system_params.h>
2121
#include <hyperv_api/hyperv_api_operation_result.h>
2222
#include <hyperv_api/hyperv_api_string_conversion.h>
23-
#include <hyperv_api/util/out_ptr.h>
2423

2524
#include <multipass/logging/log.h>
2625

@@ -33,6 +32,9 @@
3332
#include <memory>
3433

3534
#include <fmt/xchar.h>
35+
#include <ztd/out_ptr.hpp>
36+
37+
using ztd::out_ptr::out_ptr;
3638

3739
namespace multipass::hyperv::hcs
3840
{
@@ -128,7 +130,7 @@ UniqueHcsSystem open_host_compute_system(const HCSAPITable& api, const std::stri
128130

129131
UniqueHcsSystem system{};
130132
const ResultCode result =
131-
api.OpenComputeSystem(name_w.c_str(), kRequestedAccessLevel, util::out_ptr(system, api.CloseComputeSystem));
133+
api.OpenComputeSystem(name_w.c_str(), kRequestedAccessLevel, out_ptr(system, api.CloseComputeSystem));
132134
if (!result)
133135
{
134136
mpl::debug(kLogCategory,
@@ -242,7 +244,7 @@ OperationResult HCSWrapper::create_compute_system(const CreateComputeSystemParam
242244
vm_settings.c_str(),
243245
operation.get(),
244246
nullptr,
245-
util::out_ptr(system, api.CloseComputeSystem))};
247+
out_ptr(system, api.CloseComputeSystem))};
246248

247249
if (!result)
248250
{

src/platform/backends/hyperv_api/util/out_ptr.h

Lines changed: 0 additions & 113 deletions
This file was deleted.

0 commit comments

Comments
 (0)