{-# LANGUAGE ForeignFunctionInterface #-}

-- | FFI module for handling connections between nodes
module GEGL.FFI.Connection
  ( c_gegl_node_connect_from
  , c_gegl_node_connect_to
  , c_gegl_node_link
  , c_gegl_node_disconnect
  ) where

import Foreign
import Foreign.Ptr
import Foreign.C.Types
import Foreign.C.String (CString)

-- | Interface to the @gegl_node_link@ function in C
foreign import ccall unsafe "gegl.h gegl_node_link"
  c_gegl_node_link
    :: Ptr () -- ^ Source node representation
    -> Ptr () -- ^ Sink node representation
    -> IO ()

-- | Interface to the @gegl_node_connect_to@ function in C
foreign import ccall unsafe "gegl.h gegl_node_connect_to"
  c_gegl_node_connect_to
    :: Ptr () -- ^ Source node representation
    -> CString       -- ^ Name of the output pad at the source node
    -> Ptr () -- ^ Sink node representation
    -> CString       -- ^ Name of input pad at the sink node
    -> IO CInt

-- | Interface to the @gegl_node_connect_from@ function in C
foreign import ccall unsafe "gegl.h gegl_node_connect_from"
  c_gegl_node_connect_from
    :: Ptr () -- ^ Sink node representation
    -> CString       -- ^ Name of the input pad at the sink node
    -> Ptr () -- ^ Source node representation
    -> CString       -- ^ Name of the output pad at the source node
    -> IO CInt

foreign import ccall unsafe "gegl.h gegl_node_disconnect"
  c_gegl_node_disconnect
    :: Ptr ()
    -> CString
    -> IO CInt