diff --git a/Makefile b/Makefile index d9cb130..7bfd8d8 100644 --- a/Makefile +++ b/Makefile @@ -55,7 +55,10 @@ debug_integration_test: make setup_server swift test -Xswiftc -DINTEGRATION_TEST -Xswiftc -DDEBUG --filter IntegrationTests make teardown_server - + +.PHONY: demo +demo: + swift run Demo .PHONY: clean clean: diff --git a/Package.swift b/Package.swift index 3f477fc..35c7c43 100644 --- a/Package.swift +++ b/Package.swift @@ -12,7 +12,7 @@ let package = Package( // Products define the executables and libraries a package produces, and make them visible to other packages. .library( name: "LCLPing", - targets: ["LCLPing"]), + targets: ["LCLPing"]) ], dependencies: [ // Dependencies declare other packages that this package depends on. @@ -36,6 +36,11 @@ let package = Package( .product(name: "NIOSSL", package: "swift-nio-ssl"), .product(name: "Collections", package: "swift-collections") ]), + .executableTarget( + name: "Demo", + dependencies: ["LCLPing"], + exclude: ["README.md"] + ), .testTarget( name: "UtilitiesTests", dependencies: ["LCLPing"] diff --git a/README.md b/README.md index 89de0bf..39f6967 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,75 @@ -![Swift CI](https://github.com/Local-Connectivity-Lab/lcl-ping/actions/workflows/build.yaml/badge.svg?branch=main) +

+ Logo=5.9) +import Foundation +import LCLPing + +// create ping configuration for each run +let pingConfig = LCLPing.PingConfiguration(type: .icmp, endpoint: .ipv4("google.com", 0)) + +// create ping options +#if os(macOS) || os(iOS) +let options = LCLPing.Options(verbose: false, useNative: false) +#else +let options = LCLPing.Options(verbose: false) +#endif + +// initialize ping object with the options +var ping = LCLPing(options: options) + +try await ping.start(pingConfiguration: pingConfig) +switch ping.status { +case .error, .ready, .running: + print("LCLPing is in invalid state. Abort") +case .stopped, .finished: + print(ping.summary) +} +#else +fatalError("Requires at least Swift 5.9") +#endif diff --git a/images/logo.png b/images/logo.png new file mode 100644 index 0000000..00218f8 Binary files /dev/null and b/images/logo.png differ