diff -r 98ff50f8a25d -r 58e042a191a9 GDBSessionRecord.st --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/GDBSessionRecord.st Tue Jun 24 00:55:57 2014 +0100 @@ -0,0 +1,242 @@ +"{ Package: 'jv:libgdbs' }" + +OrderedCollection subclass:#GDBSessionRecord + instanceVariableNames:'lock' + classVariableNames:'' + poolDictionaries:'' + category:'GDB-Private-Simulator' +! + +Object subclass:#Command + instanceVariableNames:'string' + classVariableNames:'' + poolDictionaries:'' + privateIn:GDBSessionRecord +! + +Object subclass:#Response + instanceVariableNames:'string' + classVariableNames:'' + poolDictionaries:'' + privateIn:GDBSessionRecord +! + +!GDBSessionRecord class methodsFor:'instance creation'! + +new + ^ super new initialize. + + "Created: / 24-06-2014 / 00:07:32 / Jan Vrany " +! + +new: size + "return an initialized instance" + + ^ (super new: size) initialize. + + "Created: / 24-06-2014 / 00:06:29 / Jan Vrany " +! ! + +!GDBSessionRecord methodsFor:'adding & removing'! + +add:anObject + "add the argument, anObject to the end of the collection + Return the argument, anObject." + + ^ lock critical:[ + super add:anObject + ]. + + "Modified: / 29-01-1998 / 10:52:32 / cg" + "Modified: / 23-06-2014 / 23:55:20 / Jan Vrany " +! + +add:anObject beforeIndex:index + "add the argument, anObject to the end of the collection. + Return the receiver (sigh - ST-80 compatibility)." + + ^ lock critical:[ + super add:anObject beforeIndex:index + ]. + + "Modified: / 23-06-2014 / 23:55:33 / Jan Vrany " +! + +addAll:aCollection beforeIndex:index + "insert all elements of the argument + Return the receiver." + + ^ lock critical:[ + super addAll:aCollection beforeIndex:index + ]. + + "Modified: / 23-06-2014 / 23:55:51 / Jan Vrany " +! + +addAllLast:aCollection + "add all elements of the argument, aCollection to the end of the collection. + Return the argument, aCollection." + + ^ lock critical:[ + super addAllLast:aCollection + ]. + + "Modified: / 23-06-2014 / 23:56:55 / Jan Vrany " +! + +addFirst:anObject + "add the argument, anObject to the beginning of the collection. + Return the argument, anObject." + + ^ lock critical:[ + super addFirst:anObject + ]. + + "Modified: / 29-01-1998 / 10:53:09 / cg" + "Modified: / 23-06-2014 / 23:56:49 / Jan Vrany " +! ! + +!GDBSessionRecord methodsFor:'initialization'! + +initialize + "Invoked when a new instance is created." + + "/ please change as required (and remove this comment) + super initialize. + lock := RecursionLock new. + + "/ super initialize. -- commented since inherited method does nothing + + "Modified: / 24-06-2014 / 00:05:14 / Jan Vrany " +! ! + +!GDBSessionRecord methodsFor:'printing & storing'! + +printOn:aStream + self do:[:each | each printOn: aStream ] + + "Modified: / 23-06-2014 / 23:51:17 / Jan Vrany " +! ! + +!GDBSessionRecord methodsFor:'recording'! + +<<< aString + self add: (Response new string: aString) + + "Created: / 24-06-2014 / 00:35:42 / Jan Vrany " +! + +>>> aString + self add: (Command new string: aString) + + "Created: / 24-06-2014 / 00:35:31 / Jan Vrany " +! ! + +!GDBSessionRecord methodsFor:'saving & restoring'! + +saveInClass: class selector: selector + "Save recorded session in given class under given selector" + + | source | + + source := String new writeStream. + source nextPutAll: selector; cr; cr. + source nextPutAll:' ^ (GDBSessionRecord new: '. + self size printOn: source. + source nextPutAll: ')'; cr; cr. + + self do:[:each | + each isCommand ifTrue:[ + source nextPutLine: '>>>'. + ] ifFalse:[ + source nextPutLine: '<<<'. + ]. + each string storeOn: source. + source nextPut: $;; cr; cr. + ]. + source nextPutAll: 'yourself'. + + class compile: source contents classified: 'recorded sessions' + + "Created: / 23-06-2014 / 23:14:03 / Jan Vrany " + "Modified: / 24-06-2014 / 00:44:07 / Jan Vrany " +! + +saveInSimulatorResourceAs: selector + ^ self saveInClass: GDBSimulatorResource selector: selector + + "Created: / 23-06-2014 / 23:17:34 / Jan Vrany " +! ! + +!GDBSessionRecord::Command methodsFor:'accessing'! + +string + ^ string +! + +string:something + string := something. +! ! + +!GDBSessionRecord::Command methodsFor:'printing & storing'! + +printOn:aStream + "append a printed representation if the receiver to the argument, aStream" + + aStream nextPutLine: '>>>'. + string printOn: aStream. + aStream cr. + + "Modified: / 24-06-2014 / 00:09:01 / Jan Vrany " +! ! + +!GDBSessionRecord::Command methodsFor:'testing'! + +isCommand + ^ true + + "Created: / 24-06-2014 / 00:41:35 / Jan Vrany " +! + +isResponse + ^ false + + "Created: / 24-06-2014 / 00:41:41 / Jan Vrany " +! ! + +!GDBSessionRecord::Response methodsFor:'accessing'! + +string + ^ string +! + +string:something + string := something. +! ! + +!GDBSessionRecord::Response methodsFor:'printing & storing'! + +printOn:aStream + "append a printed representation if the receiver to the argument, aStream" + + aStream nextPutLine: '<<<'. + string printOn: aStream. + aStream cr. + + "Modified: / 24-06-2014 / 00:08:28 / Jan Vrany " +! ! + +!GDBSessionRecord::Response methodsFor:'testing'! + +isCommand + ^ false + + "Created: / 24-06-2014 / 00:41:35 / Jan Vrany " +! + +isResponse + ^ true + + "Created: / 24-06-2014 / 00:41:41 / Jan Vrany " +! ! +