@@ -49,7 +49,14 @@ module Control.Distributed.Process.Internal.Types
49 , DidSpawn(..)
49 , DidSpawn(..)
50 , WhereIsReply(..)
50 , WhereIsReply(..)
51 , RegisterReply(..)
51 , RegisterReply(..)
54+ , ProcessInfoNone(..)
55+ -- * Node controller entities required for primatives
56+ , toMarshalledPInfoKey
52 -- * Node controller internal data types
58 -- * Node controller internal data types
59+ , SerializedProcessInfoKey
53 , NCMsg(..)
60 , NCMsg(..)
54 , ProcessSignal(..)
61 , ProcessSignal(..)
55 -- * Accessors
62 -- * Accessors
@@ -68,6 +75,7 @@ module Control.Distributed.Process.Internal.Types
69import System.Mem.Weak (Weak)
76import System.Mem.Weak (Weak)
70import Data.Map (Map)
77import Data.Map (Map)
71import Data.Int (Int32)
79import Data.Int (Int32)
72import Data.Typeable (Typeable)
80import Data.Typeable (Typeable)
73import Data.Binary (Binary(put, get), putWord8, getWord8, encode)
81import Data.Binary (Binary(put, get), putWord8, getWord8, encode)
@@ -420,6 +428,66 @@ data WhereIsReply = WhereIsReply String (Maybe ProcessId)
420data RegisterReply = RegisterReply String Bool
428data RegisterReply = RegisterReply String Bool
421 deriving (Show, Typeable)
429 deriving (Show, Typeable)
431+data ProcessInfoKey =
434+ | ProcessInfoRegisteredNames
435+ | ProcessInfoMessageQueueLength
436+ | ProcessInfoMonitors
438+ deriving (Show, Typeable, Eq)
440+data SerializedProcessInfoKey = SerializedProcessInfoKey Int
442+instance Binary SerializedProcessInfoKey where
443+ put (SerializedProcessInfoKey n) = put n
444+ get = SerializedProcessInfoKey <$> get
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
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"
468+data ProcessInfo = ProcessInfo {
470+ , infoRegisteredNames :: [String]
471+ , infoMessageQueueLength :: Maybe Int
472+ , infoMonitors :: Set (ProcessId, MonitorRef)
473+ , infoLinks :: Set ProcessId
474+ } deriving (Show, Typeable)
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
484+data ProcessInfoNone = ProcessInfoNone DiedReason
485+ deriving (Show, Typeable)
487+instance Binary ProcessInfoNone where
488+ get = ProcessInfoNone <$> get
489+ put (ProcessInfoNone r) = put r
423--------------------------------------------------------------------------------
491--------------------------------------------------------------------------------
424-- Node controller internal data types --
492-- Node controller internal data types --
425--------------------------------------------------------------------------------
493--------------------------------------------------------------------------------
@@ -444,6 +512,7 @@ data ProcessSignal =
444 | NamedSend !String !Message
512 | NamedSend !String !Message
445 | Kill !ProcessId !String
513 | Kill !ProcessId !String
446 | Exit !ProcessId !Message
514 | Exit !ProcessId !Message
515+ | GetInfo !ProcessId
447 deriving Show
516 deriving Show
449--------------------------------------------------------------------------------
518--------------------------------------------------------------------------------
@@ -490,6 +559,7 @@ instance Binary ProcessSignal where
490 put (NamedSend label msg) = putWord8 8 >> put label >> put (messageToPayload msg)
559 put (NamedSend label msg) = putWord8 8 >> put label >> put (messageToPayload msg)
491 put (Kill pid reason) = putWord8 9 >> put pid >> put reason
560 put (Kill pid reason) = putWord8 9 >> put pid >> put reason
492 put (Exit pid reason) = putWord8 10 >> put pid >> put (messageToPayload reason)
561 put (Exit pid reason) = putWord8 10 >> put pid >> put (messageToPayload reason)
562+ put (GetInfo about) = putWord8 30 >> put about
494 header <- getWord8
564 header <- getWord8
495 case header of
565 case header of
@@ -504,6 +574,7 @@ instance Binary ProcessSignal where
504 8 -> NamedSend <$> get <*> (payloadToMessage <$> get)
574 8 -> NamedSend <$> get <*> (payloadToMessage <$> get)
505 9 -> Kill <$> get <*> get
575 9 -> Kill <$> get <*> get
506 10 -> Exit <$> get <*> (payloadToMessage <$> get)
576 10 -> Exit <$> get <*> (payloadToMessage <$> get)
577+ 30 -> GetInfo <$> get
507 _ -> fail "ProcessSignal.get: invalid"
578 _ -> fail "ProcessSignal.get: invalid"
509instance Binary DiedReason where
580instance Binary DiedReason where