Skip to content

Commit

Permalink
add DXFeedTimeSeriesSubscription: WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
kosyloa committed Jan 2, 2024
1 parent 23bf808 commit d8b70c4
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 0 deletions.
8 changes: 8 additions & 0 deletions DXFeedFramework.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
641C64B22B346A2E0023CFAD /* DXObservableSubscription.swift in Sources */ = {isa = PBXBuildFile; fileRef = 641C64B12B346A2E0023CFAD /* DXObservableSubscription.swift */; };
641C64B42B347C430023CFAD /* DXObservableSubscriptionTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 641C64B32B347C430023CFAD /* DXObservableSubscriptionTest.swift */; };
641E45F92B1DE51700649363 /* EventsListener.swift in Sources */ = {isa = PBXBuildFile; fileRef = 641E45F82B1DE51700649363 /* EventsListener.swift */; };
6423E4652B445B92006B208D /* DXFeedTimeSeriesSubscription.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6423E4642B445B92006B208D /* DXFeedTimeSeriesSubscription.swift */; };
6423E4672B44613D006B208D /* NativeTimeSeriesSubscription.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6423E4662B44613D006B208D /* NativeTimeSeriesSubscription.swift */; };
642528D02A3C534D00A04E41 /* TimeInterval+Ext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6469F8CD2A3B2F9900846831 /* TimeInterval+Ext.swift */; };
642528D12A3C534D00A04E41 /* TimeInterval+Ext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6469F8CD2A3B2F9900846831 /* TimeInterval+Ext.swift */; };
6426C8912A531AAE00236784 /* EndpointTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80FC416029CA376E00E6B611 /* EndpointTest.swift */; };
Expand Down Expand Up @@ -596,6 +598,8 @@
641C64B12B346A2E0023CFAD /* DXObservableSubscription.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DXObservableSubscription.swift; sourceTree = "<group>"; };
641C64B32B347C430023CFAD /* DXObservableSubscriptionTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DXObservableSubscriptionTest.swift; sourceTree = "<group>"; };
641E45F82B1DE51700649363 /* EventsListener.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventsListener.swift; sourceTree = "<group>"; };
6423E4642B445B92006B208D /* DXFeedTimeSeriesSubscription.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DXFeedTimeSeriesSubscription.swift; sourceTree = "<group>"; };
6423E4662B44613D006B208D /* NativeTimeSeriesSubscription.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativeTimeSeriesSubscription.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>"; };
Expand Down Expand Up @@ -956,6 +960,7 @@
64104FCB2A2629D800D1FC41 /* NativeSubscription.swift */,
641C64AF2B34679D0023CFAD /* NativeObservableSubscription.swift */,
641C64B12B346A2E0023CFAD /* DXObservableSubscription.swift */,
6423E4662B44613D006B208D /* NativeTimeSeriesSubscription.swift */,
);
path = Subscription;
sourceTree = "<group>";
Expand Down Expand Up @@ -1603,6 +1608,7 @@
641BCBBB2A20ED8100FE23C2 /* DXEndpointListener.swift */,
64104FC82A26298D00D1FC41 /* DXFeedSubcription.swift */,
64ACBCD82A279F7900032C53 /* DXEventListener.swift */,
6423E4642B445B92006B208D /* DXFeedTimeSeriesSubscription.swift */,
);
path = Api;
sourceTree = "<group>";
Expand Down Expand Up @@ -2355,6 +2361,7 @@
64E342522AAB29CF00457994 /* InstrumentProfileType.swift in Sources */,
648E98AA2AAF625800BFD219 /* IIndexedEvent+Ext.swift in Sources */,
64A42F452B0B933B001C3ACC /* NativeTimeUtil.swift in Sources */,
6423E4672B44613D006B208D /* NativeTimeSeriesSubscription.swift in Sources */,
6447A5E32A8F611700739CCF /* IObservableSubscription.swift in Sources */,
64A42F4E2B0B9FA4001C3ACC /* DXTimeZone.swift in Sources */,
64104FC92A26298D00D1FC41 /* DXFeedSubcription.swift in Sources */,
Expand All @@ -2378,6 +2385,7 @@
64656F772A1DFED9006A0B19 /* EndpointState+Native.swift in Sources */,
6498E6B52AB1D4480093A065 /* NativeSchedule.swift in Sources */,
64DA26BC2AA20B66005B1757 /* InstrumentProfileConnectionState+ext.swift in Sources */,
6423E4652B445B92006B208D /* DXFeedTimeSeriesSubscription.swift in Sources */,
64BA92612A306BA900BE26A0 /* Profile+Ext.swift in Sources */,
64BA926B2A3072CA00BE26A0 /* TradeMapper.swift in Sources */,
6447A5E12A8E5A5400739CCF /* IndexedEventSource.swift in Sources */,
Expand Down
5 changes: 5 additions & 0 deletions DXFeedFramework/Api/DXFeed.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,9 @@ public class DXFeed {
public func createSubscription(_ event: EventCode) throws -> DXFeedSubcription {
return try DXFeedSubcription(native: native.createSubscription(event), events: [event])
}

public func createTimeSeriesSubscription(_ event: EventCode) throws -> DXFeedTimeSeriesSubscription {
return try DXFeedTimeSeriesSubscription(native: native.createTimeSeriesSubscription(event), events: [event])

}
}
17 changes: 17 additions & 0 deletions DXFeedFramework/Api/DXFeedTimeSeriesSubscription.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
//
// Copyright (C) 2024 Devexperts LLC. All rights reserved.
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
//

import Foundation

public class DXFeedTimeSeriesSubscription: DXFeedSubcription {
private var fromTime = Long.max


internal init(native: NativeTimeSeriesSubscription?, events: [EventCode]) throws {
try super.init(native: native?.subscription, events: events)
}
}
27 changes: 27 additions & 0 deletions DXFeedFramework/Native/Feed/NativeFeed.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,31 @@ class NativeFeed {
event.nativeCode()))
return NativeSubscription(subscription: subscription)
}


func createTimeSeriesSubscription(_ events: [EventCode]) throws -> NativeTimeSeriesSubscription? {
let nativeCodes = events.map { $0.nativeCode() }
let elements = ListNative(elements: nativeCodes)
let listPointer = elements.newList()
defer {
listPointer.deinitialize(count: 1)
listPointer.deallocate()
}

let thread = currentThread()
let subscription = try ErrorCheck.nativeCall(thread,
dxfg_DXFeed_createTimeSeriesSubscription2(thread,
self.feed,
listPointer))
return NativeTimeSeriesSubscription(native: subscription)
}

func createTimeSeriesSubscription(_ event: EventCode) throws -> NativeTimeSeriesSubscription? {
let thread = currentThread()
let subscription = try ErrorCheck.nativeCall(thread,
dxfg_DXFeed_createTimeSeriesSubscription(thread,
self.feed,
event.nativeCode()))
return NativeTimeSeriesSubscription(native: subscription)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class NativeSubscription {
}

init(subscription: UnsafeMutablePointer<dxfg_subscription_t>?) {

self.subscription = subscription
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
//
// Copyright (C) 2024 Devexperts LLC. All rights reserved.
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
//

import Foundation
@_implementationOnly import graal_api

/// Native wrapper over the Java com.dxfeed.api.DXFeedTimeSeriesSubscription class.
/// The location of the imported functions is in the header files "dxfg_subscription.h".
class NativeTimeSeriesSubscription {
var native: UnsafeMutablePointer<dxfg_time_series_subscription_t>?

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

init(native: UnsafeMutablePointer<dxfg_time_series_subscription_t>?) {
self.native = native
var subscription = self.native?.pointee.sub
}

lazy var subscription: NativeSubscription? = {
if var subscr = native?.pointee.sub {
return NativeSubscription(subscription: &subscr)
} else {
return nil
}
}()

}

0 comments on commit d8b70c4

Please sign in to comment.