* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / System.Data / System.Data.SqlClient / SqlAsyncResult.cs
1 //
2 // System.Data.SqlClient.SqlAsyncResult.cs
3 //
4 // Author:
5 //   T Sureshkumar <tsureshkumar@novell.com>
6 //   Ankit Jain <radical@corewars.org>
7 //
8
9 //
10 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
11 //
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 //
32
33
34 #if NET_2_0
35 using System;
36 using System.Threading;
37
38 namespace System.Data.SqlClient
39 {
40         internal class SqlAsyncResult : IAsyncResult
41         {
42                 private SqlAsyncState   _sqlState;
43                 private WaitHandle      _waitHandle;
44                 private bool            _completed = false;
45                 private bool            _completedSyncly = false;
46                 private bool            _ended = false;
47                 private AsyncCallback   _userCallback = null;
48                 private object          _retValue;
49                 private string          _endMethod;
50                 private IAsyncResult    _internal;
51
52                 public SqlAsyncResult (AsyncCallback userCallback, SqlAsyncState sqlState)
53                 {
54                         _sqlState = sqlState;
55                         _userCallback = userCallback;
56                         _waitHandle = new ManualResetEvent (false);
57                 }
58
59                 public SqlAsyncResult (AsyncCallback userCallback, object state)
60                 {
61                         _sqlState = new SqlAsyncState (state);
62                         _userCallback = userCallback;
63                         _waitHandle = new ManualResetEvent (false);
64                 }
65                 
66                 public object AsyncState 
67                 {
68                         get {   return _sqlState.UserState; }
69                 }
70
71                 internal SqlAsyncState SqlAsyncState
72                 {
73                         get {   return _sqlState; }
74                 }
75
76                 public WaitHandle AsyncWaitHandle 
77                 {
78                         get { return _waitHandle; }
79
80                 }
81
82                 public bool IsCompleted 
83                 {
84                         get {   return _completed; }
85                 }
86
87                 public bool CompletedSynchronously 
88                 {
89                         get {   return _completedSyncly; }
90                 }
91
92                 internal object ReturnValue
93                 {
94                         get {   return _retValue; }
95                         set {   _retValue = value; }
96                 }
97
98                 public string EndMethod
99                 {
100                         get {   return _endMethod; }
101                         set {   _endMethod = value; }
102                 }
103
104                 public bool Ended
105                 {
106                         get {   return _ended; }
107                         set {   _ended = value; }
108                 }
109
110
111                 internal IAsyncResult InternalResult
112                 {
113                         get {   return _internal; }
114                         set {   _internal = value; }
115                 }
116
117                 public AsyncCallback BubbleCallback
118                 {
119                         get { return new AsyncCallback (Bubbleback); }
120                         
121                 }
122
123                 internal void MarkComplete () 
124                 {
125                         _completed = true;
126                         ((ManualResetEvent)_waitHandle).Set ();
127
128                         if (_userCallback != null)
129                                 _userCallback (this);
130                 }
131                 
132                 public void Bubbleback (IAsyncResult ar)
133                 {
134                         this.MarkComplete ();
135                 }
136         }
137 }
138
139 #endif // NET_2_0