Пример #1
0
            public BusListener()
            {
                // Can't let the GC free these delegates so they must be members
                _listenerRegistered   = new InternalListenerRegisteredDelegate(_ListenerRegistered);
                _listenerUnregistered = new InternalListenerUnregisteredDelegate(_ListenerUnregistered);
                _foundAdvertisedName  = new InternalFoundAdvertisedNameDelegate(_FoundAdvertisedName);
                _lostAdvertisedName   = new InternalLostAdvertisedNameDelegate(_LostAdvertisedName);
                _nameOwnerChanged     = new InternalNameOwnerChangedDelegate(_NameOwnerChanged);
                _busStopping          = new InternalBusStoppingDelegate(_BusStopping);
                _busDisconnected      = new InternalBusDisconnectedDelegate(_BusDisconnected);

#if UNITY_ANDROID
                _busListener = alljoyn_unitybuslistener_create(this,
                                                               _listenerRegistered, _listenerUnregistered, _foundAdvertisedName,
                                                               _lostAdvertisedName, _nameOwnerChanged, _busStopping, _busDisconnected);
#else
                BusListenerCallbacks callbacks;
                callbacks.listenerRegistered   = Marshal.GetFunctionPointerForDelegate(_listenerRegistered);
                callbacks.listenerUnregistered = Marshal.GetFunctionPointerForDelegate(_listenerUnregistered);
                callbacks.foundAdvertisedName  = Marshal.GetFunctionPointerForDelegate(_foundAdvertisedName);
                callbacks.lostAdvertisedName   = Marshal.GetFunctionPointerForDelegate(_lostAdvertisedName);
                callbacks.nameOwnerChanged     = Marshal.GetFunctionPointerForDelegate(_nameOwnerChanged);
                callbacks.busStopping          = Marshal.GetFunctionPointerForDelegate(_busStopping);
                callbacks.busDisconnected      = Marshal.GetFunctionPointerForDelegate(_busDisconnected);

                GCHandle gch = GCHandle.Alloc(callbacks, GCHandleType.Pinned);
                _busListener = alljoyn_buslistener_create(gch.AddrOfPinnedObject(), IntPtr.Zero);
                gch.Free();
#endif
            }
Пример #2
0
            /**
             * Construct a BusListener.
             */
            public BusListener()
            {
                // Can't let the GC free these delegates so they must be members
                _listenerRegistered = new InternalListenerRegisteredDelegate(_ListenerRegistered);
                _listenerUnregistered = new InternalListenerUnregisteredDelegate(_ListenerUnregistered);
                _foundAdvertisedName = new InternalFoundAdvertisedNameDelegate(_FoundAdvertisedName);
                _lostAdvertisedName = new InternalLostAdvertisedNameDelegate(_LostAdvertisedName);
                _nameOwnerChanged = new InternalNameOwnerChangedDelegate(_NameOwnerChanged);
                _busStopping = new InternalBusStoppingDelegate(_BusStopping);
                _busDisconnected = new InternalBusDisconnectedDelegate(_BusDisconnected);

                callbacks.listenerRegistered = Marshal.GetFunctionPointerForDelegate(_listenerRegistered);
                callbacks.listenerUnregistered = Marshal.GetFunctionPointerForDelegate(_listenerUnregistered);
                callbacks.foundAdvertisedName =  Marshal.GetFunctionPointerForDelegate(_foundAdvertisedName);
                callbacks.lostAdvertisedName =  Marshal.GetFunctionPointerForDelegate(_lostAdvertisedName);
                callbacks.nameOwnerChanged = Marshal.GetFunctionPointerForDelegate(_nameOwnerChanged);
                callbacks.busStopping = Marshal.GetFunctionPointerForDelegate(_busStopping);
                callbacks.busDisconnected = Marshal.GetFunctionPointerForDelegate(_busDisconnected);

                main = GCHandle.Alloc(callbacks, GCHandleType.Pinned);
                _busListener = alljoyn_buslistener_create(main.AddrOfPinnedObject(), IntPtr.Zero);
            }
Пример #3
0
            /**
             * Construct a BusListener.
             */
            public BusListener()
            {
                // Can't let the GC free these delegates so they must be members
                _listenerRegistered   = new InternalListenerRegisteredDelegate(_ListenerRegistered);
                _listenerUnregistered = new InternalListenerUnregisteredDelegate(_ListenerUnregistered);
                _foundAdvertisedName  = new InternalFoundAdvertisedNameDelegate(_FoundAdvertisedName);
                _lostAdvertisedName   = new InternalLostAdvertisedNameDelegate(_LostAdvertisedName);
                _nameOwnerChanged     = new InternalNameOwnerChangedDelegate(_NameOwnerChanged);
                _busStopping          = new InternalBusStoppingDelegate(_BusStopping);
                _busDisconnected      = new InternalBusDisconnectedDelegate(_BusDisconnected);

                callbacks.listenerRegistered   = Marshal.GetFunctionPointerForDelegate(_listenerRegistered);
                callbacks.listenerUnregistered = Marshal.GetFunctionPointerForDelegate(_listenerUnregistered);
                callbacks.foundAdvertisedName  = Marshal.GetFunctionPointerForDelegate(_foundAdvertisedName);
                callbacks.lostAdvertisedName   = Marshal.GetFunctionPointerForDelegate(_lostAdvertisedName);
                callbacks.nameOwnerChanged     = Marshal.GetFunctionPointerForDelegate(_nameOwnerChanged);
                callbacks.busStopping          = Marshal.GetFunctionPointerForDelegate(_busStopping);
                callbacks.busDisconnected      = Marshal.GetFunctionPointerForDelegate(_busDisconnected);

                main         = GCHandle.Alloc(callbacks, GCHandleType.Pinned);
                _busListener = alljoyn_buslistener_create(main.AddrOfPinnedObject(), IntPtr.Zero);
            }