2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / corlib / System.Runtime.Remoting.Messaging / AsyncResult.cs
index 78cb25ccb63fa16ca7308bef1e289cd2099ad57a..7aa60febd2aca813c2903a6e743f310286ca45b4 100644 (file)
 // (C) 2001 Ximian, Inc.  http://www.ximian.com
 //
 
+//
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
 using System;
 using System.Threading;
 using System.Runtime.CompilerServices;
@@ -25,12 +48,15 @@ public class AsyncResult : IAsyncResult, IMessageSink {
        bool sync_completed;
        bool completed;
        bool endinvoke_called;
-       object[] out_args;
-       object ret_val;
-       Exception exception;
+       object async_callback;
+       MonoMethodMessage call_message;
        IMessageCtrl message_ctrl;
        IMessage reply_message;
-               
+       
+       internal AsyncResult ()
+       {
+       }
+       
        public virtual object AsyncState
        {
                get {
@@ -38,10 +64,14 @@ public class AsyncResult : IAsyncResult, IMessageSink {
                }
        }
 
-       public virtual WaitHandle AsyncWaitHandle
-       {
+       public virtual WaitHandle AsyncWaitHandle {
                get {
-                       return handle;
+                       lock (this) {
+                               if (handle == null)
+                                       handle = new ManualResetEvent (completed);
+
+                               return handle;
+                       }
                }
        }
 
@@ -103,19 +133,32 @@ public class AsyncResult : IAsyncResult, IMessageSink {
                sync_completed = completed;
        }
 
+       internal IMessage EndInvoke ()
+       {
+               handle.WaitOne ();
+               return reply_message;
+       }
+
        public virtual IMessage SyncProcessMessage (IMessage msg)
        {
-               IMethodReturnMessage retMsg = (IMethodReturnMessage) msg;
                reply_message = msg;
-               out_args = retMsg.OutArgs;
-               ret_val = retMsg.ReturnValue;
-               exception = retMsg.Exception;
 
                completed = true;
                NativeEventCalls.SetEvent_internal (handle.Handle);
-               // TODO: invoke callback
+               
+               if (async_callback != null)
+               {
+                       AsyncCallback ac = (AsyncCallback) async_callback;
+                       ac (this);
+               }
 
                return null;
        }
+       
+       internal MonoMethodMessage CallMessage
+       {
+               get { return call_message; }
+               set { call_message = value; }
+       }
 }
 }