set priority to optional (was extra)
[debian/orchestra.git] / src / conductor / job_scope.go
1 // job_scope.go
2
3 package main
4
5 import (
6         "os"
7         "json"
8 )
9
10 const (
11         SCOPE_INVALID           = JobScope(iota)
12         SCOPE_ONEOF
13         SCOPE_ALLOF
14 )
15
16 type JobScope int
17
18 func (js JobScope) String() (strout string) {
19         switch js {
20         case SCOPE_ONEOF:
21                 strout = "one"
22         case SCOPE_ALLOF:
23                 strout = "all"
24         default:
25                 strout = ""
26         }
27         return strout
28 }
29
30 func (js JobScope) MarshalJSON() (out []byte, err os.Error) {
31         strout := js.String()
32         if strout != "" {
33                 return json.Marshal(strout)
34         }
35         return nil, InvalidValueError
36 }
37
38 func (js *JobScope) UnmarshalJSON(in []byte) (err os.Error) {
39         var scopestr string
40         err = json.Unmarshal(in, &scopestr)
41         if err != nil {
42                 return err
43         }
44         switch scopestr {
45         case "one":
46                 *js = SCOPE_ONEOF
47         case "all":
48                 *js = SCOPE_ALLOF
49         default:
50                 return InvalidValueError
51         }
52         return nil
53 }