@@ -49,7 +49,14 @@ module Control.Distributed.Process.Internal.Types
4949 , DidSpawn(..)
5050 , WhereIsReply(..)
5151 , RegisterReply(..)
52+ , ProcessInfo(..)
53+ , ProcessInfoKey
54+ , ProcessInfoNone(..)
55+ -- * Node controller entities required for primatives
56+ , toMarshalledPInfoKey
57+ , toPInfoKey
5258 -- * Node controller internal data types
59+ , SerializedProcessInfoKey
5360 , NCMsg(..)
5461 , ProcessSignal(..)
5562 -- * Accessors
@@ -68,6 +75,7 @@ module Control.Distributed.Process.Internal.Types
6875
6976import System.Mem.Weak (Weak)
7077import Data.Map (Map)
78+import Data.Set (Set)
7179import Data.Int (Int32)
7280import Data.Typeable (Typeable)
7381import Data.Binary (Binary(put, get), putWord8, getWord8, encode)
@@ -420,6 +428,66 @@ data WhereIsReply = WhereIsReply String (Maybe ProcessId)
420428data RegisterReply = RegisterReply String Bool
421429 deriving (Show, Typeable)
422430
431+data ProcessInfoKey =
432+ ProcessInfoAll
433+ | ProcessInfoNode
434+ | ProcessInfoRegisteredNames
435+ | ProcessInfoMessageQueueLength
436+ | ProcessInfoMonitors
437+ | ProcessInfoLinks
438+ deriving (Show, Typeable, Eq)
439+
440+data SerializedProcessInfoKey = SerializedProcessInfoKey Int
441+
442+instance Binary SerializedProcessInfoKey where
443+ put (SerializedProcessInfoKey n) = put n
444+ get = SerializedProcessInfoKey <$> get
445+
446+-- | Convert 'ProcessInfoKey' to/from 'SerializedProcessInfoKey'
447+toMarshalledPInfoKey :: ProcessInfoKey -> SerializedProcessInfoKey
448+toMarshalledPInfoKey ProcessInfoAll = SerializedProcessInfoKey 1
449+toMarshalledPInfoKey ProcessInfoNode = SerializedProcessInfoKey 2
450+toMarshalledPInfoKey ProcessInfoRegisteredNames = SerializedProcessInfoKey 3
451+toMarshalledPInfoKey ProcessInfoMessageQueueLength = SerializedProcessInfoKey 4
452+toMarshalledPInfoKey ProcessInfoMonitors = SerializedProcessInfoKey 5
453+toMarshalledPInfoKey ProcessInfoLinks = SerializedProcessInfoKey 6
454+
455+-- | Convert 'SerializedProcessInfoKey' back into 'ProcessInfoKey'
456+toPInfoKey :: SerializedProcessInfoKey -> ProcessInfoKey
457+toPInfoKey (SerializedProcessInfoKey n)
458+ | n == 1 = ProcessInfoAll
459+ | n == 2 = ProcessInfoNode
460+ | n == 3 = ProcessInfoRegisteredNames
461+ | n == 4 = ProcessInfoMessageQueueLength
462+ | n == 5 = ProcessInfoMonitors
463+ | n == 6 = ProcessInfoLinks
464+ -- using error is usually madness, but here represents a bit of complete
465+ -- stupidity or a deliberate attack, so how *should* we handle this?
466+ | otherwise = error "Illegal ProcessInfoKey Value"
467+
468+data ProcessInfo = ProcessInfo {
469+ infoNode :: NodeId
470+ , infoRegisteredNames :: [String]
471+ , infoMessageQueueLength :: Maybe Int
472+ , infoMonitors :: Set (ProcessId, MonitorRef)
473+ , infoLinks :: Set ProcessId
474+ } deriving (Show, Typeable)
475+
476+instance Binary ProcessInfo where
477+ get = ProcessInfo <$> get <*> get <*> get <*> get <*> get
478+ put = put . infoNode
479+ >> put . infoRegisteredNames
480+ >> put . infoMessageQueueLength
481+ >> put . infoMonitors
482+ >> put . infoLinks
483+
484+data ProcessInfoNone = ProcessInfoNone DiedReason
485+ deriving (Show, Typeable)
486+
487+instance Binary ProcessInfoNone where
488+ get = ProcessInfoNone <$> get
489+ put (ProcessInfoNone r) = put r
490+
423491--------------------------------------------------------------------------------
424492-- Node controller internal data types --
425493--------------------------------------------------------------------------------
@@ -444,6 +512,7 @@ data ProcessSignal =
444512 | NamedSend !String !Message
445513 | Kill !ProcessId !String
446514 | Exit !ProcessId !Message
515+ | GetInfo !ProcessId
447516 deriving Show
448517
449518--------------------------------------------------------------------------------
@@ -490,6 +559,7 @@ instance Binary ProcessSignal where
490559 put (NamedSend label msg) = putWord8 8 >> put label >> put (messageToPayload msg)
491560 put (Kill pid reason) = putWord8 9 >> put pid >> put reason
492561 put (Exit pid reason) = putWord8 10 >> put pid >> put (messageToPayload reason)
562+ put (GetInfo about) = putWord8 30 >> put about
493563 get = do
494564 header <- getWord8
495565 case header of
@@ -504,6 +574,7 @@ instance Binary ProcessSignal where
504574 8 -> NamedSend <$> get <*> (payloadToMessage <$> get)
505575 9 -> Kill <$> get <*> get
506576 10 -> Exit <$> get <*> (payloadToMessage <$> get)
577+ 30 -> GetInfo <$> get
507578 _ -> fail "ProcessSignal.get: invalid"
508579
509580instance Binary DiedReason where