Example #1
0
        private static int WriteResource(IntPtr aUserData, IntPtr aUriTail, uint aInterface, IntPtr aLanguageList, IntPtr aWriterData,
                                         CallbackWriteResourceBegin aWriteBegin,
                                         CallbackWriteResource aWriteResource,
                                         CallbackWriteResourceEnd aWriteEnd)
        {
            GCHandle         gch          = GCHandle.FromIntPtr(aUserData);
            DvDeviceStandard self         = (DvDeviceStandard)gch.Target;
            string           uriTail      = InteropUtils.PtrToStringUtf8(aUriTail);
            List <string>    languageList = new List <string>();
            uint             count        = DvResourceWriterLanguageCount(aLanguageList);

            for (uint i = 0; i < count; i++)
            {
                languageList.Add(InteropUtils.PtrToStringUtf8(DvResourceWriterLanguage(aLanguageList, i)));
            }
            ResourceWriter writer = new ResourceWriter(aWriterData, aWriteBegin, aWriteResource, aWriteEnd);

            try
            {
                writer.Write(self.iResourceManager, uriTail, aInterface, languageList);
            }
            catch
            {
                return(-1);
            }
            return(0);
        }
Example #2
0
        /// <summary>
        /// Query the unique identifier associated with a device
        /// </summary>
        /// <returns>Device's (universally unique) name</returns>
        public String Udn()
        {
            IntPtr ptr;
            uint   len;

            CpDeviceCGetUdn(iHandle, out ptr, out len);
            return(InteropUtils.PtrToStringUtf8(ptr, len));
        }
Example #3
0
        /// <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);
        }
Example #4
0
        /// <summary>
        /// Query the (client-specified) unique device name
        /// </summary>
        /// <returns>The name passed to the c'tor</returns>
        public unsafe String Udn()
        {
            IntPtr ptr;
            uint   len;

            DvDeviceGetUdn(iHandle, &ptr, &len);
            String udn = InteropUtils.PtrToStringUtf8(ptr, len);

            return(udn);
        }
Example #5
0
        /// <summary>
        /// Check whether the invocation failed
        /// </summary>
        /// <remarks>Only intended for use in the invocation complete callback</remarks>
        /// <returns>true if the invocation failed; false if it succeeded</returns>
        public static bool Error(IntPtr aHandle, out uint aErrorCode, out string aErrorDesc)
        {
            uint   code;
            IntPtr desc;
            uint   err = CpInvocationError(aHandle, out code, out desc);

            aErrorCode = code;
            aErrorDesc = InteropUtils.PtrToStringUtf8(desc);
            return(err != 0);
        }
Example #6
0
        /// <summary>
        /// Get the prefix to use on any uris to resources offered by the provider.
        /// </summary>
        /// <returns>The prefix to resource uris.</returns>
        public string ResourceUriPrefix()
        {
            IntPtr cPrefix;
            uint   len;

            DvInvocationGetResourceUriPrefix(iHandle, out cPrefix, out len);
            String prefix = InteropUtils.PtrToStringUtf8(cPrefix, len);

            return(prefix);
        }
Example #7
0
        /// <summary>
        /// Utility to retrieve the value of a string type output argument
        /// </summary>
        /// <remarks>Must only be called once per output argument.  (The first call extracts
        /// the string data from the underlying native object so later calls would return an
        /// empty string.)</remarks>
        /// <param name="aHandle">Invocation handle</param>
        /// <param name="aIndex">Zero-based index into array of output arguments.
        /// Must refer to an ArgumentString.</param>
        /// <returns>Value of the string output argument</returns>
        public static String OutputString(IntPtr aHandle, uint aIndex)
        {
            IntPtr ptr;
            uint   len;

            CpInvocationGetOutputString(aHandle, aIndex, out ptr, out len);
            String str = InteropUtils.PtrToStringUtf8(ptr, len);

            OhNetFree(ptr);
            return(str);
        }
Example #8
0
        /// <summary>
        /// Read the value of a binary argument.
        /// </summary>
        /// <remarks>Only intended for use with output arguments inside the invocation completed callback.
        /// Can only be called once as the first call extracts the string data from the underlying native object</remarks>
        /// <returns>Current value of the argument</returns>
        String Value()
        {
            IntPtr ptr;
            uint   len;

            ActionArgumentGetValueString(iHandle, out ptr, out len);
            String ret = InteropUtils.PtrToStringUtf8(ptr, len);

            OhNetFree(ptr);
            return(ret);
        }
Example #9
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);
        }
Example #10
0
        /// <summary>
        /// Query the base uri for the resource manager.
        /// </summary>
        /// <param name="aAdapter">The network adapter to return a uri for.</param>
        /// <returns>The base uri.  May be empty if there is no resource manager.</returns>
        public unsafe string ResourceManagerUri(Core.NetworkAdapter aAdapter)
        {
            if (aAdapter == null)
            {
                return("");
            }
            IntPtr ptr;
            uint   len;

            DvDeviceStandardGetResourceManagerUri(iHandle, aAdapter.Handle(), &ptr, &len);
            string uri = InteropUtils.PtrToStringUtf8(ptr, len);

            OhNetFree(ptr);
            return(uri);
        }
Example #11
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);
        }