 {-# LANGUAGE CPP #-}
 {-# CFILES events.c #-}
 module Graphics.UI.Gtk.WebKit.DOM.EventTargetClosures
-       (EventName(..), SaferEventListener(..), EventListener(..), unEventListener, EventListenerClass(..), eventListenerNew) where
+       (EventName(..), SaferEventListener(..), EventListener(..), unEventListener, EventListenerClass(..),
+       eventListenerNew, eventListenerNewAsync, eventListenerNewSync, eventListenerRelease) where
 import Control.Monad.Reader (ReaderT)
-import System.Glib.FFI (newStablePtr, StablePtr, Ptr(..), toBool, CInt(..), CChar,
+import System.Glib.FFI (newStablePtr, freeStablePtr, StablePtr, Ptr(..), toBool, CInt(..), CChar,
         withForeignPtr, fromBool)
 import System.Glib.UTFString
 import Control.Applicative

newtype EventName t e = EventName String
newtype SaferEventListener t e = SaferEventListener EventListener

{# pointer *GClosure as EventListener newtype #}

unEventListener (EventListener p) = p

class EventListenerClass a where
  toEventListener :: a -> EventListener

          makeNewGObject (GObject, objectUnrefFromMainloop) (return obj1) >>= \obj1' ->
          callback (unsafeCastGObject obj2')

eventListenerNewAsync :: EventClass event => (event -> IO ()) -> IO EventListener
eventListenerNewAsync = eventListenerNew

eventListenerNewSync :: EventClass event => (event -> IO ()) -> IO EventListener
eventListenerNewSync = eventListenerNew

foreign import ccall unsafe "g_closure_unref"
  g_closure_unref :: Ptr GClosure -> IO ()

eventListenerRelease :: EventListener -> IO ()
eventListenerRelease (EventListener gclosurePtr sptr) = do
  g_closure_unref gclosurePtr
  freeStablePtr sptr


