47 lines
1006 B
Go
47 lines
1006 B
Go
package prog
|
|
|
|
import (
|
|
"encoding/xml"
|
|
)
|
|
|
|
// ProcessList is a map of processes' statuses.
|
|
type ProcessList map[string]bool
|
|
|
|
// NewProcessList returns a ProcessList with initialised map.
|
|
func NewProcessList() *ProcessList {
|
|
pl := make(ProcessList)
|
|
return &pl
|
|
}
|
|
|
|
// AddProcess appends a process to a ProcessList
|
|
func (pl *ProcessList) AddProcess(name string, isup bool) {
|
|
(*pl)[name] = isup
|
|
}
|
|
|
|
// ProcessXMLEntry is a XML representation of a process stored in ProcessList.
|
|
type ProcessXMLEntry struct {
|
|
XMLName xml.Name
|
|
Name string `xml:"name,attr"`
|
|
IsUp bool `xml:",chardata"`
|
|
}
|
|
|
|
// MarshalXML implements Marshaler interface for a ProcessList.
|
|
func (l ProcessList) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
|
|
if len(l) == 0 {
|
|
return nil
|
|
}
|
|
|
|
if err := e.EncodeToken(start); err != nil {
|
|
return err
|
|
}
|
|
|
|
for key, val := range l {
|
|
e.Encode(ProcessXMLEntry{
|
|
XMLName: xml.Name{Local: "Process"},
|
|
Name: key,
|
|
IsUp: val})
|
|
}
|
|
|
|
return e.EncodeToken(start.End())
|
|
}
|