-- GENERATED by C->Haskell Compiler, version 0.13.11 (gtk2hs branch) "Bin IO", 27 May 2012 (Haskell)
-- Edit the ORIGNAL .chs file instead!


{-# LINE 1 "./Media/Streaming/GStreamer/Core/Index.chs" #-}
--  GIMP Toolkit (GTK) Binding for Haskell: binding to gstreamer -*-haskell-*-
--
--  Author : Peter Gavin
--  Created: 1-Apr-2007
--
--  Copyright (c) 2007 Peter Gavin
--
--  This library is free software: you can redistribute it and/or
--  modify it under the terms of the GNU Lesser General Public License
--  as published by the Free Software Foundation, either version 3 of
--  the License, or (at your option) any later version.
--  
--  This library is distributed in the hope that it will be useful,
--  but WITHOUT ANY WARRANTY; without even the implied warranty of
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
--  Lesser General Public License for more details.
--  
--  You should have received a copy of the GNU Lesser General Public
--  License along with this program.  If not, see
--  <http://www.gnu.org/licenses/>.
--  
--  GStreamer, the C library which this Haskell library depends on, is
--  available under LGPL Version 2. The documentation included with
--  this library is based on the original GStreamer documentation.
--  
-- | Maintainer  : gtk2hs-devel@lists.sourceforge.net
--   Stability   : alpha
--   Portability : portable (depends on GHC)
module Media.Streaming.GStreamer.Core.Index (
  
  Index,
  IndexClass,
  castToIndex,
  gTypeIndex,

  indexNew,
  indexCommit,
  indexGetGroup,
  indexNewGroup,
  indexSetGroup,
  indexSetCertainty,
  indexSetFilter,
  indexGetWriterId,
  indexAddFormat,
  indexAddAssociations,
  indexAddId,
  indexGetAssocEntry,
  indexEntryAssocMap,
  onIndexEntryAdded,
  afterIndexEntryAdded,
  
  ) where

import Control.Monad (liftM)
import Media.Streaming.GStreamer.Core.Types
{-# LINE 55 "./Media/Streaming/GStreamer/Core/Index.chs" #-}
import Media.Streaming.GStreamer.Core.Signals
{-# LINE 56 "./Media/Streaming/GStreamer/Core/Index.chs" #-}
import System.Glib.Flags
import System.Glib.FFI
import System.Glib.UTFString
import System.Glib.Signals
{-# LINE 60 "./Media/Streaming/GStreamer/Core/Index.chs" #-}
import System.Glib.GObject (destroyFunPtr)


{-# LINE 63 "./Media/Streaming/GStreamer/Core/Index.chs" #-}

indexGetFlags :: IndexClass indexT
              => indexT
              -> IO [IndexFlags]
indexGetFlags = mkObjectGetFlags

indexSetFlags :: IndexClass indexT
              => indexT
              -> [IndexFlags]
              -> IO ()
indexSetFlags = mkObjectSetFlags

indexUnsetFlags :: IndexClass indexT
                => indexT
                -> [IndexFlags]
                -> IO ()
indexUnsetFlags = mkObjectUnsetFlags

indexNew :: IO Index
indexNew =
    gst_index_new >>= takeObject

indexCommit :: IndexClass index
            => index
            -> Int
            -> IO ()
indexCommit index id =
    (\(Index arg1) arg2 -> withForeignPtr arg1 $ \argPtr1 ->gst_index_commit argPtr1 arg2) (toIndex index) $ fromIntegral id

indexGetGroup :: IndexClass index
              => index
              -> IO Int
indexGetGroup index =
    liftM fromIntegral $ (\(Index arg1) -> withForeignPtr arg1 $ \argPtr1 ->gst_index_get_group argPtr1) $ toIndex index

indexNewGroup :: IndexClass index
              => index
              -> IO Int
indexNewGroup index =
    liftM fromIntegral $ (\(Index arg1) -> withForeignPtr arg1 $ \argPtr1 ->gst_index_new_group argPtr1) $ toIndex index

indexSetGroup :: IndexClass index
              => index
              -> Int
              -> IO Bool
indexSetGroup index groupnum =
    liftM toBool $ (\(Index arg1) arg2 -> withForeignPtr arg1 $ \argPtr1 ->gst_index_set_group argPtr1 arg2) (toIndex index) $ fromIntegral groupnum

indexSetCertainty :: IndexClass index
                  => index
                  -> IndexCertainty
                  -> IO ()
indexSetCertainty index certainty =
    (\(Index arg1) arg2 -> withForeignPtr arg1 $ \argPtr1 ->gst_index_set_certainty argPtr1 arg2) (toIndex index) $ cFromEnum certainty

type CIndexFilter =  Ptr Index
                  -> Ptr IndexEntry
                  -> ((Ptr ()))
{-# LINE 121 "./Media/Streaming/GStreamer/Core/Index.chs" #-}
                  -> IO (CInt)
{-# LINE 122 "./Media/Streaming/GStreamer/Core/Index.chs" #-}
marshalIndexFilter :: IndexFilter
                   -> IO ((FunPtr ((Ptr Index) -> ((Ptr IndexEntry) -> ((Ptr ()) -> (IO CInt))))))
{-# LINE 124 "./Media/Streaming/GStreamer/Core/Index.chs" #-}
marshalIndexFilter indexFilter =
    makeIndexFilter cIndexFilter
    where cIndexFilter :: CIndexFilter
          cIndexFilter cIndex cIndexEntry _ =
              do index <- peekObject cIndex
                 indexEntry <- peekIndexEntry cIndexEntry
                 liftM fromBool $ indexFilter index indexEntry
foreign import ccall "wrapper"
    makeIndexFilter :: CIndexFilter
                    -> IO ((FunPtr ((Ptr Index) -> ((Ptr IndexEntry) -> ((Ptr ()) -> (IO CInt))))))
{-# LINE 134 "./Media/Streaming/GStreamer/Core/Index.chs" #-}

indexSetFilter :: IndexClass index
               => index
               -> IndexFilter
               -> IO ()
indexSetFilter index filter =
    do cFilter <- marshalIndexFilter filter
       (\(Index arg1) arg2 arg3 arg4 -> withForeignPtr arg1 $ \argPtr1 ->gst_index_set_filter_full argPtr1 arg2 arg3 arg4) (toIndex index) cFilter
	 (castFunPtrToPtr cFilter) destroyFunPtr

indexGetWriterId :: IndexClass index
                 => index
                 -> Object
                 -> IO (Maybe Int)
indexGetWriterId index writer =
    alloca $ \idPtr ->
        do result <- (\(Index arg1) (Object arg2) arg3 -> withForeignPtr arg1 $ \argPtr1 ->withForeignPtr arg2 $ \argPtr2 ->gst_index_get_writer_id argPtr1 argPtr2 arg3) (toIndex index) (toObject writer) idPtr
           if toBool result
               then liftM (Just . fromIntegral) $ peek idPtr
               else return Nothing

indexAddFormat :: IndexClass index
               => index
               -> Int
               -> Format
               -> IO IndexEntry
indexAddFormat index id format =
    (\(Index arg1) arg2 arg3 -> withForeignPtr arg1 $ \argPtr1 ->gst_index_add_format argPtr1 arg2 arg3) (toIndex index)
                                (fromIntegral id)
                                (fromIntegral $ fromFormat format) >>=
        peekIndexEntry

indexAddAssociations :: IndexClass index
                     => index
                     -> Int
                     -> [AssocFlags]
                     -> [IndexAssociation]
                     -> IO IndexEntry
indexAddAssociations index id flags associations =
    withArrayLen associations $ \numAssociations cAssociations ->
        (\(Index arg1) arg2 arg3 arg4 arg5 -> withForeignPtr arg1 $ \argPtr1 ->gst_index_add_associationv argPtr1 arg2 arg3 arg4 arg5) (toIndex index)
                                          (fromIntegral id)
                                          (fromIntegral $ fromFlags flags)
                                          (fromIntegral numAssociations)
                                          (castPtr cAssociations) >>=
            peekIndexEntry

indexAddId :: IndexClass index
           => index
           -> Int
           -> String
           -> IO IndexEntry
indexAddId index id description =
    withUTFString description
                  ((\(Index arg1) arg2 arg3 -> withForeignPtr arg1 $ \argPtr1 ->gst_index_add_id argPtr1 arg2 arg3) (toIndex index) $ fromIntegral id) >>=
        peekIndexEntry

indexGetAssocEntry :: IndexClass index
                   => index
                   -> Int
                   -> IndexLookupMethod
                   -> [AssocFlags]
                   -> Format
                   -> Int64
                   -> IO (Maybe IndexEntry)
indexGetAssocEntry index id method flags format value =
    (\(Index arg1) arg2 arg3 arg4 arg5 arg6 -> withForeignPtr arg1 $ \argPtr1 ->gst_index_get_assoc_entry argPtr1 arg2 arg3 arg4 arg5 arg6) (toIndex index)
                                     (fromIntegral id)
                                     (cFromEnum method)
                                     (fromIntegral $ fromFlags flags)
                                     (fromIntegral $ fromFormat format)
                                     (fromIntegral value) >>=
        maybePeek peekIndexEntry

indexEntryAssocMap :: IndexEntry
                   -> Format
                   -> Maybe Int64
indexEntryAssocMap entry format =
    unsafePerformIO $ alloca $ \valuePtr ->
        do result <- (\(IndexEntry arg1) arg2 arg3 -> withForeignPtr arg1 $ \argPtr1 ->gst_index_entry_assoc_map argPtr1 arg2 arg3) entry
                                                          (fromIntegral $ fromFormat format)
                                                          valuePtr
           if toBool result
               then liftM (Just . fromIntegral) $ peek valuePtr
               else return Nothing

onIndexEntryAdded, afterIndexEntryAdded :: IndexClass index
                                        => index
                                        -> (IndexEntry -> IO ())
                                        -> IO (ConnectId index)
onIndexEntryAdded =
    connect_BOXED__NONE "entry-added" peekIndexEntry False
afterIndexEntryAdded =
    connect_BOXED__NONE "entry-added" peekIndexEntry True

foreign import ccall safe "gst_index_new"
  gst_index_new :: (IO (Ptr Index))

foreign import ccall safe "gst_index_commit"
  gst_index_commit :: ((Ptr Index) -> (CInt -> (IO ())))

foreign import ccall safe "gst_index_get_group"
  gst_index_get_group :: ((Ptr Index) -> (IO CInt))

foreign import ccall safe "gst_index_new_group"
  gst_index_new_group :: ((Ptr Index) -> (IO CInt))

foreign import ccall safe "gst_index_set_group"
  gst_index_set_group :: ((Ptr Index) -> (CInt -> (IO CInt)))

foreign import ccall safe "gst_index_set_certainty"
  gst_index_set_certainty :: ((Ptr Index) -> (CInt -> (IO ())))

foreign import ccall safe "gst_index_set_filter_full"
  gst_index_set_filter_full :: ((Ptr Index) -> ((FunPtr ((Ptr Index) -> ((Ptr IndexEntry) -> ((Ptr ()) -> (IO CInt))))) -> ((Ptr ()) -> ((FunPtr ((Ptr ()) -> (IO ()))) -> (IO ())))))

foreign import ccall safe "gst_index_get_writer_id"
  gst_index_get_writer_id :: ((Ptr Index) -> ((Ptr Object) -> ((Ptr CInt) -> (IO CInt))))

foreign import ccall safe "gst_index_add_format"
  gst_index_add_format :: ((Ptr Index) -> (CInt -> (CInt -> (IO (Ptr IndexEntry)))))

foreign import ccall safe "gst_index_add_associationv"
  gst_index_add_associationv :: ((Ptr Index) -> (CInt -> (CInt -> (CInt -> ((Ptr ()) -> (IO (Ptr IndexEntry)))))))

foreign import ccall safe "gst_index_add_id"
  gst_index_add_id :: ((Ptr Index) -> (CInt -> ((Ptr CChar) -> (IO (Ptr IndexEntry)))))

foreign import ccall safe "gst_index_get_assoc_entry"
  gst_index_get_assoc_entry :: ((Ptr Index) -> (CInt -> (CInt -> (CInt -> (CInt -> (CLong -> (IO (Ptr IndexEntry))))))))

foreign import ccall safe "gst_index_entry_assoc_map"
  gst_index_entry_assoc_map :: ((Ptr IndexEntry) -> (CInt -> ((Ptr CLong) -> (IO CInt))))