Harald Welte | a76c4bb | 2017-12-09 02:06:07 +0100 | [diff] [blame] | 1 | module Osmocom_CTRL_Types { |
| 2 | |
| 3 | type charstring CtrlVerb ("GET", "SET") with { |
| 4 | /* see https://www.eclipse.org/forums/index.php/t/1088893/ on why this |
| 5 | * match expression is needed here */ |
Harald Welte | fdfa046 | 2017-12-10 18:09:40 +0100 | [diff] [blame] | 6 | variant "TEXT_CODING(,convert=upper_case,'((GET)|(SET))',case_insensitive)" |
Harald Welte | a76c4bb | 2017-12-09 02:06:07 +0100 | [diff] [blame] | 7 | }; |
| 8 | |
Harald Welte | 03c0e56 | 2017-12-09 02:55:12 +0100 | [diff] [blame] | 9 | type charstring CtrlReplyVerb ("GET_REPLY", "SET_REPLY") with { |
| 10 | variant "TEXT_CODING(,convert=upper_case,'((GET_REPLY)|(SET_REPLY))',case_insensitive)" |
Harald Welte | a76c4bb | 2017-12-09 02:06:07 +0100 | [diff] [blame] | 11 | }; |
| 12 | |
| 13 | type charstring CtrlId (pattern "\d#(1,9)"); |
Harald Welte | 0ac4667 | 2017-12-09 14:19:58 +0100 | [diff] [blame] | 14 | type charstring CtrlVariable (pattern "[^, \{\}\[\]\(\)<>\|~\\\^`'\"\?=;/\+&%$\#!]#(1,)"); |
| 15 | type charstring CtrlValue (pattern "[^ ]#(0,)"); |
Harald Welte | a76c4bb | 2017-12-09 02:06:07 +0100 | [diff] [blame] | 16 | type charstring CtrlReason; |
| 17 | |
| 18 | |
| 19 | type record CtrlCommand { |
| 20 | CtrlVerb verb, |
| 21 | CtrlId id, |
| 22 | CtrlVariable variable, |
| 23 | CtrlValue val optional /* only for SET */ |
| 24 | } with { |
| 25 | variant "SEPARATOR(' ',)" |
| 26 | }; |
| 27 | |
| 28 | type record CtrlResponse { |
Harald Welte | 03c0e56 | 2017-12-09 02:55:12 +0100 | [diff] [blame] | 29 | CtrlReplyVerb verb, |
Harald Welte | a76c4bb | 2017-12-09 02:06:07 +0100 | [diff] [blame] | 30 | CtrlId id, |
| 31 | CtrlVariable variable, |
| 32 | CtrlValue val |
| 33 | } with { |
Harald Welte | a76c4bb | 2017-12-09 02:06:07 +0100 | [diff] [blame] | 34 | variant "SEPARATOR(' ',)" |
| 35 | }; |
| 36 | |
| 37 | type record CtrlError { |
| 38 | CtrlId id, |
| 39 | CtrlReason reason |
| 40 | } with { |
| 41 | variant "BEGIN('ERROR ',,case_insensitive)" |
| 42 | variant "SEPARATOR(' ',)" |
| 43 | }; |
| 44 | |
| 45 | type record CtrlTrap { |
| 46 | CtrlVariable variable, |
| 47 | CtrlValue val |
| 48 | } with { |
Harald Welte | fdfa046 | 2017-12-10 18:09:40 +0100 | [diff] [blame] | 49 | variant "BEGIN('TRAP 0 ',,case_insensitive)" |
Harald Welte | a76c4bb | 2017-12-09 02:06:07 +0100 | [diff] [blame] | 50 | variant "SEPARATOR(' ',)" |
| 51 | }; |
| 52 | |
| 53 | type union CtrlMessage { |
| 54 | CtrlCommand cmd, |
| 55 | CtrlResponse resp, |
| 56 | CtrlError err, |
| 57 | CtrlTrap trap |
Harald Welte | 1697976 | 2017-12-13 00:45:44 +0100 | [diff] [blame] | 58 | } with { variant "BEGIN('')" }; |
Harald Welte | a76c4bb | 2017-12-09 02:06:07 +0100 | [diff] [blame] | 59 | |
| 60 | external function enc_CtrlMessage(in CtrlMessage id) return charstring |
| 61 | with { extension "prototype(convert) encode(TEXT)"}; |
| 62 | |
| 63 | external function dec_CtrlMessage(in charstring id) return CtrlMessage |
| 64 | with { extension "prototype(convert) decode(TEXT)"}; |
| 65 | |
| 66 | |
Harald Welte | 03c0e56 | 2017-12-09 02:55:12 +0100 | [diff] [blame] | 67 | template CtrlMessage ts_CtrlMsgGet(CtrlId id, CtrlVariable variable) := { |
| 68 | cmd := { |
| 69 | verb := "GET", |
| 70 | id := id, |
| 71 | variable := variable, |
| 72 | val := omit |
| 73 | } |
| 74 | }; |
| 75 | |
| 76 | template CtrlMessage ts_CtrlMsgSet(CtrlId id, CtrlVariable variable, CtrlValue val) := { |
| 77 | cmd := { |
| 78 | verb := "SET", |
| 79 | id := id, |
| 80 | variable := variable, |
| 81 | val := omit |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | template CtrlMessage tr_CtrlMsgGetRepl(template CtrlId id, template CtrlVariable variable := ?) := { |
| 86 | resp := { |
| 87 | verb := "GET_REPLY", |
| 88 | id := id, |
| 89 | variable := variable, |
| 90 | val := ? |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | template CtrlMessage tr_CtrlMsgSetRepl(template CtrlId id, template CtrlVariable variable := ?, |
| 95 | template CtrlValue val := ?) := { |
| 96 | resp := { |
| 97 | verb := "SET_REPLY", |
| 98 | id := id, |
| 99 | variable := variable, |
| 100 | val := val |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | template CtrlMessage tr_CtrlMsgTrap(template CtrlVariable variable := ?, |
| 105 | template CtrlValue val := ?) := { |
| 106 | trap := { |
| 107 | variable := variable, |
| 108 | val := val |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | template CtrlMessage tr_CtrlMsgError(template CtrlId id := ?, template CtrlReason reason := ?) := { |
| 113 | err := { |
| 114 | id := id, |
| 115 | reason := reason |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | |
Harald Welte | a76c4bb | 2017-12-09 02:06:07 +0100 | [diff] [blame] | 120 | } with { encode "TEXT" } |