File: DProxy.cs

package info (click to toggle)
aircrack-ng 1%3A1.6%2Bgit20210130.91820bc-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 19,056 kB
  • sloc: ansic: 67,045; cs: 5,392; sh: 3,773; python: 2,565; pascal: 1,074; asm: 570; makefile: 253; cpp: 46
file content (79 lines) | stat: -rw-r--r-- 2,501 bytes parent folder | download | duplicates (24)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright 2006 Alp Toker <alp@atoker.com>
// This software is made available under the MIT License
// See COPYING for details

using System;
using System.Reflection;
using System.Runtime.Remoting.Proxies;
using System.Runtime.Remoting.Messaging;

namespace NDesk.DBus
{
	//marked internal because this is really an implementation detail and needs to be replaced
	internal class DProxy : RealProxy
	{
		protected BusObject busObject;

		public DProxy (BusObject busObject, Type type) : base(type)
		{
			this.busObject = busObject;
		}

		static MethodInfo mi_GetHashCode = typeof (object).GetMethod ("GetHashCode");
		static MethodInfo mi_Equals = typeof (object).GetMethod ("Equals", BindingFlags.Instance);
		static MethodInfo mi_ToString = typeof (object).GetMethod ("ToString");
		static MethodInfo mi_GetLifetimeService = typeof (MarshalByRefObject).GetMethod ("GetLifetimeService");

		object GetDefaultReturn (MethodBase mi, object[] inArgs)
		{
			if (mi == mi_GetHashCode)
				return busObject.Path.Value.GetHashCode ();
			if (mi == mi_Equals)
				return busObject.Path.Value == ((BusObject)((MarshalByRefObject)inArgs[0]).GetLifetimeService ()).Path.Value;
			if (mi == mi_ToString)
				return busObject.Path.Value;
			if (mi == mi_GetLifetimeService)
				return busObject;

			return null;
		}

		public override IMessage Invoke (IMessage message)
		{
			IMethodCallMessage callMessage = (IMethodCallMessage) message;

			object defaultRetVal = GetDefaultReturn (callMessage.MethodBase, callMessage.InArgs);
			if (defaultRetVal != null) {
				MethodReturnMessageWrapper defaultReturnMessage = new MethodReturnMessageWrapper ((IMethodReturnMessage) message);
				defaultReturnMessage.ReturnValue = defaultRetVal;

				return defaultReturnMessage;
			}

			object[] outArgs;
			object retVal;
			Exception exception;
			busObject.Invoke (callMessage.MethodBase, callMessage.MethodName, callMessage.InArgs, out outArgs, out retVal, out exception);

			MethodReturnMessageWrapper returnMessage = new MethodReturnMessageWrapper ((IMethodReturnMessage) message);
			returnMessage.Exception = exception;
			returnMessage.ReturnValue = retVal;

			return returnMessage;
		}

		/*
		public override ObjRef CreateObjRef (Type ServerType)
		{
			throw new System.NotImplementedException ();
		}
		*/

		~DProxy ()
		{
			//FIXME: remove handlers/match rules here
			if (Protocol.Verbose)
				Console.Error.WriteLine ("Warning: Finalization of " + busObject.Path + " not yet supported");
		}
	}
}