示例#1
0
        internal static WiFiDirectPeer ConvertStructToDiscoveredPeer(DiscoveredPeerStruct peer)
        {
            WiFiDirectPeer resultPeer = new WiFiDirectPeer();

            resultPeer._peerDeviceName         = peer._name;
            resultPeer._peerMacAddress         = peer._macAddress;
            resultPeer._peerInterfaceAddress   = peer._interfaceAddress;
            resultPeer._peerChannel            = peer._channel;
            resultPeer._isPeerConnected        = peer._isConnected;
            resultPeer._isPeerGroupOwner       = peer._isGroupOwner;
            resultPeer._peerPrimaryType        = peer._primaryType;
            resultPeer._peerSecondaryType      = peer._secondaryType;
            resultPeer._peerWpsTypes           = peer._wpsTypes;
            resultPeer._p2PInvitationSupported = peer._isP2PInvitationSupported;
            Collection <string> uuidList = null;

            if (peer._serviceCount > 0)
            {
                IntPtr[] serviceList = new IntPtr[peer._serviceCount];
                Marshal.Copy(peer._serviceList, serviceList, 0, (int)peer._serviceCount);
                uuidList = new Collection <string>();
                foreach (IntPtr service in serviceList)
                {
                    string registeredService = Marshal.PtrToStringAnsi(service);
                    uuidList.Add(registeredService);
                }

                resultPeer._peerServiceCount = peer._serviceCount;
                resultPeer._peerServiceList  = uuidList;
            }

            resultPeer._isPeerMiracastDevice = peer._isMiracast;
            return(resultPeer);
        }
示例#2
0
        private void RegisterPeerFoundEvent()
        {
            _peerFoundCallback = (int result, WiFiDirectDiscoveryState stateInfo, string address, IntPtr userData) =>
            {
                if (_peerFound != null && stateInfo == WiFiDirectDiscoveryState.Found)
                {
                    WiFiDirectError          error = (WiFiDirectError)result;
                    WiFiDirectDiscoveryState state = stateInfo;
                    IntPtr peer;
                    Interop.WiFiDirect.GetDiscoveredPeerInfo(address, out peer);
                    DiscoveredPeerStruct peerStruct = (DiscoveredPeerStruct)Marshal.PtrToStructure(peer, typeof(DiscoveredPeerStruct));
                    _peerFound(null, new PeerFoundEventArgs(error, state, WiFiDirectUtils.ConvertStructToDiscoveredPeer(peerStruct)));
                }
            };
            int ret = Interop.WiFiDirect.SetPeerFoundCallback(_peerFoundCallback, IntPtr.Zero);

            if (ret != (int)WiFiDirectError.None)
            {
                Log.Error(Globals.LogTag, "Failed to set Wi-Fi Direct discovery state changed callback, Error - " + (WiFiDirectError)ret);
            }
        }
示例#3
0
        private void RegisterServiceStateChangedEvent()
        {
            _serviceStateChangedCallback = (int result, WiFiDirectServiceDiscoveryState stateInfo, WiFiDirectServiceType typeInfo, IntPtr responseData, string address, IntPtr userData) =>
            {
                if (_serviceStateChanged != null)
                {
                    WiFiDirectError error = (WiFiDirectError)result;
                    WiFiDirectServiceDiscoveryState state = stateInfo;
                    WiFiDirectServiceType           type  = typeInfo;
                    string response = Marshal.PtrToStringAnsi(responseData);
                    IntPtr peer;
                    Interop.WiFiDirect.GetDiscoveredPeerInfo(address, out peer);
                    DiscoveredPeerStruct peerStruct = (DiscoveredPeerStruct)Marshal.PtrToStructure(peer, typeof(DiscoveredPeerStruct));

                    _serviceStateChanged(null, new ServiceStateChangedEventArgs(error, state, type, response, WiFiDirectUtils.ConvertStructToDiscoveredPeer(peerStruct)));
                }
            };
            int ret = Interop.WiFiDirect.SetServiceStateChangedCallback(_serviceStateChangedCallback, IntPtr.Zero);

            if (ret != (int)WiFiDirectError.None)
            {
                Log.Error(Globals.LogTag, "Failed to set service state changed callback, Error - " + (WiFiDirectError)ret);
            }
        }