diff --git a/DXFeedFramework/Native/Schedule/NativeSchedule.swift b/DXFeedFramework/Native/Schedule/NativeSchedule.swift index ccd5be80f..14cde87ea 100644 --- a/DXFeedFramework/Native/Schedule/NativeSchedule.swift +++ b/DXFeedFramework/Native/Schedule/NativeSchedule.swift @@ -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())) + } } diff --git a/DXFeedFramework/Schedule/DXSchedule.swift b/DXFeedFramework/Schedule/DXSchedule.swift index f3648ebda..00586d0a0 100644 --- a/DXFeedFramework/Schedule/DXSchedule.swift +++ b/DXFeedFramework/Schedule/DXSchedule.swift @@ -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) + } } diff --git a/DXFeedFrameworkTests/ScheduleTest.swift b/DXFeedFrameworkTests/ScheduleTest.swift index 9594fdb49..22e597f1a 100644 --- a/DXFeedFrameworkTests/ScheduleTest.swift +++ b/DXFeedFrameworkTests/ScheduleTest.swift @@ -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)") + } + } + }