Ejemplo n.º 1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Creates an instance of the <see cref="LibronixPositionHandler"/> class.
        /// </summary>
        /// <param name="fStart"><c>true</c> to start Libronix if it isn't running, otherwise
        /// <c>false</c>.</param>
        /// <param name="linkSet">The 0-based index of the link set in Libronix.</param>
        /// <param name="fThrowNotRunningException"><c>true</c> to throw not running exception</param>
        /// <returns>
        /// An instance of the <see cref="LibronixPositionHandler"/> class.
        /// </returns>
        /// <exception cref="LibronixNotRunningException">Thrown if Libronix is installed but
        /// not currently running and <paramref name="fStart"/> is <c>false</c>.</exception>
        /// <exception cref="LibronixNotInstalledException">Thrown if Libronix is not installed
        /// on this machine.</exception>
        /// <developernote>This method is called on the main thread</developernote>
        /// ------------------------------------------------------------------------------------
        public static LibronixPositionHandler CreateInstance(bool fStart, int linkSet,
                                                             bool fThrowNotRunningException)
        {
            if (IsNotInstalled)
            {
                throw new LibronixNotInstalledException("Libronix isn't installed", null);
            }

            if (!s_Instances.ContainsKey(linkSet))
            {
                lock (typeof(LibronixPositionHandler))
                {
                    // We have to check again. It's possible that another thread was in the
                    // middle of creating an instance while we were waiting for the lock.
                    if (!s_Instances.ContainsKey(linkSet))
                    {
                        LibronixPositionHandler newHandler =
                            new LibronixPositionHandler(fStart, linkSet);
                        try
                        {
                            newHandler.StartLibronixThread(fThrowNotRunningException);
                        }
                        catch (LibronixNotInstalledException)
                        {
                            newHandler.Dispose();
                            throw;
                        }
                        catch (LibronixNotRunningException)
                        {
                            newHandler.Dispose();
                            throw;
                        }
                        s_Instances.Add(linkSet, newHandler);
                    }
                }
            }
            LibronixPositionHandler handler = s_Instances[linkSet];

            handler.m_ReferenceCount++;
            return(handler);
        }
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Releases unmanaged and - optionally - managed resources
 /// </summary>
 /// <param name="disposing"><c>true</c> to release both managed and unmanaged
 /// resources; <c>false</c> to release only unmanaged resources.</param>
 /// ------------------------------------------------------------------------------------
 protected override void Dispose(bool disposing)
 {
     m_LibronixPositionHandler.Dispose();
     base.Dispose(disposing);
 }
Ejemplo n.º 3
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Creates an instance of the <see cref="LibronixPositionHandler"/> class.
		/// </summary>
		/// <param name="fStart"><c>true</c> to start Libronix if it isn't running, otherwise
		/// <c>false</c>.</param>
		/// <param name="linkSet">The 0-based index of the link set in Libronix.</param>
		/// <param name="fThrowNotRunningException"><c>true</c> to throw not running exception</param>
		/// <returns>
		/// An instance of the <see cref="LibronixPositionHandler"/> class.
		/// </returns>
		/// <exception cref="LibronixNotRunningException">Thrown if Libronix is installed but
		/// not currently running and <paramref name="fStart"/> is <c>false</c>.</exception>
		/// <exception cref="LibronixNotInstalledException">Thrown if Libronix is not installed
		/// on this machine.</exception>
		/// <developernote>This method is called on the main thread</developernote>
		/// ------------------------------------------------------------------------------------
		public static LibronixPositionHandler CreateInstance(bool fStart, int linkSet,
			bool fThrowNotRunningException)
		{
			if (IsNotInstalled)
				throw new LibronixNotInstalledException("Libronix isn't installed", null);

			if (!s_Instances.ContainsKey(linkSet))
			{
				lock (typeof(LibronixPositionHandler))
				{
					// We have to check again. It's possible that another thread was in the
					// middle of creating an instance while we were waiting for the lock.
					if (!s_Instances.ContainsKey(linkSet))
					{
						LibronixPositionHandler newHandler =
							new LibronixPositionHandler(fStart, linkSet);
						try
						{
							newHandler.StartLibronixThread(fThrowNotRunningException);
						}
						catch (LibronixNotInstalledException)
						{
							newHandler.Dispose();
							throw;
						}
						catch (LibronixNotRunningException)
						{
							newHandler.Dispose();
							throw;
						}
						s_Instances.Add(linkSet, newHandler);
					}
				}
			}
			LibronixPositionHandler handler = s_Instances[linkSet];
			handler.m_ReferenceCount++;
			return handler;
		}