Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/ondemand service #8

Merged
merged 9 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions DXFeedFramework.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
/* Begin PBXBuildFile section */
6401A5152A582134009BA686 /* IsolateTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8088D76A29C0FE1700F240CB /* IsolateTest.swift */; };
6401A5162A582141009BA686 /* SystemPropertyTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8088D77829C498FA00F240CB /* SystemPropertyTest.swift */; };
64048A592BD79D7600902590 /* Role+Ext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64048A582BD79D7600902590 /* Role+Ext.swift */; };
64048A5B2BD7E5BF00902590 /* DXOnDemandServiceTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64048A5A2BD7E5BF00902590 /* DXOnDemandServiceTest.swift */; };
6406F2572AD9820700B58C42 /* NativePublisher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6406F2562AD9820700B58C42 /* NativePublisher.swift */; };
6406F25B2AD987EB00B58C42 /* PublisherTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6406F25A2AD987EB00B58C42 /* PublisherTest.swift */; };
640885C82B1F7C3200E6CF88 /* QdsTool.swift in Sources */ = {isa = PBXBuildFile; fileRef = 640885C72B1F7C3200E6CF88 /* QdsTool.swift */; };
Expand Down Expand Up @@ -111,6 +113,8 @@
6433B12D2BCE7ADD004EFED7 /* DXFeed+LastEvents.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6433B12C2BCE7ADD004EFED7 /* DXFeed+LastEvents.swift */; };
6433B1322BCFC01F004EFED7 /* DXLastEventsSubscribedTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6433B1312BCFC01F004EFED7 /* DXLastEventsSubscribedTest.swift */; };
643A329B2BD0137000F6F790 /* Optional+Ext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 643A329A2BD0137000F6F790 /* Optional+Ext.swift */; };
643A329F2BD2A04300F6F790 /* OnDemandService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 643A329E2BD2A04300F6F790 /* OnDemandService.swift */; };
643A32A22BD2AEFB00F6F790 /* NativeOnDemandService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 643A32A12BD2AEFB00F6F790 /* NativeOnDemandService.swift */; };
64437A8F2A9DEE6F005929B2 /* InstrumentProfile.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64437A8E2A9DEE6F005929B2 /* InstrumentProfile.swift */; };
64437A922A9DF1DE005929B2 /* NativeInstrumentProfileReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64437A912A9DF1DE005929B2 /* NativeInstrumentProfileReader.swift */; };
6447A5DB2A8E559000739CCF /* ILastingEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6447A5DA2A8E559000739CCF /* ILastingEvent.swift */; };
Expand Down Expand Up @@ -587,6 +591,8 @@

/* Begin PBXFileReference section */
6401A5142A5820C9009BA686 /* DXFeedAllTests.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = DXFeedAllTests.xctestplan; sourceTree = "<group>"; };
64048A582BD79D7600902590 /* Role+Ext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Role+Ext.swift"; sourceTree = "<group>"; };
64048A5A2BD7E5BF00902590 /* DXOnDemandServiceTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DXOnDemandServiceTest.swift; sourceTree = "<group>"; };
6406F2562AD9820700B58C42 /* NativePublisher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativePublisher.swift; sourceTree = "<group>"; };
6406F25A2AD987EB00B58C42 /* PublisherTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PublisherTest.swift; sourceTree = "<group>"; };
640885C42B1F477A00E6CF88 /* DxFeedIpfConnect.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = DxFeedIpfConnect.playground; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
Expand Down Expand Up @@ -671,6 +677,8 @@
6435EE3C2B1F1E9200E8496C /* PrintQuoteEvents.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = PrintQuoteEvents.playground; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
643A329A2BD0137000F6F790 /* Optional+Ext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Optional+Ext.swift"; sourceTree = "<group>"; };
643A329C2BD15F2900F6F790 /* LastEventsConsole.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = LastEventsConsole.playground; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
643A329E2BD2A04300F6F790 /* OnDemandService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnDemandService.swift; sourceTree = "<group>"; };
643A32A12BD2AEFB00F6F790 /* NativeOnDemandService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativeOnDemandService.swift; sourceTree = "<group>"; };
64437A8E2A9DEE6F005929B2 /* InstrumentProfile.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstrumentProfile.swift; sourceTree = "<group>"; };
64437A912A9DF1DE005929B2 /* NativeInstrumentProfileReader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativeInstrumentProfileReader.swift; sourceTree = "<group>"; };
644551C92B973A0D0069E3A2 /* FetchDailyCandles.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = FetchDailyCandles.playground; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
Expand Down Expand Up @@ -795,6 +803,7 @@
64A42F4D2B0B9FA4001C3ACC /* DXTimeZone.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DXTimeZone.swift; sourceTree = "<group>"; };
64A42F4F2B0BA668001C3ACC /* DXTimeFormat.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DXTimeFormat.swift; sourceTree = "<group>"; };
64A42F512B0BBB6D001C3ACC /* DXTimePeriod.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DXTimePeriod.swift; sourceTree = "<group>"; };
64A631CF2BDFAA27002E1002 /* OnDemandSample.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = OnDemandSample.playground; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
64AAF0522A8113E800E8942B /* String+Range.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+Range.swift"; sourceTree = "<group>"; };
64AAF0542A82499A00E8942B /* ConcurrentDict.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConcurrentDict.swift; sourceTree = "<group>"; };
64AAF0562A82A3FC00E8942B /* ICandleSymbolProperty.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ICandleSymbolProperty.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1104,6 +1113,7 @@
64F9C6C12B4BFD8F003ED014 /* DXFeedconnect.playground */,
644551C92B973A0D0069E3A2 /* FetchDailyCandles.playground */,
6433B1302BCE87D4004EFED7 /* RequestProfile.playground */,
64A631CF2BDFAA27002E1002 /* OnDemandSample.playground */,
643A329C2BD15F2900F6F790 /* LastEventsConsole.playground */,
);
path = Playgrounds;
Expand Down Expand Up @@ -1182,6 +1192,22 @@
path = IpfTableApp;
sourceTree = "<group>";
};
643A329D2BD2A02E00F6F790 /* OnDemand */ = {
isa = PBXGroup;
children = (
643A329E2BD2A04300F6F790 /* OnDemandService.swift */,
);
path = OnDemand;
sourceTree = "<group>";
};
643A32A02BD2AEC100F6F790 /* OnDemandService */ = {
isa = PBXGroup;
children = (
643A32A12BD2AEFB00F6F790 /* NativeOnDemandService.swift */,
);
path = OnDemandService;
sourceTree = "<group>";
};
64437A902A9DF1C4005929B2 /* Ipf */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1612,6 +1638,7 @@
8088D77A29C5D8AD00F240CB /* Native */,
64656F552A1B6A07006A0B19 /* Utils */,
64ECD6802A9DD80000B36935 /* Ipf */,
643A329D2BD2A02E00F6F790 /* OnDemand */,
64F73B9D2B67863B0088EC37 /* Promise */,
64C771FD2A9504D7009868C2 /* Extra */,
6498E6B02AB1D40C0093A065 /* Schedule */,
Expand Down Expand Up @@ -1654,6 +1681,7 @@
64EAA1A52B838ED3005087BC /* DXSnapshotProcessorTest.swift */,
64820AAE2BB2E26100BDFD0B /* DXOtcMarketOrderTest.swift */,
644B95E62BC542F600E95CB7 /* DXAttachTest.swift */,
64048A5A2BD7E5BF00902590 /* DXOnDemandServiceTest.swift */,
);
path = DXFeedFrameworkTests;
sourceTree = "<group>";
Expand All @@ -1679,6 +1707,7 @@
64104FD12A277B1A00D1FC41 /* Interop */,
64104FCA2A2629C400D1FC41 /* Subscription */,
64437A902A9DF1C4005929B2 /* Ipf */,
643A32A02BD2AEC100F6F790 /* OnDemandService */,
6498E6B32AB1D43A0093A065 /* Schedule */,
64F73BA22B67B2750088EC37 /* Promise */,
64ACBCE42A28AEE200032C53 /* SymbolMappers */,
Expand Down Expand Up @@ -1734,6 +1763,7 @@
64656F582A1B864C006A0B19 /* NativeEndpoint.swift */,
64656F722A1D0A84006A0B19 /* EndpointListener.swift */,
64656F762A1DFED9006A0B19 /* EndpointState+Native.swift */,
64048A582BD79D7600902590 /* Role+Ext.swift */,
);
path = Endpoint;
sourceTree = "<group>";
Expand Down Expand Up @@ -2444,6 +2474,7 @@
6486B9732AD045C800D8D5FA /* TheoPrice.swift in Sources */,
64ACBCDF2A2897EA00032C53 /* String+Symbol.swift in Sources */,
64C004762BA09FDC0009F7C9 /* OtcMarketsPriceType.swift in Sources */,
643A329F2BD2A04300F6F790 /* OnDemandService.swift in Sources */,
64B4363A2AB86D1A0003919E /* DayFilter.swift in Sources */,
64EAA1A42B7B4DA1005087BC /* IndexedEventSource+Ext.swift in Sources */,
64A42F3B2B07A7A3001C3ACC /* SymbolParser.swift in Sources */,
Expand Down Expand Up @@ -2552,6 +2583,7 @@
64C771F82A94B88C009868C2 /* TimeAndSaleType.swift in Sources */,
641BDD5B2AC72BD400236B78 /* ConcurrentWeakHashTable.swift in Sources */,
64BDDB242AD6F10200694210 /* Scope.swift in Sources */,
643A32A22BD2AEFB00F6F790 /* NativeOnDemandService.swift in Sources */,
6447A5DF2A8E56FC00739CCF /* IIndexedEvent.swift in Sources */,
64104FC52A26059B00D1FC41 /* ConcurrentSet.swift in Sources */,
64BA925F2A306B9600BE26A0 /* Profile.swift in Sources */,
Expand All @@ -2564,6 +2596,7 @@
64656F602A1B9EC2006A0B19 /* EnumUtil.swift in Sources */,
64A42F492B0B9683001C3ACC /* NativeTimeFormat.swift in Sources */,
642BE4CA2A2E1C640052340A /* MarketEvent.swift in Sources */,
64048A592BD79D7600902590 /* Role+Ext.swift in Sources */,
6486B95B2AD015B400D8D5FA /* PriceType.swift in Sources */,
64BDDB202AD6CC8300694210 /* AnalyticOrder.swift in Sources */,
64AAF0532A8113E800E8942B /* String+Range.swift in Sources */,
Expand Down Expand Up @@ -2621,6 +2654,7 @@
6498E6B72AB1DACE0093A065 /* ScheduleTest.swift in Sources */,
64EAA1A62B838ED3005087BC /* DXSnapshotProcessorTest.swift in Sources */,
649282ED2AD593F3008F0F04 /* OrderSourceTest.swift in Sources */,
64048A5B2BD7E5BF00902590 /* DXOnDemandServiceTest.swift in Sources */,
6426C8932A531AB500236784 /* ThreadsTest.swift in Sources */,
64EAA1A22B7A38F8005087BC /* DXPromiseTest.swift in Sources */,
);
Expand Down Expand Up @@ -3132,7 +3166,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.1.1;
MARKETING_VERSION = 1.1.2;
PRODUCT_BUNDLE_IDENTIFIER = com.dxfeed.quotesapp;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
Expand Down Expand Up @@ -3166,7 +3200,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.1.1;
MARKETING_VERSION = 1.1.2;
PRODUCT_BUNDLE_IDENTIFIER = com.dxfeed.quotesapp;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
Expand Down
7 changes: 6 additions & 1 deletion DXFeedFramework/Api/DXEndpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ public class DXEndpoint {
}
/// Endpoint native wrapper.
private let endpointNative: NativeEndpoint

internal var nativeEndpoint: NativeEndpoint {
return endpointNative
}

/// The endpoint role.
/// public let = public getter for constant value
public let role: Role
Expand All @@ -194,7 +199,7 @@ public class DXEndpoint {
try? close()
}

fileprivate init(native: NativeEndpoint, role: Role, name: String) throws {
init(native: NativeEndpoint, role: Role, name: String) throws {
self.endpointNative = native
self.role = role
self.name = name
Expand Down
2 changes: 1 addition & 1 deletion DXFeedFramework/Ipf/InstrumentProfileField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ extension InstrumentProfileField {
guard let date = dateFormatter.date(from: value) else {
return 0
}
parsedDates[value] = Entry(text: value, binary: Long(date.millisecondsSince1970) / TimeUtil.day)
parsedDates[value] = Entry(text: value, binary: date.millisecondsSince1970() / TimeUtil.day)
return parsedDates[value]?.binary ?? 0
}
}
Expand Down
2 changes: 1 addition & 1 deletion DXFeedFramework/Native/Endpoint/NativeBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class NativeBuilder {
let res = try ErrorCheck.nativeCall(thread,
dxfg_DXEndpoint_Builder_withRole(thread,
builder,
dxfg_endpoint_role_t(role.rawValue)
role.toNatie()
)
)
return res != 0
Expand Down
47 changes: 47 additions & 0 deletions DXFeedFramework/Native/Endpoint/Role+Ext.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
//
// 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

extension Role {
func toNatie() -> dxfg_endpoint_role_t {
switch self {
case .feed:
return DXFG_ENDPOINT_ROLE_FEED
case .onDemandFeed:
return DXFG_ENDPOINT_ROLE_ON_DEMAND_FEED
case .streamFeed:
return DXFG_ENDPOINT_ROLE_STREAM_FEED
case .publisher:
return DXFG_ENDPOINT_ROLE_PUBLISHER
case .streamPublisher:
return DXFG_ENDPOINT_ROLE_STREAM_PUBLISHER
case .localHub:
return DXFG_ENDPOINT_ROLE_LOCAL_HUB
}
}

static func fromNative(_ native: dxfg_endpoint_role_t) -> Role {
switch native {
case DXFG_ENDPOINT_ROLE_FEED:
return .feed
case DXFG_ENDPOINT_ROLE_ON_DEMAND_FEED:
return .onDemandFeed
case DXFG_ENDPOINT_ROLE_STREAM_FEED:
return .streamFeed
case DXFG_ENDPOINT_ROLE_PUBLISHER:
return .publisher
case DXFG_ENDPOINT_ROLE_STREAM_PUBLISHER:
return .streamPublisher
case DXFG_ENDPOINT_ROLE_LOCAL_HUB:
return .localHub
default:
fatalError("Try to initialize Role with wrong value \(native)")
}
}
}
109 changes: 109 additions & 0 deletions DXFeedFramework/Native/OnDemandService/NativeOnDemandService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
//
//
// Copyright (C) 2024 Devexperts LLC. All rights reserved.
// This Source Code Form is subject to the terms of the Mozilla 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

class NativeOnDemandService {
private let native: UnsafeMutablePointer<dxfg_on_demand_service_t>

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

init(native: UnsafeMutablePointer<dxfg_on_demand_service_t>) {
self.native = native
}

static func getInstance() throws -> NativeOnDemandService {
let thread = currentThread()
let instance = try ErrorCheck.nativeCall(thread, dxfg_OnDemandService_getInstance(thread)).value()
return NativeOnDemandService(native: instance)
}

static func getInstance(endpoint: NativeEndpoint) throws -> NativeOnDemandService {
let thread = currentThread()
let instance = try ErrorCheck.nativeCall(thread,
dxfg_OnDemandService_getInstance2(thread, endpoint.endpoint)).value()
return NativeOnDemandService(native: instance)
}

func getEndpoint() throws -> DXEndpoint {
let thread = currentThread()
let endpoint = try ErrorCheck.nativeCall(thread, dxfg_OnDemandService_getEndpoint(thread, native)).value()
let role = try ErrorCheck.nativeCall(thread, dxfg_DXEndpoint_getRole(thread, endpoint))
return try DXEndpoint(native: NativeEndpoint(endpoint), role: Role.fromNative(role), name: "")
}

var isReplaySupported: Bool? {
let thread = currentThread()
return try? ErrorCheck.nativeCall(thread, dxfg_OnDemandService_isReplaySupported(thread, native)) == 1
}

var isReplay: Bool? {
let thread = currentThread()
return try? ErrorCheck.nativeCall(thread, dxfg_OnDemandService_isReplay(thread, native)) == 1
}

var isClear: Bool? {
let thread = currentThread()
return try? ErrorCheck.nativeCall(thread, dxfg_OnDemandService_isClear(thread, native)) == 1
}

var getTime: Date? {
let thread = currentThread()
if let value = try? ErrorCheck.nativeCall(thread, dxfg_OnDemandService_getTime(thread, native)) {
return Date.init(millisecondsSince1970: value)
}
return nil
}

var getSpeed: Double? {
let thread = currentThread()
return try? ErrorCheck.nativeCall(thread, dxfg_OnDemandService_getSpeed(thread, native))
}

func replay(date: Date) throws {
let thread = currentThread()
try ErrorCheck.nativeCall(thread,
dxfg_OnDemandService_replay(thread,
native,
date.millisecondsSince1970()))
}

func replay(date: Date, speed: Double) throws {
let thread = currentThread()
try ErrorCheck.nativeCall(thread,
dxfg_OnDemandService_replay2(thread,
native,
date.millisecondsSince1970(),
speed))
}

func pause() throws {
let thread = currentThread()
try ErrorCheck.nativeCall(thread, dxfg_OnDemandService_pause(thread, native))
}

func stopAndResume() throws {
let thread = currentThread()
try ErrorCheck.nativeCall(thread, dxfg_OnDemandService_stopAndResume(thread, native))
}

func stopAndClear() throws {
let thread = currentThread()
try ErrorCheck.nativeCall(thread, dxfg_OnDemandService_stopAndClear(thread, native))
}

func setSpeed(_ speed: Double) throws {
let thread = currentThread()
try ErrorCheck.nativeCall(thread, dxfg_OnDemandService_setSpeed(thread, native, speed))
}
}
2 changes: 1 addition & 1 deletion DXFeedFramework/Native/Promise/NativePromise.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class NativePromise {
return results
}
let thread = currentThread()
let res: [MarketEvent]? = try promise?.withMemoryRebound(to: dxfg_promise_events_t.self,
let res: [MarketEvent]? = try promise?.withMemoryRebound(to: dxfg_promise_events_t.self,
capacity: 1, { promiseEvents in
guard let listPointer = try ErrorCheck.nativeCall(thread,
dxfg_Promise_List_EventType_getResult(thread,
Expand Down
Loading