Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
37e2174
adding swift wrapper
absaroj Jun 2, 2023
70984ff
moving files to sources
absaroj Jun 2, 2023
ca4c6b8
moving files to proper places
absaroj Jun 2, 2023
80790d2
adding module for header expose and importing it in swift wrapper
absaroj Jun 2, 2023
3b91ddc
correcting files for build errors and other changes
absaroj Jun 2, 2023
94f9691
adding module for objc
absaroj Jun 2, 2023
408fc8f
swift build passing'
absaroj Jun 2, 2023
1791586
adding readme
absaroj Jun 2, 2023
c24eb4a
changing the package name to 1dsswiftwrapper
absaroj Jun 6, 2023
e7e43ef
changing target name
absaroj Jun 8, 2023
477b036
adding pr suggestions
absaroj Jun 8, 2023
eb85e7f
adding build.sh changes
absaroj Jun 9, 2023
d76b833
cmake list file changes
absaroj Jun 9, 2023
2927818
creating static lib
absaroj Jun 9, 2023
85d380a
adding swift wrappers build and linking
absaroj Jun 9, 2023
da20709
adding more logic for building and producing sample app
absaroj Jun 9, 2023
bf52749
adding code for swiftc invoking
absaroj Jun 9, 2023
7b69738
adding comments
absaroj Jun 9, 2023
753bde7
adding change to create the sample app
absaroj Jun 9, 2023
fde4743
linking and includding modules in swiftc to build the sample exe: bei…
absaroj Jun 9, 2023
e96ab38
adding comments
absaroj Jun 9, 2023
df89625
removing self
absaroj Jun 9, 2023
2a129d7
compiling all files frrom sample
absaroj Jun 9, 2023
84585b4
removing extraline
absaroj Jun 9, 2023
37e75e1
correcting the output folder of swift build
absaroj Jun 11, 2023
d149e89
correcting build output folder paths
absaroj Jun 12, 2023
a536f12
Merge branch 'main' into absaroj/local_build
lalitb Jun 13, 2023
2b3105d
Merge branch 'main' into absaroj/local_build
lalitb Jun 13, 2023
8151b28
adding typealias file to stop importing the objcmodule in clients (#1…
absaroj Jun 16, 2023
9b31864
Merge branch 'main' into absaroj/local_build
absaroj Jun 16, 2023
c2ddcb9
adding call to create logger
absaroj Jun 16, 2023
ae54af1
adding changes for framework include
absaroj Jun 16, 2023
71506dc
adding fwks
absaroj Jun 16, 2023
deb2126
linking libs and fwks
absaroj Jun 16, 2023
8d30578
adding getter and setters for swift as computed properties
absaroj Jun 18, 2023
3dd219c
adding sample app changes
absaroj Jun 18, 2023
2cc34f0
adding app changes
absaroj Jun 18, 2023
526fd38
adding commondatacontext
absaroj Jun 21, 2023
ec3570b
swift build passing
absaroj Jun 21, 2023
37e7dc6
correcting common context init
absaroj Jun 21, 2023
6d51f66
adding get set in event properties list
absaroj Jun 21, 2023
03aaa67
adding getter to eventprops
absaroj Jun 21, 2023
6b01d53
removing useless methods
absaroj Jun 21, 2023
a8970a1
adding getter and setter for eventprops
absaroj Jun 21, 2023
849d730
adding getter
absaroj Jun 21, 2023
959d64d
fixing type bug
absaroj Jun 21, 2023
7415f56
fixing main app issues
absaroj Jun 21, 2023
ab4ee20
adding semantic context variable to the logger
absaroj Jun 21, 2023
524d3f0
modifying the access level for the objc types in swift to make sure t…
absaroj Jun 21, 2023
872736c
adding default constructor
absaroj Jun 21, 2023
17eb071
keeping main.swift clean
absaroj Jun 22, 2023
8b5ca34
taking merge from main
absaroj Jun 22, 2023
9a87976
correcting comment
absaroj Jun 22, 2023
8780f44
adding computed property for objc variable
absaroj Jun 22, 2023
78c4fdf
Merge branch 'main' into absaroj/no_objc_exposed
absaroj Jun 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion wrappers/swift/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ set(SWIFT_MODULE_PATH "${CMAKE_BINARY_DIR}/${PROJECT_NAME}/${LOWER_BUILD_TYPE}")
set(SWIFT_OBJECT_OUTPUT_FOLDER "${SWIFT_MODULE_PATH}/${PROJECT_NAME}.build") # Swift object file output path: debug/OneDSSwift.build/*.o
set(SWIFT_STATIC_LIB "${CMAKE_BINARY_DIR}/StaticLibs/libonedsswift.a") # Putting newly created static libs in this folder
set(OBJC_MODULE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/Modules")

# Set build and path related variables
set(INSTALLED_LIB_PATH "/usr/local/lib")

PROJECT(${PROJECT_NAME})
Expand Down Expand Up @@ -99,7 +101,9 @@ file(GLOB SWIFT_FILES "${CMAKE_CURRENT_SOURCE_DIR}/Sample/*.swift")
set(INCLUDE_LIBS
${MAT_LIB} # libmat.a contains ObjC symbols
${SWIFT_STATIC_LIB} # libonedsswift.a contains swift wrapper symbols
${SQLITE3_LIB}
"-lC++"
"-lZ"
)

# Collect all the modules to be included
Expand All @@ -108,6 +112,14 @@ set(INCLUDE_MODULES
"-I${SWIFT_MODULE_PATH}" # Swift wrappers module OneDSSwift, generated after the build
)

# Collect all frameworks to be included
set(INCLUDE_FRAMEWORKS
-framework Network
-framework SystemConfiguration
)

get_filename_component(FRAMEWORK_DIR ${SYSTEM_CONFIGURATION} DIRECTORY)

# Invoke swiftc to create the exe
message("\nRunning swiftc...")
execute_process(
Expand All @@ -116,10 +128,12 @@ execute_process(
${SWIFT_FILES} # Files to compile
${INCLUDE_MODULES} # Modules to include
${INCLUDE_LIBS} # Static libs to link
-F ${FRAMEWORK_DIR} # Set Framework search directory
${INCLUDE_FRAMEWORKS} # Frameworks to include
RESULT_VARIABLE SWIFTC_RESULT
)

if(EXISTS ${CMAKE_BINARY_DIR}/sample_app)
if((SWIFT_BUILD_RESULT EQUAL 0) AND (EXISTS ${CMAKE_BINARY_DIR}/sample_app))
message("Executable is created at: ${CMAKE_BINARY_DIR}/sample_app")
else()
message(FATALError, "Executable creation failed.")
Expand Down
2 changes: 1 addition & 1 deletion wrappers/swift/Headers/ObjCModule-Bridging-Header.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// SPDX-License-Identifier: Apache-2.0
//

// Contains all the Obj-C header files which are exposed to Swift
// Contains all the Obj-C header files which are exposed to Swift.

#import <Foundation/Foundation.h>

Expand Down
2 changes: 2 additions & 0 deletions wrappers/swift/Modules/module.modulemap
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/// Module exporting headers declared in ObjC. Imported by Swift package to have access to the ObjC types.

module ObjCModule {
header "../Headers/ObjCModule-Bridging-Header.h"
export *
Expand Down
102 changes: 102 additions & 0 deletions wrappers/swift/Sources/OneDSSwift/CommonDataContext.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
//
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
//

import ObjCModule

/// Wrapper over ODWCommonDataContext class.
public final class CommonDataContext {
/// ObjC variable which is wrapped by swift.
var odwCommonDataContext: ODWCommonDataContext

/// Contructor initialized with ObjC wrapped object.
init(odwCommonDataContext: ODWCommonDataContext) {
self.odwCommonDataContext = odwCommonDataContext
}

/// Default constructor.
public init() {
odwCommonDataContext = ODWCommonDataContext()
}

/// Domain Name for the current machine.
public var domainName:String {
get {
odwCommonDataContext.domainName
}
set {
odwCommonDataContext.domainName = newValue
}
}

/// Friendly Machine Name
public var machineName:String {
get {
odwCommonDataContext.machineName
}
set {
odwCommonDataContext.machineName = newValue
}
}

/// User Name such as the Login Name.
public var userNames:[Any] {
get {
odwCommonDataContext.userNames as? [Any] ?? []
}
set {
odwCommonDataContext.userNames = NSMutableArray(array: newValue)
}
}

/// User Alias, if different that UserName.
public var userAliases:[Any] {
get {
odwCommonDataContext.userAliases as? [Any] ?? []
}
set {
odwCommonDataContext.userAliases = NSMutableArray(array: newValue)
}
}

/// IP Addresses for local network ports such as IPv4, IPv6, etc.
public var IPAddresses:[Any] {
get {
odwCommonDataContext.ipAddresses as? [Any] ?? []
}
set {
odwCommonDataContext.ipAddresses = NSMutableArray(array: newValue)
}
}

/// Collection of Language Identifiers.
public var languageIdentifiers:[Any] {
get {
odwCommonDataContext.languageIdentifiers as? [Any] ?? []
}
set {
odwCommonDataContext.languageIdentifiers = NSMutableArray(array: newValue)
}
}

/// Collection of Machine Identifies such as Machine Name, Motherboard ID, MAC Address, etc.
public var machineIDs:[Any] {
get {
odwCommonDataContext.machineIds as? [Any] ?? []
}
set {
odwCommonDataContext.machineIds = NSMutableArray(array: newValue)
}
}

/// Collection of Out-of-Scope identifiers such as Client ID, etc.
public var outOfScopeIdentifiers:[Any] {
get {
odwCommonDataContext.outOfScopeIdentifiers as? [Any] ?? []
}
set {
odwCommonDataContext.outOfScopeIdentifiers = NSMutableArray(array: newValue)
}
}
}
54 changes: 22 additions & 32 deletions wrappers/swift/Sources/OneDSSwift/EventProperties.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,6 @@ public final class EventProperties {
odwEventProperties = ODWEventProperties(name: name, properties: properties, piiTags: piiTags)
}

/// Returns ODWEventProperties object, around which the Swift class is wrapped.
public func getODWEventPropertiesObject() -> ODWEventProperties {
return odwEventProperties
}

/// Returns all the properties as dictionary
public func properties() -> [String: Any] {
return odwEventProperties.properties
}

/// Returns all the piiTags as dictionary
public func piiTags() -> [String: Any] {
return odwEventProperties.piiTags
}

/**
Sets the base type of the event, populated in Records.Type.

Expand Down Expand Up @@ -87,9 +72,9 @@ public final class EventProperties {
- Parameters:
- name: Name of the property.
- value: Value of the property.
- piiKind: The kind of Personal Identifieable Information (PII), one from the ::ODWPiiKind enum values.
- piiKind: The kind of Personal Identifieable Information (PII), one from the ::PIIKind enum values.
*/
public func setProperty(_ name: String, withValue value: Any, withPiiKind piiKind: ODWPiiKind) {
public func setProperty(_ name: String, withValue value: Any, withPiiKind piiKind: PIIKind) {
odwEventProperties.setProperty(name, withValue: value, with: piiKind)
}

Expand All @@ -110,9 +95,9 @@ public final class EventProperties {
- Parameters:
- name: Name of the property.
- value: A Double that contains the property value.
- piiKind: The kind of Personal Identifieable Information (PII), one from the ::ODWPiiKind enum values.
- piiKind: The kind of Personal Identifieable Information (PII), one from the ::PIIKind enum values.
*/
public func setProperty(_ name: String, withDoubleValue value: Double, withPiiKind piiKind: ODWPiiKind) {
public func setProperty(_ name: String, withDoubleValue value: Double, withPiiKind piiKind: PIIKind) {
odwEventProperties.setProperty(name, withDoubleValue: value, with: piiKind)
}

Expand All @@ -133,9 +118,9 @@ public final class EventProperties {
- Parameters:
- name: Name of the property.
- value: An integer that contains the property value.
- piiKind: The kind of Personal Identifieable Information (PII), one from the ::ODWPiiKind enum values.
- piiKind: The kind of Personal Identifieable Information (PII), one from the ::PIIKind enum values.
*/
public func setProperty(_ name: String, withInt64Value value: Int64, withPiiKind piiKind: ODWPiiKind) {
public func setProperty(_ name: String, withInt64Value value: Int64, withPiiKind piiKind: PIIKind) {
odwEventProperties.setProperty(name, withInt64Value: value, with: piiKind)
}

Expand All @@ -156,9 +141,9 @@ public final class EventProperties {
- Parameters:
- name: Name of the property.
- value: An integer that contains the property value.
- piiKind: The kind of Personal Identifieable Information (PII), one from the ::ODWPiiKind enum values.
- piiKind: The kind of Personal Identifieable Information (PII), one from the ::PIIKind enum values.
*/
public func setProperty(_ name: String, withUInt8Value value: UInt8, withPiiKind piiKind: ODWPiiKind) {
public func setProperty(_ name: String, withUInt8Value value: UInt8, withPiiKind piiKind: PIIKind) {
odwEventProperties.setProperty(name, withUInt8Value: value, with: piiKind)
}

Expand All @@ -179,9 +164,9 @@ public final class EventProperties {
- Parameters:
- name: Name of the property.
- value: An integer that contains the property value.
- piiKind: The kind of Personal Identifieable Information (PII), one from the ::ODWPiiKind enum values.
- piiKind: The kind of Personal Identifieable Information (PII), one from the ::PIIKind enum values.
*/
public func setProperty(_ name: String, withUInt64Value value: UInt64, withPiiKind piiKind: ODWPiiKind) {
public func setProperty(_ name: String, withUInt64Value value: UInt64, withPiiKind piiKind: PIIKind) {
odwEventProperties.setProperty(name, withUInt64Value: value, with: piiKind)
}

Expand All @@ -202,9 +187,9 @@ public final class EventProperties {
- Parameters:
- name: Name of the property.
- value: A `Bool` that contains the property value.
- piiKind: The kind of Personal Identifieable Information (PII), one from the ::ODWPiiKind enum values.
- piiKind: The kind of Personal Identifieable Information (PII), one from the ::PIIKind enum values.
*/
public func setProperty(_ name: String, withBoolValue value: Bool, withPiiKind piiKind: ODWPiiKind) {
public func setProperty(_ name: String, withBoolValue value: Bool, withPiiKind piiKind: PIIKind) {
odwEventProperties.setProperty(name, withBoolValue: value, with: piiKind)
}

Expand All @@ -225,9 +210,9 @@ public final class EventProperties {
- Parameters:
- name: Name of the property.
- value: A "UUID" that contains the property value.
- piiKind: The kind of Personal Identifieable Information (PII), one from the ::ODWPiiKind enum values.
- piiKind: The kind of Personal Identifieable Information (PII), one from the ::PIIKind enum values.
*/
public func setProperty(_ name: String, withUUIDValue value: UUID, withPiiKind piiKind: ODWPiiKind) {
public func setProperty(_ name: String, withUUIDValue value: UUID, withPiiKind piiKind: PIIKind) {
odwEventProperties.setProperty(name, withUUIDValue: value, with: piiKind)
}

Expand All @@ -248,9 +233,9 @@ public final class EventProperties {
- Parameters:
- name: Name of the property.
- value: A `Date` that contains the property value.
- piiKind: The kind of Personal Identifieable Information (PII), one from the ::ODWPiiKind enum values.
- piiKind: The kind of Personal Identifieable Information (PII), one from the ::PIIKind enum values.
*/
public func setProperty(_ name: String, withDateValue value: Date, withPiiKind piiKind: ODWPiiKind) {
public func setProperty(_ name: String, withDateValue value: Date, withPiiKind piiKind: PIIKind) {
odwEventProperties.setProperty(name, withDateValue: value, with: piiKind)
}

Expand All @@ -261,8 +246,13 @@ public final class EventProperties {
- privTags: Privacy data type of the event.
- privLevel: Privacy diagnostic level of the event.
*/
public func setPrivacyMetadata(_ privTags: ODWPrivacyDataType, withdWDiagLevel privLevel: ODWDiagLevel) {
public func setPrivacyMetadata(_ privTags: PrivacyDataType, withdWDiagLevel privLevel: DiagnosticLevel) {
odwEventProperties.setProperty("EventInfo.PrivTags", withUInt64Value: UInt64(privTags.rawValue))
odwEventProperties.setProperty("EventInfo.Level", withUInt8Value: UInt8(privLevel.rawValue))
}

/// Returns ODWEventProperties object, around which the Swift class is wrapped.
func getODWEventPropertiesObject() -> ODWEventProperties {
return odwEventProperties
}
}
23 changes: 14 additions & 9 deletions wrappers/swift/Sources/OneDSSwift/LogConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,27 @@ import ObjCModule

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

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

- Parameters:
- config: `ODWLogConfiguration` object which would be wrapped to.
*/
public init(config: ODWLogConfiguration) {
self.odwLogConfiguration = config
init(config: ODWLogConfiguration) {
self._odwLogConfiguration = config
}

/// Return a copy of the default configuration
public static func getLogConfigurationCopy() -> LogConfiguration? {
if let odwLogConfiguration = ODWLogConfiguration.getCopy() {
return LogConfiguration(config: odwLogConfiguration)
if let _odwLogConfiguration = ODWLogConfiguration.getCopy() {
return LogConfiguration(config: _odwLogConfiguration)
} else {
return nil
}
Expand Down Expand Up @@ -191,12 +196,12 @@ public final class LogConfiguration {
- value: A value as a `String`.
*/
public func set(_ key: String, havingValue value: String) {
self.odwLogConfiguration.set(key, withValue: value)
_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)
return _odwLogConfiguration.value(forKey: key)
}

/**
Expand All @@ -206,11 +211,11 @@ public final class LogConfiguration {
- host: A host value as `String`.
*/
public func setHost(_ host: String) {
self.odwLogConfiguration.setHost(host)
_odwLogConfiguration.setHost(host)
}

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