Hello all,

I might have it.  I have been having a bad time trying to make a change set 
with the relevant code.  I tried that because I have to carefully go over 
"everything" before I release it; I trust YOU<g>, but need to be careful what I 
open to public view.  For now, hopefully an interested party can simply look at 
the code to see if it might be of interest.

A class called SessionManager registers itself for the startup and shutdown 
list, and attempts to forward only the true session starts and stops to a 
current instance.  That instance does some mild sanity checking and triggers 
#sessionStarted and #sessionStopped events.  I also added #initializeNetwork so 
I would not have to remember to do that all the time (am I the only one 
bothered by the need for that??).  With adequate testing, something like this 
would allow Pharo to know when it is coming and going, improving the handling 
of external resources and IMHO being almost essential for using native widgets.

The attached change set does not seem to want to file in, I think because one 
of the classes is not defined early enough for it to work.  It's a little late 
on a Friday to be smashing something silly like that.  I will take another look 
at it later.  It might also suffice to check and release my 
DolphinCompatibility package.

Bill


'From Pharo0.1 of 16 May 2008 [Latest update: #10373] on 28 August 2009 at 
4:27:27 pm'!
Object subclass: #SessionManager
        instanceVariableNames: 'sessionStart'
        classVariableNames: 'Current'
        poolDictionaries: ''
        category: 'Dolphincompatibility-Idioms'!

!SessionManager commentStamp: 'Bill Schwab 8/28/2009 09:38' prior: 0!
Dolphin session managers do as advertised.  Among other things, they fire off 
events to manage startup and shutdown, and unlike Squeak, those happen when the 
image loads and closes respectively.  Recreate this basic behavior for Pharo.

!


!Object methodsFor: '*dolphincompatibility-idioms' stamp: 'Bill Schwab 
8/28/2009 15:55'!
trigger:anObject
        ^self triggerEvent:anObject.
! !


!KernelLibrary methodsFor: 'as yet unclassified' stamp: 'Bill Schwab 8/28/2009 
16:15'!
outputDebugString:aString
        "8-09 - for Windows"
        
        OSPlatform current platformFamily = #Windows ifTrue:[
                ^self windowsOutputDebugString:aString.
        ].
! !

!KernelLibrary methodsFor: 'as yet unclassified' stamp: 'Bill Schwab 8/28/2009 
16:15'!
windowsOutputDebugString:aString
        "8-09 - for Windows"
        
        <apicall: void 'OutputDebugStringA' (char*) module:'kernel32.dll'>
        ^self externalCallFailed.
! !


!KernelLibrary class methodsFor: 'as yet unclassified' stamp: 'Bill Schwab 
8/28/2009 15:49'!
current
        ^self default.
! !


!SessionManager methodsFor: 'as yet unclassified' stamp: 'Bill Schwab 8/28/2009 
15:51'!
shutDown
        "8-09 - hopefully this is called only when a session ends vs. on every 
snapshot."
        
        sessionStart isNil
                ifTrue:[
                        Transcript nextPutAll:'Shutdown with no time set.'; cr.
                ]
                ifFalse:[
                        sessionStart := nil.
                ].

        KernelLibrary default outputDebugString:'Trigger #sessionStopped.'.
        self trigger:#sessionStopped.
! !

!SessionManager methodsFor: 'as yet unclassified' stamp: 'Bill Schwab 8/28/2009 
16:10'!
startUp
        "8-09 - hopefully this is called only when a session begins vs. on 
every snapshot."
        
        sessionStart notNil
                ifTrue:[
                        Transcript nextPutAll:'Startup with time set.'; cr.
                ]
                ifFalse:[
                        sessionStart := TimeStamp current.
                ].

        KernelLibrary default outputDebugString:'Trigger #sessionStarted.'.
        self trigger:#sessionStarted.

        "8-09 - Sorry, but I see NO reason for this not to be done somewhere
        on startup."
        Socket initializeNetwork.
! !


!SessionManager class methodsFor: 'as yet unclassified' stamp: 'Bill Schwab 
8/28/2009 09:29'!
current
        "8-09 - lazily create a session manager.  This seems like a class 
variable vs. class instance
        variable problem, because there should be one of these things 
regardless of (in the future)
        which subclass gets the duty.  Runtime/deployed, development and 
console are the likely players."

        Current isNil ifTrue:[
                Current := self new.
        ].

        ^Current.
! !

!SessionManager class methodsFor: 'as yet unclassified' stamp: 'Bill Schwab 
8/28/2009 15:52'!
initialize
        "8-09 - these lists are mis-named as the evens are fired around a 
snapshot.  Try make a working
        session manager that behave as in Dolphin.
        
                SessionManager initialize.
        "

        Smalltalk addToStartUpList: self.
        Smalltalk addToShutDownList: self.
! !

!SessionManager class methodsFor: 'as yet unclassified' stamp: 'Bill Schwab 
8/28/2009 11:05'!
shutDown:quitting
        "8-09 - see Behavior>>shutDown: which forwards this to #startup 
regardless of the boolean state.
        Try to do better here so the notices go out only on a true shutdown.  
Trigger off of the
        current session manager."

        quitting ifTrue:[
                self current shutDown.
        ].
! !

!SessionManager class methodsFor: 'as yet unclassified' stamp: 'Bill Schwab 
8/28/2009 11:05'!
startUp:resuming
        "8-09 - see Behavior>>startup: which forwards this to #startup 
regardless of the boolean state.
        Try to do better here so the notices go out only on a true session 
start.  Trigger off of the
        current session manager."

        "8-09 - I *think* resuming means loading an image from disk."
        resuming ifTrue:[
                self current startUp.
        ].
! !

SessionManager initialize!
SessionManager removeSelector: #shutDown:!
SessionManager removeSelector: #startUp:!
KernelLibrary removeSelector: #basicOutputDebugString:!
_______________________________________________
Pharo-project mailing list
[email protected]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project

Reply via email to