Skip to content

Commit

Permalink
add set defaults, download defaults in schedule
Browse files Browse the repository at this point in the history
  • Loading branch information
kosyloa committed Oct 9, 2023
1 parent c2ac8b3 commit ecef000
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
15 changes: 15 additions & 0 deletions DXFeedFramework/Native/Schedule/NativeSchedule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,19 @@ class NativeSchedule {
let session = try createSession(thread, session: nextSession)
return session
}

public static func setDefaults(_ data: Data) throws {
let thread = currentThread()
_ = try data.withUnsafeBytes({ pointer in
let result = try ErrorCheck.nativeCall(thread, dxfg_Schedule_setDefaults(thread,
pointer.baseAddress,
Int32(data.count)))
})
}

public static func downloadDefaults(_ url: String) throws {
let thread = currentThread()
_ = try ErrorCheck.nativeCall(thread, dxfg_Schedule_downloadDefaults(thread,
url.toCStringRef()))
}
}
19 changes: 19 additions & 0 deletions DXFeedFramework/Schedule/DXSchedule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,23 @@ public class DXSchedule {
public func getNearestSessionByTime(time: Long, filter: SessionFilter) throws -> ScheduleSession {
return try native.getNearestSessionByTime(time: time, filter: filter)
}

/// Sets shared defaults that are used by individual schedule instances.
/// - Parameters:
/// - data: content of default data
/// - Throws: GraalException. Rethrows exception from Java.
public static func setDefaults(_ data: Data) throws {
try NativeSchedule.setDefaults(data)
}
/// Downloads defaults using specified download config and optionally start periodic download.
///
/// The specified config can be one of the following:
/// "" - stop periodic download
/// URL - download once from specified URL and stop periodic download
/// URL,period - start periodic download from specified URL
/// "auto" - start periodic download from default location
/// - Throws: GraalException. Rethrows exception from Java.
public static func downloadDefaults(_ url: String) throws {
try NativeSchedule.downloadDefaults(url)
}
}
25 changes: 25 additions & 0 deletions DXFeedFrameworkTests/ScheduleTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,29 @@ final class ScheduleTest: XCTestCase {
let equals = TimeUtil.hour == startTime
XCTAssert(equals)
}

func testEmptyDownloadDefaults() throws {
do {
try DXSchedule.downloadDefaults("")
} catch {
XCTAssert(false, "\(error)")
}
}

func testCorrectDownloadDefaults() throws {
do {
try DXSchedule.downloadDefaults("http://downloads.dxfeed.com/schedule/schedule.zip,1d")
} catch {
XCTAssert(false, "\(error)")
}
}

func testAutoDownloadDefaults() throws {
do {
try DXSchedule.downloadDefaults("auto")
} catch {
XCTAssert(false, "\(error)")
}
}

}

0 comments on commit ecef000

Please sign in to comment.