Beispiel #1
0
        public virtual int send(pspNetMacAddress macAddress, int dataLen, int data)
        {
            int result = 0;

            try
            {
                AdhocMatchingEventMessage adhocMatchingEventMessage = createMessage(PSP_ADHOC_MATCHING_EVENT_DATA, data, dataLen, macAddress.macAddress);
                send(adhocMatchingEventMessage, macAddress, dataLen, data);
                result = dataLen;
            }
            catch (SocketException e)
            {
                Console.WriteLine("send", e);
            }
            catch (UnknownHostException e)
            {
                Console.WriteLine("send", e);
            }
            catch (IOException e)
            {
                Console.WriteLine("send", e);
            }

            return(result);
        }
Beispiel #2
0
        public virtual int stop()
        {
            if (connected)
            {
                //if (log.DebugEnabled)
                {
                    Console.WriteLine(string.Format("Sending disconnect to port {0:D}", Port));
                }

                try
                {
                    AdhocMatchingEventMessage adhocMatchingEventMessage = createMessage(PSP_ADHOC_MATCHING_EVENT_DISCONNECT);
                    send(adhocMatchingEventMessage);
                }
                catch (IOException e)
                {
                    Console.WriteLine("stop", e);
                }
            }

            closeSocket();
            removeMember(Wlan.MacAddress);

            return(0);
        }
Beispiel #3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: protected void send(AdhocMatchingEventMessage adhocMatchingEventMessage, pspsharp.HLE.kernel.types.pspNetMacAddress macAddress, int dataLen, int data) throws java.io.IOException
        protected internal virtual void send(AdhocMatchingEventMessage adhocMatchingEventMessage, pspNetMacAddress macAddress, int dataLen, int data)
        {
            base.send(adhocMatchingEventMessage);

            if (adhocMatchingEventMessage != null)
            {
                adhocMatchingEventMessage.processOnSend(macAddress.BaseAddress, data, dataLen);
            }
        }
Beispiel #4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void sendPing() throws java.io.IOException
        private void sendPing()
        {
            //if (log.DebugEnabled)
            {
                Console.WriteLine(string.Format("Sending ping to port {0:D}", Port));
            }
            AdhocMatchingEventMessage adhocMatchingEventMessage = createMessage(PSP_ADHOC_MATCHING_EVENT_INTERNAL_PING);

            send(adhocMatchingEventMessage);

            lastPingMicros = Emulator.Clock.microTime();
        }
Beispiel #5
0
        public virtual int selectTarget(pspNetMacAddress macAddress, int optLen, int optData)
        {
            int result = 0;

            try
            {
                int @event;
                if (pendingJoinRequest != null && sceNetAdhoc.isSameMacAddress(pendingJoinRequest, macAddress.macAddress))
                {
                    @event = PSP_ADHOC_MATCHING_EVENT_ACCEPT;
                    //if (log.DebugEnabled)
                    {
                        Console.WriteLine(string.Format("Sending accept to port {0:D}", Port));
                    }

                    if (Mode == sceNetAdhocMatching.PSP_ADHOC_MATCHING_MODE_HOST)
                    {
                        addMember(macAddress.macAddress);
                        connected    = true;
                        inConnection = false;
                    }
                }
                else
                {
                    @event = PSP_ADHOC_MATCHING_EVENT_JOIN;
                    //if (log.DebugEnabled)
                    {
                        Console.WriteLine(string.Format("Sending join to port {0:D}", Port));
                    }
                }
                AdhocMatchingEventMessage adhocMatchingEventMessage = createMessage(@event, optData, optLen, macAddress.macAddress);
                send(adhocMatchingEventMessage, macAddress, optLen, optData);

                inConnection = true;
            }
            catch (SocketException e)
            {
                Console.WriteLine("selectTarget", e);
            }
            catch (UnknownHostException e)
            {
                Console.WriteLine("selectTarget", e);
            }
            catch (IOException e)
            {
                Console.WriteLine("selectTarget", e);
            }

            return(result);
        }
Beispiel #6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void sendHello() throws java.io.IOException
        private void sendHello()
        {
            //if (log.DebugEnabled)
            {
                Console.WriteLine(string.Format("Sending hello to port {0:D}", Port));
            }
            AdhocMatchingEventMessage adhocMatchingEventMessage = createMessage(PSP_ADHOC_MATCHING_EVENT_HELLO);

            if (HelloOptLen > 0)
            {
                adhocMatchingEventMessage.Data = helloOptData;
            }
            send(adhocMatchingEventMessage);

            lastHelloMicros = Emulator.Clock.microTime();
        }
Beispiel #7
0
        public virtual int cancelTarget(pspNetMacAddress macAddress, int optLen, int optData)
        {
            int result = 0;

            try
            {
                int @event;
                if (connected)
                {
                    @event = PSP_ADHOC_MATCHING_EVENT_LEFT;
                    //if (log.DebugEnabled)
                    {
                        Console.WriteLine(string.Format("Sending leave to port {0:D}", Port));
                    }
                }
                else
                {
                    @event = PSP_ADHOC_MATCHING_EVENT_CANCEL;
                    //if (log.DebugEnabled)
                    {
                        Console.WriteLine(string.Format("Sending cancel to port {0:D}", Port));
                    }
                }
                AdhocMatchingEventMessage adhocMatchingEventMessage = createMessage(@event, optData, optLen, macAddress.macAddress);
                send(adhocMatchingEventMessage, macAddress, optLen, optData);
            }
            catch (SocketException e)
            {
                Console.WriteLine("cancelTarget", e);
            }
            catch (UnknownHostException e)
            {
                Console.WriteLine("cancelTarget", e);
            }
            catch (IOException e)
            {
                Console.WriteLine("cancelTarget", e);
            }
            removeMember(macAddress.macAddress);
            connected    = false;
            inConnection = false;

            return(result);
        }
Beispiel #8
0
        public virtual bool inputLoop()
        {
            if (socket == null || !started)
            {
                return(false);
            }

            // Execute all the pending callback events
            while (pendingCallbackEvents.Count > 0)
            {
                CallbackEvent    callbackEvent = pendingCallbackEvents.RemoveFirst();
                pspNetMacAddress macAddress    = callbackEvent.MacAddress;
                macAddress.write(Memory.Instance, buffer.addr);
                notifyCallbackEvent(callbackEvent.Event, macAddress.BaseAddress, callbackEvent.OptLen, callbackEvent.OptData);
            }

            try
            {
                sbyte[] bytes  = new sbyte[BufSize + MAX_HEADER_SIZE];
                int     Length = socket.receive(bytes, bytes.Length);
                if (Length > 0)
                {
                    int         receivedPort    = socket.ReceivedPort;
                    InetAddress receivedAddress = socket.ReceivedAddress;
                    AdhocMatchingEventMessage adhocMatchingEventMessage = createMessage(bytes, Length);
                    if (isForMe(adhocMatchingEventMessage, receivedPort, receivedAddress))
                    {
                        int @event  = adhocMatchingEventMessage.Event;
                        int macAddr = buffer.addr;
                        int optData = buffer.addr + 8;
                        int optLen  = adhocMatchingEventMessage.DataLength;
                        adhocMatchingEventMessage.writeDataToMemory(optData);
                        pspNetMacAddress macAddress = new pspNetMacAddress();
                        macAddress.MacAddress = adhocMatchingEventMessage.FromMacAddress;
                        macAddress.write(Memory.Instance, macAddr);

                        //if (log.DebugEnabled)
                        {
                            Console.WriteLine(string.Format("Received message Length={0:D}, event={1:D}, fromMac={2}, port={3:D}: {4}", adhocMatchingEventMessage.DataLength, @event, macAddress, socket.ReceivedPort, adhocMatchingEventMessage));
                            if (log.TraceEnabled && optLen > 0)
                            {
                                log.trace(string.Format("Message data: {0}", Utilities.getMemoryDump(optData, optLen)));
                            }
                        }

                        // Keep track that we received a new message from this MAC address
                        Modules.sceNetAdhocctlModule.hleNetAdhocctlPeerUpdateTimestamp(adhocMatchingEventMessage.FromMacAddress);

                        if (@event == PSP_ADHOC_MATCHING_EVENT_JOIN)
                        {
                            pendingJoinRequest = adhocMatchingEventMessage.FromMacAddress;
                            inConnection       = true;
                        }
                        adhocMatchingEventMessage.processOnReceive(macAddr, optData, optLen);

                        if (@event == PSP_ADHOC_MATCHING_EVENT_ACCEPT)
                        {
                            addMember(adhocMatchingEventMessage.FromMacAddress);
                            //if (log.DebugEnabled)
                            {
                                Console.WriteLine(string.Format("Sending complete to port {0:D}", Port));
                            }
                            adhocMatchingEventMessage = createMessage(PSP_ADHOC_MATCHING_EVENT_COMPLETE, optData, optLen, macAddress.macAddress);
                            send(adhocMatchingEventMessage);

                            pendingComplete = true;
                            connected       = true;
                            inConnection    = false;
                        }
                        else if (@event == PSP_ADHOC_MATCHING_EVENT_COMPLETE)
                        {
                            addMember(adhocMatchingEventMessage.FromMacAddress);
                            if (!pendingComplete)
                            {
                                //if (log.DebugEnabled)
                                {
                                    Console.WriteLine(string.Format("Sending complete to port {0:D}", Port));
                                }
                                adhocMatchingEventMessage = createMessage(PSP_ADHOC_MATCHING_EVENT_COMPLETE, optData, optLen, macAddress.macAddress);
                                send(adhocMatchingEventMessage);
                            }
                            connected    = true;
                            inConnection = false;
                        }
                        else if (@event == PSP_ADHOC_MATCHING_EVENT_DATA)
                        {
                            //if (log.DebugEnabled)
                            {
                                Console.WriteLine(string.Format("Sending data confirm to port {0:D}", Port));
                            }
                            adhocMatchingEventMessage = createMessage(PSP_ADHOC_MATCHING_EVENT_DATA_CONFIRM, 0, 0, macAddress.macAddress);
                            send(adhocMatchingEventMessage);
                        }
                        else if (@event == PSP_ADHOC_MATCHING_EVENT_DISCONNECT || @event == PSP_ADHOC_MATCHING_EVENT_LEFT)
                        {
                            //if (log.DebugEnabled)
                            {
                                Console.WriteLine(string.Format("Received disconnect/leave from {0}", macAddress));
                            }
                            removeMember(adhocMatchingEventMessage.FromMacAddress);
                            if (members.Count <= 1)
                            {
                                connected    = false;
                                inConnection = false;
                            }
                        }
                    }
                    else
                    {
                        //if (log.DebugEnabled)
                        {
                            Console.WriteLine(string.Format("Received message not for me: {0}", adhocMatchingEventMessage));
                        }
                    }
                }
            }
            catch (SocketTimeoutException)
            {
                // Nothing available
            }
            catch (IOException e)
            {
                Console.WriteLine("inputLoop", e);
            }

            return(true);
        }