Exporting symbols for consumers of the dll - and deleted old code

PiperOrigin-RevId: 401098019
This commit is contained in:
jfcarroll
2021-10-05 16:27:15 -07:00
committed by Copybara-Service
parent 679838223c
commit e0b1dd8dfc
6 changed files with 101 additions and 186 deletions
+33 -6
View File
@@ -11,10 +11,8 @@
// 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.
#ifndef CORE_OPTIONS_H_
#define CORE_OPTIONS_H_
#include <string>
#include "core/strategy.h"
@@ -25,7 +23,7 @@ namespace location {
namespace nearby {
namespace connections {
using Medium = ::location::nearby::proto::connections::Medium;
using Medium = location::nearby::proto::connections::Medium;
// Generic type: allows definition of a feature T for every Medium.
template <typename T>
@@ -38,7 +36,6 @@ struct MediumSelector {
constexpr MediumSelector() = default;
constexpr MediumSelector(const MediumSelector&) = default;
constexpr MediumSelector& operator=(const MediumSelector&) = default;
constexpr bool Any(T value) const {
return bluetooth == value || ble == value || web_rtc == value ||
wifi_lan == value;
@@ -89,7 +86,7 @@ enum class PowerLevel {
// Connection Options: used for both Advertising and Discovery.
// All fields are mutable, to make the type copy-assignable.
struct ConnectionOptions {
struct DLL_API ConnectionOptions {
Strategy strategy;
BooleanMediumSelector allowed{BooleanMediumSelector().SetAll(true)};
bool auto_upgrade_bandwidth;
@@ -97,16 +94,20 @@ struct ConnectionOptions {
bool low_power;
bool enable_bluetooth_listening;
bool enable_webrtc_listening;
// Whether this is intended to be used in conjunction with InjectEndpoint().
bool is_out_of_band_connection = false;
ByteArray remote_bluetooth_mac_address;
std::string fast_advertisement_service_uuid;
int keep_alive_interval_millis = 0;
int keep_alive_timeout_millis = 0;
// Verify if ConnectionOptions is in a not-initialized (Empty) state.
bool Empty() const { return strategy.IsNone(); }
// Bring ConnectionOptions to a not-initialized (Empty) state.
void Clear() { strategy.Clear(); }
// Returns a copy and normalizes allowed mediums:
// (1) If is_out_of_band_connection is true, verifies that there is only one
// medium allowed, defaulting to only Bluetooth if unspecified.
@@ -125,7 +126,6 @@ struct ConnectionOptions {
result.allowed.SetAll(false);
result.allowed.bluetooth = true;
}
return result;
}
@@ -134,7 +134,34 @@ struct ConnectionOptions {
if (!allowed.Any(true)) result.allowed.SetAll(true);
return result;
}
std::vector<Medium> GetMediums() const { return allowed.GetMediums(true); }
// This call follows the standard Microsoft calling pattern of calling first
// to get the size of the array. Caller then allocates memory for the array,
// and makes this call again to copy the array into the provided location.
void GetMediums(location::nearby::proto::connections::Medium* mediums,
uint32_t* mediumsSize) {
auto size = GetMediums().size();
// Caller is seeking the size of mediums
if (mediums == nullptr) {
*mediumsSize = size;
return;
}
// Caller has not specified enough memory
if (*mediumsSize < size) {
mediums = nullptr; // ensure nullptr return
*mediumsSize = size; // update the size to indicate the correct size
return;
}
for (uint32_t i = 0; i < size; i++) {
// Construct an array at the given location
mediums[i] = GetMediums().at(i);
}
}
};
// Metadata injected to facilitate out-of-band connections. The medium field is
+17 -7
View File
@@ -11,40 +11,52 @@
// 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.
#ifndef CORE_STRATEGY_H_
#define CORE_STRATEGY_H_
#include <string>
#ifdef _WIN32 // These storage class specifiers only matter to win32 dll
// builds.
#ifdef CORE_ADAPTER_DLL
#define DLL_API \
__declspec(dllexport) // If we're building the core, we're exporting.
#else // !CORE_ADAPTER_DLL
#define DLL_API \
__declspec(dllimport) // If we're not building the core, we're importing.
#endif // CORE_ADAPTER_DLL
#else // !_WIN32
#define DLL_API // We're not building a win32 dll, leave the source unchanged.
#endif // _WIN32
namespace location {
namespace nearby {
namespace connections {
// Defines a copyable, comparable connection strategy type.
// It is one of: kP2pCluster, kP2pStar, kP2pPointToPoint.
class Strategy {
class DLL_API Strategy {
public:
static const Strategy kNone;
static const Strategy kP2pCluster;
static const Strategy kP2pStar;
static const Strategy kP2pPointToPoint;
constexpr Strategy() : Strategy(kNone) {}
constexpr Strategy(const Strategy&) = default;
constexpr Strategy& operator=(const Strategy&) = default;
// Returns true, if strategy is kNone, false otherwise.
bool IsNone() const;
// Returns true, if a strategy is one of the supported strategies,
// false otherwise.
bool IsValid() const;
// Returns a string representing given strategy, for every valid strategy.
std::string GetName() const;
// Undefine strategy.
void Clear() { *this = kNone; }
friend bool operator==(const Strategy& lhs, const Strategy& rhs);
friend bool operator!=(const Strategy& lhs, const Strategy& rhs);
@@ -61,7 +73,6 @@ class Strategy {
};
constexpr Strategy(ConnectionType connection_type, TopologyType topology_type)
: connection_type_(connection_type), topology_type_(topology_type) {}
ConnectionType connection_type_;
TopologyType topology_type_;
};
@@ -69,5 +80,4 @@ class Strategy {
} // namespace connections
} // namespace nearby
} // namespace location
#endif // CORE_STRATEGY_H_