/// <summary> /// Initializes a new instance of the ChatSessionObject class. /// </summary> /// <param name="bus">The BusAttachment to be associated with.</param> /// <param name="path">The path for the BusObject.</param> /// <param name="host">The instance of the MainPage which handles the UI for this /// application.</param> public ChatSessionObject(BusAttachment bus, string path, MainPage host) { try { this.hostPage = host; this.busObject = new BusObject(bus, path, false); /* Add the interface to this object */ InterfaceDescription[] ifaceArr = new InterfaceDescription[1]; bus.CreateInterface(ChatServiceInterfaceName, ifaceArr, false); ifaceArr[0].AddSignal("Chat", "s", "str", 0, string.Empty); ifaceArr[0].Activate(); InterfaceDescription chatIfc = bus.GetInterface(ChatServiceInterfaceName); this.busObject.AddInterface(chatIfc); this.chatSignalReceiver = new MessageReceiver(bus); this.chatSignalReceiver.SignalHandler += new MessageReceiverSignalHandler(this.ChatSignalHandler); this.chatSignalMember = chatIfc.GetMember("Chat"); bus.RegisterSignalHandler(this.chatSignalReceiver, this.chatSignalMember, path); } catch (System.Exception ex) { QStatus errCode = AllJoyn.AllJoynException.GetErrorCode(ex.HResult); string errMsg = AllJoyn.AllJoynException.GetErrorMessage(ex.HResult); this.hostPage.DisplayStatus("Create ChatSessionObject Error : " + errMsg); } }
/// <summary> /// Initializes a new instance of the <see cref="MyBusListener" /> class. /// </summary> /// <param name="busAtt">object responsible for connecting to and optionally managing a message /// bus.</param> /// <param name="ops">Session operations object for this application</param> public MyBusListener(BusAttachment busAtt, SessionOperations ops) { this.sessionOps = ops; // Create Bus Listener and register signal handlers this.busListener = new BusListener(busAtt); this.busListener.BusDisconnected += new BusListenerBusDisconnectedHandler(this.BusListenerBusDisconnected); this.busListener.BusStopping += new BusListenerBusStoppingHandler(this.BusListenerBusStopping); this.busListener.FoundAdvertisedName += new BusListenerFoundAdvertisedNameHandler(this.BusListenerFoundAdvertisedName); this.busListener.ListenerRegistered += new BusListenerListenerRegisteredHandler(this.BusListenerListenerRegistered); this.busListener.ListenerUnregistered += new BusListenerListenerUnregisteredHandler(this.BusListenerListenerUnregistered); this.busListener.LostAdvertisedName += new BusListenerLostAdvertisedNameHandler(this.BusListenerLostAdvertisedName); this.busListener.NameOwnerChanged += new BusListenerNameOwnerChangedHandler(this.BusListenerNameOwnerChanged); // Create Session Listener and register signal handlers this.sessionListener = new SessionListener(busAtt); this.sessionListener.SessionLost += new SessionListenerSessionLostHandler(this.SessionListenerSessionLost); this.sessionListener.SessionMemberAdded += new SessionListenerSessionMemberAddedHandler(this.SessionListenerSessionMemberAdded); this.sessionListener.SessionMemberRemoved += new SessionListenerSessionMemberRemovedHandler(this.SessionListenerSessionMemberRemoved); // Create Session Port Listener and register signal handlers this.sessionPortListener = new SessionPortListener(busAtt); this.sessionPortListener.AcceptSessionJoiner += new SessionPortListenerAcceptSessionJoinerHandler(this.SessionPortListenerAcceptSessionJoiner); this.sessionPortListener.SessionJoined += new SessionPortListenerSessionJoinedHandler(this.SessionPortListenerSessionJoined); busAtt.RegisterBusListener(this.busListener); }
public void AddInterfaceTest() { BusAttachment bus = new BusAttachment("addinterface", true, 4); bus.CreateInterfacesFromXml(signalIntf); bus.CreateInterfacesFromXml(methodIntf); bus.CreateInterfacesFromXml(propertyIntf); bus.CreateInterfacesFromXml(mixedIntf); bus.CreateInterfacesFromXml(emptyIntf); InterfaceDescription[] annIntf = new InterfaceDescription[1]; bus.CreateInterface("org.alljoyn.Annotated", annIntf, false); annIntf[0].AddMethod("method", "ss", "s", "in1,in2,out1", (byte)0, ""); annIntf[0].AddProperty("property", "s", (byte)PropAccessType.PROP_ACCESS_RW); annIntf[0].AddSignal("signal", "suy", "str,uint,byte", (byte)0, ""); annIntf[0].AddAnnotation("org.freedesktop.DBus.Deprecated", "false"); annIntf[0].AddMemberAnnotation("method", "org.freedesktop.DBus.Method.NoReply", "true"); annIntf[0].AddPropertyAnnotation("property", "org.freedesktop.DBus.Property.EmitsChangedSignal", "true"); annIntf[0].Activate(); BusObject busObj = new BusObject(bus, "/addinterfaces", false); busObj.AddInterface(bus.GetInterface("org.alljoyn.Signals")); busObj.AddInterface(bus.GetInterface("org.alljoyn.Methods")); busObj.AddInterface(bus.GetInterface("org.alljoyn.Properties")); busObj.AddInterface(bus.GetInterface("org.alljoyn.Empty")); busObj.AddInterface(bus.GetInterface("org.alljoyn.Annotated")); }
/// <summary> /// Initializes a new instance of the <see cref="SignalConsumerBusListener" /> class /// </summary> /// <param name="bus">object responsible for connecting to and optionally managing a message /// bus</param> /// <param name="foundNameEvent">event to set when the well-known name being queried /// is found</param> public SignalConsumerBusListener(BusAttachment bus, AutoResetEvent foundNameEvent) { SessionidList = new List<uint>(); this.busAtt = bus; this.foundName = foundNameEvent; this.busListener = new BusListener(bus); this.busListener.BusDisconnected += new BusListenerBusDisconnectedHandler(this.BusListenerBusDisconnected); this.busListener.BusStopping += new BusListenerBusStoppingHandler(this.BusListenerBusStopping); this.busListener.FoundAdvertisedName += new BusListenerFoundAdvertisedNameHandler(this.BusListenerFoundAdvertisedName); this.busListener.ListenerRegistered += new BusListenerListenerRegisteredHandler(this.BusListenerListenerRegistered); this.busListener.ListenerUnregistered += new BusListenerListenerUnregisteredHandler(this.BusListenerListenerUnregistered); this.busListener.LostAdvertisedName += new BusListenerLostAdvertisedNameHandler(this.BusListenerLostAdvertisedName); this.busListener.NameOwnerChanged += new BusListenerNameOwnerChangedHandler(this.BusListenerNameOwnerChanged); this.sessionListener = new SessionListener(this.busAtt); this.sessionListener.SessionLost += new SessionListenerSessionLostHandler(this.SessionListenerSessionLost); this.sessionListener.SessionMemberAdded += new SessionListenerSessionMemberAddedHandler(this.SessionListenerSessionMemberAdded); this.sessionListener.SessionMemberRemoved += new SessionListenerSessionMemberRemovedHandler(this.SessionListenerSessionMemberRemoved); MessageReceiver signalReceiver = new MessageReceiver(bus); signalReceiver.SignalHandler += this.NameChangedSignalHandler; InterfaceDescription interfaceDescription2 = bus.GetInterface(SignalConsumerGlobals.InterfaceName); InterfaceMember signalMember = interfaceDescription2.GetSignal("nameChanged"); bus.RegisterSignalHandler(signalReceiver, signalMember, string.Empty); }
/// <summary> /// Initializes a new instance of the <see cref="ClientBusListener" /> class. /// </summary> /// <param name="busAtt">object responsible for connecting to and optionally managing a message /// bus.</param> /// <param name="op">Stress Operation using this class as listener object</param> /// <param name="foundNameEvent">Event to set when the first service is discovered</param> public ClientBusListener(BusAttachment busAtt, StressOperation op, AutoResetEvent foundNameEvent) { this.stressOp = op; this.mutex = new Mutex(); this.foundAvertisedName = false; this.foundName = foundNameEvent; // Create Bus Listener and register signal handlers this.busListener = new BusListener(busAtt); this.busListener.BusDisconnected += new BusListenerBusDisconnectedHandler(this.BusListenerBusDisconnected); this.busListener.BusStopping += new BusListenerBusStoppingHandler(this.BusListenerBusStopping); this.busListener.FoundAdvertisedName += new BusListenerFoundAdvertisedNameHandler(this.BusListenerFoundAdvertisedName); this.busListener.ListenerRegistered += new BusListenerListenerRegisteredHandler(this.BusListenerListenerRegistered); this.busListener.ListenerUnregistered += new BusListenerListenerUnregisteredHandler(this.BusListenerListenerUnregistered); this.busListener.LostAdvertisedName += new BusListenerLostAdvertisedNameHandler(this.BusListenerLostAdvertisedName); this.busListener.NameOwnerChanged += new BusListenerNameOwnerChangedHandler(this.BusListenerNameOwnerChanged); // Create Session Listener and register signal handlers this.sessionListener = new SessionListener(busAtt); this.sessionListener.SessionLost += new SessionListenerSessionLostHandler(this.SessionListenerSessionLost); this.sessionListener.SessionMemberAdded += new SessionListenerSessionMemberAddedHandler(this.SessionListenerSessionMemberAdded); this.sessionListener.SessionMemberRemoved += new SessionListenerSessionMemberRemovedHandler(this.SessionListenerSessionMemberRemoved); busAtt.RegisterBusListener(this.busListener); }
/// <summary> /// Initializes a new instance of the <see cref="FileTransferBusObject" /> class. /// </summary> /// <param name="busAtt">Object responsible for connecting to and optionally managing a /// message bus.</param> public FileTransferBusObject(BusAttachment busAtt) { this.Bus = busAtt; this.Folder = null; this.lastIndex = 0; this.SessionId = 0; if (null == this.Bus) { App.OutputLine("Unexpected null object in parameters to FileTransferBusObject constructor."); } }
/// <summary> /// Initializes a new instance of the <see cref="SecureBusObject" /> class. /// </summary> /// <param name="busAtt">Object responsible for connecting to and optionally managing a /// message bus.</param> /// <param name="iface">The interface used by the service that is implemented by this /// class.</param> public SecureBusObject(BusAttachment busAtt, InterfaceDescription[] iface) { this.BusObject = new BusObject(busAtt, App.ServicePath, false); this.BusObject.AddInterface(iface[0]); InterfaceMember pingMember = iface[0].GetMember("Ping"); MessageReceiver pingReceiver = new MessageReceiver(busAtt); pingReceiver.MethodHandler += new MessageReceiverMethodHandler(this.PingMethodHandler); BusObject.AddMethodHandler(pingMember, pingReceiver); busAtt.RegisterBusObject(this.BusObject); }
public AddMatchBusObj(BusAttachment bus) { this.busObj = new BusObject(bus, "/test", false); InterfaceDescription[] intf = new InterfaceDescription[1]; bus.CreateInterface("org.alljoyn.addmatchtest", intf, false); intf[0].AddSignal("testSig", "s", "str", (byte)0, ""); intf[0].Activate(); this.busObj.AddInterface(intf[0]); MessageReceiver receiver = new MessageReceiver(bus); receiver.SignalHandler += new MessageReceiverSignalHandler(this.SigHandle); bus.RegisterSignalHandler(receiver, intf[0].GetSignal("testSig"), ""); bus.RegisterBusObject(this.busObj); }
/// <summary> /// Initializes a new instance of the <see cref="SignalServiceBusObject" /> class /// </summary> /// <param name="busAtt">object responsible for connecting to and optionally managing a message /// bus</param> public SignalServiceBusObject(BusAttachment busAtt) { this.BusObject = new BusObject(busAtt, SignalServiceGlobals.ServicePath, false); this.name = string.Empty; InterfaceDescription[] interfaceDescription = new InterfaceDescription[1]; busAtt.CreateInterface(SignalServiceGlobals.InterfaceName, interfaceDescription, false); interfaceDescription[0].AddSignal("nameChanged", "s", "newName", (byte)0, string.Empty); interfaceDescription[0].AddProperty("name", "s", (byte)PropAccessType.PROP_ACCESS_RW); interfaceDescription[0].Activate(); this.BusObject.AddInterface(interfaceDescription[0]); App.OutputLine("Interface created and added to the Bus Object."); this.signalMember = interfaceDescription[0].GetSignal("nameChanged"); this.BusObject.Set += this.SetHandler; busAtt.RegisterBusObject(this.BusObject); App.OutputLine("Bus Object and property set handlers Registered."); }
/// <summary> /// Initializes a new instance of the <see cref="NameChangeBusListener" /> class /// </summary> /// <param name="bus">object responsible for connecting to and optionally managing a message /// bus</param> /// <param name="foundNameEvent">event to set when the well-known name being queried /// is found</param> public NameChangeBusListener(BusAttachment bus, AutoResetEvent foundNameEvent) { this.busAtt = bus; this.foundName = foundNameEvent; this.busListener = new BusListener(this.busAtt); this.busListener.BusDisconnected += new BusListenerBusDisconnectedHandler(this.BusListenerBusDisconnected); this.busListener.BusStopping += new BusListenerBusStoppingHandler(this.BusListenerBusStopping); this.busListener.FoundAdvertisedName += new BusListenerFoundAdvertisedNameHandler(this.BusListenerFoundAdvertisedName); this.busListener.ListenerRegistered += new BusListenerListenerRegisteredHandler(this.BusListenerListenerRegistered); this.busListener.ListenerUnregistered += new BusListenerListenerUnregisteredHandler(this.BusListenerListenerUnregistered); this.busListener.LostAdvertisedName += new BusListenerLostAdvertisedNameHandler(this.BusListenerLostAdvertisedName); this.busListener.NameOwnerChanged += new BusListenerNameOwnerChangedHandler(this.BusListenerNameOwnerChanged); this.sessionListener = new SessionListener(this.busAtt); this.sessionListener.SessionLost += new SessionListenerSessionLostHandler(this.SessionListenerSessionLost); this.sessionListener.SessionMemberAdded += new SessionListenerSessionMemberAddedHandler(this.SessionListenerSessionMemberAdded); this.sessionListener.SessionMemberRemoved += new SessionListenerSessionMemberRemovedHandler(this.SessionListenerSessionMemberRemoved); }
public AudioStream(BusAttachment bus, string name, MP3Reader mp3Reader, UInt32 jitter, UInt32 prefill) { _mediaStream = new MediaStream(bus, name, mp3Reader.GetDescription()); _mediaPacer = new MediaPacer(mp3Reader.GetDescription(), jitter, 0); _mp3Reader = mp3Reader; _prefill = prefill; _mediaStream.OnOpen += OnOpen; _mediaStream.OnClose += OnClose; _mediaStream.OnPlay += OnPlay; _mediaStream.OnPause += OnPause; _mediaStream.OnSeekRelative += OnSeekRelative; _mediaStream.OnSeekAbsolute += OnSeekAbsolute; _mediaPacer.JitterMiss += JitterMiss; _mediaPacer.RequestFrames += RequestFrames; _buffer = new byte[_frameReadLength * _mp3Reader.FrameLen]; }
/// <summary> /// Initializes a new instance of the <see cref="ServiceBusObject"/> class. /// </summary> /// <param name="busAtt">Message bus for the stress operation using this</param> /// <param name="op">Stress operation using this bus object</param> public ServiceBusObject(BusAttachment busAtt, StressOperation op) { this.stressOp = op; this.busObject = new BusObject(busAtt, ServicePath, false); // Implement the 'cat' interface InterfaceDescription[] intfDescription = new InterfaceDescription[1]; busAtt.CreateInterface(InterfaceName, intfDescription, false); intfDescription[0].AddMethod("cat", "ss", "s", "inStr1,inStr2,outStr", (byte)0, string.Empty); intfDescription[0].Activate(); this.busObject.AddInterface(intfDescription[0]); // Register 'cat' method handler InterfaceMember catMethod = intfDescription[0].GetMethod("cat"); MessageReceiver catReceiver = new MessageReceiver(busAtt); catReceiver.MethodHandler += new MessageReceiverMethodHandler(this.Cat); this.busObject.AddMethodHandler(catMethod, catReceiver); busAtt.RegisterBusObject(this.busObject); }
/// <summary> /// Initializes a new instance of the <see cref="BasicClientBusListener" /> class /// </summary> /// <param name="bus">object responsible for connecting to and optionally managing a message /// bus</param> /// <param name="foundNameEvent">event to set when the well-known name being queried /// is found</param> public BasicClientBusListener(BusAttachment bus, AutoResetEvent foundNameEvent) { SessionidList = new List<uint>(); busAtt = bus; foundName = foundNameEvent; busListener = new BusListener(bus); busListener.BusDisconnected += new BusListenerBusDisconnectedHandler(BusListenerBusDisconnected); busListener.BusStopping += new BusListenerBusStoppingHandler(BusListenerBusStopping); busListener.FoundAdvertisedName += new BusListenerFoundAdvertisedNameHandler(BusListenerFoundAdvertisedName); busListener.ListenerRegistered += new BusListenerListenerRegisteredHandler(BusListenerListenerRegistered); busListener.ListenerUnregistered += new BusListenerListenerUnregisteredHandler(BusListenerListenerUnregistered); busListener.LostAdvertisedName += new BusListenerLostAdvertisedNameHandler(BusListenerLostAdvertisedName); busListener.NameOwnerChanged += new BusListenerNameOwnerChangedHandler(BusListenerNameOwnerChanged); sessionListener = new SessionListener(bus); sessionListener.SessionLost += new SessionListenerSessionLostHandler(SessionListenerSessionLost); sessionListener.SessionMemberAdded += new SessionListenerSessionMemberAddedHandler(SessionListenerSessionMemberAdded); sessionListener.SessionMemberRemoved += new SessionListenerSessionMemberRemovedHandler(SessionListenerSessionMemberRemoved); }
/// <summary> /// Initializes a new instance of the <see cref="MyBusObject"/> class /// </summary> /// <param name="busAtt">Message bus for the sessions app</param> /// <param name="ops">Session Operations object for this application</param> public MyBusObject(BusAttachment busAtt, SessionOperations ops) { this.busObject = new BusObject(busAtt, BusObjectPath, false); this.sessionOps = ops; this.ChatEcho = true; // Implement the 'Chat' interface InterfaceDescription[] intfDescription = new InterfaceDescription[1]; busAtt.CreateInterface(SessionInterfaceName, intfDescription, false); intfDescription[0].AddSignal("Chat", "s", "str", (byte)0, string.Empty); intfDescription[0].Activate(); this.chatSignal = intfDescription[0].GetSignal("Chat"); this.busObject.AddInterface(intfDescription[0]); // Register chat signal handler MessageReceiver signalReceiver = new MessageReceiver(busAtt); signalReceiver.SignalHandler += new MessageReceiverSignalHandler(this.ChatSignalHandler); busAtt.RegisterSignalHandler(signalReceiver, this.chatSignal, string.Empty); busAtt.RegisterBusObject(this.busObject); }
/// <summary> /// Initializes a new instance of the Listeners class. /// </summary> /// <param name="bus">The bus to listen on.</param> /// <param name="host">The main page which handles the user interface.</param> public Listeners(BusAttachment bus, MainPage host) { this.hostPage = host; this.busListeners = new BusListener(bus); this.busListeners.BusDisconnected += new BusListenerBusDisconnectedHandler(this.BusListenerBusDisconnected); this.busListeners.BusStopping += new BusListenerBusStoppingHandler(this.BusListenerBusStopping); this.busListeners.FoundAdvertisedName += new BusListenerFoundAdvertisedNameHandler(this.BusListenerFoundAdvertisedName); this.busListeners.ListenerRegistered += new BusListenerListenerRegisteredHandler(this.BusListenerListenerRegistered); this.busListeners.ListenerUnregistered += new BusListenerListenerUnregisteredHandler(this.BusListenerListenerUnregistered); this.busListeners.LostAdvertisedName += new BusListenerLostAdvertisedNameHandler(this.BusListenerLostAdvertisedName); this.busListeners.NameOwnerChanged += new BusListenerNameOwnerChangedHandler(this.BusListenerNameOwnerChanged); this.sessionPortListener = new SessionPortListener(bus); this.sessionPortListener.AcceptSessionJoiner += new SessionPortListenerAcceptSessionJoinerHandler(this.SessionPortListenerAcceptSessionJoiner); this.sessionPortListener.SessionJoined += new SessionPortListenerSessionJoinedHandler(this.SessionPortListenerSessionJoined); this.sessionListener = new SessionListener(bus); this.sessionListener.SessionLost += new SessionListenerSessionLostHandler(this.SessionListenerSessionLost); this.sessionListener.SessionMemberAdded += new SessionListenerSessionMemberAddedHandler(this.SessionListenerSessionMemberAdded); this.sessionListener.SessionMemberRemoved += new SessionListenerSessionMemberRemovedHandler(this.SessionListenerSessionMemberRemoved); }
/// <summary> /// Initializes a new instance of the <see cref="BasicServiceBusObject" /> class /// </summary> /// <param name="busAtt">object responsible for connecting to and optionally managing a message /// bus</param> public BasicServiceBusObject(BusAttachment busAtt) { this.BusObject = new BusObject(busAtt, BasicServiceGlobals.ServicePath, false); // Create 'cat' interface InterfaceDescription[] interfaceDescription = new InterfaceDescription[1]; busAtt.CreateInterface(BasicServiceGlobals.InterfaceName, interfaceDescription, false); interfaceDescription[0].AddMethod("cat", "ss", "s", "inStr1,inStr2,outStr", (byte)0, string.Empty); interfaceDescription[0].Activate(); // Create and register the 'cat' method handlers this.BusObject.AddInterface(interfaceDescription[0]); InterfaceMember catMember = interfaceDescription[0].GetMember("cat"); MessageReceiver catReceiver = new MessageReceiver(busAtt); catReceiver.MethodHandler += new MessageReceiverMethodHandler(this.CatMethodHandler); this.BusObject.AddMethodHandler(catMember, catReceiver); App.OutputLine("Created 'cat' interface and registered method handlers."); busAtt.RegisterBusObject(this.BusObject); }
public BusObject(BusAttachment bus, string path, bool isPlaceholder) { // Can't let the GC free these delegates so they must be members _propertyGet = new InternalPropertyGetEventHandler(this._PropertyGet); _propertySet = new InternalPropertySetEventHandler(this._PropertySet); _objectRegistered = new InternalObjectRegisteredEventHandler(this._ObjectRegistered); _objectUnregistered = new InternalObjectUnregisteredEventHandler(this._ObjectUnregistered); // Ref holder for method handler internal delegates _methodHandlerDelegateRefHolder = new List<InternalMethodHandler>(); BusObjectCallbacks callbacks; callbacks.property_get = Marshal.GetFunctionPointerForDelegate(_propertyGet); callbacks.property_set = Marshal.GetFunctionPointerForDelegate(_propertySet); callbacks.object_registered = Marshal.GetFunctionPointerForDelegate(_objectRegistered); callbacks.object_unregistered = Marshal.GetFunctionPointerForDelegate(_objectUnregistered); GCHandle gch = GCHandle.Alloc(callbacks, GCHandleType.Pinned); _busObject = alljoyn_busobject_create(bus.UnmanagedPtr, path, isPlaceholder ? 1 : 0, gch.AddrOfPinnedObject(), IntPtr.Zero); gch.Free(); }
/// <summary> /// Initializes a new instance of the <see cref="SignalServiceBusListener" /> class. /// </summary> /// <param name="bus">object responsible for connecting to and optionally managing a message /// bus.</param> public SignalServiceBusListener(BusAttachment bus) { SessionidList = new List<uint>(); this.busAtt = bus; this.busListener = new BusListener(bus); this.busListener.BusDisconnected += new BusListenerBusDisconnectedHandler(this.BusListenerBusDisconnected); this.busListener.BusStopping += new BusListenerBusStoppingHandler(this.BusListenerBusStopping); this.busListener.FoundAdvertisedName += new BusListenerFoundAdvertisedNameHandler(this.BusListenerFoundAdvertisedName); this.busListener.ListenerRegistered += new BusListenerListenerRegisteredHandler(this.BusListenerListenerRegistered); this.busListener.ListenerUnregistered += new BusListenerListenerUnregisteredHandler(this.BusListenerListenerUnregistered); this.busListener.LostAdvertisedName += new BusListenerLostAdvertisedNameHandler(this.BusListenerLostAdvertisedName); this.busListener.NameOwnerChanged += new BusListenerNameOwnerChangedHandler(this.BusListenerNameOwnerChanged); this.sessionPortListener = new SessionPortListener(bus); this.sessionPortListener.AcceptSessionJoiner += new SessionPortListenerAcceptSessionJoinerHandler(this.SessionPortListenerAcceptSessionJoiner); this.sessionPortListener.SessionJoined += new SessionPortListenerSessionJoinedHandler(this.SessionPortListenerSessionJoined); this.sessionListener = new SessionListener(bus); this.sessionListener.SessionLost += new SessionListenerSessionLostHandler(this.SessionListenerSessionLost); this.sessionListener.SessionMemberAdded += new SessionListenerSessionMemberAddedHandler(this.SessionListenerSessionMemberAdded); this.sessionListener.SessionMemberRemoved += new SessionListenerSessionMemberRemovedHandler(this.SessionListenerSessionMemberRemoved); }
private void _ListenerUnregistered(IntPtr context) { System.Threading.Thread callIt = new System.Threading.Thread((object o) => { ListenerUnregistered(); _registeredBus = null; }); callIt.Start(); }
private void _ListenerRegistered(IntPtr context, IntPtr bus) { IntPtr _bus = bus; System.Threading.Thread callIt = new System.Threading.Thread((object o) => { _registeredBus = BusAttachment.MapBusAttachment(_bus); ListenerRegistered(_registeredBus); }); callIt.Start(); }
/** * Called by the bus when the listener is registered. This give the listener implementation the * opportunity to save a reference to the bus. * * @param busAttachment The bus the listener is registered with. */ protected virtual void ListenerRegistered(BusAttachment busAttachment) { }
public SignalBusObject(BusAttachment busAtt, string path) { this.busObject = new BusObject(busAtt, path, false); InterfaceDescription[] intf = new InterfaceDescription[1]; busAtt.CreateInterface("org.alljoyn.SignalVariety", intf, false); intf[0].AddSignal("string", "s", "str", (byte)0, ""); intf[0].AddSignal("byte", "y", "byte", (byte)0, ""); intf[0].AddSignal("bool", "b", "bool", (byte)0, ""); intf[0].AddSignal("int16", "n", "int16", (byte)0, ""); intf[0].AddSignal("uint16", "q", "uint16", (byte)0, ""); intf[0].AddSignal("int32", "i", "int32", (byte)0, ""); intf[0].AddSignal("uint32", "u", "uint32", (byte)0, ""); intf[0].AddSignal("int64", "x", "int64", (byte)0, ""); intf[0].AddSignal("uint64", "t", "uint64", (byte)0, ""); intf[0].AddSignal("double", "d", "double", (byte)0, ""); intf[0].AddSignal("dArray", "ad", "dArray", (byte)0, ""); intf[0].AddSignal("byiStruct", "(byi)", "byiStruct", (byte)0, ""); intf[0].AddSignal("isDict", "{is}", "isDict", (byte)0, ""); intf[0].Activate(); this.busObject.AddInterface(intf[0]); MessageReceiver msgReceiver1 = new MessageReceiver(busAtt); msgReceiver1.SignalHandler += new MessageReceiverSignalHandler(this.StringSig); busAtt.RegisterSignalHandler(msgReceiver1, intf[0].GetSignal("string"), ""); MessageReceiver msgReceiver2 = new MessageReceiver(busAtt); msgReceiver2.SignalHandler += new MessageReceiverSignalHandler(this.ByteSig); busAtt.RegisterSignalHandler(msgReceiver2, intf[0].GetSignal("byte"), ""); MessageReceiver msgReceiver3 = new MessageReceiver(busAtt); msgReceiver3.SignalHandler += new MessageReceiverSignalHandler(this.BoolSig); busAtt.RegisterSignalHandler(msgReceiver3, intf[0].GetSignal("bool"), ""); MessageReceiver msgReceiver4 = new MessageReceiver(busAtt); msgReceiver4.SignalHandler += new MessageReceiverSignalHandler(this.Int16Sig); busAtt.RegisterSignalHandler(msgReceiver4, intf[0].GetSignal("int16"), ""); MessageReceiver msgReceiver5 = new MessageReceiver(busAtt); msgReceiver5.SignalHandler += new MessageReceiverSignalHandler(this.Uint16Sig); busAtt.RegisterSignalHandler(msgReceiver5, intf[0].GetSignal("uint16"), ""); MessageReceiver msgReceiver6 = new MessageReceiver(busAtt); msgReceiver6.SignalHandler += new MessageReceiverSignalHandler(this.Int32Sig); busAtt.RegisterSignalHandler(msgReceiver6, intf[0].GetSignal("int32"), ""); MessageReceiver msgReceiver7 = new MessageReceiver(busAtt); msgReceiver7.SignalHandler += new MessageReceiverSignalHandler(this.Uint32Sig); busAtt.RegisterSignalHandler(msgReceiver7, intf[0].GetSignal("uint32"), ""); MessageReceiver msgReceiver8 = new MessageReceiver(busAtt); msgReceiver8.SignalHandler += new MessageReceiverSignalHandler(this.Int64Sig); busAtt.RegisterSignalHandler(msgReceiver8, intf[0].GetSignal("int64"), ""); MessageReceiver msgReceiver9 = new MessageReceiver(busAtt); msgReceiver9.SignalHandler += new MessageReceiverSignalHandler(this.Uint64Sig); busAtt.RegisterSignalHandler(msgReceiver9, intf[0].GetSignal("uint64"), ""); MessageReceiver msgReceiver10 = new MessageReceiver(busAtt); msgReceiver10.SignalHandler += new MessageReceiverSignalHandler(this.DoubleSig); busAtt.RegisterSignalHandler(msgReceiver10, intf[0].GetSignal("double"), ""); MessageReceiver msgReceiver11 = new MessageReceiver(busAtt); msgReceiver11.SignalHandler += new MessageReceiverSignalHandler(this.DArrarySig); busAtt.RegisterSignalHandler(msgReceiver11, intf[0].GetSignal("dArray"), ""); MessageReceiver msgReceiver12 = new MessageReceiver(busAtt); msgReceiver12.SignalHandler += new MessageReceiverSignalHandler(this.BYIStructSig); busAtt.RegisterSignalHandler(msgReceiver12, intf[0].GetSignal("byiStruct"), ""); MessageReceiver msgReceiver13 = new MessageReceiver(busAtt); msgReceiver13.SignalHandler += new MessageReceiverSignalHandler(this.ISDictSig); busAtt.RegisterSignalHandler(msgReceiver13, intf[0].GetSignal("isDict"), ""); busAtt.RegisterBusObject(this.busObject); }
public ServiceBusObject(BusAttachment busAtt, string path) { this.busObject = new BusObject(busAtt, path, false); InterfaceDescription[] intf = new InterfaceDescription[1]; busAtt.CreateInterface("org.alljoyn.SignalVariety", intf, false); intf[0].AddSignal("string", "s", "str", (byte)0, ""); intf[0].AddSignal("byte", "y", "byte", (byte)0, ""); intf[0].AddSignal("bool", "b", "bool", (byte)0, ""); intf[0].AddSignal("int16", "n", "int16", (byte)0, ""); intf[0].AddSignal("uint16", "q", "uint16", (byte)0, ""); intf[0].AddSignal("int32", "i", "int32", (byte)0, ""); intf[0].AddSignal("uint32", "u", "uint32", (byte)0, ""); intf[0].AddSignal("int64", "x", "int64", (byte)0, ""); intf[0].AddSignal("uint64", "t", "uint64", (byte)0, ""); intf[0].AddSignal("double", "d", "double", (byte)0, ""); intf[0].AddSignal("dArray", "ad", "dArray", (byte)0, ""); intf[0].AddSignal("byiStruct", "(byi)", "byiStruct", (byte)0, ""); intf[0].AddSignal("isDict", "{is}", "isDict", (byte)0, ""); intf[0].Activate(); this.busObject.AddInterface(intf[0]); busAtt.RegisterBusObject(this.busObject); }
public MethodHandlerBusObject(BusAttachment busAtt, string path) { this.busObject = new BusObject(busAtt, path, false); InterfaceDescription[] intf = new InterfaceDescription[1]; busAtt.CreateInterface("org.alljoyn.methodhandler", intf, false); intf[0].AddMethod("cat", "ss", "s", "in1,in2,out", (byte)0, ""); intf[0].AddMethod("sayhi", "s", "s", "in,out", (byte)0, ""); intf[0].Activate(); this.busObject.AddInterface(intf[0]); this.catMember = intf[0].GetMethod("cat"); this.sayHiMember = intf[0].GetMethod("sayhi"); MessageReceiver catReceiver = new MessageReceiver(busAtt); catReceiver.MethodHandler += new MessageReceiverMethodHandler(this.CatHandler); MessageReceiver sayHiReceiver = new MessageReceiver(busAtt); sayHiReceiver.MethodHandler += new MessageReceiverMethodHandler(this.SayHiHandler); try { busObject.AddMethodHandler(null, catReceiver); Assert.IsFalse(true); } catch (Exception ex) { Logger.LogMessage("%s", ex.Message); } try { busObject.AddMethodHandler(intf[0].GetMethod("cat"), null); Assert.IsFalse(true); } catch (Exception ex) { Logger.LogMessage("%s", ex.Message); } busObject.AddMethodHandler(intf[0].GetMethod("cat"), catReceiver); busObject.AddMethodHandler(intf[0].GetMethod("sayhi"), sayHiReceiver); busAtt.RegisterBusObject(this.busObject); }
public void SignalTest() { BusAttachment service = new BusAttachment("signalservice", true, 4); SignalBusObject busObj = new SignalBusObject(service, "/sigtest"); service.Start(); service.ConnectAsync(connectSpec).AsTask().Wait(); SessionPortListener spl = new SessionPortListener(service); spl.AcceptSessionJoiner += new SessionPortListenerAcceptSessionJoinerHandler((ushort sessionPort, string joiner, SessionOpts opts) => { Assert.AreEqual(89, sessionPort); return true; }); service.RequestName("org.alljoyn.signaltesting", (byte)RequestNameType.DBUS_NAME_DO_NOT_QUEUE); service.BindSessionPort(89, new ushort[1], new SessionOpts(TrafficType.TRAFFIC_MESSAGES, false, ProximityType.PROXIMITY_ANY, TransportMaskType.TRANSPORT_ANY), spl); service.AdvertiseName("org.alljoyn.signaltesting", TransportMaskType.TRANSPORT_ANY); BusAttachment client = new BusAttachment("methodcaller", true, 4); ServiceBusObject sbo = new ServiceBusObject(client, "/clientbusobj"); BusListener bl = new BusListener(client); client.RegisterBusListener(bl); bl.FoundAdvertisedName += new BusListenerFoundAdvertisedNameHandler( (string name, TransportMaskType transport, string namePrefix) => { foundSignalObjectName.Set(); }); client.Start(); client.ConnectAsync(connectSpec).AsTask().Wait(); client.FindAdvertisedName("org.alljoyn.signaltesting"); foundSignalObjectName.WaitOne(); Task<JoinSessionResult> joinTask = client.JoinSessionAsync("org.alljoyn.signaltesting", 89, new SessionListener(client), new SessionOpts(TrafficType.TRAFFIC_MESSAGES, false, ProximityType.PROXIMITY_ANY, TransportMaskType.TRANSPORT_ANY), new SessionOpts[1], null).AsTask<JoinSessionResult>(); joinTask.Wait(); Assert.IsTrue(QStatus.ER_OK == joinTask.Result.Status); // TODO: call BusObject.Signal() for each one of the signals in the interface and make sure // they're received and the data is consistent with what was sent. }
public void AddMethodHandlerTest() { BusAttachment service = new BusAttachment("methodhandler", true, 4); MethodHandlerBusObject busObj = new MethodHandlerBusObject(service, "/handlertest"); service.Start(); service.ConnectAsync(connectSpec).AsTask().Wait(); SessionPortListener spl = new SessionPortListener(service); spl.AcceptSessionJoiner += new SessionPortListenerAcceptSessionJoinerHandler((ushort sessionPort, string joiner, SessionOpts opts) => { Assert.AreEqual(33, sessionPort); return true; }); service.RequestName("org.alljoyn.methodhandlertest", (byte)RequestNameType.DBUS_NAME_DO_NOT_QUEUE); service.BindSessionPort(33, new ushort[1], new SessionOpts(TrafficType.TRAFFIC_MESSAGES, false, ProximityType.PROXIMITY_ANY, TransportMaskType.TRANSPORT_ANY), spl); service.AdvertiseName("org.alljoyn.methodhandlertest", TransportMaskType.TRANSPORT_ANY); BusAttachment client = new BusAttachment("methodcaller", true, 4); BusListener bl = new BusListener(client); client.RegisterBusListener(bl); bl.FoundAdvertisedName += new BusListenerFoundAdvertisedNameHandler( (string name, TransportMaskType transport, string namePrefix) => { foundMethodObjectName.Set(); }); client.Start(); client.ConnectAsync(connectSpec).AsTask().Wait(); client.FindAdvertisedName("org.alljoyn.methodhandlertest"); foundMethodObjectName.WaitOne(); Task<JoinSessionResult> joinTask = client.JoinSessionAsync("org.alljoyn.methodhandlertest", 33, new SessionListener(client), new SessionOpts(TrafficType.TRAFFIC_MESSAGES, false, ProximityType.PROXIMITY_ANY, TransportMaskType.TRANSPORT_ANY), new SessionOpts[1], null).AsTask<JoinSessionResult>(); joinTask.Wait(); Assert.IsTrue(QStatus.ER_OK == joinTask.Result.Status); ProxyBusObject proxy = new ProxyBusObject(client, "org.alljoyn.methodhandlertest", "/handlertest", joinTask.Result.SessionId); Task<IntrospectRemoteObjectResult> introTask = proxy.IntrospectRemoteObjectAsync(null).AsTask<IntrospectRemoteObjectResult>(); introTask.Wait(); Assert.IsTrue(QStatus.ER_OK == introTask.Result.Status); MsgArg[] args1 = new MsgArg[2]; args1[0] = new MsgArg("s", new object[] { "one" }); args1[1] = new MsgArg("s", new object[] { "two" }); Task<MethodCallResult> catTask = proxy.MethodCallAsync(service.GetInterface("org.alljoyn.methodhandler").GetMethod("cat"), args1, null, 60000, (byte)0).AsTask<MethodCallResult>(); catTask.Wait(); Assert.IsTrue(AllJoynMessageType.MESSAGE_METHOD_RET == catTask.Result.Message.Type); Assert.AreEqual("onetwo", catTask.Result.Message.GetArg(0).Value.ToString()); // Check BUGBUG above //MsgArg[] args2 = new MsgArg[1]; //args2[0] = new MsgArg("s", new object[] { "hello" }); //Task<MethodCallResult> sayHiTask = proxy.MethodCallAsync(service.GetInterface("org.alljoyn.methodhandler").GetMethod("sayhi"), // args2, null, 60000, (byte)0).AsTask<MethodCallResult>(); //sayHiTask.Wait(); //Assert.IsTrue(AllJoynMessageType.MESSAGE_METHOD_RET == sayHiTask.Result.Message.Type); //Assert.AreEqual("aloha", sayHiTask.Result.Message.GetArg(0).Value.ToString()); // TODO: add another method call that test function with signature MethodReply(AllJoyn.Message msg, string error, string errorMessage) }
/// <summary> /// Disconnect the bus from AllJoyn and stop its execution /// </summary> private async void TearDown() { try { await busAtt.DisconnectAsync(SignalServiceGlobals.ConnectSpec); await busAtt.StopAsync(); this.OutputLine("Signal Service has been disconnected and terminated."); } catch (Exception ex) { this.OutputLine("Exiting Basic Service Produced Errors!"); System.Diagnostics.Debug.WriteLine("Exception: "); System.Diagnostics.Debug.WriteLine(ex.ToString()); } busObject = null; busAtt = null; busListener = null; }
/// <summary> /// connects with the bus, creates an interface and advertises a well-known name for /// clients to join a session with. /// </summary> /// <param name="sender">UI control which signaled the click event.</param> /// <param name="e">arguments associated with the click event.</param> private void Button_RunClick(object sender, RoutedEventArgs e) { if (busObject == null && busAtt == null) { Task task = new Task(async () => { try { busAtt = new BusAttachment("SignalServiceApp", true, 4); busObject = new SignalServiceBusObject(busAtt); OutputLine("BusObject Created."); busListener = new SignalServiceBusListener(busAtt); OutputLine("BusAttachment and BusListener Created."); busAtt.RegisterBusListener(busListener); OutputLine("BusListener Registered."); busAtt.Start(); await busAtt.ConnectAsync(SignalServiceGlobals.ConnectSpec); OutputLine("Bundled Daemon Registered."); OutputLine("BusAttachment Connected to " + SignalServiceGlobals.ConnectSpec + "."); SessionOpts sessionOpts = new SessionOpts( SignalServiceGlobals.SessionProps.TrType, SignalServiceGlobals.SessionProps.IsMultiPoint, SignalServiceGlobals.SessionProps.PrType, SignalServiceGlobals.SessionProps.TmType); try { ushort[] portOut = new ushort[1]; busAtt.BindSessionPort(SignalServiceGlobals.SessionProps.SessionPort, portOut, sessionOpts, busListener); busAtt.RequestName(SignalServiceGlobals.WellKnownServiceName, (int)RequestNameType.DBUS_NAME_DO_NOT_QUEUE); busAtt.AdvertiseName(SignalServiceGlobals.WellKnownServiceName, TransportMaskType.TRANSPORT_ANY); OutputLine("Name is Being Advertised as: " + SignalServiceGlobals.WellKnownServiceName); } catch (COMException ce) { QStatus s = AllJoynException.GetErrorCode(ce.HResult); OutputLine("Errors were produced while establishing the service."); TearDown(); } } catch (Exception ex) { OutputLine("Errors occurred while setting up the service."); QStatus status = AllJoynException.GetErrorCode(ex.HResult); busObject = null; busAtt = null; } }); task.Start(); } }
public BusObject(BusAttachment bus, string path, bool isPlaceholder) : this(path, isPlaceholder) { }
/// <summary> /// Called by the bus when the listener is registered. This give the listener implementation /// the opportunity to save a reference to the bus. /// </summary> /// <param name="bus">The bus the listener is registered with.</param> public void BusListenerListenerRegistered(BusAttachment bus) { }
/** * Constructor for a message * * @param bus The bus that this message is sent or received on. */ public Message(BusAttachment bus) { _message = alljoyn_message_create(bus.UnmanagedPtr); }