public static object[] GetDynamicValues(Message msg, Type[] types) { //TODO: this validation check should provide better information, eg. message dump or a stack trace, or at least the interface/member if (ProtocolInformation.Verbose) { Signature expected = Signature.GetSig(types); Signature actual = msg.Signature; if (actual != expected) { Console.Error.WriteLine("Warning: The signature of the message does not match that of the handler: " + "Expected '" + expected + "', got '" + actual + "'"); } } object[] vals = new object[types.Length]; if (msg.Body != null) { MessageReader reader = new MessageReader(msg); for (int i = 0; i != types.Length; i++) { vals[i] = reader.ReadValue(types[i]); } } return(vals); }
public static object[] GetDynamicValues(Message msg, ParameterInfo[] parms) { //TODO: this validation check should provide better information, eg. message dump or a stack trace, or at least the interface/member /* * if (Protocol.Verbose) { * Signature expected = Signature.GetSig (types); * Signature actual = msg.Signature; * if (actual != expected) * Console.Error.WriteLine ("Warning: The signature of the message does not match that of the handler: " + "Expected '" + expected + "', got '" + actual + "'"); * } */ object[] vals = new object[parms.Length]; if (msg.Body != null) { MessageReader reader = new MessageReader(msg); foreach (ParameterInfo parm in parms) { if (parm.IsOut) { continue; } vals[parm.Position] = reader.ReadValue(parm.ParameterType); } } return(vals); }
public void Invoke(MethodBase methodBase, string methodName, object[] inArgs, out object[] outArgs, out object retVal, out Exception exception) { outArgs = new object[0]; retVal = null; exception = null; MethodInfo mi = methodBase as MethodInfo; if (mi != null && mi.IsSpecialName && (methodName.StartsWith("add_") || methodName.StartsWith("remove_"))) { string[] parts = methodName.Split(new char[] { '_' }, 2); string ename = parts[1]; Delegate dlg = (Delegate)inArgs[0]; ToggleSignal(Mapper.GetInterfaceName(mi), ename, dlg, parts[0] == "add"); return; } Type[] inTypes = Mapper.GetTypes(ArgDirection.In, mi.GetParameters()); Signature inSig = Signature.GetSig(inTypes); string iface = null; if (mi != null) { iface = Mapper.GetInterfaceName(mi); } if (mi != null && mi.IsSpecialName) { methodName = methodName.Replace("get_", "Get"); methodName = methodName.Replace("set_", "Set"); } MessageWriter writer = new MessageWriter(conn); if (inArgs != null && inArgs.Length != 0) { for (int i = 0; i != inTypes.Length; i++) { writer.Write(inTypes[i], inArgs[i]); } } MessageReader reader = SendMethodCall(iface, methodName, inSig.Value, writer, mi.ReturnType, out exception); if (reader == null) { return; } retVal = reader.ReadValue(mi.ReturnType); }
public object ToType(Type conversionType, IFormatProvider provider) { Signature typeSig = Signature.GetSig(conversionType); if (typeSig != signature) { throw new InvalidCastException(); } MessageReader reader = new MessageReader(endianness, data); return(reader.ReadValue(conversionType)); }
public object SendPropertyGet(string iface, string property) { Exception exception; MessageWriter writer = new MessageWriter(); writer.Write(iface); writer.Write(property); MessageReader reader = SendMethodCall("org.freedesktop.DBus.Properties", "Get", "ss", writer, typeof(object), out exception); if (exception != null) { throw exception; } return(reader.ReadValue(typeof(object))); }
public object ToType(Type conversionType, IFormatProvider provider) { Signature typeSig = Signature.GetSig (conversionType); if (typeSig != signature) throw new InvalidCastException (); MessageReader reader = new MessageReader (endianness, data); return reader.ReadValue (conversionType); }
public static object[] GetDynamicValues(Message msg, Type[] types) { //TODO: this validation check should provide better information, eg. message dump or a stack trace, or at least the interface/member if (Protocol.Verbose) { Signature expected = Signature.GetSig (types); Signature actual = msg.Signature; if (actual != expected) Console.Error.WriteLine ("Warning: The signature of the message does not match that of the handler: " + "Expected '" + expected + "', got '" + actual + "'"); } object[] vals = new object[types.Length]; if (msg.Body != null) { MessageReader reader = new MessageReader (msg); for (int i = 0 ; i != types.Length ; i++) vals[i] = reader.ReadValue (types[i]); } return vals; }
public static object[] GetDynamicValues(Message msg, ParameterInfo[] parms) { //TODO: this validation check should provide better information, eg. message dump or a stack trace, or at least the interface/member /* if (Protocol.Verbose) { Signature expected = Signature.GetSig (types); Signature actual = msg.Signature; if (actual != expected) Console.Error.WriteLine ("Warning: The signature of the message does not match that of the handler: " + "Expected '" + expected + "', got '" + actual + "'"); } */ object[] vals = new object[parms.Length]; if (msg.Body != null) { MessageReader reader = new MessageReader (msg); foreach (ParameterInfo parm in parms) { if (parm.IsOut) continue; vals[parm.Position] = reader.ReadValue (parm.ParameterType); } } return vals; }
public static void Test(HashSet<ArgMatchTest> a, Message msg) { List<Signature> sigs = new List<Signature> (); sigs.AddRange (msg.Signature.GetParts ()); if (sigs.Count == 0) { a.Clear (); return; } a.RemoveWhere ( delegate (ArgMatchTest t) { return t.ArgNum >= sigs.Count || t.Signature != sigs[t.ArgNum]; } ); // Sorting the list here is not ideal List<ArgMatchTest> tests = new List<ArgMatchTest> (a); tests.Sort ( delegate (ArgMatchTest aa, ArgMatchTest bb) { return aa.ArgNum - bb.ArgNum; } ); if (tests.Count == 0) { a.Clear (); return; } MessageReader reader = new MessageReader (msg); int argNum = 0; foreach (ArgMatchTest test in tests) { if (argNum > test.ArgNum) { // This test cannot pass because a previous test already did. // So we already know it will fail without even trying. // This logic will need to be changed to support wildcards. a.Remove (test); continue; } while (argNum != test.ArgNum) { Signature sig = sigs[argNum]; if (!reader.StepOver (sig)) throw new Exception (); argNum++; } // TODO: Avoid re-reading values int savedPos = reader.pos; if (!reader.ReadValue (test.Signature[0]).Equals (test.Value)) { a.Remove (test); reader.pos = savedPos; continue; } argNum++; } }
public static void Test(HashSet <ArgMatchTest> a, Message msg) { List <Signature> sigs = new List <Signature> (); sigs.AddRange(msg.Signature.GetParts()); if (sigs.Count == 0) { a.Clear(); return; } a.RemoveWhere(delegate(ArgMatchTest t) { return(t.ArgNum >= sigs.Count || t.Signature != sigs[t.ArgNum]); }); // Sorting the list here is not ideal List <ArgMatchTest> tests = new List <ArgMatchTest> (a); tests.Sort(delegate(ArgMatchTest aa, ArgMatchTest bb) { return(aa.ArgNum - bb.ArgNum); }); if (tests.Count == 0) { a.Clear(); return; } MessageReader reader = new MessageReader(msg); int argNum = 0; foreach (ArgMatchTest test in tests) { if (argNum > test.ArgNum) { // This test cannot pass because a previous test already did. // So we already know it will fail without even trying. // This logic will need to be changed to support wildcards. a.Remove(test); continue; } while (argNum != test.ArgNum) { Signature sig = sigs[argNum]; if (!reader.StepOver(sig)) { throw new Exception(); } argNum++; } // TODO: Avoid re-reading values int savedPos = reader.pos; if (!reader.ReadValue(test.Signature[0]).Equals(test.Value)) { a.Remove(test); reader.pos = savedPos; continue; } argNum++; } }
static void PrintValue (MessageReader reader, Signature sig, int depth) { string indent = new String (' ', depth * 2); indent += " "; //Console.Write (indent + indent + "arg" + argNum + " " + sig + ": "); Console.Write (indent); if (sig == Signature.VariantSig) { foreach (Signature elemSig in reader.StepInto (sig)) { Console.WriteLine ("Variant '{0}' (", elemSig); PrintValue (reader, elemSig, depth + 1); Console.WriteLine (indent + ")"); } } else if (sig.IsPrimitive) { object arg = reader.ReadValue (sig[0]); Type argType = sig.ToType (); if (sig == Signature.StringSig || sig == Signature.ObjectPathSig) Console.WriteLine ("{0} \"{1}\"", argType.Name, arg); else if (sig == Signature.SignatureSig) Console.WriteLine ("{0} '{1}'", argType.Name, arg); else Console.WriteLine ("{0} {1}", argType.Name, arg); } else if (sig.IsArray) { Console.WriteLine ("Array ["); foreach (Signature elemSig in reader.StepInto (sig)) PrintValue (reader, elemSig, depth + 1); Console.WriteLine (indent + "]"); } else if (sig.IsDictEntry) { Console.WriteLine ("DictEntry {"); foreach (Signature elemSig in reader.StepInto (sig)) PrintValue (reader, elemSig, depth + 1); Console.WriteLine (indent + "}"); } else if (sig.IsStruct) { Console.WriteLine ("Struct {"); foreach (Signature elemSig in reader.StepInto (sig)) PrintValue (reader, elemSig, depth + 1); Console.WriteLine (indent + "}"); } else { reader.StepOver (sig); Console.WriteLine ("'{0}'?", sig); } }