private static Int32 GetInt32Arg(MsgArg argument, string signature) { Int32 value; var status = MsgArg.alljoyn_msgarg_get(argument.Handle, signature, __arglist(out value)); AllJoynException.CheckStatus(status); return(value); }
private static double GetDoubleArg(MsgArg argument, string signature) { double value = default(double); var status = MsgArg.alljoyn_msgarg_get(argument.Handle, signature, __arglist(ref value)); AllJoynException.CheckStatus(status); return(value); }
private static bool GetBoolArg(MsgArg argument, string signature) { bool value = default(bool); var status = MsgArg.alljoyn_msgarg_get(argument.Handle, signature, __arglist(ref value)); AllJoynException.CheckStatus(status); return(value); }
private static T GetVariantArg <T>(MsgArg argument, string signature) { T value = default(T); var status = MsgArg.alljoyn_msgarg_get(argument.Handle, signature, __arglist(ref value)); AllJoynException.CheckStatus(status); return(value); }
private static string GetVariantArg_String(MsgArg argument, string signature) { IntPtr strOut; var status = MsgArg.alljoyn_msgarg_get(argument.Handle, signature, __arglist(out strOut)); AllJoynException.CheckStatus(status); var value = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(strOut); return(value); }
/*private static byte[] GetByteArrayMessageArg(MsgArg argument, string signature) * { * UIntPtr las; * IntPtr as_arg; * var status = MsgArg.alljoyn_msgarg_get(argument.Handle, AllJoynTypeIds.ByteArray, __arglist(out las, out as_arg)); * AllJoynException.CheckStatus(status); * byte[] result = new byte[(int)las]; * IntPtr val; * for (int i = 0; i < (int)las; i++) * { * var a = MsgArg.alljoyn_msgarg_array_element(as_arg, (UIntPtr)i); * status = MsgArg.alljoyn_msgarg_get(a, AllJoynTypeIds.Byte.ToString(), __arglist(out val)); * AllJoynException.CheckStatus(status); * result[i] = Marshal.ReadByte(val); * } * MsgArg.alljoyn_msgarg_destroy(as_arg); * // MsgArg.alljoyn_msgarg_stabilize(argument.Handle); * return result; * }*/ private static T[] GetPrimitiveArrayMessageArg <T>(MsgArg argument, string signature, Action <IntPtr, T[], int, int> copyAction) { UIntPtr size = UIntPtr.Zero; IntPtr valuePtr; var status = MsgArg.alljoyn_msgarg_get(argument.Handle, signature, __arglist(out size, out valuePtr)); AllJoynException.CheckStatus(status); T[] elements = new T[(int)size]; copyAction(valuePtr, elements, 0, (int)size); //Marshal.FreeCoTaskMem(valuePtr); return(elements); }
private static string[] GetStringArrayMessageArg(MsgArg argument, string signature) { UIntPtr las; IntPtr as_arg; var status = MsgArg.alljoyn_msgarg_get(argument.Handle, AllJoynTypeIds.StringArray, __arglist(out las, out as_arg)); AllJoynException.CheckStatus(status); string[] result = new string[(int)las]; IntPtr val; for (int i = 0; i < (int)las; i++) { status = MsgArg.alljoyn_msgarg_get( MsgArg.alljoyn_msgarg_array_element( as_arg, (UIntPtr)i), AllJoynTypeIds.String.ToString(), __arglist(out val)); AllJoynException.CheckStatus(status); result[i] = Marshal.PtrToStringAnsi(val); } MsgArg.alljoyn_msgarg_destroy(as_arg); // MsgArg.alljoyn_msgarg_stabilize(argument.Handle); return(result); }
public static object GetValueFromVariant(MsgArg argument, string signature) { switch (signature[0]) { case AllJoynTypeIds.Byte: { IntPtr valOut; var status = MsgArg.alljoyn_msgarg_get(argument.Handle, "y", __arglist(out valOut)); return((byte)valOut); } case AllJoynTypeIds.Boolean: return(GetBoolArg(argument, "b")); case AllJoynTypeIds.Int16: return(GetInt16Arg(argument, "n")); case AllJoynTypeIds.UInt16: return(GetUInt16Arg(argument, "q")); case AllJoynTypeIds.Int32: return(GetInt32Arg(argument, "i")); case AllJoynTypeIds.UInt32: return(GetUInt32Arg(argument, "u")); case AllJoynTypeIds.Int64: return(GetInt64Arg(argument, "x")); case AllJoynTypeIds.UInt64: return(GetUInt64Arg(argument, "t")); case AllJoynTypeIds.Double: return(GetDoubleArg(argument, "d")); case AllJoynTypeIds.String: case AllJoynTypeIds.DbusObjectPath: return(GetVariantArg_String(argument, "s")); case AllJoynTypeIds.StructBegin: return(GetVariantStructureArg(argument)); case AllJoynTypeIds.Array: if (signature.Length < 2) { throw new ArgumentException("ER_BUS_BAD_SIGNATURE"); } if (signature[1] == AllJoynTypeIds.DictionaryBegin) { if (signature.Length < 3) { throw new ArgumentException("ER_BUS_BAD_SIGNATURE"); } throw new NotImplementedException("TODO"); //return GetMapFromVariant(argument, variantSignature[2], value); } else { return(GetAllJoynMessageArgArray(argument, signature)); } } throw new ArgumentException("ER_BUS_BAD_SIGNATURE"); }