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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-
Bustle.Types: defines types used by Bustle
Copyright (C) 2008 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.Types where
import Data.Word (Word32)
import DBus.Message (ReceivedMessage)
type ObjectPath = String
type Interface = String
type MemberName = String
type ErrorName = String
type Serial = Word32
newtype UniqueName = UniqueName { unUniqueName :: String }
deriving (Ord, Show, Eq)
newtype OtherName = OtherName { unOtherName :: String }
deriving (Ord, Show, Eq)
data BusName = U UniqueName
| O OtherName
deriving (Ord, Show, Eq)
isUnique, isOther :: BusName -> Bool
isUnique (U _) = True
isUnique (O _) = False
isOther = not . isUnique
unBusName :: BusName -> String
unBusName (U (UniqueName x)) = x
unBusName (O (OtherName x)) = x
newtype Microseconds = Microseconds Integer
deriving (Show, Ord, Eq, Num, Real, Enum, Integral)
µsFromPair :: Integer
-> Integer
-> Microseconds
µsFromPair s µs = Microseconds $ (s * 1000000) + µs
µsToMs :: Microseconds
-> Integer
µsToMs (Microseconds µs) = µs `div` 1000
data Member = Member { path :: ObjectPath
, iface :: Maybe Interface
, membername :: MemberName
}
deriving (Ord, Show, Read, Eq)
data Message = MethodCall { serial :: Serial
, sender :: BusName
, destination :: BusName
, member :: Member
}
| MethodReturn { inReplyTo :: Maybe DetailedMessage
, sender :: BusName
, destination :: BusName
}
| Signal { sender :: BusName
, signalDestination :: Maybe BusName
, member :: Member
}
| Error { inReplyTo :: Maybe DetailedMessage
, sender :: BusName
, destination :: BusName
}
| Connected { actor :: UniqueName
}
| Disconnected { actor :: UniqueName
}
| NameChanged { changedName :: OtherName
, change :: Change
}
deriving (Show, Eq, Ord)
data DetailedMessage =
DetailedMessage { dmTimestamp :: Microseconds
, dmMessage :: Message
, dmDetails :: Maybe (Int, ReceivedMessage)
}
deriving (Show, Eq)
instance Ord DetailedMessage where
compare (DetailedMessage µs x _) (DetailedMessage µs' y _)
= compare (µs, x) (µs', y)
data Change = Claimed UniqueName
| Stolen UniqueName UniqueName
| Released UniqueName
deriving (Show, Eq, Ord)
isNameOwnerChanged :: Message -> Bool
isNameOwnerChanged (Connected {}) = True
isNameOwnerChanged (Disconnected {}) = True
isNameOwnerChanged (NameChanged {}) = True
isNameOwnerChanged _ = False
type Log = [DetailedMessage]
-- vim: sw=2 sts=2
|