Skip to content

Commit

Permalink
WIP: publisher doesnt work
Browse files Browse the repository at this point in the history
  • Loading branch information
kosyloa committed Oct 16, 2023
1 parent 05cc38a commit 5a78f81
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 26 deletions.
4 changes: 4 additions & 0 deletions DXFeedFramework.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@
64963B6A2A8E545C001E40F7 /* IEventType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64963B692A8E545C001E40F7 /* IEventType.swift */; };
649706842AD82B070068FF88 /* Series.swift in Sources */ = {isa = PBXBuildFile; fileRef = 649706832AD82B070068FF88 /* Series.swift */; };
649706862AD832860068FF88 /* Series+Ext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 649706852AD832860068FF88 /* Series+Ext.swift */; };
649813C42ADD5CB2003CE3B3 /* TestEndpoointStateListener.swift in Sources */ = {isa = PBXBuildFile; fileRef = 649813C32ADD5CB2003CE3B3 /* TestEndpoointStateListener.swift */; };
6498E6B22AB1D41A0093A065 /* DXSchedule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6498E6B12AB1D41A0093A065 /* DXSchedule.swift */; };
6498E6B52AB1D4480093A065 /* NativeSchedule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6498E6B42AB1D4480093A065 /* NativeSchedule.swift */; };
6498E6B72AB1DACE0093A065 /* ScheduleTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6498E6B62AB1DACE0093A065 /* ScheduleTest.swift */; };
Expand Down Expand Up @@ -682,6 +683,7 @@
64963B692A8E545C001E40F7 /* IEventType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IEventType.swift; sourceTree = "<group>"; };
649706832AD82B070068FF88 /* Series.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Series.swift; sourceTree = "<group>"; };
649706852AD832860068FF88 /* Series+Ext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Series+Ext.swift"; sourceTree = "<group>"; };
649813C32ADD5CB2003CE3B3 /* TestEndpoointStateListener.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestEndpoointStateListener.swift; sourceTree = "<group>"; };
6498E6B12AB1D41A0093A065 /* DXSchedule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DXSchedule.swift; sourceTree = "<group>"; };
6498E6B42AB1D4480093A065 /* NativeSchedule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativeSchedule.swift; sourceTree = "<group>"; };
6498E6B62AB1DACE0093A065 /* ScheduleTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScheduleTest.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1264,6 +1266,7 @@
children = (
64ACBCE92A28DDDA00032C53 /* TestEventListener.swift */,
641BCBB92A1FB42500FE23C2 /* TestListener.swift */,
649813C32ADD5CB2003CE3B3 /* TestEndpoointStateListener.swift */,
);
path = Listeners;
sourceTree = "<group>";
Expand Down Expand Up @@ -2295,6 +2298,7 @@
6426C8912A531AAE00236784 /* EndpointTest.swift in Sources */,
6401A5162A582141009BA686 /* SystemPropertyTest.swift in Sources */,
64D0DBE82A29FF4B00710605 /* EventsTest.swift in Sources */,
649813C42ADD5CB2003CE3B3 /* TestEndpoointStateListener.swift in Sources */,
64ACBCEC2A29FE2300032C53 /* XCTestCase+Utils.swift in Sources */,
64ECD67F2A9CF4CB00B36935 /* IPFTests.swift in Sources */,
64ACBCD52A2789EF00032C53 /* TestListener.swift in Sources */,
Expand Down
28 changes: 14 additions & 14 deletions DXFeedFramework/Native/Events/Markets/QuoteMapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@ class QuoteMapper: Mapper {

func toNative(event: MarketEvent) -> UnsafeMutablePointer<dxfg_event_type_t>? {
let pointer = UnsafeMutablePointer<dxfg_quote_t>.allocate(capacity: 1)
var pointee = pointer.pointee
pointee.market_event.event_symbol = event.eventSymbol.toCStringRef()
pointee.market_event.event_time = event.eventTime

pointer.pointee.market_event.event_symbol = event.eventSymbol.toCStringRef()
pointer.pointee.market_event.event_time = event.eventTime

let quote = event.quote
pointee.time_millis_sequence = quote.timeMillisSequence
pointee.time_nano_part = quote.timeNanoPart
pointee.bid_time = quote.bidTime
pointee.bid_exchange_code = quote.bidExchangeCode
pointee.bid_price = quote.bidPrice
pointee.bid_size = quote.bidSize
pointee.ask_time = quote.askTime
pointee.ask_exchange_code = quote.askExchangeCode
pointee.ask_price = quote.askPrice
pointee.ask_size = quote.askSize
pointer.pointee = pointee
pointer.pointee.time_millis_sequence = quote.timeMillisSequence
pointer.pointee.time_nano_part = quote.timeNanoPart
pointer.pointee.bid_time = quote.bidTime
pointer.pointee.bid_exchange_code = quote.bidExchangeCode
pointer.pointee.bid_price = quote.bidPrice
pointer.pointee.bid_size = quote.bidSize
pointer.pointee.ask_time = quote.askTime
pointer.pointee.ask_exchange_code = quote.askExchangeCode
pointer.pointee.ask_price = quote.askPrice
pointer.pointee.ask_size = quote.askSize

let eventType = pointer.withMemoryRebound(to: dxfg_event_type_t.self, capacity: 1) { pointer in
pointer.pointee.clazz = DXFG_EVENT_QUOTE
return pointer
Expand Down
10 changes: 1 addition & 9 deletions DXFeedFramework/Native/Feed/NativePublisher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,10 @@ class NativePublisher {
nativeEvents.forEach { mapper.releaseNative(native: $0) }

}
let count = Int(listPointer.pointee.size ?? 0)
for index in 0..<count {
if let element = listPointer.pointee.elements[index] {
if let event = try? mapper.fromNative(native: element) {
print(event)
}
}
}
let thread = currentThread()
let result = try ErrorCheck.nativeCall(thread, dxfg_DXPublisher_publishEvents(thread,
publisher,
listPointer))

print(result)
}
}
30 changes: 30 additions & 0 deletions DXFeedFrameworkTests/Listeners/TestEndpoointStateListener.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// TestEndpoointStateListener.swift
// DXFeedFrameworkTests
//
// Created by Aleksey Kosylo on 16.10.23.
//

import Foundation
@testable import DXFeedFramework

class TestEndpoointStateListener: DXEndpointObserver, Hashable {
func endpointDidChangeState(old: DXFeedFramework.DXEndpointState, new: DXFeedFramework.DXEndpointState) {
self.callback(new)
}


static func == (lhs: TestEndpoointStateListener, rhs: TestEndpoointStateListener) -> Bool {
lhs === rhs
}

func hash(into hasher: inout Hasher) {
hasher.combine("\(self):\(stringReference(self))")
}
var callback: (DXEndpointState) -> Void = { _ in }

init(overrides: (TestEndpoointStateListener) -> TestEndpoointStateListener) {
_ = overrides(self)
}
}

1 change: 1 addition & 0 deletions DXFeedFrameworkTests/Listeners/TestListener.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class TestListener: DXEndpointObserver {
self.expectations = expectations

}

func endpointDidChangeState(old: DXEndpointState,
new: DXEndpointState) {
if let expectation = expectations[new] {
Expand Down
40 changes: 37 additions & 3 deletions DXFeedFrameworkTests/PublisherTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,48 @@ final class PublisherTest: XCTestCase {
func testCreatePublisher() throws {
do {
let endpoint: DXEndpoint? = try DXEndpoint.builder().withRole(.publisher).withProperty("test", "value").build()
let publisher = endpoint?.getPublisher()
try endpoint?.connect(":7400")
let publisher = endpoint?.getPublisher()

wait(seconds: 2)
let testQuote = Quote("AAPL")
testQuote.bidSize = 100
testQuote.askPrice = 666
try publisher?.publish(events: [testQuote])

let feedEndpoint = try DXEndpoint.builder().withRole(.feed).withProperty("test", "value").build()

let connectedExpectation = expectation(description: "Connected")
let stateListener = TestEndpoointStateListener { listener in
listener.callback = { state in
if state == .connected {
connectedExpectation.fulfill()
DispatchQueue.global(qos: .background).async {
try? publisher?.publish(events: [testQuote])
}


}
}
return listener
}
feedEndpoint.add(observer: stateListener)
let subscription = try feedEndpoint.getFeed()?.createSubscription(.quote)
try feedEndpoint.connect("localhost:7400")
let receivedEventExp = expectation(description: "Received events \(EventCode.quote)")
receivedEventExp.assertForOverFulfill = false

let listener = AnonymousClass { anonymCl in
anonymCl.callback = { events in
receivedEventExp.fulfill()
}
return anonymCl
}

try subscription?.add(observer: listener)
try subscription?.addSymbols(["AAPL"])
wait(for: [connectedExpectation], timeout: 1)

wait(for: [receivedEventExp], timeout: 30)
Isolate.shared.callGC()
wait(seconds: 10)

} catch {
Expand Down

0 comments on commit 5a78f81

Please sign in to comment.