Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding config class to swift wrappers #1141

Merged
merged 13 commits into from
May 20, 2023
50 changes: 39 additions & 11 deletions wrappers/swift/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,25 +1,53 @@
#######################################################################################################
# Generates project files for Swift wrapper files and generates executable based on the main.swift file.
#
# Dependecies:
# Please build Obj-c dependencies required by Swift by running
# ./build.sh clean release
# in the source folder to generate the required Obj-C library. It should be installed at /usr/local/lib
#######################################################################################################

CMAKE_MINIMUM_REQUIRED(VERSION 3.15)

PROJECT(Swift_Wrapper)

message("${CMAKE_CURRENT_SOURCE_DIR}")

enable_language(Swift)

# TODO: add logic to build dependencies
# Set flags and paths
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_Swift_FLAGS "${CMAKE_Swift_FLAGS} -import-objc-header Swift_Wrapper-Bridging-Header.h")
set(INSTALLED_LIB_PATH "/usr/local/lib")

# Add system libs
find_library(SYSTEM_CONFIGURATION SystemConfiguration)
absaroj marked this conversation as resolved.
Show resolved Hide resolved
find_package(ZLIB REQUIRED)
find_library(NETWORK_FRAMEWORK Network)

include_directories(
../../lib/include/public/
../../lib/include/mat/
)
# Add libmat.a library which has Obj-C dependencies built needed by Swift
find_library(MAT_LIB libmat.a PATHS ${INSTALLED_LIB_PATH})
find_library(SQLITE3_LIB libsqlite3.a PATH ${INSTALLED_LIB_PATH})
absaroj marked this conversation as resolved.
Show resolved Hide resolved

if(NOT SQLITE3_LIB)
set(SQLITE3_LIB "sqlite3")
endif()

if(NOT MAT_LIB)
message(FATAL_ERROR, "libmat.a not found at /usr/local/lib. Please run ./build.sh at root and install libmat.a.")
endif()

get_property(dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
foreach(dir ${dirs})
message(STATUS "dir='${dir}'")
endforeach()

# Add source files to the target
set(PLATFORM_FILES main.swift SDWEventProperties.swift)
set(CMAKE_Swift_FLAGS "${CMAKE_Swift_FLAGS} -import-objc-header Swift_Wrapper-Bridging-Header.h")
add_executable(swift_sample ${PLATFORM_FILES})
target_link_libraries(swift_sample)
file(GLOB SWIFT_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.swift")
add_executable(swift_sample ${SWIFT_FILES})

target_link_libraries(swift_sample
absaroj marked this conversation as resolved.
Show resolved Hide resolved
${MAT_LIB}
${SYSTEM_CONFIGURATION}
${SQLITE3_LIB}
stdc++
ZLIB::ZLIB
${NETWORK_FRAMEWORK})
214 changes: 214 additions & 0 deletions wrappers/swift/LogConfiguration.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
//
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
//

/// Class wrapping `ODWLogConfiguration` ObjC class object, representing configuration related to events.
public final class LogConfiguration {
private var odwLogConfiguration: ODWLogConfiguration

/**
Constructs `self` with provided config as `ODWLogConfiguration` object.

- Parameters:
- config: `ODWLogConfiguration` object which would be wrapped to.
*/
public init(config: ODWLogConfiguration) {
absaroj marked this conversation as resolved.
Show resolved Hide resolved
self.odwLogConfiguration = config
}

/// Return a copy of the default configuration
public static func getLogConfigurationCopy() -> LogConfiguration? {
absaroj marked this conversation as resolved.
Show resolved Hide resolved
if let odwLogConfiguration = ODWLogConfiguration.getCopy() {
return LogConfiguration(config: odwLogConfiguration)
} else {
return nil
}
}

/**
Sets the "URI" of the event collector.

- Parameters:
- collectorUri: `String` for event collector uri.
*/
public static func setEventCollectorUri(_ collectorUri: String) {
ODWLogConfiguration.setEventCollectorUri(collectorUri)
}

/// Returns a `String` containing "URI" of the event collector.
public static func eventCollectorUri() -> String? {
return ODWLogConfiguration.eventCollectorUri();
}

/**
Sets the RAM queue size limit in bytes.

- Parameters:
- sizeInBytes: A `Long` value for memory size limit in bytes.
*/
public static func setCacheMemorySizeLimitInBytes(_ sizeInBytes: UInt64) {
absaroj marked this conversation as resolved.
Show resolved Hide resolved
ODWLogConfiguration.setCacheMemorySizeLimitInBytes(sizeInBytes)
}

/// Returns the RAM queue size as `Long` value having limit in bytes.
public static func cacheMemorySizeLimitInBytes() -> UInt64 {
return ODWLogConfiguration.cacheMemorySizeLimitInBytes()
}

/**
Sets the size limit of the disk file used to cache events on the client side.

- Parameters:
- sizeInBytes: A `Long` value for cache file size limit.
*/
public static func setCacheFileSizeLimitInBytes(_ sizeInBytes: UInt64) {
ODWLogConfiguration.setCacheFileSizeLimitInBytes(sizeInBytes)
}

/// Returns the size limit of the disk file as a `Long` used to cache events on the client side.
public static func cacheFileSizeLimitInBytes() -> UInt64 {
return ODWLogConfiguration.cacheFileSizeLimitInBytes()
}

/**
Sets max teardown upload time in seconds.

- Parameters:
- timeInSecs: An `Integer` that represents time in seconds.
*/
public static func setMaxTeardownUploadTimeInSec(_ timeInSecs: Int32) {
ODWLogConfiguration.setMaxTeardownUploadTimeInSec(timeInSecs)
}

/**
Sets if trace logging to file is enabled.

- Parameters:
- trace: `True` if tracing should be enabled, `False` otherwise.
*/
public static func setEnableTrace(_ trace: Bool) {
ODWLogConfiguration.setEnableTrace(trace)
}

/**
Sets if console logging from the iOS wrapper is enabled.

- Parameters:
- enableLogging: `True` if logging is enabled, `False` otherwise.
*/
public static func setEnableConsoleLogging(_ enableLogging: Bool) {
ODWLogConfiguration.setEnableConsoleLogging(enableLogging)
}

/**
Sets the internal SDK debugging trace level.

- Parameters:
- traceLevel: one of the `ACTTraceLevel` values.
*/
public static func setTraceLevel(_ traceLevel: Int32) {
ODWLogConfiguration.setTraceLevel(traceLevel)
}

/// Returns `True` if tracing is enabled, `False` otherwise.
public static func enableTrace() -> Bool {
return ODWLogConfiguration.enableTrace()
}

/// Returns `True` if console logging is enabled, `False` otherwise.
public static func enableConsoleLogging() -> Bool {
return ODWLogConfiguration.enableConsoleLogging()
}

/**
Sets if inner exceptions should be surface to Wrapper consumers.

- Parameters:
- surfaceObjCExcecptions: `True` if C++ exceptions should be surfaced, `False` otherwise.
*/
public static func setSurfaceCppExceptions(_ surfaceExceptions: Bool) {
ODWLogConfiguration.setSurfaceCppExceptions(surfaceExceptions)
}

/// Returns `True` if inner C++ exceptions are surfaced to Wrapper consumers, `False` otherwise.
public static func surfaceCppExceptions() -> Bool {
return ODWLogConfiguration.surfaceCppExceptions()
}

/**
Sets if session timestamp should be reset after a session ends.

- Parameters:
- enableSessionReset: `True` if session should be reset on session end, `False` otherwise.
*/
public static func setEnableSessionReset(_ sessionReset: Bool) {
ODWLogConfiguration.setEnableSessionReset(sessionReset)
}

/// Returns `True` if session will be reset on session end, `False` otherwise.
public static func enableSessionReset() -> Bool {
return ODWLogConfiguration.enableSessionReset()
}

/**
Set cache file path.

- Parameters:
- cacheFilePath: A `String` for the cache path.
*/
public static func setCacheFilePath(_ cacheFilePath: String) {
ODWLogConfiguration.setCacheFilePath(cacheFilePath)
}

/// Returns the cache file path as a `String`.
public static func cacheFilePath() -> String? {
return ODWLogConfiguration.cacheFilePath()
}

/**
Controls if DB will be checkpointed when flushing.

- Parameters:
- enableDBCheckpointOnFlush: `True` if DB should be checkpointed when flushing.
*/
public static func setEnableDBCheckpointOnFlush(_ enableDBCheckpointOnFlush: Bool) {
ODWLogConfiguration.setEnableDbCheckpointOnFlush(enableDBCheckpointOnFlush)
}

/// Returns `True` if DB will checkpointed when flushing, `False` otherwise.
public static func enableDBCheckpointOnFlush() -> Bool {
return ODWLogConfiguration.enableDbCheckpointOnFlush()
}

/**
Sets a config key to a string value for the copied config.

- Parameters:
- key: A key as a `String`.
- value: A value as a `String`.
*/
public func set(_ key: String, havingValue value: String) {
self.odwLogConfiguration.set(key, withValue: value)
}

/// Returns the value as `String` for the given `String` key.
public func value(forKey key: String) -> String? {
return self.odwLogConfiguration.value(forKey: key)
}

/**
Sets the host value.

- Parameters:
- host: A host value as `String`.
*/
public func setHost(_ host: String) {
self.odwLogConfiguration.setHost(host)
}

/// Returns the host value as `String`.
public func host() -> String? {
return self.odwLogConfiguration.host()
}
}