1
0
Fork 0

msg: Attempt to generalize the MSG Structure class

If things turn out this will be the base for ASN1,
GSM, ISUP, BSSAP, SCCP and the other protocols
This commit is contained in:
Holger Hans Peter Freyther 2011-03-03 20:41:57 +01:00
parent 004c0765d3
commit 7fb9b427f8
2 changed files with 151 additions and 0 deletions

149
MSG.st Normal file
View File

@ -0,0 +1,149 @@
"
(C) 2011 by Holger Hans Peter Freyther
All Rights Reserved
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"
"
The next attempt to generalize the message pattern. We will just describe
messages that have a type, mandantory and optional parameters. The parameters
will be simple ids. There should be code to generate nice parsing routines
"
Object subclass: MSGStructure [
| type mandantory variable optional |
<comment: 'Attempt to have a DSL for messages'>
MSGStructure class >> initWith: aType [
^ self new
instVarNamed: #type put: aType; yourself
]
type [
<category: 'The type of this message'>
^ type
]
addMandantory: aType [
self mandantory add: aType.
]
addOptional: aType [
self optional add: aType.
]
addOptionals: aType [
"Optional Parameters that may appear more than once."
self optional add: aType.
]
addVariable: aType [
self variable add: aType.
]
mandantory [
<category: 'private'>
^ mandantory ifNil: [mandantory := OrderedCollection new]
]
variable [
<category: 'private'>
^ variable ifNil: [variable := OrderedCollection new]
]
optional [
<category: 'private'>
^ optional ifNil: [optional := OrderedCollection new]
]
]
Object subclass: MSGField [
<category: 'osmo-networking'>
<comment: 'The description of a Information Element'>
| par name length maxLength |
name [
<category: 'accessing'>
^ name
]
parameterValue [
<category: 'accessing'>
^ par
]
octalLength [
<category: 'accessing'>
^ length
]
maxLength [
<category: 'accessing'>
^ maxLength
]
isVarible [
"If this field is variable in length"
^ self subclassResponsibility
]
isFixed [
"If this field is of a fixed length"
^ self subclassResponsibility
]
]
Object subclass: MSGFixedField [
MSGFixedField class [
initWith: aName parameter: aParm octalLength: aLen [
^ self new
instVarNamed: #name put: aName;
instVarNamed: #par put: aParm;
instVarNamed: #length put: aLen;
yourself
]
]
isVarible [ ^ false ]
isFixed [ ^ true ]
]
Object subclass: MSGVariableField [
MSGVariableField class [
initWith: aName parameter: aParm
minOctalLength: aLen [
^ self new
instVarNamed: #name put: aName;
instVarNamed: #par put: aParm;
instVarNamed: #length put: aLen;
yourself
]
initWith: aName parameter: aParm
minOctalLength: aMin maxOctalLength: aMax [
^ self new
instVarNamed: #name put: aName;
instVarNamed: #par put: aParm;
instVarNamed: #length put: aMin;
instVarNamed: #maxLength put: aMax;
yourself
]
]
isVarible [ ^ true ]
isFixed [ ^ false ]
]

View File

@ -5,6 +5,7 @@
<prereq>OsmoLogging</prereq>
<filein>Extensions.st</filein>
<filein>MSG.st</filein>
<filein>ISUP.st</filein>
<filein>IPAConstants.st</filein>
<filein>IPADispatcher.st</filein>
@ -25,6 +26,7 @@
<file>Extensions.st</file>
<file>MSG.st</file>
<file>ISUP.st</file>
<file>IPAConstants.st</file>
<file>IPADispatcher.st</file>