Skip to content

Commit

Permalink
Add impl function for WifiAccessPointGetProperties.
Browse files Browse the repository at this point in the history
  • Loading branch information
abeltrano committed Jul 26, 2024
1 parent f540afc commit 3e8a214
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 24 deletions.
54 changes: 34 additions & 20 deletions src/common/service/NetRemoteService.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <utility>
#include <vector>

#include <google/protobuf/repeated_ptr_field.h>
#include <grpcpp/impl/codegen/status.h>
#include <grpcpp/server_context.h>
#include <magic_enum.hpp>
Expand Down Expand Up @@ -423,28 +424,11 @@ NetRemoteService::WifiAccessPointSetAuthenticationDot1x([[maybe_unused]] grpc::S
::grpc::Status
NetRemoteService::WifiAccessPointGetProperties([[maybe_unused]] grpc::ServerContext* context, const WifiAccessPointGetPropertiesRequest* request, WifiAccessPointGetPropertiesResult* result)
{
WifiAccessPointOperationStatus wifiOperationStatus{};
const NetRemoteWifiApiTrace traceMe{ request->accesspointid(), result->mutable_status() };
const auto accessPointId{ request->accesspointid() };

*result->mutable_accesspointid() = accessPointId;

// Obtain the access point specified in the request.
std::shared_ptr<IAccessPoint> accessPoint{};
auto operationStatus = TryGetAccessPoint(accessPointId, accessPoint);
if (!operationStatus.Succeeded()) {
wifiOperationStatus.set_code(ToDot11AccessPointOperationStatusCode(operationStatus.Code));
return grpc::Status::OK;
}

// Populate the result with the access point properties.
{
auto properties = accessPoint->GetProperties();
*result->mutable_properties() = {
std::make_move_iterator(std::begin(properties.Properties)),
std::make_move_iterator(std::end(properties.Properties)),
};
}
auto wifiOperationStatus = WifiAccessPointGetPropertiesImpl(request->accesspointid(), *result->mutable_properties());
result->set_accesspointid(request->accesspointid());
*result->mutable_status() = std::move(wifiOperationStatus);

return grpc::Status::OK;
}
Expand Down Expand Up @@ -1282,3 +1266,33 @@ NetRemoteService::WifiAccessPointSetAuthenticationDot1xImpl(std::string_view acc

return wifiOperationStatus;
}

using google::protobuf::RepeatedPtrField;

WifiAccessPointOperationStatus
NetRemoteService::WifiAccessPointGetPropertiesImpl(std::string_view accessPointId, RepeatedPtrField<std::string>& accessPointProperties)
{
WifiAccessPointOperationStatus wifiOperationStatus{};

// Obtain the access point specified in the request.
std::shared_ptr<IAccessPoint> accessPoint{};
auto operationStatus = TryGetAccessPoint(accessPointId, accessPoint);
if (!operationStatus.Succeeded()) {
wifiOperationStatus.set_code(ToDot11AccessPointOperationStatusCode(operationStatus.Code));
wifiOperationStatus.set_message(std::format("Failed to get access point {} - {}", accessPointId, operationStatus.ToString()));
return wifiOperationStatus;
}

// Populate output argument with a copy of the access point properties.
{
auto properties = accessPoint->GetProperties();
accessPointProperties = {
std::make_move_iterator(std::begin(properties.Properties)),
std::make_move_iterator(std::end(properties.Properties)),
};
}

wifiOperationStatus.set_code(WifiAccessPointOperationStatusCode::WifiAccessPointOperationStatusCodeSucceeded);

return wifiOperationStatus;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
#define NET_REMOTE_SERVICE_HXX

#include <memory>
#include <string>
#include <string_view>

#include <google/protobuf/repeated_ptr_field.h>
#include <grpcpp/server_context.h>
#include <grpcpp/support/status.h>
#include <microsoft/net/NetworkManager.hxx>
Expand Down Expand Up @@ -148,11 +150,11 @@ private:

/**
* @brief Get the properties of the specified access point.
*
* @param context
* @param request
*
* @param context
* @param request
* @param result
* @return ::grpc::Status
* @return ::grpc::Status
*/
::grpc::Status
WifiAccessPointGetProperties(grpc::ServerContext* context, const Microsoft::Net::Remote::Wifi::WifiAccessPointGetPropertiesRequest* request, Microsoft::Net::Remote::Wifi::WifiAccessPointGetPropertiesResult* result) override;
Expand Down Expand Up @@ -314,6 +316,16 @@ protected:
Microsoft::Net::Remote::Wifi::WifiAccessPointOperationStatus
WifiAccessPointSetAuthenticationDot1xImpl(std::string_view accessPointId, const Microsoft::Net::Wifi::Dot11AuthenticationDot1x& dot11AuthenticationDot1x, std::shared_ptr<Microsoft::Net::Wifi::IAccessPointController> accessPointController = nullptr);

/**
* @brief Get the properties of the specified access point.
*
* @param accessPointId The access point identifier.
* @param accessPointProperties Output variable to receive the access point properties.
* @return Microsoft::Net::Remote::Wifi::WifiAccessPointOperationStatus
*/
Microsoft::Net::Remote::Wifi::WifiAccessPointOperationStatus
WifiAccessPointGetPropertiesImpl(std::string_view accessPointId, google::protobuf::RepeatedPtrField<std::string>& accessPointProperties);

private:
std::shared_ptr<Microsoft::Net::NetworkManager> m_networkManager;
std::shared_ptr<Microsoft::Net::Wifi::AccessPointManager> m_accessPointManager;
Expand Down

0 comments on commit 3e8a214

Please sign in to comment.