Skip to content

Commit

Permalink
swiftlint fixes.
Browse files Browse the repository at this point in the history
warning fixes

add isTools flag for CLI utils
  • Loading branch information
kosyloa committed Oct 20, 2023
1 parent db46e4e commit a9d687e
Show file tree
Hide file tree
Showing 21 changed files with 65 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
argument = "PerfTest localhost:6666 TimeAndSale YQKNT"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "ScheduleSample"
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "DXFeedIpfConnect Quote https://demo:[email protected]/ipf"
isEnabled = "NO">
Expand All @@ -76,12 +80,12 @@
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = " Dump demo.dxfeed.com:7300 timeandsale ETH/USD:GDAX -p dxfeed.wildcard.enable=true,one_more_prop=abc -t test_tape_ios.txt[format=text] -q"
argument = " Dump demo.dxfeed.com:7300 timeandsale,quote,profile,order,trade IBM,AAPL,ETH/USD:GDAX -p dxfeed.wildcard.enable=true,one_more_prop=abc -t test_tape_ios.txt[format=text] -q"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = " Dump localhost:6666 TimeAndSale all -p dxfeed.wildcard.enable=true,one_more_prop=abc -t test_tape_ios.txt[format=text] -q"
isEnabled = "YES">
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "LatencyTest mddqa.in.devexperts.com:7400 TimeAndSale ETH/USD:GDAX"
Expand Down
4 changes: 2 additions & 2 deletions DXFeedFramework/Events/Market/OptionSale.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class OptionSale: MarketEvent, IIndexedEvent {
/// Gets or sets sale conditions provided for this event by data feed.
///
/// This field format is specific for every particular data feed.
public var exchangeSaleConditions: String = ""
public var exchangeSaleConditions: String?
/// Gets or sets implementation-specific flags.
///
/// **Do not use this method directly.**
Expand Down Expand Up @@ -249,7 +249,7 @@ price=\(price), \
size=\(size), \
bid=\(bidPrice), \
ask=\(askPrice), \
ESC='\(exchangeSaleConditions ?? "null")', \
ESC=\(exchangeSaleConditions ?? "null"), \
TTE=\(StringUtil.encodeChar(char: Int16(getTradeThroughExempt().unicodeScalars.first?.value ?? 0))), \
side=\(aggressorSide), \
spread=\(isSpreadLeg), \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class OptionSaleMapper: Mapper {
pointer.pointee.size = optionSale.size
pointer.pointee.bid_price = optionSale.bidPrice
pointer.pointee.ask_price = optionSale.askPrice
pointer.pointee.exchange_sale_conditions = optionSale.exchangeSaleConditions.toCStringRef()
pointer.pointee.exchange_sale_conditions = optionSale.exchangeSaleConditions?.toCStringRef()
pointer.pointee.flags = optionSale.flags
pointer.pointee.underlying_price = optionSale.underlyingPrice
pointer.pointee.volatility = optionSale.volatility
Expand Down
2 changes: 1 addition & 1 deletion DXFeedFramework/Native/Graal/ThreadManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ThreadManager {
}
objc_sync_enter(self)
let threadPointer = UnsafeMutablePointer<OpaquePointer?>.allocate(capacity: 1)
let value = graal_attach_thread(Isolate.shared.isolate.pointee, threadPointer)
_ = graal_attach_thread(Isolate.shared.isolate.pointee, threadPointer)
_ = pthread_setspecific(ThreadManager.key.pointee, threadPointer)
return threadPointer
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class NativeInstrumentProfileConnection {
}
}

private static let listenerCallback: dxfg_ipf_connection_state_change_listener_func = {_, oldState, newState, context in
private static let listenerCallback: dxfg_ipf_connection_state_change_listener_func
= {_, oldState, newState, context in
if let context = context {
let endpoint: AnyObject = bridge(ptr: context)
if let listener = endpoint as? WeakListener {
Expand Down
6 changes: 3 additions & 3 deletions DXFeedFramework/Native/Schedule/NativeSchedule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,9 @@ class NativeSchedule {
public static func setDefaults(_ data: Data) throws {
let thread = currentThread()
_ = try data.withUnsafeBytes({ pointer in
let result = try ErrorCheck.nativeCall(thread, dxfg_Schedule_setDefaults(thread,
pointer.baseAddress,
Int32(data.count)))
_ = try ErrorCheck.nativeCall(thread, dxfg_Schedule_setDefaults(thread,
pointer.baseAddress,
Int32(data.count)))
})
}

Expand Down
2 changes: 2 additions & 0 deletions DXFeedFramework/Utils/String+Range.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,11 @@ extension String.Index {
}

extension String {
// swiftlint:disable identifier_name
public func slice(from: String, to: String) -> String? {
guard let rangeFrom = range(of: from)?.upperBound else { return nil }
guard let rangeTo = self[rangeFrom...].range(of: to)?.lowerBound else { return nil }
return String(self[rangeFrom..<rangeTo])
}
// swiftlint:enable identifier_name
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class TestEndpoointStateListener: DXEndpointObserver, Hashable {
}

deinit {
print("deinit TestEndpoointStateListener \(Thread.current.threadName) \(Thread.current.name)")
print("deinit TestEndpoointStateListener \(Thread.current.threadName) \(Thread.current.name ?? "")")
}

static func == (lhs: TestEndpoointStateListener, rhs: TestEndpoointStateListener) -> Bool {
Expand Down
16 changes: 12 additions & 4 deletions DXFeedFrameworkTests/PublisherTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,25 @@ final class PublisherTest: XCTestCase {

func execute() throws {
do {
let endpoint: DXEndpoint? = try DXEndpoint.builder().withRole(.publisher).withProperty("test", "value").build()
let endpoint: DXEndpoint? = try DXEndpoint
.builder()
.withRole(.publisher)
.withProperty("test", "value")
.build()
try endpoint?.connect(":7400")

let testQuote = Quote("AAPL")
testQuote.bidSize = 100
testQuote.askPrice = 666
try? testQuote.setSequence(10)
let feedEndpoint = try DXEndpoint.builder().withRole(.feed).withProperty("test", "value").build()
var publisher = endpoint?.getPublisher()
let feedEndpoint = try DXEndpoint
.builder()
.withRole(.feed)
.withProperty("test", "value")
.build()
let publisher = endpoint?.getPublisher()
let connectedExpectation = expectation(description: "Connected")
var stateListener: TestEndpoointStateListener? = TestEndpoointStateListener { listener in
let stateListener: TestEndpoointStateListener? = TestEndpoointStateListener { listener in
listener.callback = { state in
if state == .connected {
connectedExpectation.fulfill()
Expand Down
6 changes: 6 additions & 0 deletions Samples/PerfTestCL/Arguments.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ Cmd \(cmd) contains not enough \(cmd.count - 1) arguments. Expected \(requiredNu
arguments.count
}

public func parseTypes(at index: Int) -> [EventCode] {
return arguments[2].split(separator: ",").compactMap { str in
return EventCode(string: String(str))
}
}

public func parseSymbols(at index: Int) -> [Symbol] {
let symbols = arguments[index]
if symbols.lowercased() == "all" {
Expand Down
3 changes: 2 additions & 1 deletion Samples/PerfTestCL/ConnectCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Foundation
import DXFeedFramework

class ConnectCommand: ToolsCommand {
var isTools: Bool = true
var cmd = "Connect"
var shortDescription = "Connects to specified address(es)."

Expand Down Expand Up @@ -55,7 +56,7 @@ Where:
let listener = ConnectEventListener()
subscription.createSubscription(address: arguments[1],
symbols: arguments.parseSymbols(at: 3),
types: arguments[2],
types: arguments.parseTypes(at: 2),
listener: listener,
properties: arguments.properties,
time: arguments.time)
Expand Down
8 changes: 2 additions & 6 deletions Samples/PerfTestCL/DumpCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Foundation
import DXFeedFramework

class DumpCommand: ToolsCommand {
var isTools: Bool = true
var cmd: String = "Dump"

var shortDescription = "Dumps all events received from address."
Expand Down Expand Up @@ -41,10 +42,8 @@ class DumpCommand: ToolsCommand {
}
}()


func execute() {
let address = arguments[1]
let types = arguments[2]
let symbols = arguments.parseSymbols(at: 3)

isQuite = arguments.isQuite
Expand All @@ -58,9 +57,7 @@ class DumpCommand: ToolsCommand {
.withName("DumpTool")
.build()

let eventTypes = types.split(separator: ",").compactMap { str in
return EventCode(string: String(str))
}
let eventTypes = arguments.parseTypes(at: 2)
let subscription = try inputEndpoint.getFeed()?.createSubscription(eventTypes)
var outputEndpoint: DXEndpoint?

Expand All @@ -76,7 +73,6 @@ class DumpCommand: ToolsCommand {
}

try subscription?.add(observer: self)

try subscription?.addSymbols(symbols)

try inputEndpoint.connect(address)
Expand Down
1 change: 1 addition & 0 deletions Samples/PerfTestCL/HelpCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import Foundation

class HelpCommand: ToolsCommand {
var isTools: Bool = true
var cmd = "Help"

var shortDescription = "Help tool."
Expand Down
1 change: 1 addition & 0 deletions Samples/PerfTestCL/IpfConnectCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Foundation
import DXFeedFramework

class IpfConnectCommand: ToolsCommand {
var isTools: Bool = false
lazy var name = {
stringReference(self)
}()
Expand Down
3 changes: 2 additions & 1 deletion Samples/PerfTestCL/LatencyTestCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import Foundation

class LatencyTestCommand: ToolsCommand {
var isTools: Bool = true
var cmd = "LatencyTest"

var shortDescription = "Connects to the specified address(es) and calculates latency."
Expand Down Expand Up @@ -42,7 +43,7 @@ class LatencyTestCommand: ToolsCommand {

func execute() {
let address = arguments[1]
let types = arguments[2]
let types = arguments.parseTypes(at: 2)

let listener = LatencyEventListener()

Expand Down
3 changes: 2 additions & 1 deletion Samples/PerfTestCL/LiveIpfCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Foundation
import DXFeedFramework

class LiveIpfCommand: ToolsCommand {
var isTools: Bool = false
lazy var name = {
stringReference(self)
}()
Expand Down Expand Up @@ -51,7 +52,7 @@ class LiveIpfCommand: ToolsCommand {
func execute() {
do {
collector = try DXInstrumentProfileCollector()
connection = try DXInstrumentProfileConnection(arguments[1], collector!)
connection = try DXInstrumentProfileConnection(arguments.count > 1 ? arguments[1] : LiveIpfCommand.defaultIpfUrl, collector!)
// Update period can be used to re-read IPF files, not needed for services supporting IPF "live-update"
try connection?.setUpdatePeriod(60000)
connection?.add(observer: self)
Expand Down
4 changes: 2 additions & 2 deletions Samples/PerfTestCL/PerfTestCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Foundation
import DXFeedFramework

class PerfTestCommand: ToolsCommand {
var isTools: Bool = true
var cmd: String = "PerfTest"
var shortDescription: String = "Connects to specified address and calculates performance counters."
var fullDescription: String =
Expand Down Expand Up @@ -39,13 +40,12 @@ class PerfTestCommand: ToolsCommand {
var subscription = Subscription()
func execute() {
let address = arguments[1]
let types = arguments[2]

let listener = PerfTestEventListener()

subscription.createSubscription(address: address,
symbols: arguments.parseSymbols(at: 3),
types: types,
types: arguments.parseTypes(at: 2),
listener: listener,
properties: arguments.properties,
time: nil)
Expand Down
6 changes: 5 additions & 1 deletion Samples/PerfTestCL/ScheduleCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Foundation
import DXFeedFramework

class ScheduleCommand: ToolsCommand {
var isTools: Bool = false
var cmd = "ScheduleSample"

var shortDescription = "A sample program that demonstrates different use cases of Schedule API."
Expand Down Expand Up @@ -94,7 +95,10 @@ class ScheduleCommand: ToolsCommand {
}
}

print("Checked \(profiles.count) instrument profiles: \(successes) successes, \((profiles.count - successes)) failures")
print(
"""
Checked \(profiles.count) instrument profiles: \(successes) successes, \((profiles.count - successes)) failures
""")

}
}
8 changes: 4 additions & 4 deletions Samples/PerfTestCL/SubscriptionUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ class Subscription {

func createSubscription<O>(address: String,
symbols: [Symbol],
types: String,
types: [EventCode],
listener: O,
properties: [String: String],
time: String?)
where O: DXEventListener, O: Hashable {
print("""
Create subscription to \(address) for \(types):\(symbols) with properties:\(properties) and time \(time)
Create subscription to \(address) for \(types):\(symbols) with properties:\(properties) and time \(time ?? "---")
""")
endpoint = try? DXEndpoint
.builder()
.withRole(.feed)
.withProperties(properties)
.build()
_ = try? endpoint?.connect(address)
types.split(separator: ",").forEach { str in
let subscription = try? endpoint?.getFeed()?.createSubscription(EventCode(string: String(str)))
types.forEach { str in
let subscription = try? endpoint?.getFeed()?.createSubscription(str)
try? subscription?.add(observer: listener)
if time != nil {
guard let date = TimeUtil.parse(time!) else {
Expand Down
1 change: 1 addition & 0 deletions Samples/PerfTestCL/ToolsCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import Foundation

protocol ToolsCommand {
var isTools: Bool { get }
var cmd: String { get }
var shortDescription: String { get }
var fullDescription: String { get }
Expand Down
10 changes: 7 additions & 3 deletions Samples/PerfTestCL/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ func getCommandsDecription() -> String {
let maxSize = (commands.max { cmd1, cmd2 in
cmd1.cmd.count < cmd2.cmd.count
}?.cmd.count ?? 0) + 4
let descriptions = commands.map { cmd in
let spaces = maxSize - cmd.cmd.count
return " \(cmd.cmd + String(repeating: " ", count: spaces)): \(cmd.shortDescription)"
let descriptions = commands.compactMap { cmd in
if cmd.isTools {
let spaces = maxSize - cmd.cmd.count
return " \(cmd.cmd + String(repeating: " ", count: spaces)): \(cmd.shortDescription)"
} else {
return nil
}
}.joined(separator: "\n")

return descriptions
Expand Down

0 comments on commit a9d687e

Please sign in to comment.