/// <summary> /// Processes an incoming device message from the socket </summary> /// <param name="socket"> </param> /// <param name="length"> </param> /// <exception cref="IOException"> </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: private void processIncomingDeviceData(int length) throws java.io.IOException private void processIncomingDeviceData(int length) { List <Device> list = new List <Device>(); if (length > 0) { var buffer = new byte[length]; string result = read(mMainAdbConnection, buffer); string[] devices = StringHelperClass.StringSplit(result, "\n", true); //$NON-NLS-1$ foreach (string d in devices) { string[] param = StringHelperClass.StringSplit(d, "\t", true); //$NON-NLS-1$ if (param.Length == 2) { // new adb uses only serial numbers to identify devices Device device = new Device(this, param[0], DeviceState.getState(param[1])); //serialnumber //add the device to the list list.Add(device); } } } // now merge the new devices with the old ones. updateDevices(list); }
/// <summary> /// Reads line from the console socket. This call is blocking until we read the lines: /// <ul> /// <li>OK\r\n</li> /// <li>KO<msg>\r\n</li> /// </ul> </summary> /// <returns> the array of strings read from the emulator. </returns> private string[] readLines() { try { ByteBuffer buf = ByteBuffer.wrap(mBuffer, 0, mBuffer.Length); int numWaits = 0; bool stop = false; while (buf.position != buf.limit && stop == false) { int count; count = mSocketChannel.read(buf); if (count < 0) { return null; } else if (count == 0) { if (numWaits * WAIT_TIME > STD_TIMEOUT) { return null; } // non-blocking spin try { Thread.Sleep(WAIT_TIME); } catch (ThreadInterruptedException) { } numWaits++; } else { numWaits = 0; } // check the last few char aren't OK. For a valid message to test // we need at least 4 bytes (OK/KO + \r\n) if (buf.position >= 4) { int pos = buf.position; if (endsWithOK(pos) || lastLineIsKO(pos)) { stop = true; } } } string msg = mBuffer.getString(0, buf.position, DEFAULT_ENCODING); return StringHelperClass.StringSplit(msg, "\r\n", true); //$NON-NLS-1$ } catch (IOException) { return null; } }
public override void processNewLines(string[] lines) { foreach (string line in lines) { // no need to handle empty lines. if (line.Length == 0) { continue; } // run the line through the regexp var m = sLsPattern.Match(line); if (m.Success == false) { continue; } // get the name string name = m.Groups[6].Value; // if the parent is root, we only accept selected items if (mParentEntry.root) { bool found = false; foreach (string approved in sRootLevelApprovedItems) { if (approved.Equals(name)) { found = true; break; } } // if it's not in the approved list we skip this entry. if (found == false) { continue; } } // get the rest of the groups string permissions = m.Groups[0].Value; string owner = m.Groups[1].Value; string group = m.Groups[2].Value; string size = m.Groups[3].Value; string date = m.Groups[4].Value; string time = m.Groups[5].Value; string info = null; // and the type int objectType = TYPE_OTHER; switch (permissions[0]) { case '-': objectType = TYPE_FILE; break; case 'b': objectType = TYPE_BLOCK; break; case 'c': objectType = TYPE_CHARACTER; break; case 'd': objectType = TYPE_DIRECTORY; break; case 'l': objectType = TYPE_LINK; break; case 's': objectType = TYPE_SOCKET; break; case 'p': objectType = TYPE_FIFO; break; } // now check what we may be linking to if (objectType == TYPE_LINK) { string[] segments = StringHelperClass.StringSplit(name, "\\s->\\s", true); //$NON-NLS-1$ // we should have 2 segments if (segments.Length == 2) { // update the entry name to not contain the link name = segments[0]; // and the link name info = segments[1]; // now get the path to the link string[] pathSegments = StringHelperClass.StringSplit(info, FILE_SEPARATOR, true); if (pathSegments.Length == 1) { // the link is to something in the same directory, // unless the link is .. if ("..".Equals(pathSegments[0])) //$NON-NLS-1$ { // set the type and we're done. objectType = TYPE_DIRECTORY_LINK; } else { // either we found the object already // or we'll find it later. } } } // add an arrow in front to specify it's a link. info = "-> " + info; //$NON-NLS-1$; } // get the entry, either from an existing one, or a new one FileEntry entry = getExistingEntry(name); if (entry == null) { entry = new FileEntry(mParentEntry, name, objectType, false); // isRoot } // add some misc info entry.permissions_Renamed = permissions; entry.size_Renamed = size; entry.date_Renamed = date; entry.time_Renamed = time; entry.owner = owner; entry.group = group; if (objectType == TYPE_LINK) { entry.info_Renamed = info; } mEntryList.Add(entry); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: private void processIncomingJdwpData(Device device, java.nio.channels.SocketChannel monitorSocket, int length) throws java.io.IOException private void processIncomingJdwpData(Device device, SocketChannel monitorSocket, int length) { if (length >= 0) { // array for the current pids. List <int?> pidList = new List <int?>(); // get the string data if there are any if (length > 0) { var buffer = new byte[length]; string result = read(monitorSocket, buffer); // split each line in its own list and create an array of integer pid string[] pids = StringHelperClass.StringSplit(result, "\n", true); //$NON-NLS-1$ foreach (string pid in pids) { try { pidList.Add(Convert.ToInt32(pid)); } catch (SystemException) { // looks like this pid is not really a number. Lets ignore it. continue; } } } MonitorThread monitorThread = MonitorThread.instance; // Now we merge the current list with the old one. // this is the same mechanism as the merging of the device list. // For each client in the current list, we look for a matching the pid in the new list. // * if we find it, we do nothing, except removing the pid from its list, // to mark it as "processed" // * if we do not find any match, we remove the client from the current list. // Once this is done, the new list contains pids for which we don't have clients yet, // so we create clients for them, add them to the list, and start monitoring them. IList <Client> clients = device.clientList; bool changed = false; // because MonitorThread#dropClient acquires first the monitorThread lock and then the // Device client list lock (when removing the Client from the list), we have to make // sure we acquire the locks in the same order, since another thread (MonitorThread), // could call dropClient itself. lock (monitorThread) { lock (clients) { for (int c = 0; c < clients.Count;) { Client client = clients[c]; int pid = client.clientData.pid; // look for a matching pid int?match = null; foreach (int?matchingPid in pidList) { if (pid == (int)matchingPid) { match = matchingPid; break; } } if (match != null) { pidList.Remove(match); c++; // move on to the next client. } else { // we need to drop the client. the client will remove itself from the // list of its device which is 'clients', so there's no need to // increment c. // We ask the monitor thread to not send notification, as we'll do // it once at the end. monitorThread.dropClient(client, false); // notify changed = true; } } } } // at this point whatever pid is left in the list needs to be converted into Clients. foreach (int newPid in pidList) { openClient(device, newPid, nextDebuggerPort, monitorThread); changed = true; } if (changed) { mServer.deviceChanged(device, DeviceConstants.CHANGE_CLIENT_LIST); } } }