示例#1
0
文件: Service.cs 项目: fuzzy01/ohNet
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="aName">Parameter name</param>
        /// <param name="aMinValue">Minimum allowed value</param>
        /// <param name="aMaxValue">Maximum allowed value</param>
        /// <param name="aStep">Gap between allowed values</param>
        public unsafe ParameterUint(String aName, uint aMinValue = 0, uint aMaxValue = uint.MaxValue, uint aStep = 1)
        {
            IntPtr name = InteropUtils.StringToHGlobalUtf8(aName);

            iHandle = ServiceParameterCreateUint(name, aMinValue, aMaxValue, aStep);
            Marshal.FreeHGlobal(name);
        }
示例#2
0
文件: OhNet.cs 项目: broonie/ohNet
        /// <summary>
        /// Claim a reference to the network adapter.
        /// </summary>
        /// <remarks>Can only be called from code that can guarantee another reference is already held.
        /// Each call to AddRef() must later have exactly one matching call to RemoveRef().</remarks>
        public void AddRef(string aCookie)
        {
            IntPtr cookie = InteropUtils.StringToHGlobalUtf8(aCookie);

            OhNetNetworkAdapterAddRef(iHandle, cookie);
            AddManagedCookie(aCookie, cookie);
        }
示例#3
0
文件: Service.cs 项目: fuzzy01/ohNet
        public unsafe ParameterRelated(String aName, OpenHome.Net.Core.Property aProperty)
        {
            IntPtr name = InteropUtils.StringToHGlobalUtf8(aName);

            iHandle = ServiceParameterCreateRelated(name, aProperty.Handle());
            Marshal.FreeHGlobal(name);
        }
示例#4
0
文件: Service.cs 项目: fuzzy01/ohNet
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="aName">Parameter name</param>
        public unsafe ParameterBinary(String aName)
        {
            IntPtr name = InteropUtils.StringToHGlobalUtf8(aName);

            iHandle = ServiceParameterCreateBinary(name);
            Marshal.FreeHGlobal(name);
        }
示例#5
0
文件: Service.cs 项目: simoncn/ohNet
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="aName">Parameter name</param>
        /// <param name="aMinValue">Minimum allowed value</param>
        /// <param name="aMaxValue">Maximum allowed value</param>
        /// <param name="aStep">Gap between allowed values</param>
        public ParameterInt(String aName, int aMinValue = Int32.MinValue, int aMaxValue = Int32.MaxValue, int aStep = 1)
        {
            IntPtr name = InteropUtils.StringToHGlobalUtf8(aName);

            iHandle = ServiceParameterCreateInt(name, aMinValue, aMaxValue, aStep);
            Marshal.FreeHGlobal(name);
        }
示例#6
0
文件: OhNet.cs 项目: broonie/ohNet
        /// <summary>
        /// Get the full name for a given network interface.
        /// </summary>
        /// <returns>String in the form a.b.c.d (name).</returns>
        public string FullName()
        {
            IntPtr cStr = OhNetNetworkAdapterFullName(iHandle);
            string name = InteropUtils.PtrToStringUtf8(cStr);

            Library.Free(cStr);
            return(name);
        }
示例#7
0
文件: OhNet.cs 项目: broonie/ohNet
        /// <summary>
        /// Get the name for a given network interface.
        /// </summary>
        /// <returns>String containing name of the adapter.</returns>
        public string Name()
        {
            IntPtr cStr = OhNetNetworkAdapterName(iHandle);
            string name = InteropUtils.PtrToStringUtf8(cStr);

            // Library.Free(cStr) not necessary because a copy is not allocated by the underlying NetworkAdapter object
            return(name);
        }
示例#8
0
文件: Service.cs 项目: fuzzy01/ohNet
        /// <summary>
        /// Query the name of the action
        /// </summary>
        /// <returns>Action name</returns>
        public unsafe String Name()
        {
            IntPtr str;
            uint   len;

            ServiceActionGetName(iHandle, &str, &len);
            return(InteropUtils.PtrToStringUtf8(str, len));
        }
示例#9
0
文件: Service.cs 项目: fuzzy01/ohNet
        /// <summary>
        /// Set the value of the property
        /// </summary>
        /// <param name="aValue">New value for the property</param>
        /// <returns>True if the property's value was changed; false otherwise</returns>
        public bool SetValue(string aValue)
        {
            IntPtr val     = InteropUtils.StringToHGlobalUtf8(aValue);
            uint   changed = ServicePropertySetValueString(iHandle, val);

            Marshal.FreeHGlobal(val);
            return(changed != 0);
        }
示例#10
0
文件: Service.cs 项目: fuzzy01/ohNet
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="aName">Action name</param>
        public unsafe Action(String aName)
        {
            IntPtr name = InteropUtils.StringToHGlobalUtf8(aName);

            iHandle = ServiceActionCreate(name);
            Marshal.FreeHGlobal(name);
            iInputParameters  = new List <Parameter>();
            iOutputParameters = new List <Parameter>();
        }
示例#11
0
文件: Service.cs 项目: fuzzy01/ohNet
        /// <summary>
        /// Constructor suitable for use by clients of the control point stack
        /// </summary>
        /// <param name="aName">Property name</param>
        /// <param name="aValueChanged">Action to run when the property's value changes</param>
        public unsafe PropertyBinary(String aName, System.Action aValueChanged)
            : base(aValueChanged)
        {
            IntPtr ptr  = GCHandle.ToIntPtr(iGch);
            IntPtr name = InteropUtils.StringToHGlobalUtf8(aName);

            iHandle = ServicePropertyCreateBinaryCp(name, iCallbackValueChanged, ptr);
            Marshal.FreeHGlobal(name);
        }
示例#12
0
        /// <summary>
        /// Query the value of the property
        /// </summary>
        /// <returns>String property value</returns>
        public unsafe String Value()
        {
            IntPtr ptr;
            uint   len;

            ServicePropertyGetValueString(iHandle, &ptr, &len);
            String str = InteropUtils.PtrToStringUtf8(ptr, len);

            OhNetFree(ptr);
            return(str);
        }
示例#13
0
文件: Service.cs 项目: simoncn/ohNet
        /// <summary>
        ///
        /// </summary>
        /// <param name="aName">Parameter name</param>
        /// <param name="aAllowedValues">List of allowed values for the string</param>
        public ParameterString(String aName, List <String> aAllowedValues)
        {
            IntPtr name = InteropUtils.StringToHGlobalUtf8(aName);

            IntPtr[] allowed = aAllowedValues.Select <string, IntPtr>(InteropUtils.StringToHGlobalUtf8).ToArray();
            iHandle = ServiceParameterCreateString(name, allowed, (uint)aAllowedValues.Count);
            foreach (IntPtr allowedValue in allowed)
            {
                Marshal.FreeHGlobal(allowedValue);
            }
            Marshal.FreeHGlobal(name);
        }
示例#14
0
        /// <summary>
        /// Query which subnet is in use.
        /// </summary>
        /// <param name="aCookie">Identifier for NetworkAdapter reference.  Must be used in a later call to NetworkAdapter.RemoveRef()</param>
        /// <returns>Network adapter.  Or null if no subnet is selected or we're running the device stack on all subnets.</returns>
        public static NetworkAdapter CurrentAdapter(string aCookie)
        {
            IntPtr cookie = InteropUtils.StringToHGlobalUtf8(aCookie);
            IntPtr nif    = OhNetCurrentSubnetAdapter(cookie);

            if (nif == IntPtr.Zero)
            {
                return(null);
            }
            NetworkAdapter n = new NetworkAdapter(nif);

            n.AddManagedCookie(aCookie, cookie);
            return(n);
        }
示例#15
0
文件: Service.cs 项目: fuzzy01/ohNet
        /// <summary>
        /// Query the value of the property
        /// </summary>
        /// <returns>String property value</returns>
        public unsafe String Value()
        {
            IntPtr ptr;
            uint   len;

            if (ServicePropertyGetValueString(iHandle, &ptr, &len) == -1)
            {
                throw new PropertyError();
            }
            String str = InteropUtils.PtrToStringUtf8(ptr, len);

            OhNetFree(ptr);
            return(str);
        }