|
6 | 6 | // ??
|
7 | 7 | #endif
|
8 | 8 |
|
| 9 | +#include "../subprojects/gdk_rust/gdk_rust.h" |
| 10 | + |
| 11 | +#include "exception.hpp" |
9 | 12 | #include "ga_rust.hpp"
|
10 | 13 | #include "ga_tor.hpp"
|
11 |
| -#include "exception.hpp" |
12 | 14 | #include "logging.hpp"
|
13 | 15 | #include "session.hpp"
|
14 | 16 | #include "utils.hpp"
|
15 | 17 |
|
16 | 18 | namespace ga {
|
17 | 19 | namespace sdk {
|
18 | 20 |
|
19 |
| - static const std::string TOR_SOCKS5_PREFIX("socks5://"); |
| 21 | + namespace { |
| 22 | + static const std::string TOR_SOCKS5_PREFIX("socks5://"); |
20 | 23 |
|
21 |
| - static inline void check_code(const int32_t return_code) |
22 |
| - { |
23 |
| - switch (return_code) { |
24 |
| - case GA_OK: |
25 |
| - return; |
| 24 | + class gdkrust_json { |
| 25 | + public: |
| 26 | + explicit gdkrust_json(const nlohmann::json& val) |
| 27 | + : gdkrust_json(val.dump()) |
| 28 | + { |
| 29 | + } |
| 30 | + |
| 31 | + explicit gdkrust_json(GDKRUST_json* json) { m_json = json; } |
| 32 | + |
| 33 | + explicit gdkrust_json(const std::string& str) { GDKRUST_convert_string_to_json(str.c_str(), &m_json); } |
| 34 | + |
| 35 | + static inline nlohmann::json from_serde(GDKRUST_json* json) |
| 36 | + { |
| 37 | + char* output; |
| 38 | + GDKRUST_convert_json_to_string(json, &output); |
| 39 | + |
| 40 | + auto cppjson = nlohmann::json::parse(output); |
| 41 | + |
| 42 | + GDKRUST_destroy_json(json); |
| 43 | + GDKRUST_destroy_string(output); |
26 | 44 |
|
27 |
| - case GA_RECONNECT: |
28 |
| - case GA_SESSION_LOST: |
29 |
| - throw reconnect_error(); |
| 45 | + return cppjson; |
| 46 | + } |
| 47 | + |
| 48 | + GDKRUST_json* get() { return m_json; } |
| 49 | + |
| 50 | + ~gdkrust_json() { GDKRUST_destroy_json(m_json); } |
| 51 | + |
| 52 | + private: |
| 53 | + GDKRUST_json* m_json; |
| 54 | + }; |
30 | 55 |
|
31 |
| - case GA_TIMEOUT: |
32 |
| - throw timeout_error(); |
| 56 | + static void check_code(const int32_t return_code) |
| 57 | + { |
| 58 | + switch (return_code) { |
| 59 | + case GA_OK: |
| 60 | + return; |
33 | 61 |
|
34 |
| - case GA_NOT_AUTHORIZED: |
35 |
| - throw login_error(""); // TODO: msg from rust |
| 62 | + case GA_RECONNECT: |
| 63 | + case GA_SESSION_LOST: |
| 64 | + throw reconnect_error(); |
36 | 65 |
|
37 |
| - case GA_ERROR: |
38 |
| - default: |
39 |
| - throw std::runtime_error("call failed with: " + std::to_string(return_code)); |
40 |
| - break; |
| 66 | + case GA_TIMEOUT: |
| 67 | + throw timeout_error(); |
| 68 | + |
| 69 | + case GA_NOT_AUTHORIZED: |
| 70 | + throw login_error(""); // TODO: msg from rust |
| 71 | + |
| 72 | + case GA_ERROR: |
| 73 | + default: |
| 74 | + throw std::runtime_error("call failed with: " + std::to_string(return_code)); |
| 75 | + break; |
| 76 | + } |
41 | 77 | }
|
42 |
| - } |
| 78 | + } // namespace |
43 | 79 |
|
44 | 80 | ga_rust::ga_rust(const nlohmann::json& net_params)
|
45 | 81 | : session_impl(net_params)
|
|
0 commit comments