Skip to content

Commit

Permalink
rename and refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
kosyloa committed Sep 6, 2023
1 parent e70da4c commit 36ddbe3
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 70 deletions.
83 changes: 42 additions & 41 deletions DXFeedFramework/Api/DXEndpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public typealias Role = DXEndpoint.Role

public class DXEndpoint {

public enum Role: UInt32 {
public enum Role: UInt32 {
case feed = 0
case onDemandFeed
case streamFeed
Expand Down Expand Up @@ -66,17 +66,17 @@ public class DXEndpoint {
try native.addListener(self)
}

public func add<O>(_ observer: O)
public func add<O>(observer: O)
where O: DXEndpointObserver,
O: Hashable {
observersSet.insert(observer)
}
observersSet.insert(observer)
}

public func remove<O>(_ observer: O)
public func remove<O>(observer: O)
where O: DXEndpointObserver,
O: Hashable {
observersSet.remove(observer)
}
observersSet.remove(observer)
}

public static func builder() -> Builder {
Builder()
Expand Down Expand Up @@ -144,56 +144,57 @@ public class DXEndpoint {
}
}

// only for testing
// only for testing
func callGC() throws {
try endpointNative.callGC()
}
}

public class Builder {
var role = Role.feed
var props = [String: String]()
public class Builder {
var role = Role.feed
var props = [String: String]()

var instancesNumerator = Int64(0)
var instancesNumerator = Int64(0)

private lazy var nativeBuilder: NativeBuilder? = {
try? NativeBuilder()
}()
private lazy var nativeBuilder: NativeBuilder? = {
try? NativeBuilder()
}()

deinit {
}
deinit {
}

fileprivate init() {
public init() {

}
}

public func withRole(_ role: Role) throws -> Self {
self.role = role
_ = try nativeBuilder?.withRole(role)
return self
}
public func withRole(_ role: Role) throws -> Self {
self.role = role
_ = try nativeBuilder?.withRole(role)
return self
}

public func isSupported(property: String) throws -> Bool {
return try nativeBuilder?.isSuppored(property: property) ?? false
}
public func isSupported(_ property: String) throws -> Bool {
return try nativeBuilder?.isSuppored(property: property) ?? false
}

public func withProperty(_ key: String, _ value: String) throws -> Self {
props[key] = value
try nativeBuilder?.withProperty(key, value)
return self
}
public func withProperty(_ key: String, _ value: String) throws -> Self {
props[key] = value
try nativeBuilder?.withProperty(key, value)
return self
}

public func build() throws -> DXEndpoint {
return try DXEndpoint(native: try nativeBuilder!.build(), role: role, name: getOrCreateEndpointName())
}
public func build() throws -> DXEndpoint {
return try DXEndpoint(native: try nativeBuilder!.build(), role: role, name: getOrCreateEndpointName())
}

private func getOrCreateEndpointName() -> String {
if let name = props[DXEndpoint.Property.name.rawValue] {
return name
private func getOrCreateEndpointName() -> String {
if let name = props[DXEndpoint.Property.name.rawValue] {
return name
}
let value = OSAtomicIncrement64(&instancesNumerator)
return "qdnet_\(value == 0 ? "" : "-\(value)")"
}
let value = OSAtomicIncrement64(&instancesNumerator)
return "qdnet_\(value == 0 ? "" : "-\(value)")"
}

}

extension DXEndpoint: EndpointListener {
Expand Down
4 changes: 2 additions & 2 deletions DXFeedFramework/Api/DXFeedSubcription.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class DXFeedSubcription {
self.events = Set(events)
}

public func add<O>(_ observer: O) throws
public func add<O>(observer: O) throws
where O: DXEventListener,
O: Hashable {
try listeners.reader { [weak self] in
Expand All @@ -32,7 +32,7 @@ public class DXFeedSubcription {
listeners.insert(observer)
}

public func remove<O>(_ observer: O)
public func remove<O>(observer: O)
where O: DXEventListener,
O: Hashable {
listeners.remove(observer)
Expand Down
4 changes: 2 additions & 2 deletions DXFeedFramework/Ipf/Live/DXInstrumentProfileCollector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class DXInstrumentProfileCollector {
self.native = try NativeInstrumentProfileCollector()
}

public func add<O>(_ observer: O) throws
public func add<O>(observer: O) throws
where O: DXInstrumentProfileUpdateListener,
O: Hashable {
try listeners.reader { [weak self] in
Expand All @@ -26,7 +26,7 @@ public class DXInstrumentProfileCollector {
listeners.insert(observer)
}

public func remove<O>(_ observer: O)
public func remove<O>(observer: O)
where O: DXInstrumentProfileUpdateListener,
O: Hashable {
listeners.remove(observer)
Expand Down
4 changes: 2 additions & 2 deletions DXFeedFramework/Ipf/Live/DXInstrumentProfileConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ public class DXInstrumentProfileConnection {
try native.close()
}

public func add<O>(_ observer: O)
public func add<O>(observer: O)
where O: DXInstrumentProfileConnectionObserver,
O: Hashable {
observersSet.insert(observer)
}

public func remove<O>(_ observer: O)
public func remove<O>(observer: O)
where O: DXInstrumentProfileConnectionObserver,
O: Hashable {
observersSet.remove(observer)
Expand Down
6 changes: 3 additions & 3 deletions DXFeedFrameworkTests/CandleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ final class CandleTests: XCTestCase {
let subscription = try endpoint?.getFeed()?.createSubscription(code)
let receivedEventExp = expectation(description: "Received events \(code)")
receivedEventExp.assertForOverFulfill = false
try subscription?.add(AnonymousClass { anonymCl in
try subscription?.add(observer: AnonymousClass { anonymCl in
anonymCl.callback = { events in
if events.count > 0 {
events.forEach { event in
Expand Down Expand Up @@ -166,7 +166,7 @@ final class CandleTests: XCTestCase {
let subscription = try endpoint?.getFeed()?.createSubscription(code)
let beginEventsExp = expectation(description: "Begin events \(code)")
let endEventsExp = expectation(description: "End events \(code)")
try subscription?.add(AnonymousClass { anonymCl in
try subscription?.add(observer: AnonymousClass { anonymCl in
anonymCl.callback = { events in
if events.count > 0 {
events.forEach { event in
Expand Down Expand Up @@ -216,7 +216,7 @@ final class CandleTests: XCTestCase {
testDelegate.wasSnapshotExpect = snapshotExpect
testDelegate.wasUpdateExpect = updateExpect
snapshotProcessor.add(testDelegate)
try subscription?.add(snapshotProcessor)
try subscription?.add(observer: snapshotProcessor)
try subscription?.addSymbols(symbol)
wait(for: [snapshotExpect, updateExpect], timeout: 10)
try? endpoint?.disconnect()
Expand Down
2 changes: 1 addition & 1 deletion DXFeedFrameworkTests/EndpointPublisherTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ final class EndpointPublisherTest: XCTestCase {
let expectations = [DXEndpointState.connected: expectation(description: "Connected"),
DXEndpointState.connecting: expectation(description: "Connecting")]
let listener = TestListener(expectations: expectations)
endpoint?.add(listener)
endpoint?.add(observer: listener)
try endpoint?.connect(":4700")
let exps = Array(expectations.filter({ element in
element.key != .notConnected
Expand Down
4 changes: 2 additions & 2 deletions DXFeedFrameworkTests/EndpointTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ final class EndpointTest: XCTestCase {
DXEndpointState.connecting: expectation(description: "Connecting"),
DXEndpointState.notConnected: expectation(description: "NotConnected")]
let listener = TestListener(expectations: expectations)
endpoint?.add(listener)
endpoint?.add(observer: listener)
try endpoint?.connect(endpointAddress)
let exps = Array(expectations.filter({ element in
element.key != .notConnected
Expand Down Expand Up @@ -84,7 +84,7 @@ final class EndpointTest: XCTestCase {
func testSupportProperty() throws {
let builder = DXEndpoint.builder()
func isSupportedProperty(_ prop: String, _ expected: Bool) {
XCTAssert(try builder.isSupported(property: prop) == expected, "Graal doesn't support property \(prop)")
XCTAssert(try builder.isSupported(prop) == expected, "Graal doesn't support property \(prop)")
}
DXEndpoint.Property.allCases.forEach { prop in
isSupportedProperty(prop.rawValue, true)
Expand Down
4 changes: 2 additions & 2 deletions DXFeedFrameworkTests/FeedTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ final class FeedTest: XCTestCase {
let receivedEventExp = expectation(description: "Received events \(code)")
receivedEventExp.assertForOverFulfill = false

try subscription?.add(AnonymousClass { anonymCl in
try subscription?.add(observer: AnonymousClass { anonymCl in
anonymCl.callback = { events in
events.forEach { event in
differentSymbols.insert(event.quote.eventSymbol)
Expand Down Expand Up @@ -151,7 +151,7 @@ final class FeedTest: XCTestCase {
let subscription = try endpoint.getFeed()?.createSubscription(code)
let receivedEventExp = expectation(description: "Received events \(code)")
receivedEventExp.assertForOverFulfill = false
try subscription?.add(AnonymousClass { anonymCl in
try subscription?.add(observer: AnonymousClass { anonymCl in
anonymCl.callback = { events in
if events.count > 0 {
let event = events.first
Expand Down
6 changes: 3 additions & 3 deletions DXFeedFrameworkTests/IPFTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ STOCK,EREGL:TR,EREĞLİ DEMİR VE ÇELİK FABRİKALARI1 T.A.Ş.,TR,XIST,XIST,TRY
let newProfile = InstrumentProfile()
newProfile.symbol = "TEST_123"

try collector.add(AnonymousProfileListener { anonymCl in
try collector.add(observer: AnonymousProfileListener { anonymCl in
anonymCl.callback = { profiles in
if profiles.count == 1 {
let profile = profiles.first
Expand Down Expand Up @@ -212,7 +212,7 @@ STOCK,EREGL:TR,EREĞLİ DEMİR VE ÇELİK FABRİKALARI1 T.A.Ş.,TR,XIST,XIST,TRY
let expectationCollector = expectation(description: "Collector")
expectationCollector.assertForOverFulfill = false
let collector = try DXInstrumentProfileCollector()
try collector.add(AnonymousProfileListener { anonymCl in
try collector.add(observer: AnonymousProfileListener { anonymCl in
anonymCl.callback = { profiles in
if profiles.count > 0 {
expectationCollector.fulfill()
Expand All @@ -223,7 +223,7 @@ STOCK,EREGL:TR,EREĞLİ DEMİR VE ÇELİK FABRİKALARI1 T.A.Ş.,TR,XIST,XIST,TRY
let expectationConnection = expectation(description: "Connection")
expectationConnection.expectedFulfillmentCount = 3 // connecting, connected, completed
let connection = try DXInstrumentProfileConnection(address, collector)
connection.add(AnonymousConnectionListener { anonymCl in
connection.add(observer: AnonymousConnectionListener { anonymCl in
anonymCl.callback = { _, new in
switch new {
case .notConnected:
Expand Down
12 changes: 0 additions & 12 deletions DXFeedFrameworkTests/SystemPropertyTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,4 @@ final class SystemPropertyTest: XCTestCase {
}
XCTAssert(value == SystemProperty.getProperty(key), "Couldn't read value")
}

func testException() {
do {
try SystemProperty.test()
} catch {
print("Just test exception: \(error)")
}
}

func testSupportedProperties() {

}
}

0 comments on commit 36ddbe3

Please sign in to comment.