diff options
author | Will Thompson <will@willthompson.co.uk> | 2012-01-16 18:41:23 +0000 |
---|---|---|
committer | Will Thompson <will@willthompson.co.uk> | 2012-01-16 18:42:30 +0000 |
commit | a049cbb8818046e9b73cc39e6155a6978ef7cef0 (patch) | |
tree | 48f0bfb43a3babc47f252159e5dfb1d0187515ed | |
parent | df32c683b917e5f8039fb00b2a6e1099dde799a6 (diff) |
Include timestamps in live logs
-rw-r--r-- | Bustle/Monitor.hs | 13 | ||||
-rw-r--r-- | Bustle/UI/Recorder.hs | 4 | ||||
-rw-r--r-- | c-sources/bustle-pcap.c | 2 | ||||
-rw-r--r-- | c-sources/pcap-monitor.c | 24 |
4 files changed, 35 insertions, 8 deletions
diff --git a/Bustle/Monitor.hs b/Bustle/Monitor.hs index 2b5845e..d1e5c1d 100644 --- a/Bustle/Monitor.hs +++ b/Bustle/Monitor.hs @@ -28,6 +28,8 @@ import System.Glib.GObject import System.Glib.GError import System.Glib.Signals +import Bustle.Types (Microseconds) + -- Gtk2HS boilerplate newtype Monitor = Monitor { unMonitor :: ForeignPtr Monitor } deriving (Eq, Ord) @@ -81,18 +83,21 @@ monitorStop :: Monitor monitorStop monitor = do withForeignPtr (unMonitor monitor) bustle_pcap_monitor_stop -messageLoggedHandler :: (BS.ByteString -> IO ()) +messageLoggedHandler :: (Microseconds -> BS.ByteString -> IO ()) -> a -> Ptr () -> CInt + -> CLong + -> CLong -> Ptr CChar -> CUInt -> IO () -messageLoggedHandler user _obj _messageObject _isIncoming blob blobLength = do +messageLoggedHandler user _obj _messageObject _isIncoming sec usec blob blobLength = do blobBS <- BS.packCStringLen (blob, fromIntegral blobLength) - failOnGError $ user blobBS + let µsec = fromIntegral sec * (10 ^ (6 :: Int)) + fromIntegral usec + failOnGError $ user µsec blobBS -monitorMessageLogged :: Signal Monitor (BS.ByteString -> IO ()) +monitorMessageLogged :: Signal Monitor (Microseconds -> BS.ByteString -> IO ()) monitorMessageLogged = Signal $ \after_ obj user -> connectGeneric "message-logged" after_ obj $ messageLoggedHandler user diff --git a/Bustle/UI/Recorder.hs b/Bustle/UI/Recorder.hs index 161ca88..bab2038 100644 --- a/Bustle/UI/Recorder.hs +++ b/Bustle/UI/Recorder.hs @@ -47,10 +47,10 @@ recorderRun filename mwindow incoming finished = handleGError newFailed $ do -- FIXME: this is stupid. If we have to manually combine the outputs, it's -- basically just more state. rendererResultRef <- newMVar mempty - let updateLabel body = do + let updateLabel µs body = do -- of course, modifyMVar and runStateT have their tuples back to front. m <- modifyMVar loaderStateRef $ \s -> do - (m, s') <- runStateT (convert 0 body) s + (m, s') <- runStateT (convert µs body) s return (s', m) case m of diff --git a/c-sources/bustle-pcap.c b/c-sources/bustle-pcap.c index 8c03b93..5d32cf5 100644 --- a/c-sources/bustle-pcap.c +++ b/c-sources/bustle-pcap.c @@ -148,6 +148,8 @@ message_logged_cb ( BustlePcapMonitor *pcap, GDBusMessage *message, gboolean is_incoming, + glong sec, + glong usec, guint8 *data, guint len, gpointer user_data) diff --git a/c-sources/pcap-monitor.c b/c-sources/pcap-monitor.c index 191323f..cd1a687 100644 --- a/c-sources/pcap-monitor.c +++ b/c-sources/pcap-monitor.c @@ -187,12 +187,29 @@ bustle_pcap_monitor_class_init (BustlePcapMonitorClass *klass) G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); g_object_class_install_property (object_class, PROP_FILENAME, param_spec); + /** + * BustlePcapMonitor::message-logged: + * @self: the monitor. + * @message: the #GDBusMessage object logged. + * @is_incoming: if %TRUE, @message has come in from the bus daemon; if + * %FALSE, this is a message we're in the process of sending. Note that this + * can be %TRUE for messages our process sends, because we eavesdrop all + * messages, including our own. + * @sec: seconds since 1970. + * @usec: microseconds! (These are not combined into a single %gint64 because + * my version of gtk2hs crashes when it encounters %G_TYPE_UINT64 in a + * #GValue.) + * @blob: an array of bytes containing the serialized message. + * @length: the size in bytes of @blob. + */ 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, 6, G_TYPE_DBUS_MESSAGE, G_TYPE_BOOLEAN, + G_TYPE_LONG, + G_TYPE_LONG, G_TYPE_POINTER, G_TYPE_UINT); } @@ -225,11 +242,14 @@ emit_me (gpointer data) { IdleEmitData *ied = data; BustlePcapMonitor *self = BUSTLE_PCAP_MONITOR (ied->self); + glong sec = ied->message.ts.tv_sec; + glong usec = ied->message.ts.tv_usec; g_signal_emit (self, signals[SIG_MESSAGE_LOGGED], 0, ied->dbus_message, ied->is_incoming, - /* FIXME: include timestamp */ + sec, + usec, ied->message.blob->data, ied->message.blob->len); g_object_unref (self); |