Skip to content

Commit

Permalink
IPF: Connection ✅
Browse files Browse the repository at this point in the history
  • Loading branch information
kosyloa committed Sep 4, 2023
1 parent b14763a commit 5aa6b28
Show file tree
Hide file tree
Showing 13 changed files with 184 additions and 62 deletions.
24 changes: 12 additions & 12 deletions DXFeedFramework.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
6426C8912A531AAE00236784 /* EndpointTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80FC416029CA376E00E6B611 /* EndpointTest.swift */; };
6426C8932A531AB500236784 /* ThreadsTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8088D76C29C101CF00F240CB /* ThreadsTest.swift */; };
6426C8952A531ABB00236784 /* EndpointPublisherTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 641BCBB72A1FA72000FE23C2 /* EndpointPublisherTest.swift */; };
64278C6C2A602CA20074B5AA /* DXCandleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64278C6B2A602CA20074B5AA /* DXCandleTests.swift */; };
64278C6C2A602CA20074B5AA /* CandleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64278C6B2A602CA20074B5AA /* CandleTests.swift */; };
64278C6E2A602D2B0074B5AA /* Candle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64278C6D2A602D2B0074B5AA /* Candle.swift */; };
64278C702A602FA00074B5AA /* Candle+Ext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64278C6F2A602FA00074B5AA /* Candle+Ext.swift */; };
64278C722A6030290074B5AA /* CandleMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64278C712A6030290074B5AA /* CandleMapper.swift */; };
Expand All @@ -86,7 +86,7 @@
6447A5E52A8F736E00739CCF /* TimeUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6447A5E42A8F736E00739CCF /* TimeUtil.swift */; };
6447A5E92A8F9E0B00739CCF /* TimeNanosUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6447A5E82A8F9E0B00739CCF /* TimeNanosUtil.swift */; };
6447A5EB2A8FC70800739CCF /* StringUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6447A5EA2A8FC70800739CCF /* StringUtil.swift */; };
6447A5ED2A8FCC2200739CCF /* DXUtilsTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6447A5EC2A8FCC2200739CCF /* DXUtilsTest.swift */; };
6447A5ED2A8FCC2200739CCF /* UtilsTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6447A5EC2A8FCC2200739CCF /* UtilsTest.swift */; };
6447A5EF2A8FD1CD00739CCF /* DayUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6447A5EE2A8FD1CD00739CCF /* DayUtil.swift */; };
6447A5F12A8FDD1B00739CCF /* BitUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6447A5F02A8FDD1B00739CCF /* BitUtil.swift */; };
644BD75D2A44726F00A0BF99 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 644BD75C2A44726F00A0BF99 /* AppDelegate.swift */; };
Expand Down Expand Up @@ -218,7 +218,7 @@
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 */; };
64ECD67F2A9CF4CB00B36935 /* IPFTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64ECD67E2A9CF4CB00B36935 /* IPFTest.swift */; };
64ECD6822A9DDC2800B36935 /* InstrumentProfileReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64ECD6812A9DDC2800B36935 /* InstrumentProfileReader.swift */; };
64ECD6852A9DDF6200B36935 /* InstrumentProfileCollector.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64ECD6842A9DDF6200B36935 /* InstrumentProfileCollector.swift */; };
64ECD6872A9DDFBE00B36935 /* InstrumentProfileConnection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64ECD6862A9DDFBE00B36935 /* InstrumentProfileConnection.swift */; };
Expand Down Expand Up @@ -398,7 +398,7 @@
64262CE02A4DADCF00BA6BA3 /* Endpoint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Endpoint.swift; sourceTree = "<group>"; };
64262CE32A4DC16F00BA6BA3 /* QuoteViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuoteViewModel.swift; sourceTree = "<group>"; };
64262CEC2A4DC8BC00BA6BA3 /* DataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataSource.swift; sourceTree = "<group>"; };
64278C6B2A602CA20074B5AA /* DXCandleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DXCandleTests.swift; sourceTree = "<group>"; };
64278C6B2A602CA20074B5AA /* CandleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CandleTests.swift; sourceTree = "<group>"; };
64278C6D2A602D2B0074B5AA /* Candle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Candle.swift; sourceTree = "<group>"; };
64278C6F2A602FA00074B5AA /* Candle+Ext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Candle+Ext.swift"; sourceTree = "<group>"; };
64278C712A6030290074B5AA /* CandleMapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CandleMapper.swift; sourceTree = "<group>"; };
Expand All @@ -421,7 +421,7 @@
6447A5E42A8F736E00739CCF /* TimeUtil.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimeUtil.swift; sourceTree = "<group>"; };
6447A5E82A8F9E0B00739CCF /* TimeNanosUtil.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimeNanosUtil.swift; sourceTree = "<group>"; };
6447A5EA2A8FC70800739CCF /* StringUtil.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringUtil.swift; sourceTree = "<group>"; };
6447A5EC2A8FCC2200739CCF /* DXUtilsTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DXUtilsTest.swift; sourceTree = "<group>"; };
6447A5EC2A8FCC2200739CCF /* UtilsTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UtilsTest.swift; sourceTree = "<group>"; };
6447A5EE2A8FD1CD00739CCF /* DayUtil.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DayUtil.swift; sourceTree = "<group>"; };
6447A5F02A8FDD1B00739CCF /* BitUtil.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BitUtil.swift; sourceTree = "<group>"; };
644BD75A2A44726F00A0BF99 /* DXARQuoteTableApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DXARQuoteTableApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -529,7 +529,7 @@
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 /* 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>"; };
64ECD67E2A9CF4CB00B36935 /* IPFTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IPFTest.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>"; };
64ECD6862A9DDFBE00B36935 /* InstrumentProfileConnection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstrumentProfileConnection.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1019,9 +1019,9 @@
641BCBB72A1FA72000FE23C2 /* EndpointPublisherTest.swift */,
64104FC02A210DDD00D1FC41 /* FeedTest.swift */,
64104FCD2A2637EA00D1FC41 /* EventsTest.swift */,
64278C6B2A602CA20074B5AA /* DXCandleTests.swift */,
6447A5EC2A8FCC2200739CCF /* DXUtilsTest.swift */,
64ECD67E2A9CF4CB00B36935 /* DXIPFTest.swift */,
64278C6B2A602CA20074B5AA /* CandleTests.swift */,
6447A5EC2A8FCC2200739CCF /* UtilsTest.swift */,
64ECD67E2A9CF4CB00B36935 /* IPFTest.swift */,
);
path = DXFeedFrameworkTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -1676,13 +1676,13 @@
64D0DBE82A29FF4B00710605 /* EventsTest.swift in Sources */,
6426C8952A531ABB00236784 /* EndpointPublisherTest.swift in Sources */,
64ACBCEC2A29FE2300032C53 /* XCTestCase+Utils.swift in Sources */,
64ECD67F2A9CF4CB00B36935 /* DXIPFTest.swift in Sources */,
64ECD67F2A9CF4CB00B36935 /* IPFTest.swift in Sources */,
64ACBCD52A2789EF00032C53 /* TestListener.swift in Sources */,
64ACBCEA2A28DDDA00032C53 /* TestEventListener.swift in Sources */,
6401A5152A582134009BA686 /* IsolateTest.swift in Sources */,
64ACBCCF2A27851C00032C53 /* FeedTest.swift in Sources */,
6447A5ED2A8FCC2200739CCF /* DXUtilsTest.swift in Sources */,
64278C6C2A602CA20074B5AA /* DXCandleTests.swift in Sources */,
6447A5ED2A8FCC2200739CCF /* UtilsTest.swift in Sources */,
64278C6C2A602CA20074B5AA /* CandleTests.swift in Sources */,
6426C8932A531AB500236784 /* ThreadsTest.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
17 changes: 8 additions & 9 deletions DXFeedFramework/Ipf/Live/InstrumentProfileCollector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import Foundation

public class InstrumentProfileCollector {
private let listeners = ConcurrentSet<AnyHashable>()

internal let native: NativeInstrumentProfileCollector
let native: NativeInstrumentProfileCollector

public init() throws {
self.native = try NativeInstrumentProfileCollector()
Expand All @@ -37,29 +36,29 @@ public class InstrumentProfileCollector {
return native.getLastUpdateTime()
}

func updateInstrumentProfile(profile: InstrumentProfile) throws {
public func updateInstrumentProfile(profile: InstrumentProfile) throws {
try native.updateInstrumentProfile(profile: profile)
}

func view() throws -> ProfileIterator {
public func view() throws -> ProfileIterator {
let iterator = try native.view()
return ProfileIterator(iterator)
}

func createOnConcurrentLinkedQueue() throws -> Bool {
public func createOnConcurrentLinkedQueue() throws -> Bool {
let nativeExecutor = try NativeExecutor.createOnConcurrentLinkedQueue()
return try native.setExecutor(nativeExecutor)
}

func createOnScheduledThreadPool(numberOfThreads: Int32,
nameOfthread: String) throws -> Bool {
public func createOnScheduledThreadPool(numberOfThreads: Int32,
nameOfthread: String) throws -> Bool {
let nativeExecutor = try NativeExecutor.createOnScheduledThreadPool(numberOfThreads: numberOfThreads,
nameOfthread: nameOfthread)
return try native.setExecutor(nativeExecutor)
}

func createOnFixedThreadPool(numberOfThreads: Int32,
nameOfthread: String) throws -> Bool {
public func createOnFixedThreadPool(numberOfThreads: Int32,
nameOfthread: String) throws -> Bool {
let nativeExecutor = try NativeExecutor.createOnFixedThreadPool(numberOfThreads: numberOfThreads,
nameOfthread: nameOfthread)
return try native.setExecutor(nativeExecutor)
Expand Down
8 changes: 4 additions & 4 deletions DXFeedFramework/Ipf/Live/InstrumentProfileConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public class InstrumentProfileConnection {
return observersSet.reader { $0.compactMap { value in value as? InstrumentProfileConnectionObserver } }
}

init(_ address: String) throws {
collector = try InstrumentProfileCollector()
public init(_ address: String, _ collector: InstrumentProfileCollector) throws {
self.collector = collector
native = try NativeInstrumentProfileConnection(collector.native, address)
try native.addListener(self)
}
Expand All @@ -30,8 +30,8 @@ public class InstrumentProfileConnection {
return native.getUpdatePeriod()
}

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

public func getLastModified() -> Long {
Expand Down
6 changes: 3 additions & 3 deletions DXFeedFramework/Ipf/Live/ProfileIterator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@

import Foundation

class ProfileIterator {
public class ProfileIterator {
private let native: NativeProfileIterator

init(_ native: NativeProfileIterator) {
self.native = native
}

func hasNext() throws -> Bool {
public func hasNext() throws -> Bool {
try self.native.hasNext()
}

func next() throws -> InstrumentProfile {
public func next() throws -> InstrumentProfile {
return try self.native.next()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ extension InstrumentProfileConnectionState {
static func convert(_ state: dxfg_ipf_connection_state_t) -> InstrumentProfileConnectionState? {
switch state {
case DXFG_IPF_CONNECTION_STATE_NOT_CONNECTED:
return .closed
return .notConnected
case DXFG_IPF_CONNECTION_STATE_CONNECTING:
return .connected
case DXFG_IPF_CONNECTION_STATE_CONNECTED:
return .connecting
case DXFG_IPF_CONNECTION_STATE_CONNECTED:
return .connected
case DXFG_IPF_CONNECTION_STATE_COMPLETED:
return .notConnected
return .completed
case DXFG_IPF_CONNECTION_STATE_CLOSED:
return .notConnected
return .closed
default:
return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,38 @@ class NativeInstrumentProfileCollector {
let listener: AnyObject = bridge(ptr: context)
if let listener = listener as? NativeInstrumentProfileCollector {
let iterator = NativeProfileIterator(nativeProfiles)

while (try? iterator.hasNext()) ?? false {
do {
let profile = try iterator.next()
profiles.append(profile)
} catch {
print("NativeInstrumentProfileCollector: excpetion \(error)")
}
listener.listener?.instrumentProfilesUpdated(profiles)
}
listener.listener?.instrumentProfilesUpdated(profiles)

}
}
}

deinit {
let thread = currentThread()
private func removeListener() {
if let nativeListener = nativeListener {
let thread = currentThread()
_ = try? ErrorCheck.nativeCall(thread,
dxfg_InstrumentProfileCollector_removeUpdateListener(thread,
self.collector,
nativeListener))
_ = try? ErrorCheck.nativeCall(thread,
dxfg_JavaObjectHandler_release(thread,
&(nativeListener.pointee.handler)))
self.listener = nil
}
}

deinit {
removeListener()
let thread = currentThread()
if let collector = collector {
_ = try? ErrorCheck.nativeCall(thread,
dxfg_JavaObjectHandler_release(thread,
Expand Down Expand Up @@ -93,7 +101,7 @@ class NativeInstrumentProfileCollector {
let result = try ErrorCheck.nativeCall(thread, dxfg_InstrumentProfileCollector_setExecutor(thread,
collector,
executor.executor))
return result != 0
return result == 0
}

func getExecutor() throws -> NativeExecutor {
Expand All @@ -103,18 +111,8 @@ class NativeInstrumentProfileCollector {
}

func addListener(_ listener: InstrumentProfileUpdateListener?) throws {
removeListener()
let thread = currentThread()

if let nativeListener = nativeListener {
_ = try? ErrorCheck.nativeCall(thread,
dxfg_InstrumentProfileCollector_removeUpdateListener(thread,
self.collector,
nativeListener))
_ = try? ErrorCheck.nativeCall(thread,
dxfg_JavaObjectHandler_release(thread,
&(nativeListener.pointee.handler)))
}

self.listener = listener
let voidPtr = bridge(obj: self)
let callback = NativeInstrumentProfileCollector.listenerCallback
Expand Down
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: NativeIPFConnectionListener?
private weak var listener: NativeIPFConnectionListener?

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

Expand Down Expand Up @@ -76,9 +77,9 @@ class NativeInstrumentProfileConnection {
return result ?? NativeInstrumentProfileConnection.defaultUpdatePeriod
}

func setUpdatePeriod(_ value: Long) {
func setUpdatePeriod(_ value: Long) throws {
let thread = currentThread()
_ = try? ErrorCheck.nativeCall(thread,
_ = try ErrorCheck.nativeCall(thread,
dxfg_InstrumentProfileConnection_setUpdatePeriod(
thread,
connection,
Expand Down Expand Up @@ -126,6 +127,7 @@ class NativeInstrumentProfileConnection {

func addListener(_ listener: NativeIPFConnectionListener) throws {
removeListener()
self.listener = listener
let voidPtr = bridge(obj: self)
let thread = currentThread()
let listener = try ErrorCheck.nativeCall(thread,
Expand Down
4 changes: 0 additions & 4 deletions DXFeedFramework/Native/Ipf/Live/NativeProfileIterator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ class NativeProfileIterator {
let mapper = InstrumentProfileMapper()

deinit {
let thread = currentThread()
_ = try? ErrorCheck.nativeCall(thread,
dxfg_JavaObjectHandler_release(thread,
&(iterator.pointee.handler)))
}

init(_ iterator: UnsafeMutablePointer<dxfg_iterable_ip_t>) {
Expand Down
Loading

0 comments on commit 5aa6b28

Please sign in to comment.