This class describes a port. This description is used to add the port to a port supplier. It implements IDebugPortRequest2 (http://msdn.microsoft.com/en-us/library/bb146168.aspx)
Inheritance: IDebugPortRequest2
Exemple #1
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="supplier"> The port supplier for this port. </param>
 /// <param name="request"> The request used to create the port. </param>
 /// <param name="guid"> The GUID that identifies the port. </param>
 /// <param name="portName"> The name of the port. </param>
 /// <param name="password"> The password needed to have access to the port. </param>
 /// <param name="isSimulator"> Variable that indicates if the port is associated to the Simulator or the Device. </param>
 /// <param name="toolsPath"> The NDK host path. </param>
 public AD7Port(AD7PortSupplier supplier, AD7PortRequest request, Guid guid, string portName, string password, bool isSimulator, string toolsPath)
 {
     m_name     = portName;
     m_request  = request;
     m_supplier = supplier;
     m_guid     = guid;
     if (m_name != "")
     {
         if (isSimulator)
         {
             m_IP = m_name.Substring(11);
         }
         else
         {
             m_IP = m_name.Substring(8);
         }
     }
     else
     {
         m_name = " ";
         m_IP   = "";
     }
     m_password    = password;
     m_isSimulator = isSimulator;
     m_toolsPath   = toolsPath;
 }
        /// <summary>
        /// Adds a port. (http://msdn.microsoft.com/en-ca/library/bb161980.aspx)
        /// </summary>
        /// <param name="pRequest"> An IDebugPortRequest2 object that describes the port to be added. </param>
        /// <param name="ppPort"> Returns an IDebugPort2 object that represents the port. </param>
        /// <returns> VSConstants.S_OK. </returns>
        public int AddPort(IDebugPortRequest2 pRequest, out IDebugPort2 ppPort)
        {
            AD7PortRequest port_request = (AD7PortRequest)pRequest;
            var            port         = CreatePort(port_request);

            m_ports.Add(port.m_guid, port);
            ppPort = port;
            return(VSConstants.S_OK);
        }
        /// <summary>
        /// Creates an AD7Port.
        /// </summary>
        /// <param name="port_request"> Port request. </param>
        /// <returns> Returns an AD7Port. </returns>
        AD7Port CreatePort(AD7PortRequest port_request)
        {
            string portname;
            Guid   guid;
            bool   isSimulator = false;

            port_request.GetPortName(out portname);
            string password = portname.Substring(portname.IndexOf('-') + 1);

            portname = portname.Remove(portname.IndexOf('-'));
            if (portname.Substring(0, 6) == "Device")
            {
                guid = new Guid("{69519DBB-5329-4CCE-88A9-EC1628AD99C2}");
            }
            else
            {
                guid        = new Guid("{25040BDD-6683-4D5C-8EFA-EB4DDF5CA08E}");
                isSimulator = true;
            }

            return(new AD7Port(this, port_request, guid, portname, password, isSimulator, m_toolsPath));
        }
        /// <summary>
        /// Creates an AD7Port.
        /// </summary>
        /// <param name="port_request"> Port request. </param>
        /// <returns> Returns an AD7Port. </returns>
        AD7Port CreatePort(AD7PortRequest port_request)
        {
            string portname;
            Guid guid;
            bool isSimulator = false;
            port_request.GetPortName(out portname);
            string password = portname.Substring(portname.IndexOf('-') + 1);
            portname = portname.Remove(portname.IndexOf('-'));
            if (portname.Substring(0, 6) == "Device")
                guid = new Guid("{69519DBB-5329-4CCE-88A9-EC1628AD99C2}");
            else
            {
                guid = new Guid("{25040BDD-6683-4D5C-8EFA-EB4DDF5CA08E}");
                isSimulator = true;
            }

            return new AD7Port(this, port_request, guid, portname, password, isSimulator, m_toolsPath);
        }
Exemple #5
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="supplier"> The port supplier for this port. </param>
 /// <param name="request"> The request used to create the port. </param>
 /// <param name="guid"> The GUID that identifies the port. </param>
 /// <param name="portName"> The name of the port. </param>
 /// <param name="password"> The password needed to have access to the port. </param>
 /// <param name="isSimulator"> Variable that indicates if the port is associated to the Simulator or the Device. </param>
 /// <param name="toolsPath"> The NDK host path. </param>
 public AD7Port(AD7PortSupplier supplier, AD7PortRequest request, Guid guid, string portName, string password, bool isSimulator, string toolsPath)
 {
     m_name = portName;
     m_request = request;
     m_supplier = supplier;
     m_guid = guid;
     if (isSimulator)
         m_IP = m_name.Substring(11);
     else
         m_IP = m_name.Substring(8);
     m_password = password;
     m_isSimulator = isSimulator;
     m_toolsPath = toolsPath;
 }
        /// <summary>
        /// Adds a port. (http://msdn.microsoft.com/en-ca/library/bb161980.aspx)
        /// </summary>
        /// <param name="pRequest"> An IDebugPortRequest2 object that describes the port to be added. </param>
        /// <param name="ppPort"> Returns an IDebugPort2 object that represents the port. </param>
        /// <returns> VSConstants.S_OK. </returns>
        public int AddPort(IDebugPortRequest2 pRequest, out IDebugPort2 ppPort)
        {
            bool           sucess       = true;
            AD7PortRequest port_request = null;
            AD7Port        port         = null;

            try
            {
                port_request = (AD7PortRequest)pRequest;
            }
            catch
            {
                sucess = false;
                string  portRequestName;
                AD7Port defaultPort = null;
                pRequest.GetPortName(out portRequestName);
                string search = "";
                if (portRequestName.ToLower().Contains("device"))
                {
                    search = "device";
                }
                else if (portRequestName.ToLower().Contains("simulator"))
                {
                    search = "simulator";
                }
                else
                {
                    search = portRequestName.ToLower();
                }
                foreach (var p in m_ports)
                {
                    AD7Port tempPort = p.Value;
                    if (defaultPort == null)
                    {
                        defaultPort = tempPort;
                    }

                    string tempPortName = "";
                    tempPort.GetPortName(out tempPortName);
                    if (tempPortName.ToLower().Contains(search))
                    {
                        port = tempPort;
                        break;
                    }
                    else
                    {
                        string IP = search;
                        do
                        {
                            int pos = IP.LastIndexOf('.');
                            if (pos != -1)
                            {
                                IP = IP.Remove(pos);
                                if (tempPortName.Contains(IP))
                                {
                                    port = tempPort;
                                    break;
                                }
                            }
                            else
                            {
                                IP = "";
                            }
                        } while (IP != "");
                        if (IP != "")
                        {
                            break;
                        }
                    }
                }
                if (port == null)
                {
                    if (defaultPort != null)
                    {
                        port = defaultPort;
                    }
                    else
                    {
                        port = new AD7Port(this, port_request, Guid.NewGuid(), "", "", true, "");
                    }
                }
            }
            if (sucess)
            {
                port = CreatePort(port_request);
                Guid portGuid;
                port.GetPortId(out portGuid);
                m_ports.Add(portGuid, port);
            }
            ppPort = port;
            return(VSConstants.S_OK);
        }