File: Loader.hs

package info (click to toggle)
bustle 0.7.4-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 720 kB
  • sloc: haskell: 3,938; ansic: 939; makefile: 110; sh: 8
file content (67 lines) | stat: -rw-r--r-- 2,181 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
{-
Bustle.Loader: loads logs using one of the two sub-loaders
Copyright © 2011–2012 Collabora Ltd.

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
-}
module Bustle.Loader
  ( readLog
  , LoadError(..)

  -- * This function bothers me, but it's used by the live recorder for now...
  , isRelevant
  )
where

import Control.Monad.Except
import Control.Arrow (second)

import qualified Bustle.Loader.Pcap as Pcap
import Bustle.Types
import Bustle.Util (io)

data LoadError = LoadError FilePath String

-- this nested case stuff is ugly, but it's less ugly than it looked with
-- combinators to turn IO (Either a b) into ErrorT LoadError IO b using various
-- a -> LoadError functions.
readLog :: MonadIO io
        => FilePath
        -> ExceptT LoadError io ([String], Log)
readLog f = do
    pcapResult <- io $ Pcap.readPcap f
    case pcapResult of
        Right ms -> return $ second (filter (isRelevant . deEvent)) ms
        Left ioe -> throwError $ LoadError f (show ioe)

isRelevant :: Event
           -> Bool
isRelevant (NOCEvent _) = True
isRelevant (MessageEvent m) = case m of
    Signal {}       -> not senderIsBus
    MethodCall {}   -> none3
    MethodReturn {} -> none3
    Error {}        -> none3
  where
    -- FIXME: really? Maybe we should allow people to be interested in,
    --        say, binding to signals?
    senderIsBus = sender m == busDriver
    destIsBus = destination m == busDriver
    busDriver = O (OtherName dbusName)

    none bs = not $ or bs
    none3 = none [senderIsBus, destIsBus]