{-# LINE 1 "src/System/Proc/Bindings/Flags/C.hsc" #-}


module System.Proc.Bindings.Flags.C
  ( -- * Binary flags
    Flags (..)
  , flagsAsInt
  )
where

import Data.Bits
import Data.Foldable
import Foreign.C.Types

------------------------------------------------------------
-- Binary flags

{- | What information do we want about the processes?

This type will be translated into a C @int@ to be passed to the underlying library
(see 'flagsAsInt').

It's easiest to construct these using the 'Semigroup' instance:

@
myFlags :: 'Flags'
myFlags =
  'System.Proc.Bindings.Tab.Config.fillMem'
    <> 'System.Proc.Bindings.Tab.Config.fillCom'
    <> 'System.Proc.Bindings.Tab.Config.fillEnv'
    <> 'System.Proc.Bindings.Tab.Config.fillUser'
    <> 'System.Proc.Bindings.Tab.Config.fillGroup'
@
-}
data Flags = Flags
  { -- | Read @\/proc\/#\/statm@?
    Flags -> Bool
flagMem :: Bool
  , -- | Read @\/proc\/#\/cmdline@?
    Flags -> Bool
flagCom :: Bool
  , -- | Read @\/proc\/#\/environ@?
    Flags -> Bool
flagEnv :: Bool
  , -- | Resolve user id number -> user name?
    Flags -> Bool
flagUser :: Bool
  , -- | Resolve group id number -> group name?
    Flags -> Bool
flagGroup :: Bool
  , -- | Read @\/proc\/#\/status@?
    Flags -> Bool
flagStatus :: Bool
  , -- | Read @\/proc\/#\/stat@?
    Flags -> Bool
flagStat :: Bool
  , -- | Read @\/proc\/#\/cmdline@?
    Flags -> Bool
flagArg :: Bool
  , -- | Read @\/proc\/#\/cgroup@?
    Flags -> Bool
flagCGroup :: Bool
  , -- | Resolve supplementary group id -> group name?
    Flags -> Bool
flagSupGroup :: Bool
  , -- | Read @\/proc\/#\/oom_{score,adj}@?
    Flags -> Bool
flagOOM :: Bool
  , -- | Read @\/proc\/#\/ns/@?
    Flags -> Bool
flagNS :: Bool
  , -- | Read systemd information?
    Flags -> Bool
flagSystemd :: Bool
  , -- | Read LXC name, if possible?
    Flags -> Bool
flagLxc :: Bool
  , -- | Treat threads as if they were processes?
    Flags -> Bool
flagLooseTasks :: Bool
  , -- | Edit @cgroup@ as a single vector?
    Flags -> Bool
flagEditCGroupSingleVector :: Bool
  , -- | Edit @cmdline@ as a single vector?
    Flags -> Bool
flagEditCmdlineSingleVector :: Bool
  , -- | Edit @environ@ as a single vector?
    Flags -> Bool
flagEditEnvironSingleVector :: Bool
  }
  deriving (Int -> Flags -> ShowS
[Flags] -> ShowS
Flags -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Flags] -> ShowS
$cshowList :: [Flags] -> ShowS
show :: Flags -> String
$cshow :: Flags -> String
showsPrec :: Int -> Flags -> ShowS
$cshowsPrec :: Int -> Flags -> ShowS
Show, Flags -> Flags -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Flags -> Flags -> Bool
$c/= :: Flags -> Flags -> Bool
== :: Flags -> Flags -> Bool
$c== :: Flags -> Flags -> Bool
Eq)

{- | Translate our nice haskell 'Flags' type into a C @int@. Basically a bitwise @OR@ of
the fields (see all the lines at the end of @readproc.h@ starting with @#define PROC_@).
-}
flagsAsInt :: Flags -> CInt
flagsAsInt :: Flags -> CInt
flagsAsInt Flags {Bool
flagEditEnvironSingleVector :: Bool
flagEditCmdlineSingleVector :: Bool
flagEditCGroupSingleVector :: Bool
flagLooseTasks :: Bool
flagLxc :: Bool
flagSystemd :: Bool
flagNS :: Bool
flagOOM :: Bool
flagSupGroup :: Bool
flagCGroup :: Bool
flagArg :: Bool
flagStat :: Bool
flagStatus :: Bool
flagGroup :: Bool
flagUser :: Bool
flagEnv :: Bool
flagCom :: Bool
flagMem :: Bool
flagEditEnvironSingleVector :: Flags -> Bool
flagEditCmdlineSingleVector :: Flags -> Bool
flagEditCGroupSingleVector :: Flags -> Bool
flagLooseTasks :: Flags -> Bool
flagLxc :: Flags -> Bool
flagSystemd :: Flags -> Bool
flagNS :: Flags -> Bool
flagOOM :: Flags -> Bool
flagSupGroup :: Flags -> Bool
flagCGroup :: Flags -> Bool
flagArg :: Flags -> Bool
flagStat :: Flags -> Bool
flagStatus :: Flags -> Bool
flagGroup :: Flags -> Bool
flagUser :: Flags -> Bool
flagEnv :: Flags -> Bool
flagCom :: Flags -> Bool
flagMem :: Flags -> Bool
..} =
  forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' CInt -> (Bool, CInt) -> CInt
f (CInt
0 :: CInt) [(Bool, CInt)]
bits
  where
    f :: CInt -> (Bool, CInt) -> CInt
    f :: CInt -> (Bool, CInt) -> CInt
f CInt
acc (Bool
False, CInt
_) = CInt
acc
    f CInt
acc (Bool
True, CInt
fl) = CInt
acc forall a. Bits a => a -> a -> a
.|. CInt
fl

    bits :: [(Bool, CInt)]
bits =
      [ (Bool
flagMem, CInt
1)
{-# LINE 87 "src/System/Proc/Bindings/Flags/C.hsc" #-}
      , (Bool
flagCom, CInt
2)
{-# LINE 88 "src/System/Proc/Bindings/Flags/C.hsc" #-}
      , (Bool
flagEnv, CInt
4)
{-# LINE 89 "src/System/Proc/Bindings/Flags/C.hsc" #-}
      , (Bool
flagUser, CInt
8)
{-# LINE 90 "src/System/Proc/Bindings/Flags/C.hsc" #-}
      , (Bool
flagGroup, CInt
16)
{-# LINE 91 "src/System/Proc/Bindings/Flags/C.hsc" #-}
      , (Bool
flagStatus, CInt
32)
{-# LINE 92 "src/System/Proc/Bindings/Flags/C.hsc" #-}
      , (Bool
flagStat, CInt
64)
{-# LINE 93 "src/System/Proc/Bindings/Flags/C.hsc" #-}
      , (Bool
flagArg, CInt
256)
{-# LINE 94 "src/System/Proc/Bindings/Flags/C.hsc" #-}
      , (Bool
flagCGroup, CInt
512)
{-# LINE 95 "src/System/Proc/Bindings/Flags/C.hsc" #-}
      , (Bool
flagSupGroup, CInt
1024)
{-# LINE 96 "src/System/Proc/Bindings/Flags/C.hsc" #-}
      , (Bool
flagOOM, CInt
2048)
{-# LINE 97 "src/System/Proc/Bindings/Flags/C.hsc" #-}
      , (Bool
flagNS, CInt
32768)
{-# LINE 98 "src/System/Proc/Bindings/Flags/C.hsc" #-}
      , (Bool
flagSystemd, CInt
524288)
{-# LINE 99 "src/System/Proc/Bindings/Flags/C.hsc" #-}
      , (Bool
flagLxc, CInt
8388608)
{-# LINE 100 "src/System/Proc/Bindings/Flags/C.hsc" #-}
      , (Bool
flagLooseTasks, CInt
8192)
{-# LINE 101 "src/System/Proc/Bindings/Flags/C.hsc" #-}
      , (Bool
flagEditCGroupSingleVector, CInt
65536)
{-# LINE 102 "src/System/Proc/Bindings/Flags/C.hsc" #-}
      , (Bool
flagEditCmdlineSingleVector, CInt
131072)
{-# LINE 103 "src/System/Proc/Bindings/Flags/C.hsc" #-}
      , (Bool
flagEditEnvironSingleVector, CInt
262144)
{-# LINE 104 "src/System/Proc/Bindings/Flags/C.hsc" #-}
      ]

instance Semigroup Flags where
  Flags
f1 <> :: Flags -> Flags -> Flags
<> Flags
f2 =
    Flags
      { flagMem :: Bool
flagMem = Flags -> Bool
flagMem Flags
f1 Bool -> Bool -> Bool
|| Flags -> Bool
flagMem Flags
f2
      , flagCom :: Bool
flagCom = Flags -> Bool
flagCom Flags
f1 Bool -> Bool -> Bool
|| Flags -> Bool
flagCom Flags
f2
      , flagEnv :: Bool
flagEnv = Flags -> Bool
flagEnv Flags
f1 Bool -> Bool -> Bool
|| Flags -> Bool
flagEnv Flags
f2
      , flagUser :: Bool
flagUser = Flags -> Bool
flagUser Flags
f1 Bool -> Bool -> Bool
|| Flags -> Bool
flagUser Flags
f2
      , flagGroup :: Bool
flagGroup = Flags -> Bool
flagGroup Flags
f1 Bool -> Bool -> Bool
|| Flags -> Bool
flagGroup Flags
f2
      , flagStatus :: Bool
flagStatus = Flags -> Bool
flagStatus Flags
f1 Bool -> Bool -> Bool
|| Flags -> Bool
flagStatus Flags
f2
      , flagStat :: Bool
flagStat = Flags -> Bool
flagStat Flags
f1 Bool -> Bool -> Bool
|| Flags -> Bool
flagStat Flags
f2
      , flagArg :: Bool
flagArg = Flags -> Bool
flagArg Flags
f1 Bool -> Bool -> Bool
|| Flags -> Bool
flagArg Flags
f2
      , flagCGroup :: Bool
flagCGroup = Flags -> Bool
flagCGroup Flags
f1 Bool -> Bool -> Bool
|| Flags -> Bool
flagCGroup Flags
f2
      , flagSupGroup :: Bool
flagSupGroup = Flags -> Bool
flagSupGroup Flags
f1 Bool -> Bool -> Bool
|| Flags -> Bool
flagSupGroup Flags
f2
      , flagOOM :: Bool
flagOOM = Flags -> Bool
flagOOM Flags
f1 Bool -> Bool -> Bool
|| Flags -> Bool
flagOOM Flags
f2
      , flagNS :: Bool
flagNS = Flags -> Bool
flagNS Flags
f1 Bool -> Bool -> Bool
|| Flags -> Bool
flagNS Flags
f2
      , flagSystemd :: Bool
flagSystemd = Flags -> Bool
flagSystemd Flags
f1 Bool -> Bool -> Bool
|| Flags -> Bool
flagSystemd Flags
f2
      , flagLxc :: Bool
flagLxc = Flags -> Bool
flagLxc Flags
f1 Bool -> Bool -> Bool
|| Flags -> Bool
flagLxc Flags
f2
      , flagLooseTasks :: Bool
flagLooseTasks = Flags -> Bool
flagLooseTasks Flags
f1 Bool -> Bool -> Bool
|| Flags -> Bool
flagLooseTasks Flags
f2
      , flagEditCGroupSingleVector :: Bool
flagEditCGroupSingleVector = Flags -> Bool
flagEditCGroupSingleVector Flags
f1 Bool -> Bool -> Bool
|| Flags -> Bool
flagEditCGroupSingleVector Flags
f2
      , flagEditCmdlineSingleVector :: Bool
flagEditCmdlineSingleVector = Flags -> Bool
flagEditCmdlineSingleVector Flags
f1 Bool -> Bool -> Bool
|| Flags -> Bool
flagEditCmdlineSingleVector Flags
f2
      , flagEditEnvironSingleVector :: Bool
flagEditEnvironSingleVector = Flags -> Bool
flagEditEnvironSingleVector Flags
f1 Bool -> Bool -> Bool
|| Flags -> Bool
flagEditEnvironSingleVector Flags
f2
      }

instance Monoid Flags where
  mempty :: Flags
mempty =
    Flags
      { flagMem :: Bool
flagMem = Bool
False
      , flagCom :: Bool
flagCom = Bool
False
      , flagEnv :: Bool
flagEnv = Bool
False
      , flagUser :: Bool
flagUser = Bool
False
      , flagGroup :: Bool
flagGroup = Bool
False
      , flagStatus :: Bool
flagStatus = Bool
False
      , flagStat :: Bool
flagStat = Bool
False
      , flagArg :: Bool
flagArg = Bool
False
      , flagCGroup :: Bool
flagCGroup = Bool
False
      , flagSupGroup :: Bool
flagSupGroup = Bool
False
      , flagOOM :: Bool
flagOOM = Bool
False
      , flagNS :: Bool
flagNS = Bool
False
      , flagSystemd :: Bool
flagSystemd = Bool
False
      , flagLxc :: Bool
flagLxc = Bool
False
      , flagLooseTasks :: Bool
flagLooseTasks = Bool
False
      , flagEditCGroupSingleVector :: Bool
flagEditCGroupSingleVector = Bool
False
      , flagEditCmdlineSingleVector :: Bool
flagEditCmdlineSingleVector = Bool
False
      , flagEditEnvironSingleVector :: Bool
flagEditEnvironSingleVector = Bool
False
      }