Skip to content

Commit

Permalink
Merge 2d10d2e into e9ab483
Browse files Browse the repository at this point in the history
  • Loading branch information
iphydf committed Nov 2, 2016
2 parents e9ab483 + 2d10d2e commit c4c2a18
Show file tree
Hide file tree
Showing 9 changed files with 244 additions and 133 deletions.
10 changes: 6 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ cache:
- $HOME/.ghc

install:
- export CABAL_FLAGS="--enable-tests --enable-benchmarks --extra-include-dirs=$HOME/.ghc/usr/include --extra-lib-dirs=$HOME/.ghc/usr/lib"
# Install a recent version of happy, so other dependencies can be installed.
- cabal install happy
- cabal install hpc-coveralls "aeson < 0.11"
# Where to find libraries.
Expand All @@ -16,12 +18,12 @@ install:
- git clone --depth=1 --branch=stable https://github.com/jedisct1/libsodium
- (cd libsodium && ./configure --prefix=$HOME/.ghc/usr && make install -j$(nproc))
# c-toxcore
- git clone --depth=1 https://github.com/TokTok/toxcore
- (cd toxcore && cmake -B_build -H. -DCMAKE_INSTALL_PREFIX:PATH=$HOME/.ghc/usr && make -C_build install -j$(nproc))
- cabal install --only-dependencies --enable-tests --enable-benchmarks --extra-include-dirs=$HOME/.ghc/usr/include --extra-lib-dirs=$HOME/.ghc/usr/lib
- git clone --depth=1 https://github.com/TokTok/c-toxcore
- (cd c-toxcore && cmake -B_build -H. -DCMAKE_INSTALL_PREFIX:PATH=$HOME/.ghc/usr && make -C_build install -j$(nproc))
- cabal install --only-dependencies $CABAL_FLAGS

script:
- cabal configure --enable-tests --enable-benchmarks --enable-library-coverage
- cabal configure --enable-library-coverage $CABAL_FLAGS
- cabal build
- cabal test

Expand Down
15 changes: 7 additions & 8 deletions src/Network/Tox/C/Callbacks.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ import Network.Tox.C.Type (Tox)


-- | Low level event handler. The functions in this class are directly
-- registered with the corresponding C callback. Since userdata @a@ needs to be
-- in C memory, we recommend to keep it small, so marshalling costs are kept to
-- a minimum. Use 'StablePtr' to pass larger opaque Haskell values around in C.
-- registered with the corresponding C callback. We use 'StablePtr' to pass
-- opaque Haskell values around in C.
class CHandler a where
cSelfConnectionStatus :: Tox.SelfConnectionStatusCb a
cFriendName :: Tox.FriendNameCb a
Expand All @@ -32,10 +31,10 @@ class CHandler a where
-- | Installs an event handler into the passed 'Tox' instance. After performing
-- the IO action, all event handlers are reset to null. This function does not
-- save the original event handlers.
withHandler :: CHandler a => Tox a -> IO r -> IO r
withHandler tox =
install Tox.tox_callback_self_connection_status (Tox.wrapSelfConnectionStatusCb cSelfConnectionStatus ) .
install Tox.tox_callback_friend_name (Tox.wrapFriendNameCb cFriendName ) .
withCHandler :: CHandler a => Tox a -> IO r -> IO r
withCHandler tox =
install Tox.tox_callback_self_connection_status (Tox.selfConnectionStatusCb cSelfConnectionStatus ) .
install Tox.tox_callback_friend_name (Tox.friendNameCb cFriendName ) .
install Tox.tox_callback_friend_status_message (Tox.wrapFriendStatusMessageCb cFriendStatusMessage ) .
install Tox.tox_callback_friend_status (Tox.wrapFriendStatusCb cFriendStatus ) .
install Tox.tox_callback_friend_connection_status (Tox.wrapFriendConnectionStatusCb cFriendConnectionStatus) .
Expand All @@ -56,5 +55,5 @@ withHandler tox =
action

uninstall cInstall cb = do
() <- cInstall tox nullFunPtr
freeHaskellFunPtr cb
cInstall tox nullFunPtr
45 changes: 10 additions & 35 deletions src/Network/Tox/C/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@
{-# LANGUAGE Safe #-}
module Network.Tox.C.Options where

import Control.Applicative ((<$>), (<*>))
import Control.Exception (bracket)
import Data.ByteString (ByteString)
import qualified Data.ByteString as BS
import Data.ByteString.Arbitrary (fromABS)
import Data.Default.Class (Default (..))
import Data.Word (Word16)
import Foreign.C.String (CString, peekCString, withCString)
import Foreign.C.Types (CInt (..), CSize (..))
import Foreign.Ptr (Ptr, nullPtr)
import GHC.Generics (Generic)
import Test.QuickCheck.Arbitrary (Arbitrary (..),
arbitraryBoundedEnum)
import Control.Applicative ((<$>))
import Control.Exception (bracket)
import Data.ByteString (ByteString)
import qualified Data.ByteString as BS
import Data.Default.Class (Default (..))
import Data.Word (Word16)
import Foreign.C.String (CString, peekCString, withCString)
import Foreign.C.Types (CInt (..), CSize (..))
import Foreign.Ptr (Ptr, nullPtr)
import GHC.Generics (Generic)

import Network.Tox.C.CEnum

Expand All @@ -36,9 +33,6 @@ data ProxyType
-- SOCKS proxy for simple socket pipes.
deriving (Eq, Ord, Enum, Bounded, Read, Show)

instance Arbitrary ProxyType where
arbitrary = arbitraryBoundedEnum


-- Type of savedata to create the Tox instance from.
data SavedataType
Expand All @@ -50,9 +44,6 @@ data SavedataType
-- Savedata is a secret key of length 'tox_secret_key_size'
deriving (Eq, Ord, Enum, Bounded, Read, Show)

instance Arbitrary SavedataType where
arbitrary = arbitraryBoundedEnum


-- This struct contains all the startup options for Tox. You can either allocate
-- this object yourself, and pass it to tox_options_default, or call
Expand Down Expand Up @@ -143,22 +134,6 @@ instance Default Options where
}


instance Arbitrary Options where
arbitrary = Options
<$> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitraryCString
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> (fromABS <$> arbitrary)
where
arbitraryCString = filter (/= '\NUL') <$> arbitrary


data OptionsStruct
type OptionsPtr = Ptr OptionsStruct

Expand Down

0 comments on commit c4c2a18

Please sign in to comment.