1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

Simplify network GDExtension bindings using EXBIND macros.

Simplify StreamPeer, PacketPeer, MultiplayerPeer extension.

Simplify and update WebRTC*Extension with newly supported types.
This commit is contained in:
Fabio Alessandrelli
2022-09-01 05:09:07 +02:00
parent 8c7be63588
commit fbbd3950c8
15 changed files with 124 additions and 498 deletions

View File

@@ -48,7 +48,7 @@
</description>
</method>
<method name="_get_packet" qualifiers="virtual">
<return type="int" />
<return type="int" enum="Error" />
<param index="0" name="r_buffer" type="const uint8_t **" />
<param index="1" name="r_buffer_size" type="int32_t*" />
<description>
@@ -60,12 +60,12 @@
</description>
</method>
<method name="_get_ready_state" qualifiers="virtual const">
<return type="int" />
<return type="int" enum="WebRTCDataChannel.ChannelState" />
<description>
</description>
</method>
<method name="_get_write_mode" qualifiers="virtual const">
<return type="int" />
<return type="int" enum="WebRTCDataChannel.WriteMode" />
<description>
</description>
</method>
@@ -80,12 +80,12 @@
</description>
</method>
<method name="_poll" qualifiers="virtual">
<return type="int" />
<return type="int" enum="Error" />
<description>
</description>
</method>
<method name="_put_packet" qualifiers="virtual">
<return type="int" />
<return type="int" enum="Error" />
<param index="0" name="p_buffer" type="const uint8_t*" />
<param index="1" name="p_buffer_size" type="int" />
<description>
@@ -93,7 +93,7 @@
</method>
<method name="_set_write_mode" qualifiers="virtual">
<return type="void" />
<param index="0" name="p_write_mode" type="int" />
<param index="0" name="p_write_mode" type="int" enum="WebRTCDataChannel.WriteMode" />
<description>
</description>
</method>

View File

@@ -8,7 +8,7 @@
</tutorials>
<methods>
<method name="_add_ice_candidate" qualifiers="virtual">
<return type="int" />
<return type="int" enum="Error" />
<param index="0" name="p_sdp_mid_name" type="String" />
<param index="1" name="p_sdp_mline_index" type="int" />
<param index="2" name="p_sdp_name" type="String" />
@@ -28,35 +28,35 @@
</description>
</method>
<method name="_create_offer" qualifiers="virtual">
<return type="int" />
<return type="int" enum="Error" />
<description>
</description>
</method>
<method name="_get_connection_state" qualifiers="virtual const">
<return type="int" />
<return type="int" enum="WebRTCPeerConnection.ConnectionState" />
<description>
</description>
</method>
<method name="_initialize" qualifiers="virtual">
<return type="int" />
<return type="int" enum="Error" />
<param index="0" name="p_config" type="Dictionary" />
<description>
</description>
</method>
<method name="_poll" qualifiers="virtual">
<return type="int" />
<return type="int" enum="Error" />
<description>
</description>
</method>
<method name="_set_local_description" qualifiers="virtual">
<return type="int" />
<return type="int" enum="Error" />
<param index="0" name="p_type" type="String" />
<param index="1" name="p_sdp" type="String" />
<description>
</description>
</method>
<method name="_set_remote_description" qualifiers="virtual">
<return type="int" />
<return type="int" enum="Error" />
<param index="0" name="p_type" type="String" />
<param index="1" name="p_sdp" type="String" />
<description>

View File

@@ -56,160 +56,20 @@ void WebRTCDataChannelExtension::_bind_methods() {
GDVIRTUAL_BIND(_get_buffered_amount);
}
int WebRTCDataChannelExtension::get_available_packet_count() const {
int count;
if (GDVIRTUAL_CALL(_get_available_packet_count, count)) {
return count;
}
WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_available_packet_count is unimplemented!");
return -1;
}
Error WebRTCDataChannelExtension::get_packet(const uint8_t **r_buffer, int &r_buffer_size) {
int err;
Error err;
if (GDVIRTUAL_CALL(_get_packet, r_buffer, &r_buffer_size, err)) {
return (Error)err;
return err;
}
WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_packet_native is unimplemented!");
return FAILED;
}
Error WebRTCDataChannelExtension::put_packet(const uint8_t *p_buffer, int p_buffer_size) {
int err;
Error err;
if (GDVIRTUAL_CALL(_put_packet, p_buffer, p_buffer_size, err)) {
return (Error)err;
return err;
}
WARN_PRINT_ONCE("WebRTCDataChannelExtension::_put_packet_native is unimplemented!");
return FAILED;
}
int WebRTCDataChannelExtension::get_max_packet_size() const {
int size;
if (GDVIRTUAL_CALL(_get_max_packet_size, size)) {
return size;
}
WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_max_packet_size is unimplemented!");
return 0;
}
Error WebRTCDataChannelExtension::poll() {
int err;
if (GDVIRTUAL_CALL(_poll, err)) {
return (Error)err;
}
WARN_PRINT_ONCE("WebRTCDataChannelExtension::_poll is unimplemented!");
return ERR_UNCONFIGURED;
}
void WebRTCDataChannelExtension::close() {
if (GDVIRTUAL_CALL(_close)) {
return;
}
WARN_PRINT_ONCE("WebRTCDataChannelExtension::_close is unimplemented!");
}
void WebRTCDataChannelExtension::set_write_mode(WriteMode p_mode) {
if (GDVIRTUAL_CALL(_set_write_mode, p_mode)) {
return;
}
WARN_PRINT_ONCE("WebRTCDataChannelExtension::_set_write_mode is unimplemented!");
}
WebRTCDataChannel::WriteMode WebRTCDataChannelExtension::get_write_mode() const {
int mode;
if (GDVIRTUAL_CALL(_get_write_mode, mode)) {
return (WriteMode)mode;
}
WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_write_mode is unimplemented!");
return WRITE_MODE_BINARY;
}
bool WebRTCDataChannelExtension::was_string_packet() const {
bool was_string;
if (GDVIRTUAL_CALL(_was_string_packet, was_string)) {
return was_string;
}
WARN_PRINT_ONCE("WebRTCDataChannelExtension::_was_string_packet is unimplemented!");
return false;
}
WebRTCDataChannel::ChannelState WebRTCDataChannelExtension::get_ready_state() const {
int state;
if (GDVIRTUAL_CALL(_get_ready_state, state)) {
return (ChannelState)state;
}
WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_ready_state is unimplemented!");
return STATE_CLOSED;
}
String WebRTCDataChannelExtension::get_label() const {
String label;
if (GDVIRTUAL_CALL(_get_label, label)) {
return label;
}
WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_label is unimplemented!");
return label;
}
bool WebRTCDataChannelExtension::is_ordered() const {
bool ordered;
if (GDVIRTUAL_CALL(_is_ordered, ordered)) {
return ordered;
}
WARN_PRINT_ONCE("WebRTCDataChannelExtension::_is_ordered is unimplemented!");
return false;
}
int WebRTCDataChannelExtension::get_id() const {
int id;
if (GDVIRTUAL_CALL(_get_id, id)) {
return id;
}
WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_id is unimplemented!");
return -1;
}
int WebRTCDataChannelExtension::get_max_packet_life_time() const {
int lifetime;
if (GDVIRTUAL_CALL(_get_max_packet_life_time, lifetime)) {
return lifetime;
}
WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_max_packet_life_time is unimplemented!");
return -1;
}
int WebRTCDataChannelExtension::get_max_retransmits() const {
int retransmits;
if (GDVIRTUAL_CALL(_get_max_retransmits, retransmits)) {
return retransmits;
}
WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_max_retransmits is unimplemented!");
return -1;
}
String WebRTCDataChannelExtension::get_protocol() const {
String protocol;
if (GDVIRTUAL_CALL(_get_protocol, protocol)) {
return protocol;
}
WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_protocol is unimplemented!");
return protocol;
}
bool WebRTCDataChannelExtension::is_negotiated() const {
bool negotiated;
if (GDVIRTUAL_CALL(_is_negotiated, negotiated)) {
return negotiated;
}
WARN_PRINT_ONCE("WebRTCDataChannelExtension::_is_negotiated is unimplemented!");
return false;
}
int WebRTCDataChannelExtension::get_buffered_amount() const {
int amount;
if (GDVIRTUAL_CALL(_get_buffered_amount, amount)) {
return amount;
}
WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_buffered_amount is unimplemented!");
return -1;
}

View File

@@ -33,6 +33,7 @@
#include "webrtc_data_channel.h"
#include "core/extension/ext_wrappers.gen.inc"
#include "core/object/gdvirtual.gen.inc"
#include "core/object/script_language.h"
#include "core/variant/native_ptr.h"
@@ -44,53 +45,33 @@ protected:
static void _bind_methods();
public:
virtual void set_write_mode(WriteMode mode) override;
virtual WriteMode get_write_mode() const override;
virtual bool was_string_packet() const override;
EXBIND0R(Error, poll);
EXBIND0(close);
virtual ChannelState get_ready_state() const override;
virtual String get_label() const override;
virtual bool is_ordered() const override;
virtual int get_id() const override;
virtual int get_max_packet_life_time() const override;
virtual int get_max_retransmits() const override;
virtual String get_protocol() const override;
virtual bool is_negotiated() const override;
virtual int get_buffered_amount() const override;
EXBIND1(set_write_mode, WriteMode);
EXBIND0RC(WriteMode, get_write_mode);
virtual Error poll() override;
virtual void close() override;
EXBIND0RC(bool, was_string_packet);
EXBIND0RC(ChannelState, get_ready_state);
EXBIND0RC(String, get_label);
EXBIND0RC(bool, is_ordered);
EXBIND0RC(int, get_id);
EXBIND0RC(int, get_max_packet_life_time);
EXBIND0RC(int, get_max_retransmits);
EXBIND0RC(String, get_protocol);
EXBIND0RC(bool, is_negotiated);
EXBIND0RC(int, get_buffered_amount);
/** Inherited from PacketPeer: **/
virtual int get_available_packet_count() const override;
EXBIND0RC(int, get_available_packet_count);
EXBIND0RC(int, get_max_packet_size);
virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size) override; ///< buffer is GONE after next get_packet
virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size) override;
virtual int get_max_packet_size() const override;
/** GDExtension **/
GDVIRTUAL0RC(int, _get_available_packet_count);
GDVIRTUAL2R(int, _get_packet, GDNativeConstPtr<const uint8_t *>, GDNativePtr<int>);
GDVIRTUAL2R(int, _put_packet, GDNativeConstPtr<const uint8_t>, int);
GDVIRTUAL0RC(int, _get_max_packet_size);
GDVIRTUAL0R(int, _poll);
GDVIRTUAL0(_close);
GDVIRTUAL1(_set_write_mode, int);
GDVIRTUAL0RC(int, _get_write_mode);
GDVIRTUAL0RC(bool, _was_string_packet);
GDVIRTUAL0RC(int, _get_ready_state);
GDVIRTUAL0RC(String, _get_label);
GDVIRTUAL0RC(bool, _is_ordered);
GDVIRTUAL0RC(int, _get_id);
GDVIRTUAL0RC(int, _get_max_packet_life_time);
GDVIRTUAL0RC(int, _get_max_retransmits);
GDVIRTUAL0RC(String, _get_protocol);
GDVIRTUAL0RC(bool, _is_negotiated);
GDVIRTUAL0RC(int, _get_buffered_amount);
GDVIRTUAL2R(Error, _get_packet, GDNativeConstPtr<const uint8_t *>, GDNativePtr<int>);
GDVIRTUAL2R(Error, _put_packet, GDNativeConstPtr<const uint8_t>, int);
WebRTCDataChannelExtension() {}
};

View File

@@ -42,24 +42,6 @@ void WebRTCPeerConnectionExtension::_bind_methods() {
GDVIRTUAL_BIND(_close);
}
WebRTCPeerConnection::ConnectionState WebRTCPeerConnectionExtension::get_connection_state() const {
int state;
if (GDVIRTUAL_CALL(_get_connection_state, state)) {
return (ConnectionState)state;
}
WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_get_connection_state is unimplemented!");
return STATE_DISCONNECTED;
}
Error WebRTCPeerConnectionExtension::initialize(Dictionary p_config) {
int err;
if (GDVIRTUAL_CALL(_initialize, p_config, err)) {
return (Error)err;
}
WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_initialize is unimplemented!");
return ERR_UNCONFIGURED;
}
Ref<WebRTCDataChannel> WebRTCPeerConnectionExtension::create_data_channel(String p_label, Dictionary p_options) {
Object *ret = nullptr;
if (GDVIRTUAL_CALL(_create_data_channel, p_label, p_options, ret)) {
@@ -70,55 +52,3 @@ Ref<WebRTCDataChannel> WebRTCPeerConnectionExtension::create_data_channel(String
WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_create_data_channel is unimplemented!");
return nullptr;
}
Error WebRTCPeerConnectionExtension::create_offer() {
int err;
if (GDVIRTUAL_CALL(_create_offer, err)) {
return (Error)err;
}
WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_create_offer is unimplemented!");
return ERR_UNCONFIGURED;
}
Error WebRTCPeerConnectionExtension::set_local_description(String p_type, String p_sdp) {
int err;
if (GDVIRTUAL_CALL(_set_local_description, p_type, p_sdp, err)) {
return (Error)err;
}
WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_set_local_description is unimplemented!");
return ERR_UNCONFIGURED;
}
Error WebRTCPeerConnectionExtension::set_remote_description(String p_type, String p_sdp) {
int err;
if (GDVIRTUAL_CALL(_set_remote_description, p_type, p_sdp, err)) {
return (Error)err;
}
WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_set_remote_description is unimplemented!");
return ERR_UNCONFIGURED;
}
Error WebRTCPeerConnectionExtension::add_ice_candidate(String p_sdp_mid_name, int p_sdp_mline_index, String p_sdp_name) {
int err;
if (GDVIRTUAL_CALL(_add_ice_candidate, p_sdp_mid_name, p_sdp_mline_index, p_sdp_name, err)) {
return (Error)err;
}
WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_add_ice_candidate is unimplemented!");
return ERR_UNCONFIGURED;
}
Error WebRTCPeerConnectionExtension::poll() {
int err;
if (GDVIRTUAL_CALL(_poll, err)) {
return (Error)err;
}
WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_poll is unimplemented!");
return ERR_UNCONFIGURED;
}
void WebRTCPeerConnectionExtension::close() {
if (GDVIRTUAL_CALL(_close)) {
return;
}
WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_close is unimplemented!");
}

View File

@@ -33,6 +33,7 @@
#include "webrtc_peer_connection.h"
#include "core/extension/ext_wrappers.gen.inc"
#include "core/object/gdvirtual.gen.inc"
#include "core/object/script_language.h"
#include "core/variant/native_ptr.h"
@@ -44,27 +45,21 @@ protected:
static void _bind_methods();
public:
virtual ConnectionState get_connection_state() const override;
virtual Error initialize(Dictionary p_config = Dictionary()) override;
// FIXME Can't be directly exposed due to issues in exchanging Ref(s) between godot and extensions.
// See godot-cpp GH-652 .
virtual Ref<WebRTCDataChannel> create_data_channel(String p_label, Dictionary p_options = Dictionary()) override;
virtual Error create_offer() override;
virtual Error set_remote_description(String type, String sdp) override;
virtual Error set_local_description(String type, String sdp) override;
virtual Error add_ice_candidate(String p_sdp_mid_name, int p_sdp_mline_index, String p_sdp_name) override;
virtual Error poll() override;
virtual void close() override;
GDVIRTUAL2R(Object *, _create_data_channel, String, Dictionary);
// EXBIND2R(Ref<WebRTCDataChannel>, create_data_channel, String, Dictionary);
/** GDExtension **/
GDVIRTUAL0RC(int, _get_connection_state);
GDVIRTUAL1R(int, _initialize, Dictionary);
GDVIRTUAL2R(Object *, _create_data_channel, String, Dictionary);
GDVIRTUAL0R(int, _create_offer);
GDVIRTUAL2R(int, _set_remote_description, String, String);
GDVIRTUAL2R(int, _set_local_description, String, String);
GDVIRTUAL3R(int, _add_ice_candidate, String, int, String);
GDVIRTUAL0R(int, _poll);
GDVIRTUAL0(_close);
EXBIND0RC(ConnectionState, get_connection_state);
EXBIND1R(Error, initialize, Dictionary);
EXBIND0R(Error, create_offer);
EXBIND2R(Error, set_remote_description, String, String);
EXBIND2R(Error, set_local_description, String, String);
EXBIND3R(Error, add_ice_candidate, String, int, String);
EXBIND0R(Error, poll);
EXBIND0(close);
WebRTCPeerConnectionExtension() {}
};