sfml3-rb 0.0.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (191) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +342 -0
  3. data/README.md +51 -14
  4. data/TODO.md +199 -0
  5. data/ext/audio/audio_enums.c +131 -0
  6. data/ext/audio/audio_enums.h +18 -0
  7. data/ext/audio/effect_processor.c +233 -0
  8. data/ext/audio/effect_processor.h +25 -0
  9. data/ext/audio/listener.c +83 -0
  10. data/ext/audio/listener.h +8 -0
  11. data/ext/audio/music.c +174 -0
  12. data/ext/audio/music.h +14 -0
  13. data/ext/audio/sound.c +139 -0
  14. data/ext/audio/sound.h +14 -0
  15. data/ext/audio/sound_buffer.c +274 -0
  16. data/ext/audio/sound_buffer.h +18 -0
  17. data/ext/audio/sound_buffer_recorder.c +109 -0
  18. data/ext/audio/sound_buffer_recorder.h +14 -0
  19. data/ext/audio/sound_recorder.c +268 -0
  20. data/ext/audio/sound_recorder.h +14 -0
  21. data/ext/audio/sound_source.h +13 -0
  22. data/ext/audio/sound_source.inc +271 -0
  23. data/ext/audio/sound_source_cone.c +138 -0
  24. data/ext/audio/sound_source_cone.h +20 -0
  25. data/ext/audio/sound_stream.c +294 -0
  26. data/ext/audio/sound_stream.h +14 -0
  27. data/ext/{exceptions.c → core/exceptions.c} +10 -8
  28. data/ext/{ext → core}/exceptions.h +3 -3
  29. data/ext/core/foreign_thread.c +149 -0
  30. data/ext/core/foreign_thread.h +31 -0
  31. data/ext/core/macros.h +8 -0
  32. data/ext/{ext → core}/sfml.h +5 -3
  33. data/ext/core/unicode.c +46 -0
  34. data/ext/core/unicode.h +25 -0
  35. data/ext/ext.c +125 -14
  36. data/ext/extconf.rb +51 -6
  37. data/ext/graphics/blend_mode.c +261 -0
  38. data/ext/graphics/blend_mode.h +18 -0
  39. data/ext/graphics/circle.c +319 -0
  40. data/ext/{ext/klass/drawable → graphics}/circle.h +3 -3
  41. data/ext/graphics/color.c +318 -0
  42. data/ext/graphics/color.h +37 -0
  43. data/ext/{drawable.c → graphics/drawable.c} +11 -11
  44. data/ext/graphics/drawable.h +10 -0
  45. data/ext/graphics/enums.c +123 -0
  46. data/ext/graphics/enums.h +20 -0
  47. data/ext/graphics/font.c +148 -0
  48. data/ext/graphics/font.h +14 -0
  49. data/ext/graphics/glyph.c +60 -0
  50. data/ext/graphics/glyph.h +14 -0
  51. data/ext/graphics/image.c +205 -0
  52. data/ext/graphics/image.h +16 -0
  53. data/ext/graphics/polygon.c +300 -0
  54. data/ext/graphics/polygon.h +10 -0
  55. data/ext/graphics/rect.c +287 -0
  56. data/ext/graphics/rect.h +30 -0
  57. data/ext/graphics/rectangle.c +302 -0
  58. data/ext/graphics/rectangle.h +10 -0
  59. data/ext/graphics/render_state.c +204 -0
  60. data/ext/graphics/render_state.h +18 -0
  61. data/ext/graphics/render_target.inc +181 -0
  62. data/ext/graphics/render_texture.c +182 -0
  63. data/ext/graphics/render_texture.h +14 -0
  64. data/ext/graphics/shader.c +540 -0
  65. data/ext/graphics/shader.h +14 -0
  66. data/ext/graphics/shape.c +311 -0
  67. data/ext/graphics/shape.h +10 -0
  68. data/ext/graphics/sprite.c +249 -0
  69. data/ext/graphics/sprite.h +10 -0
  70. data/ext/graphics/stencil_mode.c +211 -0
  71. data/ext/graphics/stencil_mode.h +18 -0
  72. data/ext/graphics/target.c +133 -0
  73. data/ext/graphics/target.h +40 -0
  74. data/ext/graphics/text.c +344 -0
  75. data/ext/graphics/text.h +10 -0
  76. data/ext/graphics/texture.c +379 -0
  77. data/ext/graphics/texture.h +16 -0
  78. data/ext/graphics/transform.c +372 -0
  79. data/ext/graphics/transform.h +35 -0
  80. data/ext/{transformable.c → graphics/transformable.c} +168 -144
  81. data/ext/{ext/klass → graphics}/transformable.h +3 -3
  82. data/ext/graphics/vertex.c +179 -0
  83. data/ext/graphics/vertex.h +23 -0
  84. data/ext/graphics/vertex_array.c +127 -0
  85. data/ext/graphics/vertex_array.h +10 -0
  86. data/ext/graphics/vertex_buffer.c +211 -0
  87. data/ext/graphics/vertex_buffer.h +14 -0
  88. data/ext/{view.c → graphics/view.c} +168 -169
  89. data/ext/{ext/klass → graphics}/view.h +3 -3
  90. data/ext/network/ftp.c +405 -0
  91. data/ext/network/ftp.h +20 -0
  92. data/ext/network/http.c +243 -0
  93. data/ext/network/http.h +18 -0
  94. data/ext/network/ip_address.c +164 -0
  95. data/ext/network/ip_address.h +20 -0
  96. data/ext/network/network_enums.c +298 -0
  97. data/ext/network/network_enums.h +26 -0
  98. data/ext/network/packet.c +189 -0
  99. data/ext/network/packet.h +14 -0
  100. data/ext/network/socket_selector.c +142 -0
  101. data/ext/network/socket_selector.h +14 -0
  102. data/ext/network/tcp_listener.c +115 -0
  103. data/ext/network/tcp_listener.h +14 -0
  104. data/ext/network/tcp_socket.c +199 -0
  105. data/ext/network/tcp_socket.h +17 -0
  106. data/ext/network/udp_socket.c +190 -0
  107. data/ext/network/udp_socket.h +14 -0
  108. data/ext/ports.rb +97 -21
  109. data/ext/system/buffer.c +77 -0
  110. data/ext/system/buffer.h +14 -0
  111. data/ext/system/clock.c +100 -0
  112. data/ext/{ext/klass → system}/clock.h +3 -3
  113. data/ext/system/input_stream.c +229 -0
  114. data/ext/system/input_stream.h +23 -0
  115. data/ext/system/sleep.c +16 -0
  116. data/ext/system/sleep.h +8 -0
  117. data/ext/system/time.c +218 -0
  118. data/ext/system/time.h +18 -0
  119. data/ext/system/vec2.c +251 -0
  120. data/ext/system/vec2.h +55 -0
  121. data/ext/system/vec3.c +219 -0
  122. data/ext/system/vec3.h +18 -0
  123. data/ext/window/clipboard.c +89 -0
  124. data/ext/window/clipboard.h +8 -0
  125. data/ext/window/context.c +70 -0
  126. data/ext/window/context.h +8 -0
  127. data/ext/window/context_settings.c +220 -0
  128. data/ext/window/context_settings.h +18 -0
  129. data/ext/window/cursor.c +56 -0
  130. data/ext/window/cursor.h +14 -0
  131. data/ext/window/event.c +216 -0
  132. data/ext/window/event.h +14 -0
  133. data/ext/{event_name.c → window/event_name.c} +2 -2
  134. data/ext/window/event_name.h +8 -0
  135. data/ext/window/input_enums.c +261 -0
  136. data/ext/window/input_enums.h +36 -0
  137. data/ext/window/joystick.c +60 -0
  138. data/ext/window/joystick.h +8 -0
  139. data/ext/{keyboard.c → window/keyboard.c} +74 -2
  140. data/ext/window/keyboard.h +12 -0
  141. data/ext/window/mouse.c +70 -0
  142. data/ext/window/mouse.h +8 -0
  143. data/ext/window/sensor.c +30 -0
  144. data/ext/window/sensor.h +8 -0
  145. data/ext/window/touch.c +49 -0
  146. data/ext/window/touch.h +8 -0
  147. data/ext/window/video_mode.c +133 -0
  148. data/ext/window/video_mode.h +14 -0
  149. data/ext/window/vulkan.c +44 -0
  150. data/ext/window/vulkan.h +8 -0
  151. data/ext/window/window.c +414 -0
  152. data/ext/{ext/klass → window}/window.h +3 -3
  153. data/lib/sfml/version.rb +4 -2
  154. data/lib/sfml.rb +2 -0
  155. metadata +163 -56
  156. data/ext/circle.c +0 -198
  157. data/ext/clock.c +0 -65
  158. data/ext/color.c +0 -43
  159. data/ext/event.c +0 -148
  160. data/ext/ext/klass/color.h +0 -26
  161. data/ext/ext/klass/drawable/image.h +0 -4
  162. data/ext/ext/klass/drawable/polygon.h +0 -4
  163. data/ext/ext/klass/drawable/rectangle.h +0 -4
  164. data/ext/ext/klass/drawable/sprite.h +0 -4
  165. data/ext/ext/klass/drawable/texture.h +0 -4
  166. data/ext/ext/klass/event/event_name.h +0 -8
  167. data/ext/ext/klass/event.h +0 -12
  168. data/ext/ext/klass/keyboard.h +0 -8
  169. data/ext/ext/klass/render_state.h +0 -16
  170. data/ext/ext/klass/target.h +0 -18
  171. data/ext/ext/klass/transform.h +0 -17
  172. data/ext/ext/klass/video_mode.h +0 -12
  173. data/ext/ext/module/drawable/drawable.h +0 -10
  174. data/ext/ext/module/transform.h +0 -18
  175. data/ext/ext/module.h +0 -10
  176. data/ext/ext/rect.h +0 -16
  177. data/ext/ext/style_name.h +0 -11
  178. data/ext/ext/vec2.h +0 -38
  179. data/ext/image.c +0 -5
  180. data/ext/polygon.c +0 -5
  181. data/ext/rect.c +0 -26
  182. data/ext/rectangle.c +0 -5
  183. data/ext/render_state.c +0 -109
  184. data/ext/sprite.c +0 -5
  185. data/ext/style_name.c +0 -15
  186. data/ext/target.c +0 -106
  187. data/ext/texture.c +0 -5
  188. data/ext/transform.c +0 -107
  189. data/ext/vec2.c +0 -42
  190. data/ext/video_mode.c +0 -78
  191. data/ext/window.c +0 -274
@@ -0,0 +1,164 @@
1
+ #include "network/ip_address.h"
2
+
3
+ #include <ruby.h>
4
+ #include <stdlib.h>
5
+
6
+ #include "core/exceptions.h"
7
+ #include "core/macros.h"
8
+ #include "system/time.h"
9
+
10
+ typedef struct {
11
+ sfIpAddress address;
12
+ } IpAddress;
13
+
14
+ static VALUE rb_cIpAddress;
15
+
16
+ static void IpAddress_free(void *ptr) {
17
+ free(ptr);
18
+ }
19
+
20
+ static const rb_data_type_t IpAddress_data_type = {
21
+ .wrap_struct_name = "SFML::IpAddress",
22
+ .function = {.dmark = NULL, .dfree = IpAddress_free, .dsize = NULL},
23
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY
24
+ };
25
+
26
+ VALUE ip_address_to_rb(sfIpAddress address) {
27
+ IpAddress *ptr = malloc(sizeof(IpAddress));
28
+
29
+ ptr->address = address;
30
+
31
+ return TypedData_Wrap_Struct(rb_cIpAddress, &IpAddress_data_type, ptr);
32
+ }
33
+
34
+ static VALUE IpAddress_from_string(VALUE klass, VALUE rb_address) {
35
+ return ip_address_to_rb(sfIpAddress_fromString(StringValueCStr(rb_address)));
36
+ }
37
+
38
+ static VALUE IpAddress_from_bytes(VALUE klass, VALUE rb0, VALUE rb1, VALUE rb2, VALUE rb3) {
39
+ return ip_address_to_rb(sfIpAddress_fromBytes((uint8_t) NUM2INT(rb0), (uint8_t) NUM2INT(rb1),
40
+ (uint8_t) NUM2INT(rb2), (uint8_t) NUM2INT(rb3)));
41
+ }
42
+
43
+ static VALUE IpAddress_from_integer(VALUE klass, VALUE rb_integer) {
44
+ return ip_address_to_rb(sfIpAddress_fromInteger((uint32_t) NUM2UINT(rb_integer)));
45
+ }
46
+
47
+ static VALUE IpAddress_new(VALUE klass, VALUE rb_address) {
48
+ if (RB_INTEGER_TYPE_P(rb_address)) {
49
+ return IpAddress_from_integer(klass, rb_address);
50
+ }
51
+
52
+ if (RB_TYPE_P(rb_address, T_STRING)) {
53
+ return IpAddress_from_string(klass, rb_address);
54
+ }
55
+
56
+ if (rb_obj_is_kind_of(rb_address, rb_cIpAddress)) {
57
+ return ip_address_to_rb(((IpAddress *) Get_IpAddress_Struct(rb_address))->address);
58
+ }
59
+
60
+ raise_invalid_argument_class(rb_cIpAddress);
61
+
62
+ return Qnil;
63
+ }
64
+
65
+ static VALUE IpAddress_local_address(VALUE klass) {
66
+ return ip_address_to_rb(sfIpAddress_getLocalAddress());
67
+ }
68
+
69
+ static VALUE IpAddress_public_address(int argc, VALUE *argv, VALUE klass) {
70
+ VALUE rb_timeout;
71
+ sfTime timeout = sfTime_Zero;
72
+
73
+ rb_scan_args(argc, argv, "01", &rb_timeout);
74
+
75
+ if (!NIL_P(rb_timeout)) {
76
+ timeout = time_from_rb(rb_timeout);
77
+ }
78
+
79
+ return ip_address_to_rb(sfIpAddress_getPublicAddress(timeout));
80
+ }
81
+
82
+ static VALUE IpAddress_to_s(VALUE self) {
83
+ char buffer[16];
84
+
85
+ sfIpAddress_toString(((IpAddress *) Get_IpAddress_Struct(self))->address, buffer);
86
+
87
+ return rb_str_new_cstr(buffer);
88
+ }
89
+
90
+ static VALUE IpAddress_to_integer(VALUE self) {
91
+ return UINT2NUM(sfIpAddress_toInteger(((IpAddress *) Get_IpAddress_Struct(self))->address));
92
+ }
93
+
94
+ static VALUE IpAddress_eql(VALUE self, VALUE rb_other) {
95
+ sfIpAddress a = ((IpAddress *) Get_IpAddress_Struct(self))->address;
96
+ sfIpAddress b;
97
+
98
+ if (!rb_obj_is_kind_of(rb_other, rb_cIpAddress)) {
99
+ return Qfalse;
100
+ }
101
+
102
+ b = ((IpAddress *) Get_IpAddress_Struct(rb_other))->address;
103
+
104
+ return BOOL2RB(sfIpAddress_toInteger(a) == sfIpAddress_toInteger(b));
105
+ }
106
+
107
+ static VALUE IpAddress_hash(VALUE self) {
108
+ return UINT2NUM(sfIpAddress_toInteger(((IpAddress *) Get_IpAddress_Struct(self))->address));
109
+ }
110
+
111
+ void Init_IpAddress(VALUE rb_module) {
112
+ rb_cIpAddress = rb_define_class_under(rb_module, "IpAddress", rb_cObject);
113
+
114
+ rb_define_singleton_method(rb_cIpAddress, "new", IpAddress_new, 1);
115
+ rb_define_singleton_method(rb_cIpAddress, "from_string", IpAddress_from_string, 1);
116
+ rb_define_singleton_method(rb_cIpAddress, "from_bytes", IpAddress_from_bytes, 4);
117
+ rb_define_singleton_method(rb_cIpAddress, "from_integer", IpAddress_from_integer, 1);
118
+ rb_define_singleton_method(rb_cIpAddress, "local_address", IpAddress_local_address, 0);
119
+ rb_define_singleton_method(rb_cIpAddress, "public_address", IpAddress_public_address, -1);
120
+
121
+ rb_define_method(rb_cIpAddress, "to_s", IpAddress_to_s, 0);
122
+ rb_define_method(rb_cIpAddress, "to_str", IpAddress_to_s, 0);
123
+ rb_define_method(rb_cIpAddress, "to_integer", IpAddress_to_integer, 0);
124
+ rb_define_method(rb_cIpAddress, "hash", IpAddress_hash, 0);
125
+ rb_define_method(rb_cIpAddress, "==", IpAddress_eql, 1);
126
+ rb_define_method(rb_cIpAddress, "eql?", IpAddress_eql, 1);
127
+
128
+ rb_define_const(rb_cIpAddress, "NONE", ip_address_to_rb(sfIpAddress_None));
129
+ rb_define_const(rb_cIpAddress, "ANY", ip_address_to_rb(sfIpAddress_Any));
130
+ rb_define_const(rb_cIpAddress, "LOCAL_HOST", ip_address_to_rb(sfIpAddress_LocalHost));
131
+ rb_define_const(rb_cIpAddress, "BROADCAST", ip_address_to_rb(sfIpAddress_Broadcast));
132
+ }
133
+
134
+ VALUE Get_Klass_IpAddress(void) {
135
+ return rb_cIpAddress;
136
+ }
137
+
138
+ void *Get_IpAddress_Struct(VALUE self) {
139
+ IpAddress *ptr;
140
+ TypedData_Get_Struct(self, IpAddress, &IpAddress_data_type, ptr);
141
+ return ptr;
142
+ }
143
+
144
+ sfIpAddress ip_address_from_rb(VALUE rb_address, sfIpAddress fallback) {
145
+ if (NIL_P(rb_address)) {
146
+ return fallback;
147
+ }
148
+
149
+ if (rb_obj_is_kind_of(rb_address, rb_cIpAddress)) {
150
+ return ((IpAddress *) Get_IpAddress_Struct(rb_address))->address;
151
+ }
152
+
153
+ if (RB_TYPE_P(rb_address, T_STRING)) {
154
+ return sfIpAddress_fromString(StringValueCStr(rb_address));
155
+ }
156
+
157
+ if (RB_INTEGER_TYPE_P(rb_address)) {
158
+ return sfIpAddress_fromInteger((uint32_t) NUM2UINT(rb_address));
159
+ }
160
+
161
+ raise_invalid_argument_class(rb_cIpAddress);
162
+
163
+ return fallback;
164
+ }
@@ -0,0 +1,20 @@
1
+ #ifndef SFML_RB_NETWORK_IP_ADDRESS_H
2
+ #define SFML_RB_NETWORK_IP_ADDRESS_H
3
+
4
+ #include <ruby.h>
5
+
6
+ #include "core/sfml.h"
7
+
8
+ void Init_IpAddress(VALUE rb_module);
9
+
10
+ VALUE Get_Klass_IpAddress(void);
11
+
12
+ void *Get_IpAddress_Struct(VALUE self);
13
+
14
+ VALUE ip_address_to_rb(sfIpAddress address);
15
+
16
+ /* Accepts an SFML::IpAddress, a dotted-quad String, or nil (which yields
17
+ `fallback`, so callers can implement optional address arguments). */
18
+ sfIpAddress ip_address_from_rb(VALUE rb_address, sfIpAddress fallback);
19
+
20
+ #endif //SFML_RB_NETWORK_IP_ADDRESS_H
@@ -0,0 +1,298 @@
1
+ #include "network/network_enums.h"
2
+
3
+ #include <ruby.h>
4
+ #include <string.h>
5
+
6
+ static const char *socket_status_names[] = {"done", "not_ready", "partial", "disconnected", "error"};
7
+ static const char *http_method_names[] = {"get", "post", "head", "put", "delete"};
8
+ static const char *ftp_transfer_mode_names[] = {"binary", "ascii", "ebcdic"};
9
+
10
+ typedef struct {
11
+ int value;
12
+ const char *name;
13
+ } EnumName;
14
+
15
+ /* The HTTP and FTP status enums are sparse and mostly meaningful by number,
16
+ so they are stored as value/name pairs and looked up linearly. */
17
+ static const EnumName http_status_names[] = {
18
+ {sfHttpOk, "ok"},
19
+ {sfHttpCreated, "created"},
20
+ {sfHttpAccepted, "accepted"},
21
+ {sfHttpNoContent, "no_content"},
22
+ {sfHttpResetContent, "reset_content"},
23
+ {sfHttpPartialContent, "partial_content"},
24
+ {sfHttpMultipleChoices, "multiple_choices"},
25
+ {sfHttpMovedPermanently, "moved_permanently"},
26
+ {sfHttpMovedTemporarily, "moved_temporarily"},
27
+ {sfHttpNotModified, "not_modified"},
28
+ {sfHttpBadRequest, "bad_request"},
29
+ {sfHttpUnauthorized, "unauthorized"},
30
+ {sfHttpForbidden, "forbidden"},
31
+ {sfHttpNotFound, "not_found"},
32
+ {sfHttpRangeNotSatisfiable, "range_not_satisfiable"},
33
+ {sfHttpInternalServerError, "internal_server_error"},
34
+ {sfHttpNotImplemented, "not_implemented"},
35
+ {sfHttpBadGateway, "bad_gateway"},
36
+ {sfHttpServiceNotAvailable, "service_not_available"},
37
+ {sfHttpGatewayTimeout, "gateway_timeout"},
38
+ {sfHttpVersionNotSupported, "version_not_supported"},
39
+ {sfHttpInvalidResponse, "invalid_response"},
40
+ {sfHttpConnectionFailed, "connection_failed"}
41
+ };
42
+
43
+ static const EnumName ftp_status_names[] = {
44
+ {sfFtpRestartMarkerReply, "restart_marker_reply"},
45
+ {sfFtpServiceReadySoon, "service_ready_soon"},
46
+ {sfFtpDataConnectionAlreadyOpened, "data_connection_already_opened"},
47
+ {sfFtpOpeningDataConnection, "opening_data_connection"},
48
+ {sfFtpOk, "ok"},
49
+ {sfFtpPointlessCommand, "pointless_command"},
50
+ {sfFtpSystemStatus, "system_status"},
51
+ {sfFtpDirectoryStatus, "directory_status"},
52
+ {sfFtpFileStatus, "file_status"},
53
+ {sfFtpHelpMessage, "help_message"},
54
+ {sfFtpSystemType, "system_type"},
55
+ {sfFtpServiceReady, "service_ready"},
56
+ {sfFtpClosingConnection, "closing_connection"},
57
+ {sfFtpDataConnectionOpened, "data_connection_opened"},
58
+ {sfFtpClosingDataConnection, "closing_data_connection"},
59
+ {sfFtpEnteringPassiveMode, "entering_passive_mode"},
60
+ {sfFtpLoggedIn, "logged_in"},
61
+ {sfFtpFileActionOk, "file_action_ok"},
62
+ {sfFtpDirectoryOk, "directory_ok"},
63
+ {sfFtpNeedPassword, "need_password"},
64
+ {sfFtpNeedAccountToLogIn, "need_account_to_log_in"},
65
+ {sfFtpNeedInformation, "need_information"},
66
+ {sfFtpServiceUnavailable, "service_unavailable"},
67
+ {sfFtpDataConnectionUnavailable, "data_connection_unavailable"},
68
+ {sfFtpTransferAborted, "transfer_aborted"},
69
+ {sfFtpFileActionAborted, "file_action_aborted"},
70
+ {sfFtpLocalError, "local_error"},
71
+ {sfFtpInsufficientStorageSpace, "insufficient_storage_space"},
72
+ {sfFtpCommandUnknown, "command_unknown"},
73
+ {sfFtpParametersUnknown, "parameters_unknown"},
74
+ {sfFtpCommandNotImplemented, "command_not_implemented"},
75
+ {sfFtpBadCommandSequence, "bad_command_sequence"},
76
+ {sfFtpParameterNotImplemented, "parameter_not_implemented"},
77
+ {sfFtpNotLoggedIn, "not_logged_in"},
78
+ {sfFtpNeedAccountToStore, "need_account_to_store"},
79
+ {sfFtpFileUnavailable, "file_unavailable"},
80
+ {sfFtpPageTypeUnknown, "page_type_unknown"},
81
+ {sfFtpNotEnoughMemory, "not_enough_memory"},
82
+ {sfFtpFilenameNotAllowed, "filename_not_allowed"},
83
+ {sfFtpInvalidResponse, "invalid_response"},
84
+ {sfFtpConnectionFailed, "connection_failed"},
85
+ {sfFtpConnectionClosed, "connection_closed"},
86
+ {sfFtpInvalidFile, "invalid_file"}
87
+ };
88
+
89
+ static int symbol_index(VALUE rb_symbol, const char *const *names, size_t count) {
90
+ const char *name;
91
+ size_t i;
92
+
93
+ if (!SYMBOL_P(rb_symbol)) {
94
+ return -1;
95
+ }
96
+
97
+ name = rb_id2name(SYM2ID(rb_symbol));
98
+
99
+ for (i = 0; i < count; i++) {
100
+ if (strcmp(name, names[i]) == 0) {
101
+ return (int) i;
102
+ }
103
+ }
104
+
105
+ return -1;
106
+ }
107
+
108
+ const char *socket_status_name(sfSocketStatus status) {
109
+ if (status >= sfSocketDone && status <= sfSocketError) {
110
+ return socket_status_names[status];
111
+ }
112
+
113
+ return "error";
114
+ }
115
+
116
+ sfSocketStatus socket_status_from_rb(VALUE rb_status) {
117
+ int index;
118
+
119
+ if (RB_INTEGER_TYPE_P(rb_status)) {
120
+ return (sfSocketStatus) NUM2INT(rb_status);
121
+ }
122
+
123
+ index = symbol_index(rb_status, socket_status_names, 5);
124
+
125
+ if (index < 0) {
126
+ rb_raise(rb_eArgError, "unknown socket status");
127
+ }
128
+
129
+ return (sfSocketStatus) index;
130
+ }
131
+
132
+ const char *http_method_name(sfHttpMethod method) {
133
+ if (method >= sfHttpGet && method <= sfHttpDelete) {
134
+ return http_method_names[method];
135
+ }
136
+
137
+ return "get";
138
+ }
139
+
140
+ sfHttpMethod http_method_from_rb(VALUE rb_method) {
141
+ int index;
142
+
143
+ if (RB_INTEGER_TYPE_P(rb_method)) {
144
+ return (sfHttpMethod) NUM2INT(rb_method);
145
+ }
146
+
147
+ index = symbol_index(rb_method, http_method_names, 5);
148
+
149
+ if (index < 0) {
150
+ rb_raise(rb_eArgError, "unknown HTTP method");
151
+ }
152
+
153
+ return (sfHttpMethod) index;
154
+ }
155
+
156
+ static const char *lookup_name(const EnumName *table, size_t count, int value) {
157
+ size_t i;
158
+
159
+ for (i = 0; i < count; i++) {
160
+ if (table[i].value == value) {
161
+ return table[i].name;
162
+ }
163
+ }
164
+
165
+ return NULL;
166
+ }
167
+
168
+ const char *http_status_name(sfHttpStatus status) {
169
+ const char *name = lookup_name(http_status_names,
170
+ sizeof(http_status_names) / sizeof(http_status_names[0]), status);
171
+
172
+ return name != NULL ? name : "unknown";
173
+ }
174
+
175
+ const char *ftp_transfer_mode_name(sfFtpTransferMode mode) {
176
+ if (mode >= sfFtpBinary && mode <= sfFtpEbcdic) {
177
+ return ftp_transfer_mode_names[mode];
178
+ }
179
+
180
+ return "binary";
181
+ }
182
+
183
+ sfFtpTransferMode ftp_transfer_mode_from_rb(VALUE rb_mode) {
184
+ int index;
185
+
186
+ if (RB_INTEGER_TYPE_P(rb_mode)) {
187
+ return (sfFtpTransferMode) NUM2INT(rb_mode);
188
+ }
189
+
190
+ index = symbol_index(rb_mode, ftp_transfer_mode_names, 3);
191
+
192
+ if (index < 0) {
193
+ rb_raise(rb_eArgError, "unknown FTP transfer mode");
194
+ }
195
+
196
+ return (sfFtpTransferMode) index;
197
+ }
198
+
199
+ const char *ftp_status_name(sfFtpStatus status) {
200
+ const char *name = lookup_name(ftp_status_names,
201
+ sizeof(ftp_status_names) / sizeof(ftp_status_names[0]), status);
202
+
203
+ return name != NULL ? name : "unknown";
204
+ }
205
+
206
+ #define DEFINE_CONST(module, name, value) rb_define_const(module, name, INT2NUM(value))
207
+
208
+ void Init_NetworkEnums(VALUE rb_module) {
209
+ VALUE rb_mSocketStatus = rb_define_module_under(rb_module, "SocketStatus");
210
+ VALUE rb_mHttpMethod = rb_define_module_under(rb_module, "HttpMethod");
211
+ VALUE rb_mHttpStatus = rb_define_module_under(rb_module, "HttpStatus");
212
+ VALUE rb_mFtpTransferMode = rb_define_module_under(rb_module, "FtpTransferMode");
213
+ VALUE rb_mFtpStatus = rb_define_module_under(rb_module, "FtpStatus");
214
+
215
+ DEFINE_CONST(rb_mSocketStatus, "DONE", sfSocketDone);
216
+ DEFINE_CONST(rb_mSocketStatus, "NOT_READY", sfSocketNotReady);
217
+ DEFINE_CONST(rb_mSocketStatus, "PARTIAL", sfSocketPartial);
218
+ DEFINE_CONST(rb_mSocketStatus, "DISCONNECTED", sfSocketDisconnected);
219
+ DEFINE_CONST(rb_mSocketStatus, "ERROR", sfSocketError);
220
+
221
+ DEFINE_CONST(rb_mHttpMethod, "GET", sfHttpGet);
222
+ DEFINE_CONST(rb_mHttpMethod, "POST", sfHttpPost);
223
+ DEFINE_CONST(rb_mHttpMethod, "HEAD", sfHttpHead);
224
+ DEFINE_CONST(rb_mHttpMethod, "PUT", sfHttpPut);
225
+ DEFINE_CONST(rb_mHttpMethod, "DELETE", sfHttpDelete);
226
+
227
+ DEFINE_CONST(rb_mHttpStatus, "OK", sfHttpOk);
228
+ DEFINE_CONST(rb_mHttpStatus, "CREATED", sfHttpCreated);
229
+ DEFINE_CONST(rb_mHttpStatus, "ACCEPTED", sfHttpAccepted);
230
+ DEFINE_CONST(rb_mHttpStatus, "NO_CONTENT", sfHttpNoContent);
231
+ DEFINE_CONST(rb_mHttpStatus, "RESET_CONTENT", sfHttpResetContent);
232
+ DEFINE_CONST(rb_mHttpStatus, "PARTIAL_CONTENT", sfHttpPartialContent);
233
+ DEFINE_CONST(rb_mHttpStatus, "MULTIPLE_CHOICES", sfHttpMultipleChoices);
234
+ DEFINE_CONST(rb_mHttpStatus, "MOVED_PERMANENTLY", sfHttpMovedPermanently);
235
+ DEFINE_CONST(rb_mHttpStatus, "MOVED_TEMPORARILY", sfHttpMovedTemporarily);
236
+ DEFINE_CONST(rb_mHttpStatus, "NOT_MODIFIED", sfHttpNotModified);
237
+ DEFINE_CONST(rb_mHttpStatus, "BAD_REQUEST", sfHttpBadRequest);
238
+ DEFINE_CONST(rb_mHttpStatus, "UNAUTHORIZED", sfHttpUnauthorized);
239
+ DEFINE_CONST(rb_mHttpStatus, "FORBIDDEN", sfHttpForbidden);
240
+ DEFINE_CONST(rb_mHttpStatus, "NOT_FOUND", sfHttpNotFound);
241
+ DEFINE_CONST(rb_mHttpStatus, "RANGE_NOT_SATISFIABLE", sfHttpRangeNotSatisfiable);
242
+ DEFINE_CONST(rb_mHttpStatus, "INTERNAL_SERVER_ERROR", sfHttpInternalServerError);
243
+ DEFINE_CONST(rb_mHttpStatus, "NOT_IMPLEMENTED", sfHttpNotImplemented);
244
+ DEFINE_CONST(rb_mHttpStatus, "BAD_GATEWAY", sfHttpBadGateway);
245
+ DEFINE_CONST(rb_mHttpStatus, "SERVICE_NOT_AVAILABLE", sfHttpServiceNotAvailable);
246
+ DEFINE_CONST(rb_mHttpStatus, "GATEWAY_TIMEOUT", sfHttpGatewayTimeout);
247
+ DEFINE_CONST(rb_mHttpStatus, "VERSION_NOT_SUPPORTED", sfHttpVersionNotSupported);
248
+ DEFINE_CONST(rb_mHttpStatus, "INVALID_RESPONSE", sfHttpInvalidResponse);
249
+ DEFINE_CONST(rb_mHttpStatus, "CONNECTION_FAILED", sfHttpConnectionFailed);
250
+
251
+ DEFINE_CONST(rb_mFtpTransferMode, "BINARY", sfFtpBinary);
252
+ DEFINE_CONST(rb_mFtpTransferMode, "ASCII", sfFtpAscii);
253
+ DEFINE_CONST(rb_mFtpTransferMode, "EBCDIC", sfFtpEbcdic);
254
+
255
+ DEFINE_CONST(rb_mFtpStatus, "RESTART_MARKER_REPLY", sfFtpRestartMarkerReply);
256
+ DEFINE_CONST(rb_mFtpStatus, "SERVICE_READY_SOON", sfFtpServiceReadySoon);
257
+ DEFINE_CONST(rb_mFtpStatus, "DATA_CONNECTION_ALREADY_OPENED", sfFtpDataConnectionAlreadyOpened);
258
+ DEFINE_CONST(rb_mFtpStatus, "OPENING_DATA_CONNECTION", sfFtpOpeningDataConnection);
259
+ DEFINE_CONST(rb_mFtpStatus, "OK", sfFtpOk);
260
+ DEFINE_CONST(rb_mFtpStatus, "POINTLESS_COMMAND", sfFtpPointlessCommand);
261
+ DEFINE_CONST(rb_mFtpStatus, "SYSTEM_STATUS", sfFtpSystemStatus);
262
+ DEFINE_CONST(rb_mFtpStatus, "DIRECTORY_STATUS", sfFtpDirectoryStatus);
263
+ DEFINE_CONST(rb_mFtpStatus, "FILE_STATUS", sfFtpFileStatus);
264
+ DEFINE_CONST(rb_mFtpStatus, "HELP_MESSAGE", sfFtpHelpMessage);
265
+ DEFINE_CONST(rb_mFtpStatus, "SYSTEM_TYPE", sfFtpSystemType);
266
+ DEFINE_CONST(rb_mFtpStatus, "SERVICE_READY", sfFtpServiceReady);
267
+ DEFINE_CONST(rb_mFtpStatus, "CLOSING_CONNECTION", sfFtpClosingConnection);
268
+ DEFINE_CONST(rb_mFtpStatus, "DATA_CONNECTION_OPENED", sfFtpDataConnectionOpened);
269
+ DEFINE_CONST(rb_mFtpStatus, "CLOSING_DATA_CONNECTION", sfFtpClosingDataConnection);
270
+ DEFINE_CONST(rb_mFtpStatus, "ENTERING_PASSIVE_MODE", sfFtpEnteringPassiveMode);
271
+ DEFINE_CONST(rb_mFtpStatus, "LOGGED_IN", sfFtpLoggedIn);
272
+ DEFINE_CONST(rb_mFtpStatus, "FILE_ACTION_OK", sfFtpFileActionOk);
273
+ DEFINE_CONST(rb_mFtpStatus, "DIRECTORY_OK", sfFtpDirectoryOk);
274
+ DEFINE_CONST(rb_mFtpStatus, "NEED_PASSWORD", sfFtpNeedPassword);
275
+ DEFINE_CONST(rb_mFtpStatus, "NEED_ACCOUNT_TO_LOG_IN", sfFtpNeedAccountToLogIn);
276
+ DEFINE_CONST(rb_mFtpStatus, "NEED_INFORMATION", sfFtpNeedInformation);
277
+ DEFINE_CONST(rb_mFtpStatus, "SERVICE_UNAVAILABLE", sfFtpServiceUnavailable);
278
+ DEFINE_CONST(rb_mFtpStatus, "DATA_CONNECTION_UNAVAILABLE", sfFtpDataConnectionUnavailable);
279
+ DEFINE_CONST(rb_mFtpStatus, "TRANSFER_ABORTED", sfFtpTransferAborted);
280
+ DEFINE_CONST(rb_mFtpStatus, "FILE_ACTION_ABORTED", sfFtpFileActionAborted);
281
+ DEFINE_CONST(rb_mFtpStatus, "LOCAL_ERROR", sfFtpLocalError);
282
+ DEFINE_CONST(rb_mFtpStatus, "INSUFFICIENT_STORAGE_SPACE", sfFtpInsufficientStorageSpace);
283
+ DEFINE_CONST(rb_mFtpStatus, "COMMAND_UNKNOWN", sfFtpCommandUnknown);
284
+ DEFINE_CONST(rb_mFtpStatus, "PARAMETERS_UNKNOWN", sfFtpParametersUnknown);
285
+ DEFINE_CONST(rb_mFtpStatus, "COMMAND_NOT_IMPLEMENTED", sfFtpCommandNotImplemented);
286
+ DEFINE_CONST(rb_mFtpStatus, "BAD_COMMAND_SEQUENCE", sfFtpBadCommandSequence);
287
+ DEFINE_CONST(rb_mFtpStatus, "PARAMETER_NOT_IMPLEMENTED", sfFtpParameterNotImplemented);
288
+ DEFINE_CONST(rb_mFtpStatus, "NOT_LOGGED_IN", sfFtpNotLoggedIn);
289
+ DEFINE_CONST(rb_mFtpStatus, "NEED_ACCOUNT_TO_STORE", sfFtpNeedAccountToStore);
290
+ DEFINE_CONST(rb_mFtpStatus, "FILE_UNAVAILABLE", sfFtpFileUnavailable);
291
+ DEFINE_CONST(rb_mFtpStatus, "PAGE_TYPE_UNKNOWN", sfFtpPageTypeUnknown);
292
+ DEFINE_CONST(rb_mFtpStatus, "NOT_ENOUGH_MEMORY", sfFtpNotEnoughMemory);
293
+ DEFINE_CONST(rb_mFtpStatus, "FILENAME_NOT_ALLOWED", sfFtpFilenameNotAllowed);
294
+ DEFINE_CONST(rb_mFtpStatus, "INVALID_RESPONSE", sfFtpInvalidResponse);
295
+ DEFINE_CONST(rb_mFtpStatus, "CONNECTION_FAILED", sfFtpConnectionFailed);
296
+ DEFINE_CONST(rb_mFtpStatus, "CONNECTION_CLOSED", sfFtpConnectionClosed);
297
+ DEFINE_CONST(rb_mFtpStatus, "INVALID_FILE", sfFtpInvalidFile);
298
+ }
@@ -0,0 +1,26 @@
1
+ #ifndef SFML_RB_NETWORK_NETWORK_ENUMS_H
2
+ #define SFML_RB_NETWORK_NETWORK_ENUMS_H
3
+
4
+ #include <ruby.h>
5
+
6
+ #include "core/sfml.h"
7
+
8
+ void Init_NetworkEnums(VALUE rb_module);
9
+
10
+ const char *socket_status_name(sfSocketStatus status);
11
+
12
+ sfSocketStatus socket_status_from_rb(VALUE rb_status);
13
+
14
+ const char *http_method_name(sfHttpMethod method);
15
+
16
+ sfHttpMethod http_method_from_rb(VALUE rb_method);
17
+
18
+ const char *http_status_name(sfHttpStatus status);
19
+
20
+ const char *ftp_transfer_mode_name(sfFtpTransferMode mode);
21
+
22
+ sfFtpTransferMode ftp_transfer_mode_from_rb(VALUE rb_mode);
23
+
24
+ const char *ftp_status_name(sfFtpStatus status);
25
+
26
+ #endif //SFML_RB_NETWORK_NETWORK_ENUMS_H