コード例 #1
0
ファイル: CpService.cs プロジェクト: simoncn/ohNet
        /// <summary>
        /// Constructor for string input argument for an action
        /// </summary>
        /// <remarks>Intended to be write only (its value is written on construction and not be later read)</remarks>
        /// <param name="aParameter">Defines the name plus any bounds to the value for the argument.
        /// Must have been previously added to the action using Action.AddInputParameter</param>
        /// <param name="aValue">Value for the argument</param>
        public ArgumentString(ParameterString aParameter, String aValue)
        {
            IntPtr value = InteropUtils.StringToHGlobalUtf8(aValue);

            iHandle = ActionArgumentCreateStringInput(aParameter.Handle(), value);
            Marshal.FreeHGlobal(value);
        }
コード例 #2
0
ファイル: DvDevice.cs プロジェクト: fuzzy01/ohNet
        /// <summary>
        /// Constructor.  Creates a device capable of operating on any of the protocols the device
        /// stack supports as standard but with no services or attributes as yet
        /// </summary>
        /// <param name="aUdn">Universally unique identifier.  The caller is responsible for calculating/assigning this</param>
        public unsafe DvDeviceStandard(string aUdn)
        {
            IntPtr udn = InteropUtils.StringToHGlobalUtf8(aUdn);

            iHandle = DvDeviceStandardCreateNoResources(udn);
            Marshal.FreeHGlobal(udn);
        }
コード例 #3
0
ファイル: CpDeviceUpnp.cs プロジェクト: RoonLabs/ohNet
        public void TryAdd(string aLocation)
        {
            IntPtr location = InteropUtils.StringToHGlobalUtf8(aLocation);

            CpDeviceListUpnpTryAdd(iHandle, location);
            Marshal.FreeHGlobal(location);
        }
コード例 #4
0
        /// <summary>
        /// Report an error reading or writing an invocation
        /// </summary>
        /// <remarks>Must be called if ReadEnd() isn't reached.
        /// May be called if WriteStart() or later have been called.</remarks>
        /// <param name="aCode">Error code</param>
        /// <param name="aDescription">Error description</param>
        public void ReportError(uint aCode, String aDescription)
        {
            IntPtr desc = InteropUtils.StringToHGlobalUtf8(aDescription);

            // no point in propogating any error - client code can't cope with error reporting failing
            DvInvocationReportError(iHandle, aCode, desc);
            Marshal.FreeHGlobal(desc);
        }
コード例 #5
0
ファイル: DvDevice.cs プロジェクト: fuzzy01/ohNet
        /// <summary>
        /// Constructor.  Creates a device without support for any protocol but capable of adding services or attributes.
        /// This should only be used with CpDeviceDv.
        /// </summary>
        /// <param name="aUdn">Universally unique identifier.  The caller is responsible for calculating/assigning this</param>
        public unsafe DvDevice(string aUdn)
        {
            IntPtr udn = InteropUtils.StringToHGlobalUtf8(aUdn);

            iHandle = DvDeviceCreate(udn);
            Marshal.FreeHGlobal(udn);
            iCallbackDisabled = new DisabledCallback(Disabled);
        }
コード例 #6
0
        /// <summary>
        /// Set the value of an unsigned integer output argument for an invocation.
        /// </summary>
        /// <param name="aName">Name of the parameter associated with this output argument</param>
        /// <param name="aValue">Value of the output argument</param>
        public void WriteUint(String aName, uint aValue)
        {
            IntPtr name = InteropUtils.StringToHGlobalUtf8(aName);
            int    err  = DvInvocationWriteUint(iHandle, name, aValue);

            Marshal.FreeHGlobal(name);
            CheckError(err);
        }
コード例 #7
0
ファイル: DvDevice.cs プロジェクト: fuzzy01/ohNet
        /// <summary>
        /// Query the value of an atrribute
        /// </summary>
        /// <param name="aKey">string of the form protocol_name.protocol_specific_key.
        /// Commonly used keys are published ... (!!!! where?)</param>
        /// <param name="aValue">string containing the attribute or null if the attribute has not been set.</param>
        public unsafe void GetAttribute(string aKey, out string aValue)
        {
            IntPtr key = InteropUtils.StringToHGlobalUtf8(aKey);
            char * value;

            DvDeviceGetAttribute(iHandle, key, &value);
            Marshal.FreeHGlobal(key);
            aValue = InteropUtils.PtrToStringUtf8((IntPtr)value);
        }
コード例 #8
0
ファイル: DvDevice.cs プロジェクト: fuzzy01/ohNet
        /// <summary>
        /// Set the value of an attribute
        /// </summary>
        /// <param name="aKey">string of the form protocol_name.protocol_specific_key</param>
        /// <param name="aValue">attribute will be set to a copy of this string</param>
        public unsafe void SetAttribute(string aKey, string aValue)
        {
            IntPtr key   = InteropUtils.StringToHGlobalUtf8(aKey);
            IntPtr value = InteropUtils.StringToHGlobalUtf8(aValue);

            DvDeviceSetAttribute(iHandle, key, value);
            Marshal.FreeHGlobal(key);
            Marshal.FreeHGlobal(value);
        }
コード例 #9
0
ファイル: CpDeviceUpnp.cs プロジェクト: RoonLabs/ohNet
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="aUuid">Unique identifier for the target device.</param>
        /// <param name="aAdded">Delegate which will be run when a new device is detected.
        /// Clients who are interested this new device should call AddRef() on it and add it to some local collection.
        /// This callback will never be run for a device that is already in the list.</param>
        /// <param name="aRemoved">Delegatewhich will be run when a device is removed from the network.
        /// Clients who had previously stored a reference to the device in their aAdded callback should call RemoveRef()
        /// and remove the device from their local collection.
        /// Clients who had not previously claimed a reference to a device must not call ReleaseRef().</param>
        public CpDeviceListUpnpUuid(String aUuid, ChangeHandler aAdded, ChangeHandler aRemoved)
            : base(aAdded, aRemoved)
        {
            IntPtr uuid = InteropUtils.StringToHGlobalUtf8(aUuid);
            IntPtr ptr  = GCHandle.ToIntPtr(iGch);

            iHandle = CpDeviceListCreateUpnpUuid(uuid, iFnAdded, ptr, iFnRemoved, ptr);
            Marshal.FreeHGlobal(uuid);
        }
コード例 #10
0
        /// <summary>
        /// Set the value of a boolean output argument for an invocation.
        /// </summary>
        /// <param name="aName">Name of the parameter associated with this output argument</param>
        /// <param name="aValue">Value of the output argument</param>
        public void WriteBool(String aName, bool aValue)
        {
            IntPtr name = InteropUtils.StringToHGlobalUtf8(aName);
            uint   val  = (aValue? 1u : 0u);
            int    err  = DvInvocationWriteBool(iHandle, name, val);

            Marshal.FreeHGlobal(name);
            CheckError(err);
        }
コード例 #11
0
        /// <summary>
        /// Read the value of a boolean input argument for an invocation
        /// </summary>
        /// <param name="aName">Name of the parameter associated with this input argument</param>
        /// <returns>Value of the input argument</returns>
        public bool ReadBool(String aName)
        {
            IntPtr name = InteropUtils.StringToHGlobalUtf8(aName);
            uint   val;
            int    err = DvInvocationReadBool(iHandle, name, out val);

            Marshal.FreeHGlobal(name);
            CheckError(err);
            return(val != 0);
        }
コード例 #12
0
ファイル: DvProvider.cs プロジェクト: fuzzy01/ohNet
        /// <summary>
        /// Read the value of an unsigned integer input argument for an invocation
        /// </summary>
        /// <param name="aName">Name of the parameter associated with this input argument</param>
        /// <returns>Value of the input argument</returns>
        public unsafe uint ReadUint(String aName)
        {
            IntPtr name = InteropUtils.StringToHGlobalUtf8(aName);
            uint   val;
            int    err = DvInvocationReadUint(iHandle, name, &val);

            Marshal.FreeHGlobal(name);
            CheckError(err);
            return(val);
        }
コード例 #13
0
ファイル: DvDevice.cs プロジェクト: fuzzy01/ohNet
        public unsafe void WriteResourceBegin(int aTotalBytes, string aMimeType)
        {
            IntPtr mimeType = InteropUtils.StringToHGlobalUtf8(aMimeType);
            int    err      = iWriteBegin(iWriterData, aTotalBytes, mimeType);

            Marshal.FreeHGlobal(mimeType);
            if (err != 0)
            {
                throw new ResourceWriterError();
            }
        }
コード例 #14
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="aDevice">Device the service is being added to and will be offered by</param>
        /// <param name="aDomain">Domain of the vendor who defined the service</param>
        /// <param name="aType">Name of the service</param>
        /// <param name="aVersion">Version number of the service</param>
        protected DvProvider(DvDevice aDevice, String aDomain, String aType, uint aVersion)
        {
            IntPtr domain = InteropUtils.StringToHGlobalUtf8(aDomain);
            IntPtr type   = InteropUtils.StringToHGlobalUtf8(aType);

            iHandle = DvProviderCreate(aDevice.Handle(), domain, type, aVersion);
            Marshal.FreeHGlobal(type);
            Marshal.FreeHGlobal(domain);
            iActions    = new List <OpenHome.Net.Core.Action>();
            iProperties = new List <OpenHome.Net.Core.Property>();
        }
コード例 #15
0
ファイル: DvDevice.cs プロジェクト: fuzzy01/ohNet
        /// <summary>
        /// Constructor.  Creates a device capable of serving UI files and of operating on any of the
        /// protocols the device stack supports as standard but with no services or attributes as yet
        /// </summary>
        /// <param name="aUdn">Universally unique identifier.  The caller is responsible for calculating/assigning this</param>
        /// <param name="aResourceManager">Allows the owner of a device to serve UI files</param>
        public unsafe DvDeviceStandard(string aUdn, IResourceManager aResourceManager)
        {
            iResourceManager = aResourceManager;
            iGch             = GCHandle.Alloc(this);
            IntPtr ptr = GCHandle.ToIntPtr(iGch);
            IntPtr udn = InteropUtils.StringToHGlobalUtf8(aUdn);

            iCallbackResourceManager = new CallbackResourceManager(WriteResource);
            iHandle = DvDeviceStandardCreate(udn, iCallbackResourceManager, ptr);
            Marshal.FreeHGlobal(udn);
        }
コード例 #16
0
ファイル: CpDeviceUpnp.cs プロジェクト: RoonLabs/ohNet
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="aDomainName">Vendor domain for the target service (e.g. upnp.org).</param>
        /// <param name="aServiceType">Name of the target service.</param>
        /// <param name="aVersion">Version number for the target service.</param>
        /// <param name="aAdded">Delegate which will be run when a new device is detected.
        /// Clients who are interested this new device should call AddRef() on it and add it to some local collection.
        /// This callback will never be run for a device that is already in the list.</param>
        /// <param name="aRemoved">Delegatewhich will be run when a device is removed from the network.
        /// Clients who had previously stored a reference to the device in their aAdded callback should call RemoveRef()
        /// and remove the device from their local collection.
        /// Clients who had not previously claimed a reference to a device must not call ReleaseRef().</param>
        public CpDeviceListUpnpServiceType(String aDomainName, String aServiceType, uint aVersion,
                                           ChangeHandler aAdded, ChangeHandler aRemoved)
            : base(aAdded, aRemoved)
        {
            IntPtr domain = InteropUtils.StringToHGlobalUtf8(aDomainName);
            IntPtr type   = InteropUtils.StringToHGlobalUtf8(aServiceType);
            IntPtr ptr    = GCHandle.ToIntPtr(iGch);

            iHandle = CpDeviceListCreateUpnpServiceType(domain, type, aVersion, iFnAdded, ptr, iFnRemoved, ptr);
            Marshal.FreeHGlobal(domain);
            Marshal.FreeHGlobal(type);
        }
コード例 #17
0
        /// <summary>
        /// Utility function which updates the value of a PropertyString. (Not intended for external use)
        /// </summary>
        /// <remarks>If the property value has changed and the properties are not locked (PropertiesLock()
        /// called more recently than PropertiesUnlock()), publication of an update is scheduled.
        ///
        /// Throws ParameterValidationError if the property has a range of allowed values and
        /// the new value is not in this range</remarks>
        /// <param name="aProperty">Property to be updated</param>
        /// <param name="aValue">New value for the property</param>
        /// <returns>true if the property's value has changed (aValue was different to the previous value)</returns>
        protected bool SetPropertyString(PropertyString aProperty, String aValue)
        {
            uint   changed;
            IntPtr value = InteropUtils.StringToHGlobalUtf8(aValue);
            int    err   = DvProviderSetPropertyString(iHandle, aProperty.Handle(), value, out changed);

            Marshal.FreeHGlobal(value);
            if (err != 0)
            {
                throw new PropertyUpdateError();
            }
            return(changed != 0);
        }
コード例 #18
0
        protected CpProxy(String aDomain, String aName, uint aVersion, CpDevice aDevice)
        {
            IntPtr domain = InteropUtils.StringToHGlobalUtf8(aDomain);
            IntPtr name   = InteropUtils.StringToHGlobalUtf8(aName);

            iHandle = CpProxyCreate(domain, name, aVersion, aDevice.Handle());
            Marshal.FreeHGlobal(domain);
            Marshal.FreeHGlobal(name);
            IntPtr serviceHandle = CpProxyService(iHandle);

            iService  = new CpService(serviceHandle);
            iGchProxy = GCHandle.Alloc(this);
            iSubscriptionStatusLock = new Mutex();
        }
コード例 #19
0
        /// <summary>
        /// Read the value of a string input argument for an invocation
        /// </summary>
        /// <param name="aName">Name of the parameter associated with this input argument</param>
        /// <returns>Value of the input argument</returns>
        public String ReadString(String aName)
        {
            IntPtr name = InteropUtils.StringToHGlobalUtf8(aName);
            IntPtr ptr;
            uint   len;
            int    err = DvInvocationReadStringAsBuffer(iHandle, name, out ptr, out len);

            Marshal.FreeHGlobal(name);
            String str = InteropUtils.PtrToStringUtf8(ptr, len);

            OhNetFree(ptr);
            CheckError(err);
            return(str);
        }
コード例 #20
0
        /// <summary>
        /// Query the value of one of the device's attributes
        /// </summary>
        /// <param name="aKey">The name of the attribute being queried.  Available attributes
        /// will be listed in a protocol-specific header</param>
        /// <param name="aValue">The value of the attribute</param>
        /// <returns>true if the attribute was available on the device; false otherwise.
        /// aValue will not have been set if false is returned</returns>
        public bool GetAttribute(string aKey, out string aValue)
        {
            IntPtr key = InteropUtils.StringToHGlobalUtf8(aKey);
            IntPtr value;
            int    ret = CpDeviceCGetAttribute(iHandle, key, out value);

            Marshal.FreeHGlobal(key);
            if (ret != 0)
            {
                aValue = InteropUtils.PtrToStringUtf8(value);
                OhNetFree(value);
                return(true);
            }
            aValue = null;
            return(false);
        }
コード例 #21
0
        /// <summary>
        /// Read the value of a binary input argument for an invocation
        /// </summary>
        /// <param name="aName">Name of the parameter associated with this input argument</param>
        /// <returns>Value of the input argument</returns>
        public byte[] ReadBinary(String aName)
        {
            IntPtr name = InteropUtils.StringToHGlobalUtf8(aName);
            IntPtr data;
            uint   len;
            int    err = DvInvocationReadBinary(iHandle, name, out data, out len);

            Marshal.FreeHGlobal(name);

            byte[] bin = new byte[len];
            if (len > 0)
            {
                Marshal.Copy(data, bin, 0, (int)len);
            }
            OhNetFree((IntPtr)data);
            CheckError(err);
            return(bin);
        }
コード例 #22
0
        /// <summary>
        /// Set the value of a binary output argument for an invocation.
        /// </summary>
        /// <param name="aName">Name of the parameter associated with this output argument</param>
        /// <param name="aData">Value of the output argument</param>
        public void WriteBinary(String aName, byte[] aData)
        {
            IntPtr name = InteropUtils.StringToHGlobalUtf8(aName);
            int    err  = DvInvocationWriteBinaryStart(iHandle, name);

            if (err == 0)
            {
                GCHandle h = GCHandle.Alloc(aData, GCHandleType.Pinned);
                err = DvInvocationWriteBinary(iHandle, h.AddrOfPinnedObject(), (uint)aData.Length);
                h.Free();
            }
            if (err == 0)
            {
                err = DvInvocationWriteBinaryEnd(iHandle, name);
            }
            Marshal.FreeHGlobal(name);
            CheckError(err);
        }
コード例 #23
0
        /// <summary>
        /// Set the value of a string output argument for an invocation.
        /// </summary>
        /// <param name="aName">Name of the parameter associated with this output argument</param>
        /// <param name="aValue">Value of the output argument</param>
        public void WriteString(String aName, String aValue)
        {
            IntPtr name  = InteropUtils.StringToHGlobalUtf8(aName);
            IntPtr value = InteropUtils.StringToHGlobalUtf8(aValue);
            int    err   = DvInvocationWriteStringStart(iHandle, name);

            if (err == 0)
            {
                err = DvInvocationWriteString(iHandle, value);
            }
            Marshal.FreeHGlobal(value);
            if (err == 0)
            {
                err = DvInvocationWriteStringEnd(iHandle, name);
            }
            Marshal.FreeHGlobal(name);
            CheckError(err);
        }
コード例 #24
0
ファイル: DvProvider.cs プロジェクト: fuzzy01/ohNet
        /// <summary>
        /// Set the value of a binary output argument for an invocation.
        /// </summary>
        /// <param name="aName">Name of the parameter associated with this output argument</param>
        /// <param name="aData">Value of the output argument</param>
        public unsafe void WriteBinary(String aName, byte[] aData)
        {
            IntPtr name = InteropUtils.StringToHGlobalUtf8(aName);
            int    err  = DvInvocationWriteBinaryStart(iHandle, name);

            if (err == 0)
            {
                fixed(byte *data = aData)
                {
                    err = DvInvocationWriteBinary(iHandle, data, (uint)aData.Length);
                }
            }
            if (err == 0)
            {
                err = DvInvocationWriteBinaryEnd(iHandle, name);
            }
            Marshal.FreeHGlobal(name);
            CheckError(err);
        }