Skip to content

Commit

Permalink
Access access point factory from access point manager.
Browse files Browse the repository at this point in the history
  • Loading branch information
abeltrano committed Jan 18, 2024
1 parent 281d84f commit a04adc6
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 6 deletions.
14 changes: 12 additions & 2 deletions src/common/wifi/apmanager/AccessPointManager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,22 @@

using namespace Microsoft::Net::Wifi;

AccessPointManager::AccessPointManager() = default;
AccessPointManager::AccessPointManager(std::unique_ptr<IAccessPointFactory> accessPointFactory) :
m_accessPointFactory(std::move(accessPointFactory))
{}

/* static */
std::shared_ptr<AccessPointManager>
AccessPointManager::Create(std::unique_ptr<IAccessPointFactory> accessPointFactory)
{
return std::make_shared<notstd::enable_make_protected<AccessPointManager>>(std::move(accessPointFactory));
}

/* static */
std::shared_ptr<AccessPointManager>
AccessPointManager::Create()
{
return std::make_shared<notstd::enable_make_protected<AccessPointManager>>();
return Create(std::make_unique<AccessPointFactory>());
}

std::shared_ptr<AccessPointManager>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace Microsoft::Net::Wifi
{
struct IAccessPoint;
struct IAccessPointFactory;
struct AccessPointDiscoveryAgent;
enum class AccessPointPresenceEvent;

Expand All @@ -26,13 +27,23 @@ class AccessPointManager :
{
public:
/**
* @brief Safely create an instance of the access point manager.
* @brief Safely create an instance of the access point manager with a default access point factory that creates
* AccessPoint instances.
*
* @return std::shared_ptr<AccessPointManager>
*/
[[nodiscard]] static std::shared_ptr<AccessPointManager>
Create();

/**
* @brief Safely create an instance of the access point manager.
*
* @param accessPointFactory
* @return std::shared_ptr<AccessPointManager>
*/
[[nodiscard]] static std::shared_ptr<AccessPointManager>
Create(std::unique_ptr<IAccessPointFactory> accessPointFactory);

/**
* @brief Get an instance of this access point manager.
*
Expand Down Expand Up @@ -95,7 +106,7 @@ protected:
* Consequently, the = default implementation is done in the source file
* instead.
*/
AccessPointManager();
AccessPointManager(std::unique_ptr<IAccessPointFactory> accessPointFactory);

private:
/**
Expand Down Expand Up @@ -125,6 +136,8 @@ private:
RemoveAccessPoint(std::shared_ptr<IAccessPoint> accessPoint);

private:
std::unique_ptr<IAccessPointFactory> m_accessPointFactory;

mutable std::mutex m_accessPointGate;
std::vector<std::shared_ptr<IAccessPoint>> m_accessPoints{};

Expand Down
6 changes: 6 additions & 0 deletions src/common/wifi/core/AccessPoint.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ AccessPoint::CreateController()
{
throw std::runtime_error("this function must be overridden by a derived class");
}

std::shared_ptr<IAccessPoint>
AccessPointFactory::Create(std::string_view interface)
{
return std::make_shared<AccessPoint>(interface);
}
21 changes: 19 additions & 2 deletions src/common/wifi/core/include/microsoft/net/wifi/AccessPoint.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#define ACCESS_POINT_HXX

#include <microsoft/net/wifi/IAccessPoint.hxx>
#include <microsoft/net/wifi/IAccessPointFactory.hxx>

#include <string>
#include <string_view>
Expand Down Expand Up @@ -34,15 +35,31 @@ struct AccessPoint :

/**
* @brief Create a controller object.
*
* @return std::unique_ptr<Microsoft::Net::Wifi::IAccessPointController>
*
* @return std::unique_ptr<Microsoft::Net::Wifi::IAccessPointController>
*/
virtual std::unique_ptr<Microsoft::Net::Wifi::IAccessPointController>
CreateController() override;

private:
const std::string m_interface;
};

/**
* @brief Creates instances of the AccessPoint class.
*/
struct AccessPointFactory :
public IAccessPointFactory
{
/**
* @brief Create a new access point object for the given network interface.
*
* @param interface
* @return std::shared_ptr<AccessPoint>
*/
virtual std::shared_ptr<IAccessPoint>
Create(std::string_view interface) override;
};
} // namespace Microsoft::Net::Wifi

#endif // ACCESS_POINT_HXX

0 comments on commit a04adc6

Please sign in to comment.