Exemplo n.º 1
0
        /// <summary>
        /// <para>Construct an ICE client handler to process messages for
        /// a particular ICE protocol.</para>
        /// </summary>
        ///
        /// <param name="dpy">
        /// <para>The display to attach to the ICE iceConn's message
        /// processor.</para>
        /// </param>
        ///
        /// <param name="protocolName">
        /// <para>The name of the protocol to register.</para>
        /// </param>
        ///
        /// <param name="vendor">
        /// <para>The name of the vendor for the protocol being registered.</para>
        /// </param>
        ///
        /// <param name="release">
        /// <para>The name of the release for the protocol being registered.</para>
        /// </param>
        ///
        /// <param name="majorVersion">
        /// <para>The major vesion number for the protocol being registered.</para>
        /// </param>
        ///
        /// <param name="minorVersion">
        /// <para>The minor vesion number for the protocol being registered.</para>
        /// </param>
        ///
        /// <param name="serverAddress">
        /// <para>The address of the ICE server to connect to.</para>
        /// </param>
        ///
        /// <exception cref="T:System.ArgumentNullException">
        /// <para>Raised if <paramref name="protocolName"/>,
        /// <paramref name="vendor"/>, <paramref name="release"/>, or
        /// <paramref name="serverAddress"/> is <see langword="null"/>.
        /// </para>
        /// </exception>
        ///
        /// <exception cref="T:Xsharp.XInvalidOperationException">
        /// <para>Raised if the protocol could not be registered or the
        /// iceConn to the ICE server could not be established.</para>
        /// </exception>
        public IceClient(Display dpy, String protocolName, String vendor,
                         String release, int majorVersion, int minorVersion,
                         String serverAddress)
        {
            // Validate the parameters.
            if (dpy == null)
            {
                throw new ArgumentNullException("dpy");
            }
            if (protocolName == null)
            {
                throw new ArgumentNullException("protocolName");
            }
            if (vendor == null)
            {
                throw new ArgumentNullException("vendor");
            }
            if (release == null)
            {
                throw new ArgumentNullException("release");
            }
            if (serverAddress == null)
            {
                throw new ArgumentNullException("serverAddress");
            }

            // Register the protocol with "libICE".
            IcePoVersionRec version = new IcePoVersionRec();

            version.major_version    = majorVersion;
            version.minor_version    = minorVersion;
            version.process_msg_proc =
                new IcePoProcessMsgProc(ProcessMessage);
            String[] authNames = new String[] { "MIT-MAGIC-COOKIE-1" };
            ICE.IcePoAuthProcIncapsulator authProc =
                new ICE.IcePoAuthProcIncapsulator(new IcePoAuthProc(ICE._IcePoMagicCookie1Proc));
            // FIXME: this is overhead, it should be done if (_IceLastMajorOpcode < 1 ) only
            // FIXME: This should be called, but this sevgvs. If someone will take care of segv - decomment and delete hack from this::ProcessResponces()

/*				ICE.IceRegisterForProtocolSetup
 *                                      ("DUMMY", "DUMMY", "DUMMY",
 *                                       (Xlib.Xint)1, ref version,
 *                                       (Xlib.Xint)1, authNames, ref authProc, null);*/
            majorOpcode = (int)ICE.IceRegisterForProtocolSetup
                              (protocolName, vendor, release,
                              (Xlib.Xint) 1, ref version,
                              (Xlib.Xint) 1, authNames, ref authProc, null);
            if (majorOpcode < 0)
            {
                throw new XInvalidOperationException();
            }

            // Open the ICE iceConn to the server.
            byte[] errorBuffer = new byte [1024];
            iceConn = ICE.IceOpenConnection
                          (serverAddress, (IntPtr)this.GetHashCode() /* This is hash code is not it? */, XBool.False,
                          (Xlib.Xint)majorOpcode, (Xlib.Xint) 1024, errorBuffer);
            if (iceConn == null)
            {
                throw new XInvalidOperationException();
            }

            // We don't want shutdown negotiation.
            ICE.IceSetShutdownNegotiation(iceConn, XBool.False);

            // Perform protocol setup on the iceConn.
            IceProtocolSetupStatus status;

            Xlib.Xint majorRet, minorRet;
            IntPtr    vendorRet, releaseRet;

            status = (IceProtocolSetupStatus)ICE.IceProtocolSetup
                         (iceConn, (Xlib.Xint)majorOpcode, IntPtr.Zero,                // We use OO language so we do not need to pass any pointers to callback; he already have its object
                         XBool.False, out majorRet, out minorRet,
                         out vendorRet, out releaseRet,
                         (Xlib.Xint) 1024, errorBuffer);
            if (status != IceProtocolSetupStatus.IceProtocolSetupSuccess)
            {
                ICE.IceCloseConnection(iceConn);
                iceConn = null;
                throw new XInvalidOperationException();
            }

            // Check the iceConn status.
            if (ICE.IceConnectionStatus(iceConn) !=
                (Xlib.Xint)(IceConnectStatus.IceConnectAccepted))
            {
                ICE.IceCloseConnection(iceConn);
                iceConn = null;
                throw new XInvalidOperationException();
            }

            // Initialize other state information.
            this.buffer             = errorBuffer;
            this.dpy                = dpy;
            this.messageTransaction = false;

            // TODO: register IceConnectionNumber(iceConn) with
            // the select loop.
        }
Exemplo n.º 2
0
	/// <summary>
	/// <para>Construct an ICE client handler to process messages for
	/// a particular ICE protocol.</para>
	/// </summary>
	///
	/// <param name="dpy">
	/// <para>The display to attach to the ICE iceConn's message
	/// processor.</para>
	/// </param>
	///
	/// <param name="protocolName">
	/// <para>The name of the protocol to register.</para>
	/// </param>
	///
	/// <param name="vendor">
	/// <para>The name of the vendor for the protocol being registered.</para>
	/// </param>
	///
	/// <param name="release">
	/// <para>The name of the release for the protocol being registered.</para>
	/// </param>
	///
	/// <param name="majorVersion">
	/// <para>The major vesion number for the protocol being registered.</para>
	/// </param>
	///
	/// <param name="minorVersion">
	/// <para>The minor vesion number for the protocol being registered.</para>
	/// </param>
	///
	/// <param name="serverAddress">
	/// <para>The address of the ICE server to connect to.</para>
	/// </param>
	///
	/// <exception cref="T:System.ArgumentNullException">
	/// <para>Raised if <paramref name="protocolName"/>,
	/// <paramref name="vendor"/>, <paramref name="release"/>, or
	/// <paramref name="serverAddress"/> is <see langword="null"/>.
	/// </para>
	/// </exception>
	///
	/// <exception cref="T:Xsharp.XInvalidOperationException">
	/// <para>Raised if the protocol could not be registered or the
	/// iceConn to the ICE server could not be established.</para>
	/// </exception>
	public IceClient(Display dpy, String protocolName, String vendor,
					 String release, int majorVersion, int minorVersion,
					 String serverAddress)
			{
				// Validate the parameters.
				if(dpy == null)
				{
					throw new ArgumentNullException("dpy");
				}
				if(protocolName == null)
				{
					throw new ArgumentNullException("protocolName");
				}
				if(vendor == null)
				{
					throw new ArgumentNullException("vendor");
				}
				if(release == null)
				{
					throw new ArgumentNullException("release");
				}
				if(serverAddress == null)
				{
					throw new ArgumentNullException("serverAddress");
				}

				// Register the protocol with "libICE".
				IcePoVersionRec version = new IcePoVersionRec();
				version.major_version = majorVersion;
				version.minor_version = minorVersion;
				version.process_msg_proc =
					new IcePoProcessMsgProc(ProcessMessage);
				String[] authNames = new String[] {"MIT-MAGIC-COOKIE-1"};
				ICE.IcePoAuthProcIncapsulator authProc =
					new ICE.IcePoAuthProcIncapsulator(new IcePoAuthProc(ICE._IcePoMagicCookie1Proc));
				// FIXME: this is overhead, it should be done if (_IceLastMajorOpcode < 1 ) only
				// FIXME: This should be called, but this sevgvs. If someone will take care of segv - decomment and delete hack from this::ProcessResponces()
/*				ICE.IceRegisterForProtocolSetup
					("DUMMY", "DUMMY", "DUMMY",
					 (Xlib.Xint)1, ref version,
					 (Xlib.Xint)1, authNames, ref authProc, null);*/
				majorOpcode = (int)ICE.IceRegisterForProtocolSetup
					(protocolName, vendor, release,
					 (Xlib.Xint)1, ref version,
					 (Xlib.Xint)1, authNames, ref authProc, null);
				if(majorOpcode < 0)
				{
					throw new XInvalidOperationException();
				}

				// Open the ICE iceConn to the server.
				byte[] errorBuffer = new byte [1024];
				iceConn = ICE.IceOpenConnection
					(serverAddress, (IntPtr)this.GetHashCode() /* This is hash code is not it? */, XBool.False,
					 (Xlib.Xint)majorOpcode, (Xlib.Xint)1024, errorBuffer);
				if(iceConn == null)
				{
					throw new XInvalidOperationException();
				}

				// We don't want shutdown negotiation.
				ICE.IceSetShutdownNegotiation(iceConn, XBool.False);

				// Perform protocol setup on the iceConn.
				IceProtocolSetupStatus status;
				Xlib.Xint majorRet, minorRet;
				IntPtr vendorRet, releaseRet;
				status = (IceProtocolSetupStatus)ICE.IceProtocolSetup
					(iceConn, (Xlib.Xint)majorOpcode, IntPtr.Zero, // We use OO language so we do not need to pass any pointers to callback; he already have its object
					 XBool.False, out majorRet, out minorRet,
					 out vendorRet, out releaseRet,
					 (Xlib.Xint)1024, errorBuffer);
				if(status != IceProtocolSetupStatus.IceProtocolSetupSuccess)
				{
					ICE.IceCloseConnection(iceConn);
					iceConn = null;
					throw new XInvalidOperationException();
				}

				// Check the iceConn status.
				if(ICE.IceConnectionStatus(iceConn) !=
						(Xlib.Xint)(IceConnectStatus.IceConnectAccepted))
				{
					ICE.IceCloseConnection(iceConn);
					iceConn = null;
					throw new XInvalidOperationException();
				}

				// Initialize other state information.
				this.buffer = errorBuffer;
				this.dpy = dpy;
				this.messageTransaction = false;

				// TODO: register IceConnectionNumber(iceConn) with
				// the select loop.
			}