Cairo__RefCountedStructure.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Sun, 17 Jun 2012 14:49:30 +0000
changeset 16 a810555a635c
parent 12 e5f0c18af8a9
child 23 38ee47dbd976
permissions -rw-r--r--
- Cairo::Surface class definition added:6 methods changed: #update:with:from: - Cairo::ClockView changed: #redraw - extensions ...

"{ Package: 'stx:goodies/libcairo' }"

"{ NameSpace: Cairo }"

ExternalStructure subclass:#RefCountedStructure
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'Cairo-Objects'
!


!RefCountedStructure class methodsFor:'accessing'!

dllPath

    OperatingSystem isMSWINDOWSlike ifTrue:[
        ^ #( 'C:\Windows' 'C:\Windows\System32' "Wild guess, should not harm" )
    ].

    OperatingSystem isUNIXlike ifTrue:[
        OperatingSystem getSystemType == #linux ifTrue:[
            | path |

            path := #( '/lib' '/usr/lib' '/usr/local/lib' ).
            (OperatingSystem getSystemInfo at:#machine) = 'x86_64' ifTrue:[
                "If the machine is 64bit, prepend standard path for 32bit libs.
                 Leave standard paths at the end, as the system might be completely 
                 32bit but running on 64bit-capable CPU.

                CAVEAT: This is bit dangerous, as on 64bit OS, if ia32 libs are
                not installed byt 64bit sqlite libs are, then 64bit libs are found
                and when a function is called, segfault will occur!!

                Q: Is there a way how to figure out if the OS itself is 32bit,
                regardles on CPU?"
                path := #( '/lib32' '/usr/lib32' '/usr/local/lib32' ) , path.
            ].
            ^path

        ].
    ].

    self error:'Unsupported operating system'

    "
        SqliteLibrary dllPath
    "

    "Created: / 31-08-2011 / 18:02:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!RefCountedStructure class methodsFor:'primitives'!

primDestroy: anObject

    self subclassResponsibility

    "Created: / 09-09-2008 / 20:30:54 / Jan Vrany <vranyj1@fel.cvut.cz>"
!

primGetReferenceCount: anObject

    self subclassResponsibility

    "Created: / 09-09-2008 / 20:31:04 / Jan Vrany <vranyj1@fel.cvut.cz>"
!

primReference: anObject

    self subclassResponsibility

    "Created: / 09-09-2008 / 20:31:08 / Jan Vrany <vranyj1@fel.cvut.cz>"
! !

!RefCountedStructure methodsFor:'accessing'!

referenceCount

    ^self class primGetReferenceCount: self

    "Created: / 09-09-2008 / 20:33:48 / Jan Vrany <vranyj1@fel.cvut.cz>"
! !

!RefCountedStructure methodsFor:'finalization'!

executor

    ^self class basicNew
        setAddress: self address size: self basicSize;
        yourself

    "Created: / 10-09-2008 / 18:57:28 / Jan Vrany <vranyj1@fel.cvut.cz>"
!

finalize
    self infoPrintCR:'Instance destroyed'.
    self class primDestroy:self

    "Created: / 09-09-2008 / 20:30:22 / Jan Vrany <vranyj1@fel.cvut.cz>"
    "Modified: / 10-09-2008 / 18:45:23 / Jan Vrany <vranyj1@fel.cvut.cz>"
! !

!RefCountedStructure methodsFor:'initialization & release'!

retain
    "
        Increases cairo's internal ref-count!!
    "

    ^self class primReference: self

    "Created: / 09-09-2008 / 20:33:16 / Jan Vrany <vranyj1@fel.cvut.cz>"
! !

!RefCountedStructure methodsFor:'private'!

fromExternalAddress:anExternalAddress 
    super fromExternalAddress:anExternalAddress.
    self registerForFinalization.
    self infoPrintCR:'Instance created'.

    "Created: / 09-09-2008 / 20:35:23 / Jan Vrany <vranyj1@fel.cvut.cz>"
    "Modified: / 10-09-2008 / 18:45:23 / Jan Vrany <vranyj1@fel.cvut.cz>"
!

infoPrintCR:aString 
    Stdout
        nextPutAll:'Cairo [info] (';
        nextPutAll:self class nameWithoutPrefix;
        nextPutAll:' @ 0x';
        nextPutAll:(self address printStringRadix:16);
        nextPutAll:' @ ';
        nextPutAll:(self referenceCount printString);
        nextPutAll:': ';
        nextPutAll:aString;
        cr

    "Created: / 10-09-2008 / 18:45:23 / Jan Vrany <vranyj1@fel.cvut.cz>"
! !

!RefCountedStructure class methodsFor:'documentation'!

version
    ^'$Id$'
!

version_SVN
    ^ '$Id::                                                                                                                        $'
! !