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
43 changes: 32 additions & 11 deletions wrappers/swift/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,25 +1,46 @@
#######################################################################################################
# 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 14)
absaroj marked this conversation as resolved.
Show resolved Hide resolved
set(CMAKE_Swift_FLAGS "${CMAKE_Swift_FLAGS} -import-objc-header Swift_Wrapper-Bridging-Header.h")
set(INSTALLED_LIB_PATH "/usr/local/lib")

include_directories(
../../lib/include/public/
../../lib/include/mat/
)
# 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)

# 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

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")
#set(PLATFORM_FILES main.swift SDWEventProperties.swift SDWLogger.swift SDWLogManager.swift)
absaroj marked this conversation as resolved.
Show resolved Hide resolved
absaroj marked this conversation as resolved.
Show resolved Hide resolved
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})
208 changes: 208 additions & 0 deletions wrappers/swift/SDWLogConfiguration.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
//
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
//

/// Reresents general logging properties.
public class LogConfiguration {
private var odwLogConfiguration: ODWLogConfiguration

public init(withConfig config: ODWLogConfiguration) {
self.odwLogConfiguration = config
}

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

/**
Sets the URI of the event collector.

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

/// Returns the 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(withCacheMeomorySizeLimitInBytes sizeInBytes: UInt64) {
ODWLogConfiguration.setCacheMemorySizeLimitInBytes(sizeInBytes)
}

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

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

- Parameters:
- sizeInBytes: A long value for cache file sizse limit.
*/
public static func setCacheFileSizeLimitInBytes(withCacheFileSizeLimitInBytes sizeInBytes: UInt64) {
ODWLogConfiguration.setCacheFileSizeLimitInBytes(sizeInBytes)
}

/// Returns the size limit of the disk file 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(withMaxTeardownUploadTimeInSec timeInSec: Int32) {
ODWLogConfiguration.setMaxTeardownUploadTimeInSec(timeInSec)
}

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

- Parameters:
- trace: True if tracing is enabled.
*/
public static func setEnableTrace(withEnableTrace trace: Bool) {
ODWLogConfiguration.setEnableTrace(trace)
}

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

- Parameters:
- enableLogging: True if logging is enabled.
*/
public static func setEnableConsoleLogging(withEnableConsoleLogging enableLogging: Bool) {
ODWLogConfiguration.setEnableConsoleLogging(enableLogging)
}

/**
Sets the internal SDK debugging trace level.

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

/// Returns true if tracing is enabled
public static func enableTrace() -> Bool {
return ODWLogConfiguration.enableTrace()
}

/// Returns true if console logging is enabled.
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.
*/
public static func setSurfaceCppExceptions(withSurfaceExceptions surfaceExceptions: Bool) {
ODWLogConfiguration.setSurfaceCppExceptions(surfaceExceptions)
}

/// Returns true if inner C++ exceptions are surfaced to Wrapper consumers.
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.
*/
public static func setEnableSessionReset(withEnableSessionReset sessionReset: Bool) {
ODWLogConfiguration.setEnableSessionReset(sessionReset)
}

/// Returns true if session will be reset on session end.
public static func enableSessionReset() -> Bool {
return ODWLogConfiguration.enableSessionReset()
}

/**
Set cache file path.

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

/// Returns the cache file path.
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(withEnableDBCheckpointOnFlush enableDBCheckpointOnFlush: Bool) {
ODWLogConfiguration.setEnableDbCheckpointOnFlush(enableDBCheckpointOnFlush)
}

/// Returns true if DB will checkpointed when flushing.
public static func enableDBCheckpointOnFlush() -> Bool {
return ODWLogConfiguration.enableDbCheckpointOnFlush()
}

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

- Parameters:
- key: A key
- value: A value
*/
public func set(withKey key: String!, withValue value: String!) {
self.odwLogConfiguration.set(key, withValue: value)
}

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

/**
Sets the host value

- Parameters:
- host: A host.
*/
public func setHost(host: String!) {
self.odwLogConfiguration.setHost(host)
}

/// Returns the host value.
public func host() -> String? {
return self.odwLogConfiguration.host()
}
}
3 changes: 3 additions & 0 deletions wrappers/swift/Swift_Wrapper-Bridging-Header.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@
#import <Foundation/Foundation.h>

#import "../obj-c/ODWEventProperties.h"
#import "../obj-c/ODWLogConfiguration.h"
#import "../obj-c/ODWLogger.h"
absaroj marked this conversation as resolved.
Show resolved Hide resolved
#import "../obj-c/ODWLogManager.h"