summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWill Thompson <will@willthompson.co.uk>2020-05-16 08:47:10 +0100
committerWill Thompson <will@willthompson.co.uk>2020-06-05 09:24:02 +0100
commit3ac734ab948998e1386ac6f6738c68eeac9f03fd (patch)
tree6a27a4e1465e1415e41b30aaf91b03f81bcf73ed
parente506b5ca71e14af3d2ebd0a63c1b8d3ea0fb1795 (diff)
monitor: include GDBusMessage in ::message-logged
Not used on the Haskell side yet.
-rw-r--r--Bustle/GDBusMessage.hs49
-rw-r--r--Bustle/Monitor.hs4
-rw-r--r--bustle.cabal1
-rw-r--r--c-sources/bustle-pcap.c18
-rw-r--r--c-sources/pcap-monitor.c16
5 files changed, 72 insertions, 16 deletions
diff --git a/Bustle/GDBusMessage.hs b/Bustle/GDBusMessage.hs
new file mode 100644
index 0000000..8a29896
--- /dev/null
+++ b/Bustle/GDBusMessage.hs
@@ -0,0 +1,49 @@
+{-
+Bustle.GDBusMessage: bindings for GDBusMessage
+Copyright © 2020 Will Thompson
+
+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 2.1 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 library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+-}
+{-# LANGUAGE ForeignFunctionInterface #-}
+module Bustle.GDBusMessage
+ (
+-- * Types
+ GDBusMessage
+
+{-
+-- * Methods
+ , monitorNew
+ , monitorStop
+
+-- * Signals
+ , monitorMessageLogged
+ , monitorStopped
+ -}
+ )
+where
+
+import Foreign.ForeignPtr
+
+import System.Glib.GObject
+
+newtype GDBusMessage = GDBusMessage { unGDBusMessage :: ForeignPtr GDBusMessage }
+ deriving (Eq, Ord)
+
+mkGDBusMessage :: (ForeignPtr GDBusMessage -> GDBusMessage, FinalizerPtr a)
+mkGDBusMessage = (GDBusMessage, objectUnref)
+
+instance GObjectClass GDBusMessage where
+ toGObject = GObject . castForeignPtr . unGDBusMessage
+ unsafeCastGObject = GDBusMessage . castForeignPtr . unGObject
diff --git a/Bustle/Monitor.hs b/Bustle/Monitor.hs
index cb9d4ef..9bd4f50 100644
--- a/Bustle/Monitor.hs
+++ b/Bustle/Monitor.hs
@@ -44,6 +44,7 @@ import System.Glib.GObject
import System.Glib.GError
import System.Glib.Signals
+import Bustle.GDBusMessage
import Bustle.Types (Microseconds)
-- Gtk2HS boilerplate
@@ -104,8 +105,9 @@ messageLoggedHandler :: (Microseconds -> BS.ByteString -> IO ())
-> CLong
-> Ptr CChar
-> CUInt
+ -> GDBusMessage
-> IO ()
-messageLoggedHandler user _obj sec usec blob blobLength = do
+messageLoggedHandler user _obj sec usec blob blobLength _message = do
blobBS <- BS.packCStringLen (blob, fromIntegral blobLength)
let µsec = fromIntegral sec * (10 ^ (6 :: Int)) + fromIntegral usec
failOnGError $ user µsec blobBS
diff --git a/bustle.cabal b/bustle.cabal
index 3220392..544f681 100644
--- a/bustle.cabal
+++ b/bustle.cabal
@@ -79,6 +79,7 @@ Executable bustle
Main-is: Bustle.hs
Other-modules: Bustle.Application.Monad
, Bustle.Diagram
+ , Bustle.GDBusMessage
, Bustle.Loader
, Bustle.Loader.Pcap
, Bustle.Marquee
diff --git a/c-sources/bustle-pcap.c b/c-sources/bustle-pcap.c
index 93c6f95..2a39797 100644
--- a/c-sources/bustle-pcap.c
+++ b/c-sources/bustle-pcap.c
@@ -181,20 +181,14 @@ message_logged_cb (
glong usec,
guint8 *data,
guint len,
+ GDBusMessage *message,
gpointer user_data)
{
- g_autoptr(GError) error = NULL;
- g_autoptr(GDBusMessage) message = g_dbus_message_new_from_blob (
- data, len, G_DBUS_CAPABILITY_FLAGS_UNIX_FD_PASSING, &error);
-
- if (message == NULL)
- g_warning ("%s", error->message);
- else
- g_print ("%s -> %s: %d %s\n",
- g_dbus_message_get_sender (message),
- g_dbus_message_get_destination (message),
- g_dbus_message_get_message_type (message),
- g_dbus_message_get_member (message));
+ g_print ("%s -> %s: %d %s\n",
+ g_dbus_message_get_sender (message),
+ g_dbus_message_get_destination (message),
+ g_dbus_message_get_message_type (message),
+ g_dbus_message_get_member (message));
}
static void
diff --git a/c-sources/pcap-monitor.c b/c-sources/pcap-monitor.c
index 9800cc4..18b15e4 100644
--- a/c-sources/pcap-monitor.c
+++ b/c-sources/pcap-monitor.c
@@ -300,15 +300,17 @@ bustle_pcap_monitor_class_init (BustlePcapMonitorClass *klass)
* #GValue.)
* @blob: an array of bytes containing the serialized message.
* @length: the size in bytes of @blob.
+ * @message: @blob as a #GDBusMessage.
*/
signals[SIG_MESSAGE_LOGGED] = g_signal_new ("message-logged",
BUSTLE_TYPE_PCAP_MONITOR, G_SIGNAL_RUN_FIRST,
0, NULL, NULL,
- NULL, G_TYPE_NONE, 4,
+ NULL, G_TYPE_NONE, 5,
G_TYPE_LONG,
G_TYPE_LONG,
G_TYPE_POINTER,
- G_TYPE_UINT);
+ G_TYPE_UINT,
+ G_TYPE_DBUS_MESSAGE);
/**
* BustlePcapMonitor::stopped:
@@ -705,13 +707,21 @@ read_one (
struct pcap_pkthdr *hdr;
const guchar *blob;
int ret;
+ g_autoptr(GDBusMessage) message = NULL;
ret = pcap_next_ex (self->pcap_in, &hdr, &blob);
switch (ret)
{
case 1:
+ message = g_dbus_message_new_from_blob ((guchar *) blob, hdr->caplen, G_DBUS_CAPABILITY_FLAGS_UNIX_FD_PASSING, error);
+ if (message == NULL)
+ {
+ g_prefix_error (error, "Error while parsing message from dbus-monitor: ");
+ return FALSE;
+ }
+
g_signal_emit (self, signals[SIG_MESSAGE_LOGGED], 0,
- hdr->ts.tv_sec, hdr->ts.tv_usec, blob, hdr->caplen);
+ hdr->ts.tv_sec, hdr->ts.tv_usec, blob, hdr->caplen, message);
/* cast necessary because pcap_dump has a type matching the callback
* argument to pcap_loop()