1 /*
2  * Copyright (c) 2013 Derelict Developers
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  *   notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  *   notice, this list of conditions and the following disclaimer in the
14  *   documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the names 'Derelict', 'DerelictILUT', nor the names of its contributors
17  *   may be used to endorse or promote products derived from this software
18  *   without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 module derelict.enet.enet;
33 
34 public
35 {
36     import derelict.enet.types;
37     import derelict.enet.funcs;
38 }
39 
40 private
41 {
42     import derelict.util.loader;
43 
44     version(darwin)
45         version = MacOSX;
46     version(OSX)
47         version = MacOSX;
48 }
49 
50 private
51 {
52     import derelict.util.loader;
53     import derelict.util.system;
54 
55     static if(Derelict_OS_Windows)
56         enum libNames = "libenet.dll, enet.dll";    
57     else static if (Derelict_OS_Mac)
58         enum libNames = "libenet.dylib";
59     else static if (Derelict_OS_Linux)
60         enum libNames = "libenet.so";
61     else
62         static assert(0, "Need to implement ENet libNames for this operating system.");
63 }
64 
65 class DerelictENetLoader : SharedLibLoader
66 {
67 
68     protected
69     {
70         override void loadSymbols()
71         {
72             bindFunc(cast(void**)&enet_initialize, "enet_initialize");
73             bindFunc(cast(void**)&enet_initialize_with_callbacks, "enet_initialize_with_callbacks");
74             bindFunc(cast(void**)&enet_deinitialize, "enet_deinitialize");
75             bindFunc(cast(void**)&enet_linked_version, "enet_linked_version");
76             bindFunc(cast(void**)&enet_time_get, "enet_time_get");
77             bindFunc(cast(void**)&enet_socket_create, "enet_socket_create");
78             bindFunc(cast(void**)&enet_socket_bind, "enet_socket_bind");
79             bindFunc(cast(void**)&enet_socket_get_address, "enet_socket_get_address");
80             bindFunc(cast(void**)&enet_socket_listen, "enet_socket_listen");
81             bindFunc(cast(void**)&enet_socket_accept, "enet_socket_accept");
82             bindFunc(cast(void**)&enet_socket_connect, "enet_socket_connect");
83             bindFunc(cast(void**)&enet_socket_send, "enet_socket_send");
84             bindFunc(cast(void**)&enet_socket_receive, "enet_socket_receive");
85             bindFunc(cast(void**)&enet_socket_wait, "enet_socket_wait");
86             bindFunc(cast(void**)&enet_socket_set_option, "enet_socket_set_option");
87             bindFunc(cast(void**)&enet_socket_get_option, "enet_socket_get_option");
88             bindFunc(cast(void**)&enet_socket_shutdown, "enet_socket_shutdown");
89             bindFunc(cast(void**)&enet_socket_destroy, "enet_socket_destroy");
90             bindFunc(cast(void**)&enet_socketset_select, "enet_socketset_select");
91             bindFunc(cast(void**)&enet_address_set_host, "enet_address_set_host");
92             bindFunc(cast(void**)&enet_address_get_host_ip, "enet_address_get_host_ip");
93             bindFunc(cast(void**)&enet_address_get_host, "enet_address_get_host");
94             bindFunc(cast(void**)&enet_packet_create, "enet_packet_create");
95             bindFunc(cast(void**)&enet_packet_destroy, "enet_packet_destroy");
96             bindFunc(cast(void**)&enet_packet_resize, "enet_packet_resize");
97             bindFunc(cast(void**)&enet_crc32, "enet_crc32");
98             bindFunc(cast(void**)&enet_host_create, "enet_host_create");
99             bindFunc(cast(void**)&enet_host_destroy, "enet_host_destroy");
100             bindFunc(cast(void**)&enet_host_connect, "enet_host_connect");
101             bindFunc(cast(void**)&enet_host_check_events, "enet_host_check_events");
102             bindFunc(cast(void**)&enet_host_service, "enet_host_service");
103             bindFunc(cast(void**)&enet_host_flush, "enet_host_flush");
104             bindFunc(cast(void**)&enet_host_broadcast, "enet_host_broadcast");
105             bindFunc(cast(void**)&enet_host_compress, "enet_host_compress");
106             bindFunc(cast(void**)&enet_host_compress_with_range_coder, "enet_host_compress_with_range_coder");
107             bindFunc(cast(void**)&enet_host_channel_limit, "enet_host_channel_limit");
108             bindFunc(cast(void**)&enet_host_bandwidth_limit, "enet_host_bandwidth_limit");
109             bindFunc(cast(void**)&enet_peer_send, "enet_peer_send");
110             bindFunc(cast(void**)&enet_peer_receive, "enet_peer_receive");
111             bindFunc(cast(void**)&enet_peer_ping, "enet_peer_ping");
112             bindFunc(cast(void**)&enet_peer_ping_interval, "enet_peer_ping_interval");
113             bindFunc(cast(void**)&enet_peer_timeout, "enet_peer_timeout");
114             bindFunc(cast(void**)&enet_peer_reset, "enet_peer_reset");
115             bindFunc(cast(void**)&enet_peer_disconnect, "enet_peer_disconnect");
116             bindFunc(cast(void**)&enet_peer_disconnect_now, "enet_peer_disconnect_now");
117             bindFunc(cast(void**)&enet_peer_disconnect_later, "enet_peer_disconnect_later");
118             bindFunc(cast(void**)&enet_peer_throttle_configure, "enet_peer_throttle_configure");
119             bindFunc(cast(void**)&enet_range_coder_create, "enet_range_coder_create");
120             bindFunc(cast(void**)&enet_range_coder_destroy, "enet_range_coder_destroy");
121             bindFunc(cast(void**)&enet_range_coder_compress, "enet_range_coder_compress");
122             bindFunc(cast(void**)&enet_range_coder_decompress, "enet_range_coder_decompress");
123         }
124     }
125 
126     public
127     {
128         this()
129         {
130             super(libNames);
131         }
132     }
133 }
134 
135 __gshared DerelictENetLoader DerelictENet;
136 
137 shared static this()
138 {
139     DerelictENet = new DerelictENetLoader();
140 }