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