Skip to content

Commit

Permalink
IPF: Connection WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
kosyloa committed Sep 4, 2023
1 parent 0387069 commit b14763a
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 22 deletions.
8 changes: 4 additions & 4 deletions DXFeedFramework.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@
64DA26BA2AA20AAA005B1757 /* InstrumentProfileConnectionState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64DA26B92AA20AAA005B1757 /* InstrumentProfileConnectionState.swift */; };
64DA26BC2AA20B66005B1757 /* InstrumentProfileConnectionState+ext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64DA26BB2AA20B66005B1757 /* InstrumentProfileConnectionState+ext.swift */; };
64DA26BE2AA20EDB005B1757 /* InstrumentProfileConnectionObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64DA26BD2AA20EDB005B1757 /* InstrumentProfileConnectionObserver.swift */; };
64DA26C02AA224EB005B1757 /* NativeInstrumentProfileConnectionListener.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64DA26BF2AA224EB005B1757 /* NativeInstrumentProfileConnectionListener.swift */; };
64DA26C02AA224EB005B1757 /* NativeIPFConnectionListener.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64DA26BF2AA224EB005B1757 /* NativeIPFConnectionListener.swift */; };
64DB79342A376E1B00229597 /* DXFeedFramework.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 803BAC0D29BFA50700FFAB1C /* DXFeedFramework.framework */; };
64DB79352A376E1B00229597 /* DXFeedFramework.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 803BAC0D29BFA50700FFAB1C /* DXFeedFramework.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
64ECD67F2A9CF4CB00B36935 /* DXIPFTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64ECD67E2A9CF4CB00B36935 /* DXIPFTest.swift */; };
Expand Down Expand Up @@ -528,7 +528,7 @@
64DA26B92AA20AAA005B1757 /* InstrumentProfileConnectionState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstrumentProfileConnectionState.swift; sourceTree = "<group>"; };
64DA26BB2AA20B66005B1757 /* InstrumentProfileConnectionState+ext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "InstrumentProfileConnectionState+ext.swift"; sourceTree = "<group>"; };
64DA26BD2AA20EDB005B1757 /* InstrumentProfileConnectionObserver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstrumentProfileConnectionObserver.swift; sourceTree = "<group>"; };
64DA26BF2AA224EB005B1757 /* NativeInstrumentProfileConnectionListener.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativeInstrumentProfileConnectionListener.swift; sourceTree = "<group>"; };
64DA26BF2AA224EB005B1757 /* NativeIPFConnectionListener.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativeIPFConnectionListener.swift; sourceTree = "<group>"; };
64ECD67E2A9CF4CB00B36935 /* DXIPFTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DXIPFTest.swift; sourceTree = "<group>"; };
64ECD6812A9DDC2800B36935 /* InstrumentProfileReader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstrumentProfileReader.swift; sourceTree = "<group>"; };
64ECD6842A9DDF6200B36935 /* InstrumentProfileCollector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstrumentProfileCollector.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -751,7 +751,7 @@
6464075A2AA0CEF2006FF769 /* NativeExecutor.swift */,
646407582AA0CA8D006FF769 /* NativeProfileIterator.swift */,
64DA26BB2AA20B66005B1757 /* InstrumentProfileConnectionState+ext.swift */,
64DA26BF2AA224EB005B1757 /* NativeInstrumentProfileConnectionListener.swift */,
64DA26BF2AA224EB005B1757 /* NativeIPFConnectionListener.swift */,
);
path = Live;
sourceTree = "<group>";
Expand Down Expand Up @@ -1631,7 +1631,7 @@
642BE4D22A2F5D230052340A /* TimeAndSale.swift in Sources */,
64BA92692A306E6000BE26A0 /* TradeBase.swift in Sources */,
640C3FD02A6178B400555161 /* CandlePrice.swift in Sources */,
64DA26C02AA224EB005B1757 /* NativeInstrumentProfileConnectionListener.swift in Sources */,
64DA26C02AA224EB005B1757 /* NativeIPFConnectionListener.swift in Sources */,
8088D77D29C8DAF800F240CB /* GraalErrorCode.swift in Sources */,
64DA26B62AA1EF47005B1757 /* ProfileIterator.swift in Sources */,
8088D76929C0FC5C00F240CB /* Isolate.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion DXFeedFramework/Ipf/Live/InstrumentProfileCollector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation
public class InstrumentProfileCollector {
private let listeners = ConcurrentSet<AnyHashable>()

private let native: NativeInstrumentProfileCollector
internal let native: NativeInstrumentProfileCollector

public init() throws {
self.native = try NativeInstrumentProfileCollector()
Expand Down
55 changes: 55 additions & 0 deletions DXFeedFramework/Ipf/Live/InstrumentProfileConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,60 @@
import Foundation

public class InstrumentProfileConnection {
private let native: NativeInstrumentProfileConnection
private let collector: InstrumentProfileCollector

private var observersSet = ConcurrentSet<AnyHashable>()
private var observers: [InstrumentProfileConnectionObserver] {
return observersSet.reader { $0.compactMap { value in value as? InstrumentProfileConnectionObserver } }
}

init(_ address: String) throws {
collector = try InstrumentProfileCollector()
native = try NativeInstrumentProfileConnection(collector.native, address)
try native.addListener(self)
}

public func getAddress() -> String {
return native.getAddress()
}

public func getUpdatePeriod() -> Long {
return native.getUpdatePeriod()
}

public func setUpdatePeriod(_ value: Long) {
native.setUpdatePeriod(value)
}

public func getLastModified() -> Long {
return native.getLastModified()
}

public func start() throws {
try native.start()
}

public func close() throws {
try native.close()
}

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

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

}

extension InstrumentProfileConnection: NativeIPFConnectionListener {
func connectionDidChangeState(old: InstrumentProfileConnectionState, new: InstrumentProfileConnectionState) {
observers.forEach { $0.connectionDidChangeState(old: old, new: new) }
}
}
2 changes: 1 addition & 1 deletion DXFeedFramework/Native/Endpoint/NativeEndpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class NativeEndpoint {
self.listener = nil
}
}

deinit {
removeListener()
if let endpoint = self.endpoint {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@

import Foundation

public protocol NativeInstrumentProfileConnectionListener: AnyObject {
protocol NativeIPFConnectionListener: AnyObject {
func connectionDidChangeState(old: InstrumentProfileConnectionState, new: InstrumentProfileConnectionState)
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class NativeInstrumentProfileConnection {
private static let defaultUpdatePeriod = Long(1 * 60 * 1000) // 1 minute

var nativeListener: UnsafeMutablePointer<dxfg_ipf_connection_state_change_listener_t>?
weak var listener: NativeInstrumentProfileConnectionListener?
weak var listener: NativeIPFConnectionListener?

static let listenerCallback: dxfg_ipf_connection_state_change_listener_func = {_, oldState, newState, context in
if let context = context {
Expand All @@ -39,7 +39,7 @@ class NativeInstrumentProfileConnection {
_ = try? ErrorCheck.nativeCall(thread, dxfg_JavaObjectHandler_release(thread, &(listener.pointee.handler)))
}
}

deinit {
removeListener()

Expand Down Expand Up @@ -124,8 +124,8 @@ class NativeInstrumentProfileConnection {
connection))
}

func addListener(_ listener: NativeInstrumentProfileConnectionListener) throws {
removeListener()
func addListener(_ listener: NativeIPFConnectionListener) throws {
removeListener()
let voidPtr = bridge(obj: self)
let thread = currentThread()
let listener = try ErrorCheck.nativeCall(thread,
Expand Down
11 changes: 0 additions & 11 deletions DXFeedFrameworkTests/DXFeedFrameworkTests.xctestplan
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,6 @@
"testTargets" : [
{
"parallelizable" : true,
"skippedTests" : [
"DXCandleTests",
"DXUtilsTest",
"EndpointPublisherTest",
"EndpointTest",
"EventsTest",
"FeedTest",
"IsolateTest",
"SystemPropertyTest",
"ThreadsTest"
],
"target" : {
"containerPath" : "container:DXFeedFramework.xcodeproj",
"identifier" : "803BAC1429BFA50700FFAB1C",
Expand Down

0 comments on commit b14763a

Please sign in to comment.