AllJoynUnity.AllJoyn.BusAttachment.AdvertiseName C# (CSharp) Method

AdvertiseName() public method

public AdvertiseName ( string name, TransportMask transports ) : QStatus
name string
transports TransportMask
return QStatus
            public QStatus AdvertiseName(string name, TransportMask transports)
            {
                return alljoyn_busattachment_advertisename(_busAttachment, name, (ushort)transports);
            }

Usage Example

Exemplo n.º 1
0
        public void StartUp()
        {
            chatText = "Starting AllJoyn\n\n\n" + chatText;
            AllJoynStarted = true;
            AllJoyn.QStatus status = AllJoyn.QStatus.OK;
            {
                chatText = "Creating BusAttachment\n" + chatText;
                // Create message bus
                msgBus = new AllJoyn.BusAttachment("myApp", true);

                // Add org.alljoyn.Bus.method_sample interface
                status = msgBus.CreateInterface(INTERFACE_NAME, false, out testIntf);
                if(status)
                {

                    chatText = "Chat Interface Created.\n" + chatText;
                    Debug.Log("Chat Interface Created.");
                    testIntf.AddSignal("chat", "s", "msg", 0);
                    testIntf.Activate();
                }
                else
                {
                    chatText = "Failed to create interface 'org.alljoyn.Bus.chat'\n" + chatText;
                    Debug.Log("Failed to create interface 'org.alljoyn.Bus.chat'");
                }

                // Create a bus listener
                busListener = new MyBusListener();
                if(status)
                {

                    msgBus.RegisterBusListener(busListener);
                    chatText = "Chat BusListener Registered.\n" + chatText;
                    Debug.Log("Chat BusListener Registered.");
                }

                if(testObj == null)
                    testObj = new TestBusObject(msgBus, SERVICE_PATH);

                // Start the msg bus
                if(status)
                {

                    status = msgBus.Start();
                    if(status)
                    {
                        chatText = "Chat BusAttachment started.\n" + chatText;
                        Debug.Log("Chat BusAttachment started.");

                        msgBus.RegisterBusObject(testObj);
                        for (int i = 0; i < connectArgs.Length; ++i)
                        {
                            chatText = "Chat Connect trying: "+connectArgs[i]+"\n" + chatText;
                            Debug.Log("Chat Connect trying: "+connectArgs[i]);
                            status = msgBus.Connect(connectArgs[i]);
                            if (status)
                            {
                                chatText = "BusAttchement.Connect(" + connectArgs[i] + ") SUCCEDED.\n" + chatText;
                                Debug.Log("BusAttchement.Connect(" + connectArgs[i] + ") SUCCEDED.");
                                connectedVal = connectArgs[i];
                                break;
                            }
                            else
                            {
                                chatText = "BusAttachment.Connect(" + connectArgs[i] + ") failed.\n" + chatText;
                                Debug.Log("BusAttachment.Connect(" + connectArgs[i] + ") failed.");
                            }
                        }
                        if(!status)
                        {
                            chatText = "BusAttachment.Connect failed.\n" + chatText;
                            Debug.Log("BusAttachment.Connect failed.");
                        }
                    }
                    else
                    {
                        chatText = "Chat BusAttachment.Start failed.\n" + chatText;
                        Debug.Log("Chat BusAttachment.Start failed.");
                    }
                }

                myAdvertisedName = SERVICE_NAME+"._"+msgBus.GlobalGUIDString;

                AllJoyn.InterfaceDescription.Member chatMember = testIntf.GetMember("chat");
                status = msgBus.RegisterSignalHandler(this.ChatSignalHandler, chatMember, null);
                if(!status)
                {
                    chatText ="Chat Failed to add signal handler " + status + "\n" + chatText;
                    Debug.Log("Chat Failed to add signal handler " + status);
                }
                else {
                    chatText ="Chat add signal handler " + status + "\n" + chatText;
                    Debug.Log("Chat add signal handler " + status);
                }

                status = msgBus.AddMatch("type='signal',member='chat'");
                if(!status)
                {
                    chatText ="Chat Failed to add Match " + status.ToString() + "\n" + chatText;
                    Debug.Log("Chat Failed to add Match " + status.ToString());
                }
                else {
                    chatText ="Chat add Match " + status.ToString() + "\n" + chatText;
                    Debug.Log("Chat add Match " + status.ToString());
                }
            }

            // Request name
            if(status)
            {

                status = msgBus.RequestName(myAdvertisedName,
                    AllJoyn.DBus.NameFlags.ReplaceExisting | AllJoyn.DBus.NameFlags.DoNotQueue);
                if(!status)
                {
                    chatText ="Chat RequestName(" + SERVICE_NAME + ") failed (status=" + status + ")\n" + chatText;
                    Debug.Log("Chat RequestName(" + SERVICE_NAME + ") failed (status=" + status + ")");
                }
            }

            // Create session
            opts = new AllJoyn.SessionOpts(AllJoyn.SessionOpts.TrafficType.Messages, false,
                    AllJoyn.SessionOpts.ProximityType.Any, AllJoyn.TransportMask.Any);
            if(status)
            {

                ushort sessionPort = SERVICE_PORT;
                sessionPortListener = new MySessionPortListener();
                status = msgBus.BindSessionPort(ref sessionPort, opts, sessionPortListener);
                if(!status || sessionPort != SERVICE_PORT)
                {
                    chatText = "Chat BindSessionPort failed (" + status + ")\n" + chatText;
                    Debug.Log("Chat BindSessionPort failed (" + status + ")");
                }
                chatText = "Chat BindSessionPort on port (" + sessionPort + ")\n" + chatText;
                Debug.Log("Chat BBindSessionPort on port (" + sessionPort + ")");;
            }

            // Advertise name
            if(status)
            {
                status = msgBus.AdvertiseName(myAdvertisedName, opts.Transports);
                if(!status)
                {
                    chatText = "Chat Failed to advertise name " + myAdvertisedName + " (" + status + ")\n" + chatText;
                    Debug.Log("Chat Failed to advertise name " + myAdvertisedName + " (" + status + ")");
                }
            }

            status = msgBus.FindAdvertisedName(SERVICE_NAME);
            if(!status)
            {
                chatText = "Chat org.alljoyn.Bus.FindAdvertisedName failed.\n" + chatText;
                Debug.Log("Chat org.alljoyn.Bus.FindAdvertisedName failed.");
            }

            Debug.Log("Completed ChatService Constructor");
        }
All Usage Examples Of AllJoynUnity.AllJoyn.BusAttachment::AdvertiseName
AllJoyn.BusAttachment