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 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 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); }
internal AboutObjectDescription(MsgArg arg) : base(AboutObjectDescription.alljoyn_aboutobjectdescription_create()) { var status = AboutObjectDescription.alljoyn_aboutobjectdescription_createfrommsgarg(Handle, arg.Handle); if (status != QStatus.ER_OK) { throw new AllJoynException(status); } }
public MsgArg GetField(string fieldName, string language = null) { IntPtr outvalue; var status = alljoyn_aboutdata_getfield(Handle, fieldName, out outvalue, language); AllJoynException.CheckStatus(status); var tmp = new MsgArg(outvalue); return(tmp); }
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); }
public AboutData GetAboutData(string language) { MsgArg arg = new MsgArg(); var status = alljoyn_aboutproxy_getaboutdata(Handle, language, arg.Handle); if (status != QStatus.ER_OK) { throw new AllJoynException(status); } return(new AboutData(arg, "en")); }
/*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); }
public static object GetAllJoynMessageArgArray(MsgArg argument, string signature) { if (signature[0] != AllJoynTypeIds.Array) { throw new ArgumentException("not an array"); } if (IsArrayOfPrimitives(signature)) { switch (signature[1]) { case AllJoynTypeIds.Int16: return(GetPrimitiveArrayMessageArg <short>(argument, signature, Marshal.Copy)); case AllJoynTypeIds.Int32: return(GetPrimitiveArrayMessageArg <Int32>(argument, signature, Marshal.Copy)); case AllJoynTypeIds.Int64: return(GetPrimitiveArrayMessageArg <Int64>(argument, signature, Marshal.Copy)); case AllJoynTypeIds.Double: return(GetPrimitiveArrayMessageArg <double>(argument, signature, Marshal.Copy)); case AllJoynTypeIds.Byte: return(GetPrimitiveArrayMessageArg <byte>(argument, signature, Marshal.Copy)); //return GetByteArrayMessageArg(argument, signature); case AllJoynTypeIds.UInt16: return(GetPrimitiveArrayMessageArg <ushort>(argument, signature, MarshalHelpers.Copy)); case AllJoynTypeIds.UInt32: return(GetPrimitiveArrayMessageArg <uint>(argument, signature, MarshalHelpers.Copy)); case AllJoynTypeIds.UInt64: return(GetPrimitiveArrayMessageArg <ulong>(argument, signature, MarshalHelpers.Copy)); case AllJoynTypeIds.Boolean: { var result = GetPrimitiveArrayMessageArg <int>(argument, signature, Marshal.Copy); return(result.Select(t => t == 1).ToArray()); } default: throw new Exception("TODO"); } } if (signature == AllJoynTypeIds.StringArray) { return(GetStringArrayMessageArg(argument, signature)); } throw new NotSupportedException($"ArrayType '{signature}' not implemented"); }
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); }
private static object GetVariantStructureArg(MsgArg argument) { throw new NotImplementedException("TODO"); }
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"); }
internal AboutData(MsgArg arg, string defaultLanguage) : base(AboutData.alljoyn_aboutdata_create(defaultLanguage)) { var status = AboutData.alljoyn_aboutdata_createfrommsgarg(Handle, arg.Handle, null); AllJoynException.CheckStatus(status); }
public Message MethodCall(BusAttachment bus, string ifaceName, string methodName, MsgArg args, uint numArgs, TimeSpan timeout, MessageFlag flags = 0) { if (timeout.Ticks < 0) { throw new ArgumentOutOfRangeException(nameof(timeout)); } var replyMsg = new Message(bus); AllJoynException.CheckStatus( alljoyn_proxybusobject_methodcall(Handle, ifaceName, methodName, args.Handle, (UIntPtr)numArgs, replyMsg.Handle, (uint)timeout.TotalMilliseconds, (byte)flags) ); return(replyMsg); }
public async Task <Message> MethodCallAsync(BusAttachment bus, string ifaceName, string methodName, MsgArg args, uint numArgs, TimeSpan timeout, MessageFlag flags = 0) { if (timeout.Ticks < 0) { throw new ArgumentOutOfRangeException(nameof(timeout)); } var replyMsg = Message.alljoyn_message_create(bus.Handle); TaskCompletionSource <Message> tcs = new TaskCompletionSource <Message>(); alljoyn_messagereceiver_replyhandler_ptr replyFunc = (a, b) => { tcs.SetResult(new Message(a)); }; var handle = GCHandle.Alloc(replyFunc); AllJoynException.CheckStatus( alljoyn_proxybusobject_methodcallasync(Handle, ifaceName, methodName, replyFunc, args.Handle, (UIntPtr)numArgs, replyMsg, (uint)timeout.TotalMilliseconds, (byte)flags) ); Message message; try { message = await tcs.Task; } finally { handle.Free(); } return(message); }
public void MethodReplyArgs(Message message, MsgArg msgArg, int numArgs) { alljoyn_busobject_methodreply_args(Handle, message.Handle, msgArg.Handle, (UIntPtr)numArgs); }