Skip to content

Commit

Permalink
[MDAPI-26] Update Graal SDK to v1.1.21
Browse files Browse the repository at this point in the history
TimePeriod
  • Loading branch information
AnatolyKalin committed Jul 10, 2024
1 parent 01e0e9a commit 781a909
Show file tree
Hide file tree
Showing 12 changed files with 283 additions and 11 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ set(dxFeedGraalCxxApi_Isolated_Sources
src/isolated/internal/IsolatedString.cpp
src/isolated/internal/IsolatedTimeFormat.cpp
src/isolated/internal/IsolatedTools.cpp
src/isolated/util/IsolatedTimePeriod.cpp
)

set(dxFeedGraalCxxApi_Api_Sources
Expand Down Expand Up @@ -326,6 +327,10 @@ set(dxFeedGraalCxxApi_Schedule_Sources
src/schedule/Schedule.cpp
)

set(dxFeedGraalCxxApi_Util_Sources
src/util/TimePeriod.cpp
)

set(dxFeedGraalCxxApi_Sources
${dxFeedGraalCxxApi_Internal_Sources}
${dxFeedGraalCxxApi_InternalUtils_Sources}
Expand All @@ -345,6 +350,7 @@ set(dxFeedGraalCxxApi_Sources
${dxFeedGraalCxxApi_EventOption_Sources}
${dxFeedGraalCxxApi_EventMisc_Sources}
${dxFeedGraalCxxApi_Schedule_Sources}
${dxFeedGraalCxxApi_Util_Sources}
)

if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
Expand Down
3 changes: 3 additions & 0 deletions include/dxfeed_graal_cpp_api/api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ DXFCXX_DISABLE_MSC_WARNINGS_PUSH(4251 4996)
#include "internal/utils/StringUtils.hpp"
#include "internal/utils/debug/Debug.hpp"

#include "util/TimePeriod.hpp"

#include "api/ApiModule.hpp"
#include "ipf/IpfModule.hpp"
#include "entity/EntityModule.hpp"
Expand All @@ -62,6 +64,7 @@ DXFCXX_DISABLE_MSC_WARNINGS_PUSH(4251 4996)
#include "isolated/internal/IsolatedString.hpp"
#include "isolated/internal/IsolatedTimeFormat.hpp"
#include "isolated/internal/IsolatedTools.hpp"
#include "isolated/util/IsolatedTimePeriod.hpp"

#include "ondemand/OnDemandService.hpp"

Expand Down
8 changes: 8 additions & 0 deletions include/dxfeed_graal_cpp_api/exceptions/JavaException.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ struct DXFCPP_EXPORT JavaException : public std::runtime_error {
return v;
}

template <typename T> static constexpr T throwIfMinusOne(T v) {
if (v == T(-1)) {
throwIfJavaThreadExceptionExists();
}

return v;
}

/**
* @return dxFeed Graal CXX API stack trace + Java (GraalVM) exception's stack trace.
*/
Expand Down
6 changes: 3 additions & 3 deletions include/dxfeed_graal_cpp_api/internal/TimeFormat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ struct DXFCPP_EXPORT TimeFormat {
private:
JavaObjectHandle<TimeFormat> handle_;

explicit TimeFormat(JavaObjectHandle<TimeFormat> &&handle);

public:
explicit TimeFormat(void* handle = nullptr);
explicit TimeFormat(JavaObjectHandle<TimeFormat>&& handle);
virtual ~TimeFormat() noexcept = default;

TimeFormat(const TimeFormat &) = delete;
Expand Down Expand Up @@ -111,7 +111,7 @@ struct DXFCPP_EXPORT TimeFormat {
* @param value String value to parse.
* @return Date's timestamp parsed from <tt>value</tt> or `0` if <tt>value</tt> has wrong format.
*/
std::int64_t parse(const std::string& value) const;
std::int64_t parse(const StringLikeWrapper &value) const;

/**
* Converts timestamp into string according to the format
Expand Down
8 changes: 8 additions & 0 deletions include/dxfeed_graal_cpp_api/isolated/IsolatedCommon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ constexpr auto throwIfLessThanZero = [](auto v) {
return JavaException::throwIfLessThanZero(v);
};

constexpr auto throwIfMinusOne = [](auto v) {
return JavaException::throwIfMinusOne(v);
};

constexpr auto runGraalFunction(auto graalFunction, auto &&...params) {
return runIsolatedThrow(
[](auto threadHandle, auto &&graalFunction, auto &&...params) {
Expand All @@ -66,6 +70,10 @@ constexpr auto runGraalFunctionAndThrowIfLessThanZero(auto graalFunction, auto &
return runGraalFunctionAndThrow(throwIfLessThanZero, graalFunction, params...);
}

constexpr auto runGraalFunctionAndThrowIfMinusOne(auto graalFunction, auto &&...params) {
return runGraalFunctionAndThrow(throwIfMinusOne, graalFunction, params...);
}

} // namespace isolated

DXFCPP_END_NAMESPACE
Expand Down
45 changes: 45 additions & 0 deletions include/dxfeed_graal_cpp_api/isolated/util/IsolatedTimePeriod.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (c) 2024 Devexperts LLC.
// SPDX-License-Identifier: MPL-2.0

#pragma once

#include "../../internal/Conf.hpp"

#include <cstdint>
#include <string>
#include <string_view>

DXFCXX_DISABLE_MSC_WARNINGS_PUSH(4251)

#include "../../util/TimePeriod.hpp"

DXFCPP_BEGIN_NAMESPACE

namespace isolated::util::IsolatedTimePeriod {

/*
dxfg_time_period_t* dxfg_TimePeriod_ZERO(graal_isolatethread_t *thread);
dxfg_time_period_t* dxfg_TimePeriod_UNLIMITED(graal_isolatethread_t *thread);
dxfg_time_period_t* dxfg_TimePeriod_valueOf(graal_isolatethread_t *thread, int64_t value);
dxfg_time_period_t* dxfg_TimePeriod_valueOf2(graal_isolatethread_t *thread, const char* value);
int64_t dxfg_TimePeriod_getTime(graal_isolatethread_t *thread, dxfg_time_period_t* timePeriod);
int32_t dxfg_TimePeriod_getSeconds(graal_isolatethread_t *thread, dxfg_time_period_t* timePeriod);
int64_t dxfg_TimePeriod_getNanos(graal_isolatethread_t *thread, dxfg_time_period_t* timePeriod);
*/

/* dxfg_time_period_t* */ JavaObjectHandle<TimePeriod> ZERO();
/* dxfg_time_period_t* */ JavaObjectHandle<TimePeriod> UNLIMITED();
/* dxfg_time_period_t* */ JavaObjectHandle<TimePeriod> valueOf(std::int64_t value);
/* dxfg_time_period_t* */ JavaObjectHandle<TimePeriod> valueOf(std::string_view value);
std::int64_t getTime(/* dxfg_time_period_t* */ const JavaObjectHandle<TimePeriod>& timePeriod);
std::int32_t getSeconds(/* dxfg_time_period_t* */ const JavaObjectHandle<TimePeriod>& timePeriod);
std::int64_t getNanos(/* dxfg_time_period_t* */ const JavaObjectHandle<TimePeriod>& timePeriod);

}

DXFCPP_END_NAMESPACE

DXFCXX_DISABLE_MSC_WARNINGS_POP()

96 changes: 96 additions & 0 deletions include/dxfeed_graal_cpp_api/util/TimePeriod.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// Copyright (c) 2024 Devexperts LLC.
// SPDX-License-Identifier: MPL-2.0

#pragma once

#include "../internal/Conf.hpp"

DXFCXX_DISABLE_MSC_WARNINGS_PUSH(4251)

#include <cstdint>

DXFCPP_BEGIN_NAMESPACE

/**
* Value class for period of time with support for ISO8601 duration format.
*/
struct DXFCPP_EXPORT TimePeriod {
/// Time-period of zero.
static const TimePeriod ZERO;

/// Time-period of "infinity" (time of `std::numeric_limits<std::int64_t>::max()` or `LLONG_MAX`).
static const TimePeriod UNLIMITED;

/**
* Returns TimePeriod with <tt>value</tt> milliseconds.
*
* @param value value in milliseconds
* @return TimePeriod with <tt>value</tt> milliseconds.
*/
static TimePeriod valueOf(std::int64_t value);

/**
* Returns TimePeriod with <tt>value</tt> milliseconds.
*
* @param value value in milliseconds
* @return TimePeriod with <tt>value</tt> milliseconds.
*/
static TimePeriod valueOf(std::chrono::milliseconds value) {
return valueOf(value.count());
}

/**
* Returns TimePeriod represented with a given string.
*
* Allowable format is ISO8601 duration, but there are some simplifications and modifications available:
* <ul>
* <li> Letters are case insensitive.
* <li> Letters "P" and "T" can be omitted.
* <li> Letter "S" can be also omitted. In this case last number will be supposed to be seconds.
* <li> Number of seconds can be fractional. So it is possible to define duration accurate within milliseconds.
* <li> Every part can be omitted. It is supposed that it's value is zero then.
* <li> String "inf" recognized as unlimited period.
* </ul>
*
* @param value The string representation
* @return TimePeriod represented with a given string.
*/
static TimePeriod valueOf(const StringLikeWrapper &value);

/**
* Returns value in milliseconds.
*
* @return value in milliseconds
*/
std::int64_t getTime() const;

/**
* Returns value in seconds.
*
* @return value in seconds
*/
std::int32_t getSeconds() const;

/**
* Returns value in nanoseconds.
*
* @return value in nanoseconds
*/
std::int64_t getNanos() const;

virtual ~TimePeriod() noexcept = default;

TimePeriod(const TimePeriod &) = delete;
TimePeriod(TimePeriod &&) noexcept = delete;
TimePeriod &operator=(const TimePeriod &) = delete;
TimePeriod &operator=(const TimePeriod &&) noexcept = delete;

private:
JavaObjectHandle<TimePeriod> handle_;

explicit TimePeriod(JavaObjectHandle<TimePeriod> &&handle);
};

DXFCPP_END_NAMESPACE

DXFCXX_DISABLE_MSC_WARNINGS_POP()
2 changes: 2 additions & 0 deletions src/internal/JavaObjectHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,6 @@ template struct JavaObjectHandle<PromiseImpl>;
template struct JavaObjectHandle<EventPromiseImpl>;
template struct JavaObjectHandle<EventsPromiseImpl>;

template struct JavaObjectHandle<TimePeriod>;

DXFCPP_END_NAMESPACE
8 changes: 3 additions & 5 deletions src/internal/TimeFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@

DXFCPP_BEGIN_NAMESPACE

TimeFormat::TimeFormat(void *handle) : handle_(handle){};

TimeFormat::TimeFormat(JavaObjectHandle<TimeFormat> &&handle) : handle_(std::move(handle)){};

const TimeFormat TimeFormat::DEFAULT(isolated::internal::IsolatedTimeFormat::getDefault());
const TimeFormat
TimeFormat::DEFAULT_WITH_MILLIS(DEFAULT.handle_
Expand All @@ -23,7 +19,9 @@ const TimeFormat TimeFormat::DEFAULT_WITH_MILLIS_WITH_TIMEZONE(
: JavaObjectHandle<TimeFormat>{nullptr});
const TimeFormat TimeFormat::GMT(isolated::internal::IsolatedTimeFormat::getGmt());

std::int64_t TimeFormat::parse(const std::string &value) const {
TimeFormat::TimeFormat(JavaObjectHandle<TimeFormat> &&handle) : handle_(std::move(handle)){};

std::int64_t TimeFormat::parse(const StringLikeWrapper &value) const {
return isolated::internal::IsolatedTimeFormat::parse(handle_, value);
}

Expand Down
6 changes: 3 additions & 3 deletions src/isolated/internal/IsolatedTimeFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ std::int64_t parse(/* dxfg_time_format_t* */ const JavaObjectHandle<dxfcpp::Time
"Unable to execute function `dxfg_TimeFormat_parse`. The `timeFormat` handle is invalid");
}

return runGraalFunctionAndThrowIfLessThanZero(dxfg_TimeFormat_parse,
static_cast<dxfg_time_format_t *>(timeFormat.get()), value.data());
return runGraalFunctionAndThrowIfMinusOne(dxfg_TimeFormat_parse,
static_cast<dxfg_time_format_t *>(timeFormat.get()), value.data());
}

std::string format(/* dxfg_time_format_t* */ const JavaObjectHandle<dxfcpp::TimeFormat> &timeFormat,
Expand All @@ -62,7 +62,7 @@ std::string format(/* dxfg_time_format_t* */ const JavaObjectHandle<dxfcpp::Time
}

auto format = runGraalFunctionAndThrowIfNullptr(dxfg_TimeFormat_format,
static_cast<dxfg_time_format_t *>(timeFormat.get()), value);
static_cast<dxfg_time_format_t *>(timeFormat.get()), value);
auto result = dxfcpp::toString(format);

isolated::internal::IsolatedString::release(format);
Expand Down
60 changes: 60 additions & 0 deletions src/isolated/util/IsolatedTimePeriod.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright (c) 2024 Devexperts LLC.
// SPDX-License-Identifier: MPL-2.0

#include <dxfg_api.h>

#include <dxfeed_graal_cpp_api/isolated/IsolatedCommon.hpp>
#include <dxfeed_graal_cpp_api/isolated/util/IsolatedTimePeriod.hpp>

DXFCPP_BEGIN_NAMESPACE

namespace isolated::util::IsolatedTimePeriod {
/* dxfg_time_period_t* */ JavaObjectHandle<TimePeriod> ZERO() {
return JavaObjectHandle<TimePeriod>(runGraalFunctionAndThrowIfNullptr(dxfg_TimePeriod_ZERO));
}

/* dxfg_time_period_t* */ JavaObjectHandle<TimePeriod> UNLIMITED() {
return JavaObjectHandle<TimePeriod>(runGraalFunctionAndThrowIfNullptr(dxfg_TimePeriod_UNLIMITED));
}

/* dxfg_time_period_t* */ JavaObjectHandle<TimePeriod> valueOf(std::int64_t value) {
return JavaObjectHandle<TimePeriod>(runGraalFunctionAndThrowIfNullptr(dxfg_TimePeriod_valueOf, value));
}

/* dxfg_time_period_t* */ JavaObjectHandle<TimePeriod> valueOf(std::string_view value) {
return JavaObjectHandle<TimePeriod>(runGraalFunctionAndThrowIfNullptr(dxfg_TimePeriod_valueOf2, value.data()));
}

std::int64_t getTime(/* dxfg_time_period_t* */ const JavaObjectHandle<TimePeriod> &timePeriod) {
if (!timePeriod) {
throw std::invalid_argument(
"Unable to execute function `dxfg_TimePeriod_getTime`. The `timePeriod` handle is invalid");
}

return runGraalFunctionAndThrowIfMinusOne(dxfg_TimePeriod_getTime,
static_cast<dxfg_time_period_t *>(timePeriod.get()));
}

std::int32_t getSeconds(/* dxfg_time_period_t* */ const JavaObjectHandle<TimePeriod> &timePeriod) {
if (!timePeriod) {
throw std::invalid_argument(
"Unable to execute function `dxfg_TimePeriod_getSeconds`. The `timePeriod` handle is invalid");
}

return runGraalFunctionAndThrowIfMinusOne(dxfg_TimePeriod_getSeconds,
static_cast<dxfg_time_period_t *>(timePeriod.get()));
}

std::int64_t getNanos(/* dxfg_time_period_t* */ const JavaObjectHandle<TimePeriod> &timePeriod) {
if (!timePeriod) {
throw std::invalid_argument(
"Unable to execute function `dxfg_TimePeriod_getNanos`. The `timePeriod` handle is invalid");
}

return runGraalFunctionAndThrowIfMinusOne(dxfg_TimePeriod_getNanos,
static_cast<dxfg_time_period_t *>(timePeriod.get()));
}

} // namespace isolated::util::IsolatedTimePeriod

DXFCPP_END_NAMESPACE
Loading

0 comments on commit 781a909

Please sign in to comment.