예제 #1
0
        static void TestReadWriteVariantStruct()
        {
            using (Udbus.Core.MockStoreUdbusTransport transport = new Udbus.Core.MockStoreUdbusTransport())
            {
                //Udbus.Serialization.UdbusConnector connector = Udbus.Serialization.UdbusConnector.CreateAuthorised(transport);
                Udbus.Serialization.UdbusConnector connector = new Udbus.Serialization.UdbusConnector(transport);
                Udbus.Serialization.UdbusMessageBuilderTracker builder = new Udbus.Serialization.UdbusMessageBuilderTracker();

                Udbus.Core.IUdbusMessageVisitor visitor = new Udbus.Core.UdbusMessageVisitorDumpXen();
                Udbus.Core.IUdbusMessageVisitor visitorTrack = new Udbus.Core.UdbusMessageVisitorFind(builder);
                Udbus.Core.IUdbusMessageVisitor visitors = new Udbus.Core.UdbusMessageVisitorMulti(visitor, visitorTrack);

                int result;
                using (var msg = builder.UdbusMethodMessage(
                                    "org.freedesktop.DBus", "/org/freedesktop/DBus",
                                    "org.freedesktop.DBus", "VariantStructMessage").Message)
                {
                    Udbus.Types.dbus_sig signature = Udbus.Types.dbus_sig.Initialiser;
                    signature.a[0] = Udbus.Types.dbus_type.DBUS_SIGNATURE;
                    signature.a[1] = Udbus.Types.dbus_type.DBUS_INVALID;
                    // As it happens these struct fields will double as dictionary entries...
                    object[] structFields = new object[] { 1, new object[] {"one", true } };

                    Udbus.Containers.dbus_union variantStruct = Udbus.Containers.dbus_union.CreateStruct(structFields,
                        new Udbus.Types.dbus_type[] {
                            Udbus.Types.dbus_type.DBUS_STRUCT_BEGIN,
                            Udbus.Types.dbus_type.DBUS_INT32,
                            Udbus.Types.dbus_type.DBUS_STRUCT_BEGIN,
                            Udbus.Types.dbus_type.DBUS_STRING,
                            Udbus.Types.dbus_type.DBUS_BOOLEAN,
                            Udbus.Types.dbus_type.DBUS_STRUCT_END,
                            Udbus.Types.dbus_type.DBUS_STRUCT_END,
                            Udbus.Types.dbus_type.DBUS_INVALID
                        }
                    );

                    builder.SetSignature(ref signature)
                        .BodyAdd(4096);
                    builder
                        .BodyAdd_Variant(variantStruct)
                    ;
                    result = connector.Send(msg);
                    Console.WriteLine("VariantStructMessage send result: {0}", result);
                }

                using (var msg = connector.ReceiveHandle(out result))
                {
                    Console.WriteLine("VariantStructMessage recv result: {0}. msg: {1}", result, msg);
                    if (result == 0) // If got message ok
                    {
                        Udbus.Core.UdbusMessagePair messageData = new Udbus.Core.UdbusMessagePair(msg);
                        Udbus.Serialization.UdbusMessageReader reader = new Udbus.Serialization.UdbusMessageReader(msg);

                        Udbus.Core.UdbusVisitorFunctions.Visit(result, msg, visitor);
                        Udbus.Containers.dbus_union variantReadStruct = reader.ReadVariant();
                        Console.WriteLine(string.Format("variantReadStruct: {0}", variantReadStruct.ToString()));

                    } // Ends if message ok
                } // Ends using receive message
            } // Ends using transport
        }
예제 #2
0
        static void TestReadWriteString()
        {
            using (Udbus.Core.MockStoreUdbusTransport transport = new Udbus.Core.MockStoreUdbusTransport())
            {
                //Udbus.Serialization.UdbusConnector connector = Udbus.Serialization.UdbusConnector.CreateAuthorised(transport);
                Udbus.Serialization.UdbusConnector connector = new Udbus.Serialization.UdbusConnector(transport);
                Udbus.Serialization.UdbusMessageBuilderTracker builder = new Udbus.Serialization.UdbusMessageBuilderTracker();

                Udbus.Core.IUdbusMessageVisitor visitor = new Udbus.Core.UdbusMessageVisitorDumpXen();
                Udbus.Core.IUdbusMessageVisitor visitorTrack = new Udbus.Core.UdbusMessageVisitorFind(builder);
                Udbus.Core.IUdbusMessageVisitor visitors = new Udbus.Core.UdbusMessageVisitorMulti(visitor, visitorTrack);

                int result;
                using (var msg = builder.UdbusMethodMessage(
                                    "org.freedesktop.DBus", "/org/freedesktop/DBus",
                                    "org.freedesktop.DBus", "NotARealMessage").Message)
                {
                    Udbus.Types.dbus_sig signature = Udbus.Types.dbus_sig.Initialiser;
                    signature.a[0] = Udbus.Types.dbus_type.DBUS_STRING;
                    signature.a[1] = Udbus.Types.dbus_type.DBUS_INVALID;
                    builder.SetSignature(ref signature)
                        .BodyAdd(4096)
                        .BodyAdd_String("param1")
                    ;
                    result = connector.Send(msg);
                    Console.WriteLine("NotARealMessagesend result: {0}", result);
                }

                using (var msg = connector.ReceiveHandle(out result))
                {
                    Console.WriteLine("NotARealMessage recv result: {0}. msg: {1}", result, msg);
                    if (result == 0) // If got message ok
                    {
                        Udbus.Core.UdbusMessagePair messageData = new Udbus.Core.UdbusMessagePair(msg);
                        Udbus.Serialization.UdbusMessageReader reader = new Udbus.Serialization.UdbusMessageReader(msg);

                        Udbus.Core.UdbusVisitorFunctions.Visit(result, msg, visitor);
                        //Udbus.Core.UdbusVisitorFunctions.Visit(result, msg, visitor);
                        string param1 = reader.ReadString();
                        Console.WriteLine(string.Format("Param1: {0}", param1));

                    } // Ends if message ok
                } // Ends using receive message
            } // Ends using transport
        }