Changeset 58


Ignore:
Timestamp:
Jan 12, 2007, 3:21:30 AM (17 years ago)
Author:
dai
Message:

例外処理用に必要なコードを追加。
空間統括ファイル(index.ab)を作成。
その他クラスの調整。

Location:
Include
Files:
5 added
6 edited

Legend:

Unmodified
Added
Removed
  • Include/Classes/System/Diagnostics/Trace.ab

    r45 r58  
    11
    2 ' リスナ
    3 Class TraceListener
    4 End Class
    52
    63' リスナコレクション
    74Class TraceListenerCollection
     5    ppListeners As **TraceListener
     6    count As Long
    87Public
     8
     9    Sub TraceListenerCollection()
     10        ppListeners = _System_malloc( 1 )
     11    End Sub
     12    Sub ~TraceListenerCollection()
     13        Dim i As Long
     14        For i = 0 To ELM( count )
     15            Delete ppListeners[i]
     16        Next
     17        _System_free( ppListeners )
     18    End Sub
    919
    1020    '----------------------------------------------------------------
     
    1323
    1424    ' リスナを追加
    15     Function Add( listener As TraceListener )
    16         ' TODO: 実装
    17     End Function
     25    Sub Add( listener As TraceListener ) As Long
     26        ppListeners = _System_realloc( ppListeners, ( count + 1 ) * SizeOf( *TraceListener ) )
     27        ppListeners[count] = New TraceListener( listener )
     28        count++
     29    End Sub
    1830
    1931    ' 複数のリスナを追加
    2032    Sub AddRange( listeners As TraceListenerCollection )
    2133        ' TODO: 実装
    22     End Function
     34    End Sub
    2335
    2436    ' リストからすべてのリスナを削除
     
    5062    '----------------------------------------------------------------
    5163
     64    ' インデクサ ( Getter )
     65    Function Operator[] ( index As Long ) As TraceListener
     66        If index < 0 or count <= index Then
     67            ' TODO: エラー処理
     68            debug
     69        End If
     70
     71        Dim tempListener As TraceListener( ByVal ppListeners[index] )
     72        Return tempListener
     73    End Function
     74
    5275    ' 保有するリスナの数を取得する
    5376    Function Count() As Long
    54         ' TODO: 実装
    55     End Function
    56 
    57     ' リスナを取得する
    58     Function Item( index As Long ) As TraceListener
    59         ' TODO: 実装
     77        Return count
    6078    End Function
    6179End Class
     
    6583    Static indentSize = 4 As Long
    6684
    67     Static Function GetIndentString() As String
    68         Dim i As Long
    6985
    70         Dim IndentStr = ""
    71         For i = 0 To ELM( indentSize )
    72             IndentStr = IndentStr + " "
    73         Next
    74 
    75         Dim ResultStr = ""
    76         For i = 0 To ELM( indentLevel )
    77             ResultStr = ResultStr + IndentStr
    78         Next
    79 
    80         Return ResultStr
    81     End Function
     86    ' リスナ管理
     87    Static Listeners As TraceListenerCollection
    8288
    8389Public
     
    113119    ' インデントレベルを上げる
    114120    Static Sub Indent()
    115         indentLevel++
     121        IndentLevel = indentLevel + 1
    116122    End Sub
    117123
     
    122128            Return
    123129        End If
    124         indentLevel--
     130        IndentLevel = indentLevel - 1
     131    End Sub
     132
     133    Static Sub Write( message As String )
     134       
    125135    End Sub
    126136
    127137    ' 一行の文字列を出力
    128138    Static Sub WriteLine( message As String )
    129         Dim tempmsg = GetIndentString() + message + Ex"\n"
    130 
    131         ' TODO: リスナへの出力を実装
     139        Dim i As Long
     140        For i = 0 To ELM( Listeners.Count )
     141            Dim temp As TraceListener
     142            temp = Listeners[i]
     143            temp.WriteLine( message )
     144        Next
    132145    End Sub
    133146
     
    141154        Return indentLevel
    142155    End Function
    143     Static Sub IndentLevel( level As Long )
    144         indentLevel = level
     156    Static Sub IndentLevel( indentLevel As Long )
     157        This.indentLevel = indentLevel
     158
     159        Dim i As Long
     160        For i = 0 To ELM( Listeners.Count )
     161            Dim temp As TraceListener
     162            temp = Listeners[i]
     163            temp.IndentLevel = indentLevel
     164        Next
    145165    End Sub
    146166
     
    151171    Static Sub IndentSize( size As Long )
    152172        indentSize = size
    153     End Sub
    154173
    155     ' Listenersプロパティ
    156     Static Function Listeners() As TraceListenerCollection
    157         Return listeners
    158     End Function
    159     Static Sub Listeners( listeners As TraceListenerCollection )
    160         This.listeners = listeners
     174        Dim i As Long
     175        For i = 0 To ELM( Listeners.Count )
     176            Dim temp As TraceListener
     177            temp = Listeners[i]
     178            temp.IndentSize = indentSize
     179        Next
    161180    End Sub
    162181
  • Include/Classes/System/Object.ab

    r51 r58  
    11Class Object
    22Public
     3
     4    Sub Object()
     5    End Sub
     6    Sub ~Object()
     7    End Sub
    38
    49    ' 2つのオブジェクトが等しいかどうかを判断する
  • Include/Classes/System/Threading/Thread.ab

    r42 r58  
    11'threading.sbp
    22
     3
     4'--------------------------------------------------------------------
     5' スレッドの優先順位
     6'--------------------------------------------------------------------
    37Enum ThreadPriority
    48    Highest =      2
     
    1115TypeDef PTHREAD_START_ROUTINE = *Function(args As VoidPtr) As DWord
    1216
     17
     18'--------------------------------------------------------------------
     19' スレッド クラス
     20'--------------------------------------------------------------------
    1321Class Thread
    1422    m_hThread As HANDLE
     
    1927    m_fp As PTHREAD_START_ROUTINE
    2028    m_args As VoidPtr
     29
    2130Public
    2231    Sub Thread()
     
    137146        Return GetThreadContext(m_hThread,Context)
    138147    End Function
     148    Function __SetContext(ByRef Context As CONTEXT) As BOOL
     149        Return SetThreadContext(m_hThread,Context)
     150    End Function
    139151
    140152
     
    147159
    148160
    149 'すべてのスレッドの管理
     161'--------------------------------------------------------------------
     162' すべてのスレッドの管理
     163'--------------------------------------------------------------------
     164' TODO: このクラスをシングルトンにする
    150165Class _System_CThreadCollection
    151166Public
     
    159174        ppobj_Thread=HeapAlloc(_System_hProcessHeap,0,1)
    160175        pStackBase=HeapAlloc(_System_hProcessHeap,0,1)
     176        ppException=HeapAlloc(_System_hProcessHeap,0,1)
    161177        ThreadNum=0
    162178
     
    175191        pStackBase=0
    176192
     193        HeapFree(_System_hProcessHeap,0,ppException)
     194        ppException = 0
     195
    177196        ThreadNum=0
    178197
     
    185204        EnterCriticalSection(CriticalSection)
    186205
     206            'スレッドオブジェクトを生成
    187207            Dim pobj_NewThread As *Thread
    188208            pobj_NewThread=New Thread(obj_Thread)
    189209
     210            '例外処理管理用オブジェクトを生成
     211            Dim pException As *ExceptionService
     212            pException = New ExceptionService
     213
    190214            Dim i As Long
    191215            For i=0 To ELM(ThreadNum)
    192                 If ppobj_Thread[i]=0 Then
    193                     ppobj_Thread[i]=pobj_NewThread
    194                     pStackBase[i]=NowSp
     216                If ppobj_Thread[i] = 0 Then
     217                    ppobj_Thread[i] = pobj_NewThread
     218                    pStackBase[i] = NowSp
     219                    ppException[i] = pException
    195220                    Exit For
    196221                End If
    197222            Next
    198223
    199             If i=ThreadNum Then
     224            If i = ThreadNum Then
    200225                ppobj_Thread=HeapReAlloc(_System_hProcessHeap,0,ppobj_Thread,(ThreadNum+1)*SizeOf(*Thread))
    201226                ppobj_Thread[ThreadNum]=pobj_NewThread
    202227                pStackBase=HeapReAlloc(_System_hProcessHeap,0,pStackBase,(ThreadNum+1)*SizeOf(LONG_PTR))
    203228                pStackBase[ThreadNum]=NowSp
     229                ppException=HeapReAlloc(_System_hProcessHeap,0,ppException,(ThreadNum+1)*SizeOf(*ExceptionService))
     230                ppException[ThreadNum]=pException
    204231                ThreadNum++
    205232            End If
     
    242269    End Sub
    243270
    244 
     271    'カレントスレッドを取得
    245272    Function CurrentThread(ByRef obj_Thread As Thread) As BOOL
    246273        Dim dwNowThreadId As DWord
     
    257284        Return 0
    258285    End Function
     286
     287
     288Private
     289    '------------------------------------------
     290    ' スレッド固有の例外処理制御
     291    '------------------------------------------
     292    ppException As **ExceptionService
     293
     294Public
     295    Function GetCurrentException() As *ExceptionService
     296        Dim dwNowThreadId As DWord
     297        dwNowThreadId=GetCurrentThreadId()
     298
     299        Dim i As Long
     300        For i=0 To ELM(ThreadNum)
     301            If ppobj_Thread[i]->ThreadId=dwNowThreadId Then
     302                Return ppException[i]
     303            End If
     304        Next
     305
     306        Return NULL
     307    End Function
    259308End Class
    260309Dim _System_pobj_AllThreads As *_System_CThreadCollection
  • Include/Classes/System/Threading/WaitHandle.ab

    r47 r58  
    9999                ExitThread(0)
    100100        End Select
    101     End Sub
     101    End Function
    102102End Class
    103103
  • Include/Classes/index.ab

    r56 r58  
    1 #include "System\String.ab"
    2 #include "System\Object.ab"
     1' コンパイルに最低限必要なファイル
    32
    4 #include "System\Data\Odbc\Odbc.ab"
     3' System
     4#require "System\index.ab"
    55
    6 #include "System\Threading\Thread.ab"
     6' System.Thread
     7#require "System\Threading\index.ab"
  • Include/basic.sbp

    r50 r58  
    131131#include <system\gc.sbp>
    132132#include <system\enum.sbp>
    133 '#include <system\exception.ab>
     133#include <system\exception.ab>
    134134
    135135#include <Classes\index.ab>
Note: See TracChangeset for help on using the changeset viewer.