3
3
{-# LANGUAGE StrictData #-}
4
4
module Network.Tox.C.Options where
5
5
6
- import Control.Exception (bracket )
7
- import Data.ByteString (ByteString )
8
- import qualified Data.ByteString as BS
9
- import Data.Word (Word16 , Word32 )
10
- import Foreign.C.String (CString , peekCString , withCString )
11
- import Foreign.C.Types (CInt (.. ), CSize (.. ))
12
- import Foreign.Ptr (FunPtr , Ptr , nullPtr )
13
- import GHC.Generics (Generic )
14
-
15
- import Network.Tox.C.CEnum
6
+ import Control.Exception (bracket )
7
+ import Data.ByteString (ByteString )
8
+ import qualified Data.ByteString as BS
9
+ import Data.Word (Word16 )
10
+ import Foreign.C.Enum
11
+ import Foreign.C.String (peekCString , withCString )
12
+ import Foreign.Ptr (nullPtr )
13
+ import GHC.Generics (Generic )
14
+
15
+ import FFI.Tox.Tox (LogCb , LogLevel (.. ), OptionsPtr ,
16
+ ProxyType (.. ), SavedataType (.. ),
17
+ tox_options_get_end_port ,
18
+ tox_options_get_ipv6_enabled ,
19
+ tox_options_get_proxy_host ,
20
+ tox_options_get_proxy_port ,
21
+ tox_options_get_proxy_type ,
22
+ tox_options_get_savedata_data ,
23
+ tox_options_get_savedata_length ,
24
+ tox_options_get_savedata_type ,
25
+ tox_options_get_start_port ,
26
+ tox_options_get_tcp_port ,
27
+ tox_options_get_udp_enabled ,
28
+ tox_options_set_end_port ,
29
+ tox_options_set_ipv6_enabled ,
30
+ tox_options_set_log_callback ,
31
+ tox_options_set_proxy_host ,
32
+ tox_options_set_proxy_port ,
33
+ tox_options_set_proxy_type ,
34
+ tox_options_set_savedata_data ,
35
+ tox_options_set_savedata_length ,
36
+ tox_options_set_savedata_type ,
37
+ tox_options_set_start_port ,
38
+ tox_options_set_tcp_port ,
39
+ tox_options_set_udp_enabled , wrapLogCb )
16
40
17
41
--------------------------------------------------------------------------------
18
42
--
@@ -21,28 +45,6 @@ import Network.Tox.C.CEnum
21
45
--------------------------------------------------------------------------------
22
46
23
47
24
- -- | Type of proxy used to connect to TCP relays.
25
- data ProxyType
26
- = ProxyTypeNone
27
- -- Don't use a proxy.
28
- | ProxyTypeHttp
29
- -- HTTP proxy using CONNECT.
30
- | ProxyTypeSocks5
31
- -- SOCKS proxy for simple socket pipes.
32
- deriving (Eq , Ord , Enum , Bounded , Read , Show , Generic )
33
-
34
-
35
- -- Type of savedata to create the Tox instance from.
36
- data SavedataType
37
- = SavedataTypeNone
38
- -- No savedata.
39
- | SavedataTypeToxSave
40
- -- Savedata is one that was obtained from tox_get_savedata
41
- | SavedataTypeSecretKey
42
- -- Savedata is a secret key of length 'tox_secret_key_size'
43
- deriving (Eq , Ord , Enum , Bounded , Read , Show , Generic )
44
-
45
-
46
48
-- This struct contains all the startup options for Tox. You can either allocate
47
49
-- this object yourself, and pass it to tox_options_default, or call
48
50
-- tox_options_new to get a new default options object.
@@ -132,54 +134,13 @@ defaultOptions = Options
132
134
}
133
135
134
136
135
- data OptionsStruct
136
- type OptionsPtr = Ptr OptionsStruct
137
-
138
-
139
- foreign import ccall tox_options_get_ipv6_enabled :: OptionsPtr -> IO Bool
140
- foreign import ccall tox_options_get_udp_enabled :: OptionsPtr -> IO Bool
141
- foreign import ccall tox_options_get_proxy_type :: OptionsPtr -> IO (CEnum ProxyType )
142
- foreign import ccall tox_options_get_proxy_host :: OptionsPtr -> IO CString
143
- foreign import ccall tox_options_get_proxy_port :: OptionsPtr -> IO Word16
144
- foreign import ccall tox_options_get_start_port :: OptionsPtr -> IO Word16
145
- foreign import ccall tox_options_get_end_port :: OptionsPtr -> IO Word16
146
- foreign import ccall tox_options_get_tcp_port :: OptionsPtr -> IO Word16
147
- foreign import ccall tox_options_get_savedata_type :: OptionsPtr -> IO (CEnum SavedataType )
148
- foreign import ccall tox_options_get_savedata_data :: OptionsPtr -> IO CString
149
- foreign import ccall tox_options_get_savedata_length :: OptionsPtr -> IO CSize
150
-
151
- foreign import ccall tox_options_set_ipv6_enabled :: OptionsPtr -> Bool -> IO ()
152
- foreign import ccall tox_options_set_udp_enabled :: OptionsPtr -> Bool -> IO ()
153
- foreign import ccall tox_options_set_proxy_type :: OptionsPtr -> CEnum ProxyType -> IO ()
154
- foreign import ccall tox_options_set_proxy_host :: OptionsPtr -> CString -> IO ()
155
- foreign import ccall tox_options_set_proxy_port :: OptionsPtr -> Word16 -> IO ()
156
- foreign import ccall tox_options_set_start_port :: OptionsPtr -> Word16 -> IO ()
157
- foreign import ccall tox_options_set_end_port :: OptionsPtr -> Word16 -> IO ()
158
- foreign import ccall tox_options_set_tcp_port :: OptionsPtr -> Word16 -> IO ()
159
- foreign import ccall tox_options_set_savedata_type :: OptionsPtr -> CEnum SavedataType -> IO ()
160
- foreign import ccall tox_options_set_savedata_data :: OptionsPtr -> CString -> CSize -> IO ()
161
- foreign import ccall tox_options_set_savedata_length :: OptionsPtr -> CSize -> IO ()
162
-
163
-
164
- data LogLevel
165
- = LogLevelTrace
166
- | LogLevelDebug
167
- | LogLevelInfo
168
- | LogLevelWarning
169
- | LogLevelError
170
- deriving (Eq , Ord , Enum , Bounded , Read , Show )
171
-
172
137
logLevelName :: LogLevel -> Char
173
138
logLevelName LogLevelTrace = ' T'
174
139
logLevelName LogLevelDebug = ' D'
175
140
logLevelName LogLevelInfo = ' I'
176
141
logLevelName LogLevelWarning = ' W'
177
142
logLevelName LogLevelError = ' E'
178
143
179
- type LogCb = Ptr () -> CEnum LogLevel -> CString -> Word32 -> CString -> CString -> Ptr () -> IO ()
180
- foreign import ccall tox_options_set_log_callback :: OptionsPtr -> FunPtr LogCb -> IO ()
181
- foreign import ccall " wrapper" wrapLogCb :: LogCb -> IO (FunPtr LogCb )
182
-
183
144
logHandler :: LogCb
184
145
logHandler _ cLevel cFile line cFunc cMsg _ = do
185
146
let level = fromCEnum cLevel
0 commit comments