From 8fc5ff2c18bad38c6000210245b6933085dc7ad7 Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Mon, 25 Apr 2016 14:04:32 -0700 Subject: [PATCH] match signatures between header and code --- .gitignore | 1 + cbits/grpc_haskell.c | 20 ++++++++++++----- include/grpc_haskell.h | 6 +++-- src/Network/GRPC/Core.chs | 15 ++++++++++--- src/Network/GRPC/Core/Constants.hsc | 23 +++++++++++-------- stack.yaml | 35 +++++++++++++++++++++++++++++ 6 files changed, 80 insertions(+), 20 deletions(-) create mode 100644 stack.yaml diff --git a/.gitignore b/.gitignore index 1521c8b..99ed843 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ dist +.stack-work/ diff --git a/cbits/grpc_haskell.c b/cbits/grpc_haskell.c index 27c65cd..9461af4 100644 --- a/cbits/grpc_haskell.c +++ b/cbits/grpc_haskell.c @@ -1,15 +1,23 @@ #include +#include +#include +#include +#include -grpc_event grpc_completion_queue_next_(grpc_completion_queue *cq, +grpc_event *grpc_completion_queue_next_(grpc_completion_queue *cq, gpr_timespec *deadline, void *reserved) { - return grpc_completion_queue_next(cq, *deadline, reserved); + grpc_event *toReturn = malloc(sizeof(grpc_event)); + *toReturn = grpc_completion_queue_next(cq, *deadline, reserved); + return toReturn; } -grpc_event grpc_completion_queue_pluck_(grpc_completion_queue *cq, void *tag, +grpc_event *grpc_completion_queue_pluck_(grpc_completion_queue *cq, void *tag, gpr_timespec *deadline, void *reserved) { - return grpc_completion_queue_pluck(cq, tag, *deadline, reserved); + grpc_event *toReturn = malloc(sizeof(grpc_event)); + *toReturn = grpc_completion_queue_pluck(cq, tag, *deadline, reserved); + return toReturn; } grpc_call *grpc_channel_create_call_(grpc_channel *channel, @@ -19,6 +27,6 @@ grpc_call *grpc_channel_create_call_(grpc_channel *channel, const char *method, const char *host, gpr_timespec *deadline, void *reserved) { return grpc_channel_create_call(channel, parent_call, propagation_mask, - completion_queue, method, host, *deadline, - reserved); + completion_queue, method, host, + *deadline, reserved); } diff --git a/include/grpc_haskell.h b/include/grpc_haskell.h index b25d364..034abad 100644 --- a/include/grpc_haskell.h +++ b/include/grpc_haskell.h @@ -1,10 +1,12 @@ #include grpc_event *grpc_completion_queue_next_(grpc_completion_queue *cq, - gpr_timespec *deadline); + gpr_timespec *deadline, + void *reserved); grpc_event *grpc_completion_queue_pluck_(grpc_completion_queue *cq, void *tag, - gpr_timespec *deadline); + gpr_timespec *deadline, + void *reserved); grpc_call *grpc_channel_create_call_(grpc_channel *channel, grpc_call *parent_call, diff --git a/src/Network/GRPC/Core.chs b/src/Network/GRPC/Core.chs index 92b2ddf..cab926a 100644 --- a/src/Network/GRPC/Core.chs +++ b/src/Network/GRPC/Core.chs @@ -5,8 +5,11 @@ module Network.GRPC.Core where import Foreign.C.String import Foreign.C.Types import Foreign.Ptr +import Foreign.Storable +import Foreign.Marshal.Utils import Network.GRPC.Core.Time +import Network.GRPC.Core.Constants #include #include @@ -21,6 +24,8 @@ import Network.GRPC.Core.Time {#pointer *grpc_channel as Channel newtype #} {#pointer *grpc_server as Server newtype #} {#pointer *grpc_call as Call newtype #} +{#pointer *grpc_call_details as CallDetails newtype #} +{#pointer *grpc_metadata_array as MetadataArray newtype #} -- {#enum grpc_arg_type as ArgType {underscoreToCase} deriving (Eq)#} @@ -48,13 +53,13 @@ data ArgValue = ArgString String | ArgInt Int {#fun grpc_completion_queue_create as ^ {`Ptr ()'} -> `CompletionQueue'#} -{#fun grpc_completion_queue_next_ as ^ {`CompletionQueue', `CTimeSpecPtr'} -> `Event'#} -{#fun grpc_completion_queue_pluck_ as ^ {`CompletionQueue', `Ptr ()', `CTimeSpecPtr'} -> `Event'#} +{#fun grpc_completion_queue_next_ as ^ {`CompletionQueue', `CTimeSpecPtr', `Ptr ()'} -> `Event'#} +{#fun grpc_completion_queue_pluck_ as ^ {`CompletionQueue', `Ptr ()', `CTimeSpecPtr', `Ptr ()'} -> `Event'#} {#fun grpc_completion_queue_shutdown as ^ {`CompletionQueue'} -> `()'#} {#fun grpc_completion_queue_destroy as ^ {`CompletionQueue'} -> `()'#} -{#fun grpc_channel_create_call_ as ^ {`Channel', `Call', `Int', `CompletionQueue', `String', `String', `CTimeSpecPtr', `Ptr ()'} -> `Call'#} +{#fun grpc_channel_create_call_ as ^ {`Channel', `Call', fromIntegral `PropagationMask', `CompletionQueue', `String', `String', `CTimeSpecPtr', `Ptr ()'} -> `Call'#} {#fun grpc_insecure_channel_create as ^ {`String', `ChannelArgsPtr', `Ptr ()'} -> `Channel'#} {#fun grpc_channel_destroy as ^ {`Channel'} -> `()'#} @@ -62,3 +67,7 @@ data ArgValue = ArgString String | ArgInt Int {#fun grpc_call_cancel as ^ {`Call', `Ptr ()'} -> `()'#} {#fun grpc_call_cancel_with_status as ^ {`Call', `StatusCode', `String', `Ptr ()'} -> `()'#} {#fun grpc_call_destroy as ^ {`Call'} -> `()'#} + +-- Server stuff + +--{#fun grpc_server_request_call as ^ {`Server',with* `Call' peek*, `CallDetails', `MetadataArray', `CompletionQueue', `CompletionQueue', `Ptr ()'} -> `CallError'#} diff --git a/src/Network/GRPC/Core/Constants.hsc b/src/Network/GRPC/Core/Constants.hsc index 0ff3b59..86989f0 100644 --- a/src/Network/GRPC/Core/Constants.hsc +++ b/src/Network/GRPC/Core/Constants.hsc @@ -1,3 +1,5 @@ +{-# LANGUAGE GeneralizedNewtypeDeriving #-} + module Network.GRPC.Core.Constants where #include "grpc/grpc.h" @@ -19,16 +21,19 @@ writeNoCompress :: Int writeNoCompress = #const GRPC_WRITE_NO_COMPRESS newtype PropagationMask = PropagationMask {unPropagationMask :: Int} - deriving (Show, Eq, Ord) + deriving (Show, Eq, Ord, Integral, Enum, Real, Num) -propagateDeadline :: Int -propagateDeadline = #const GRPC_PROPAGATE_DEADLINE +propagateDeadline :: PropagationMask +propagateDeadline = PropagationMask $ #const GRPC_PROPAGATE_DEADLINE -propagateCensusStatsContext :: Int -propagateCensusStatsContext = #const GRPC_PROPAGATE_CENSUS_STATS_CONTEXT +propagateCensusStatsContext :: PropagationMask +propagateCensusStatsContext = + PropagationMask $ #const GRPC_PROPAGATE_CENSUS_STATS_CONTEXT -propagateCensusTracingContext :: Int -propagateCensusTracingContext = #const GRPC_PROPAGATE_CENSUS_TRACING_CONTEXT +propagateCensusTracingContext :: PropagationMask +propagateCensusTracingContext = + PropagationMask $ #const GRPC_PROPAGATE_CENSUS_TRACING_CONTEXT -propagateCancellation :: Int -propagateCancellation = #const GRPC_PROPAGATE_CANCELLATION +propagateCancellation :: PropagationMask +propagateCancellation = + PropagationMask $ #const GRPC_PROPAGATE_CANCELLATION diff --git a/stack.yaml b/stack.yaml new file mode 100644 index 0000000..a614a5b --- /dev/null +++ b/stack.yaml @@ -0,0 +1,35 @@ +# This file was automatically generated by stack init +# For more information, see: http://docs.haskellstack.org/en/stable/yaml_configuration/ + +# Specifies the GHC version and set of packages available (e.g., lts-3.5, nightly-2015-09-21, ghc-7.10.2) +resolver: lts-5.10 + +# Local packages, usually specified by relative directory name +packages: +- '.' +# Packages to be pulled from upstream that are not in the resolver (e.g., acme-missiles-0.3) +extra-deps: [] + +# Override default flag values for local packages and extra-deps +flags: {} + +# Extra package databases containing global packages +extra-package-dbs: [] + +# Control whether we use the GHC we find on the path +# system-ghc: true + +# Require a specific version of stack, using version ranges +# require-stack-version: -any # Default +# require-stack-version: >= 1.0.0 + +# Override the architecture used by stack, especially useful on Windows +# arch: i386 +# arch: x86_64 + +# Extra directories used by stack for building +# extra-include-dirs: [/path/to/dir] +# extra-lib-dirs: [/path/to/dir] + +# Allow a newer minor version of GHC than the snapshot specifies +# compiler-check: newer-minor