public IMessage Invoke(IMessage message) { IMessage returnMessage; object[] attribs; uint addr; uint retval; IMethodCallMessage methodMessage = new MethodCallMessageWrapper((IMethodCallMessage)message); MethodBase method = methodMessage.MethodBase; object returnValue = null; if (method.MethodHandle == GetTypeMethodHandle) { returnValue = m_Interface; } else if (((attribs = method.GetCustomAttributes(typeof(SyncAttribute), true)).Length > 0) && (Client.Default.InvokeRequired)) { //m_Async value overrides Sync.Async if (m_Async.ContainsKey((int)method.MethodHandle.Value)) { if ((m_Async[(int)method.MethodHandle.Value]))//async override { Client.Default.BeginInvoke(new InvokeDelegate(Invoke), new object[] { message }); return(new ReturnMessage(null, methodMessage.Args, methodMessage.ArgCount, methodMessage.LogicalCallContext, methodMessage)); } else//sync override { return((IMessage)Client.Default.Invoke(new InvokeDelegate(Invoke), new object[] { message })); } } else if (((SyncAttribute)attribs[0]).Async)//preconfigured async { Client.Default.BeginInvoke(new InvokeDelegate(Invoke), new object[] { message }); return(new ReturnMessage(null, methodMessage.Args, methodMessage.ArgCount, methodMessage.LogicalCallContext, methodMessage)); } else//preconfigured sync { return((IMessage)Client.Default.Invoke(new InvokeDelegate(Invoke), new object[] { message })); } } else { if ((attribs = method.GetCustomAttributes(typeof(UMethodAttribute), true)).Length > 0) { UMethodAttribute mattrib = (UMethodAttribute)attribs[0]; addr = (uint)UOCallibration.Callibrations[(uint)mattrib.CallibratedOffsetFeature]; retval = PerformCall(addr, methodMessage); if (mattrib.HasReturnValue) { returnValue = MarshalFromUnmanaged(retval, mattrib.ReturnType, mattrib.SizeConstant, mattrib.KnownType); } else { returnValue = null; } } else if ((attribs = method.GetCustomAttributes(typeof(UFieldAttribute), true)).Length > 0) { UFieldAttribute fattrib = (UFieldAttribute)attribs[0]; UnmanagedBuffer buff = new UnmanagedBuffer((IntPtr)((uint)m_Address + (uint)UOCallibration.Callibrations[(uint)fattrib.CallibratedOffsetFeature])); retval = buff.Read <uint>(); returnValue = MarshalFromUnmanaged(retval, fattrib.ReturnType, fattrib.SizeConstant, fattrib.KnownType); } else if ((attribs = method.GetCustomAttributes(typeof(UGlobalAttribute), true)).Length > 0) { UGlobalAttribute gattrib = (UGlobalAttribute)attribs[0]; UnmanagedBuffer buff = new UnmanagedBuffer((IntPtr)UOCallibration.Callibrations[(uint)gattrib.CallibratedOffsetFeature]); retval = buff.Read <uint>(); returnValue = MarshalFromUnmanaged(retval, gattrib.ReturnType, gattrib.SizeConstant, gattrib.KnownType); } else if ((attribs = method.GetCustomAttributes(typeof(UVtblMethodAttribute), true)).Length > 0) { UVtblMethodAttribute mattrib = (UVtblMethodAttribute)attribs[0]; UnmanagedBuffer m_This = new UnmanagedBuffer(m_Address); addr = m_This.ReadAt <uint>(0); if (mattrib.hasidx) { addr += 4 * mattrib.index; } else { addr += (uint)UOCallibration.Callibrations[(uint)mattrib.CallibratedOffsetFeature]; } retval = PerformCall(addr, methodMessage); if (mattrib.HasReturnValue) { returnValue = MarshalFromUnmanaged(retval, mattrib.ReturnType, mattrib.SizeConstant, mattrib.KnownType); } else { returnValue = null; } } else if ((attribs = method.GetCustomAttributes(typeof(UForwardAttribute), true)).Length > 0) { UForwardAttribute fattrib = (UForwardAttribute)attribs[0]; /*if (fattrib.Target == null) * { * if (m_EventsByAddHandler.ContainsKey((int)method.MethodHandle.Value)) * returnValue = fattrib.onAdd.Invoke(null, methodMessage.Args); * else if (m_EventsByRemoveHandler.ContainsKey((int)method.MethodHandle.Value)) * returnValue = fattrib.onRemove.Invoke(null, methodMessage.Args); * else * returnValue = null; * } * else*/ returnValue = fattrib.Target.Invoke(null, methodMessage.Args); } else if ((methodMessage.ArgCount == 1) && (methodMessage.Args[0] is Delegate)) { returnValue = null; if (m_EventsByAddHandler.ContainsKey((int)method.MethodHandle.Value)) { m_EventsByAddHandler[(int)method.MethodHandle.Value].Add((Delegate)methodMessage.Args[0]); } else if (m_EventsByRemoveHandler.ContainsKey((int)method.MethodHandle.Value)) { m_EventsByRemoveHandler[(int)method.MethodHandle.Value].Remove((Delegate)methodMessage.Args[0]); } } } returnMessage = new ReturnMessage(returnValue, methodMessage.Args, methodMessage.ArgCount, methodMessage.LogicalCallContext, methodMessage); return(returnMessage); }
public UnmanagedEvent(UForwardAttribute _attrib) { IsForward = true; fwattrib = _attrib; }