Skip to content

Commit

Permalink
Merge pull request #2 from ttldtor/main
Browse files Browse the repository at this point in the history
Bring the list of unimplemented functions to comply with Graal Native SDK v1.1.22 and v1.1.23
  • Loading branch information
Montura authored Sep 23, 2024
2 parents 58cc091 + 2f2c467 commit 027478c
Show file tree
Hide file tree
Showing 129 changed files with 5,585 additions and 3,500 deletions.
14 changes: 14 additions & 0 deletions src/main/c/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright (c) 2024 Devexperts LLC.
# SPDX-License-Identifier: MPL-2.0
BasedOnStyle: LLVM
ColumnLimit: 120
ContinuationIndentWidth: 4
IndentPPDirectives: AfterHash
TabWidth: 4
IndentWidth: 4
UseTab: Never
AllowShortBlocksOnASingleLine: Never
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: None
AllowShortLoopsOnASingleLine: false
90 changes: 90 additions & 0 deletions src/main/c/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
### C++ template
# Prerequisites
*.d

# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app

### C template
# Prerequisites
*.d

# Object files
*.o
*.ko
*.obj
*.elf

# Linker output
*.ilk
*.map
*.exp

# Precompiled Headers
*.gch
*.pch

# Libraries
*.lib
*.a
*.la
*.lo

# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib

# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex

# Debug files
*.dSYM/
*.su
*.idb
*.pdb

# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf

cmake-build-*/

2 changes: 2 additions & 0 deletions src/main/c/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) 2024 Devexperts LLC.
# SPDX-License-Identifier: MPL-2.0
cmake_minimum_required(VERSION 3.15)
project(DxFeedJniNativeSdk)

Expand Down
2 changes: 2 additions & 0 deletions src/main/c/demo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) 2024 Devexperts LLC.
# SPDX-License-Identifier: MPL-2.0
cmake_minimum_required(VERSION 3.15)
project(DxFeedDemo)
enable_language(CXX)
Expand Down
104 changes: 49 additions & 55 deletions src/main/c/demo/demo.cpp
Original file line number Diff line number Diff line change
@@ -1,79 +1,73 @@
// Copyright © 2023 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/.
// Copyright (c) 2024 Devexperts LLC.
// SPDX-License-Identifier: MPL-2.0

#include <iostream>
#include <chrono>
#include <iostream>
#include <thread>

#include "api/dxfg_api.h"

void c_print(graal_isolatethread_t *thread, dxfg_event_type_list *events, void *user_data) {
for (int i = 0; i < events->size; ++i) {
auto pEvent = events->elements ? events->elements[i] : nullptr;
if (pEvent && pEvent->clazz == DXFG_EVENT_QUOTE) {
const auto* quote = (const dxfg_quote_t*) pEvent;
printf(
"C: QUOTE{event_symbol=%s, bid_price=%f, bid_time=%lld, ask_price=%f, ask_time=%lld}\n",
quote->market_event.event_symbol,
quote->bid_price,
quote->bid_time,
quote->ask_price,
quote->ask_time
);
for (int i = 0; i < events->size; ++i) {
auto pEvent = events->elements ? events->elements[i] : nullptr;
if (pEvent && pEvent->clazz == DXFG_EVENT_QUOTE) {
const auto *quote = (const dxfg_quote_t *)pEvent;
printf("C: QUOTE{event_symbol=%s, bid_price=%f, bid_time=%lld, ask_price=%f, ask_time=%lld}\n",
quote->market_event.event_symbol, quote->bid_price, quote->bid_time, quote->ask_price,
quote->ask_time);
}
fflush(stdout);
}
fflush(stdout);
}
}

void endpoint_state_change_listener(graal_isolatethread_t *thread, dxfg_endpoint_state_t old_state,
dxfg_endpoint_state_t new_state, void *user_data) {
printf("C: state %d -> %d\n", old_state, new_state);
printf("C: state %d -> %d\n", old_state, new_state);
}

void dxEndpointSubscription(graal_isolatethread_t *thread, const char* address, const char* symbol) {
dxfg_endpoint_t* endpoint = dxfg_DXEndpoint_create(thread);
dxfg_DXEndpoint_connect(thread, endpoint, address);
dxfg_feed_t* feed = dxfg_DXEndpoint_getFeed(thread, endpoint);
void dxEndpointSubscription(graal_isolatethread_t *thread, const char *address, const char *symbol) {
dxfg_endpoint_t *endpoint = dxfg_DXEndpoint_create(thread);
dxfg_DXEndpoint_connect(thread, endpoint, address);
dxfg_feed_t *feed = dxfg_DXEndpoint_getFeed(thread, endpoint);

dxfg_subscription_t* subscription = dxfg_DXFeed_createSubscription(thread, feed, DXFG_EVENT_QUOTE);
dxfg_feed_event_listener_t* listener = dxfg_DXFeedEventListener_new(thread, &c_print, nullptr);
dxfg_DXFeedSubscription_addEventListener(thread, subscription, listener);
dxfg_subscription_t *subscription = dxfg_DXFeed_createSubscription(thread, feed, DXFG_EVENT_QUOTE);
dxfg_feed_event_listener_t *listener = dxfg_DXFeedEventListener_new(thread, &c_print, nullptr);
dxfg_DXFeedSubscription_addEventListener(thread, subscription, listener);

dxfg_endpoint_state_change_listener_t* stateListener =
dxfg_PropertyChangeListener_new(thread, endpoint_state_change_listener, nullptr);
dxfg_DXEndpoint_addStateChangeListener(thread, endpoint, stateListener);
dxfg_endpoint_state_change_listener_t *stateListener =
dxfg_PropertyChangeListener_new(thread, endpoint_state_change_listener, nullptr);
dxfg_DXEndpoint_addStateChangeListener(thread, endpoint, stateListener);

dxfg_string_symbol_t symbolAAPL;
symbolAAPL.supper.type = STRING;
symbolAAPL.symbol = symbol;
dxfg_string_symbol_t symbolAAPL;
symbolAAPL.supper.type = STRING;
symbolAAPL.symbol = symbol;

dxfg_DXFeedSubscription_setSymbol(thread, subscription, &symbolAAPL.supper);
std::chrono::seconds seconds(10);
std::this_thread::sleep_for(seconds);
dxfg_DXFeedSubscription_setSymbol(thread, subscription, &symbolAAPL.supper);
std::chrono::seconds seconds(10);
std::this_thread::sleep_for(seconds);

dxfg_DXFeedSubscription_close(thread, subscription);
dxfg_DXEndpoint_removeStateChangeListener(thread, endpoint, stateListener);
dxfg_DXEndpoint_close(thread, endpoint);
dxfg_JavaObjectHandler_release(thread, &stateListener->handler);
dxfg_JavaObjectHandler_release(thread, &listener->handler);
dxfg_JavaObjectHandler_release(thread, &subscription->handler);
dxfg_JavaObjectHandler_release(thread, &endpoint->handler);
dxfg_DXFeedSubscription_close(thread, subscription);
dxfg_DXEndpoint_removeStateChangeListener(thread, endpoint, stateListener);
dxfg_DXEndpoint_close(thread, endpoint);
dxfg_JavaObjectHandler_release(thread, &stateListener->handler);
dxfg_JavaObjectHandler_release(thread, &listener->handler);
dxfg_JavaObjectHandler_release(thread, &subscription->handler);
dxfg_JavaObjectHandler_release(thread, &endpoint->handler);
}

int main(int argc, char** argv) {
// load cmd args
const int defaultArgSize = 3;
if (argc < defaultArgSize) {
std::cerr << "Error: expected 2 args: <address:port, symbol>" << std::endl;
return -1;
}
int main(int argc, char **argv) {
// load cmd args
const int defaultArgSize = 3;
if (argc < defaultArgSize) {
std::cerr << "Error: expected 2 args: <address:port, symbol>" << std::endl;
return -1;
}

const auto address = argv[1]; // "demo.dxfeed.com:7300";
const auto symbol = argv[2]; // "APPL";
const auto address = argv[1]; // "demo.dxfeed.com:7300";
const auto symbol = argv[2]; // "APPL";

auto thread = create_thread();
if (thread != nullptr) {
dxEndpointSubscription(thread, address, symbol);
}
auto thread = create_thread();
if (thread != nullptr) {
dxEndpointSubscription(thread, address, symbol);
}
}
6 changes: 6 additions & 0 deletions src/main/c/jni-lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) 2024 Devexperts LLC.
# SPDX-License-Identifier: MPL-2.0
cmake_minimum_required(VERSION 3.15)
project(DxFeedJniNativeSdk)
enable_language(CXX)
Expand Down Expand Up @@ -47,9 +49,13 @@ set(SOURCE_FILES
src/api/dxfg_api.cpp
src/api/dxfg_catch_exception.cpp
src/api/dxfg_dxfeed.cpp
src/api/dxfg_ipf.cpp
src/api/dxfg_ondemand.cpp
src/api/dxfg_endpoint.cpp
src/api/dxfg_event_model.cpp
src/api/dxfg_events.cpp
src/api/dxfg_publisher.cpp
src/api/dxfg_qds.cpp
src/api/dxfg_schedule.cpp
src/api/dxfg_subscription.cpp
src/api/dxfg_system.cpp
Expand Down
16 changes: 11 additions & 5 deletions src/main/c/jni-lib/include/api/dxfg_api.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright © 2023 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/.
// Copyright (c) 2024 Devexperts LLC.
// SPDX-License-Identifier: MPL-2.0

#ifndef DXFEED_JNI_NATIVE_API_API_H_
#define DXFEED_JNI_NATIVE_API_API_H_
Expand All @@ -9,14 +8,21 @@
extern "C" {
#endif

#include "dxfg_catch_exception.h"
#include "dxfg_endpoint.h"
#include "dxfg_event_model.h"
#include "dxfg_events.h"
#include "dxfg_feed.h"
#include "dxfg_subscription.h"
#include "dxfg_ipf.h"
#include "dxfg_javac.h"
#include "dxfg_ondemand.h"
#include "dxfg_publisher.h"
#include "dxfg_qds.h"
#include "dxfg_schedule.h"
#include "dxfg_subscription.h"
#include "dxfg_system.h"
#include "dxfg_javac.h"
#include "graal_isolate.h"
// #include "graal_isolate_dynamic.h"

#ifdef __cplusplus
}
Expand Down
38 changes: 29 additions & 9 deletions src/main/c/jni-lib/include/api/dxfg_catch_exception.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright © 2023 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/.
// Copyright (c) 2024 Devexperts LLC.
// SPDX-License-Identifier: MPL-2.0

#ifndef DXFEED_GRAAL_NATIVE_SDK_CATCH_EXCEPTION_H_
#define DXFEED_GRAAL_NATIVE_SDK_CATCH_EXCEPTION_H_
Expand All @@ -14,19 +13,40 @@ extern "C" {

#include "graal_isolate.h"

typedef struct dxfg_stack_trace_element_t {
const char *class_name;
const char *class_loader_name;
const char *file_name;
const char *method_name;
int32_t line_number;
int32_t is_native_method;
const char *module_name;
const char *module_version;
} dxfg_stack_trace_element_t;

typedef struct dxfg_stack_trace_element_list {
int32_t size;
dxfg_stack_trace_element_t **elements;
} dxfg_stack_trace_element_list;

/**
* @brief The Exception.
* <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Exception.html">Javadoc</a>
* <a
* href="https://docs.oracle.com/javase/8/docs/api/java/lang/Exception.html">Javadoc</a>
*/
typedef struct dxfg_exception_t {
const char* className;
const char* message;
const char* stackTrace;
// dxfg_exception_t *cause;
const char *class_name;
const char *message;
const char *print_stack_trace;
dxfg_stack_trace_element_list *stack_trace;
struct dxfg_exception_t *cause;
} dxfg_exception_t;

dxfg_exception_t* dxfg_get_and_clear_thread_exception_t(graal_isolatethread_t *thread);
dxfg_exception_t *dxfg_get_and_clear_thread_exception_t(graal_isolatethread_t *thread);
void dxfg_Exception_release(graal_isolatethread_t *thread, dxfg_exception_t *exception);

// JNI impl specific

void dxfg_print_exception(graal_isolatethread_t *thread, dxfg_exception_t* exception);

#ifdef __cplusplus
Expand Down
Loading

0 comments on commit 027478c

Please sign in to comment.