Inheritance: INativeObject, IDisposable
Example #1
0
		public string GetDescription (IntPtr handle)
		{
			if (handle == IntPtr.Zero)
				throw new ArgumentNullException ("handle");
			
			using (var s = new CFString (CFCopyDescription (handle)))
				return s.ToString ();
		}
		static public string ToString (IntPtr pdfString)
		{
			if (pdfString == IntPtr.Zero)
				return null;
			
			using (var cfs = new CFString (CGPDFStringCopyTextString (pdfString), true)) {
				return cfs.ToString ();
			}
		}
Example #3
0
		static public CFUrl FromFile (string filename)
		{
			using (var str = new CFString (filename)){
				IntPtr handle = CFURLCreateWithFileSystemPath (IntPtr.Zero, str.Handle, CFUrlPathStyle.POSIX, false);
				if (handle == IntPtr.Zero)
					return null;
				return new CFUrl (handle);
			}
		}
Example #4
0
        public CGColor(string name)
        {
            if (name == null)
                throw new ArgumentNullException ("name");

            using (var s = new CFString (name)){
                handle = CGColorGetConstantColor (s.handle);
                if (handle == IntPtr.Zero)
                    throw new ArgumentException ("name");
            }
        }
Example #5
0
        public static IntPtr GetUsbProperty (IntPtr registry_entry, CFString key)
        {
            if (registry_entry == IntPtr.Zero || key.Handle == IntPtr.Zero) {
                return IntPtr.Zero;
            }

            IntPtr parent_entry = IOKit.FindInParent (registry_entry, key);
            if (parent_entry == IntPtr.Zero) {
                return IntPtr.Zero;
            }

            IntPtr ptr = IORegistryEntryCreateCFProperty (parent_entry, key.Handle, IntPtr.Zero, 0);
            //CFShow (ptr);
            return ptr;
        }
Example #6
0
        public static IntPtr FindInParent (IntPtr entry , CFString field)
        {
            // the field we search for, i.e. idVendor as the usb vendor id
            IntPtr key = field.Handle;

            IntPtr ptr = IORegistryEntryCreateCFProperty (entry, key, IntPtr.Zero, 0);
            if (ptr == IntPtr.Zero) {
                // key does not exist, go up one level
                IntPtr parent;

                // we search in the IOService plane - other planes might be IOUSB or IODeviceTree etc.
                // see IORegistryExplorer program that ships with OS X Xcode.
                IORegistryEntryGetParentEntry (entry , "IOService", out parent);
                if (parent != IntPtr.Zero) {
                    return FindInParent (parent, field);
                } else {
                    return IntPtr.Zero;
                }
            } else {
                return entry;
            }
        }
Example #7
0
		public override string ToString ()
		{
			using (var str = new CFString (CFURLGetString (handle))) {
				return str.ToString ();
			}
		}
Example #8
0
		static void Cancel (IntPtr info, IntPtr runLoop, IntPtr mode)
		{
			var source = GCHandle.FromIntPtr (info).Target as CFRunLoopSourceCustom;

			var loop = new CFRunLoop (runLoop);
			var mstring = new CFString (mode);

			try {
				source.OnCancel (loop, (string)mstring);
			} finally {
				loop.Dispose ();
				mstring.Dispose ();
			}
		}
Example #9
0
		public ushort GetGlyphWithGlyphName (string s)
		{
			using (var cs = new CFString (s)){
				return CGFontGetGlyphWithGlyphName (handle, cs.handle);
			}
		}
		public bool ContainsKey (string key)
		{
			using (var str = new CFString (key)) {
				return CFDictionaryContainsKey (Handle, str.handle);
			}
		}
Example #11
0
		public void SetCFProperty (string name, INativeObject value)
		{
			ThrowIfDisposed ();
			var nameCFString = new CFString (name);
			var result = IOConnectSetCFProperty (Handle, nameCFString.Handle, value.Handle);
			ThrowIfError (result);
		}
Example #12
0
 public static CFUrl FromUrlString(string url, CFUrl baseurl)
 {
     using (var str = new CFString (url)){
         IntPtr handle = CFURLCreateWithString (IntPtr.Zero, str.Handle, baseurl != null ? baseurl.Handle : IntPtr.Zero);
         if (handle == IntPtr.Zero)
             return null;
         return new CFUrl (handle);
     }
 }
Example #13
0
		public NSObject this [string key] {
			get {
				ThrowIfDisposed ();
				if (key == null)
					throw new ArgumentNullException ("propertyName");
				using (var propertyNameString = new CFString (key)) {
					var valueRef = IOHIDManagerGetProperty (Handle, propertyNameString.Handle);
					if (valueRef == IntPtr.Zero)
						return null;
					return Runtime.GetNSObject (valueRef);
				}
			}
			set {
				ThrowIfDisposed ();
				if (key == null)
					throw new ArgumentNullException ("propertyName");
				using (var propertyNameString = new CFString (key)) {
					if (!IOHIDManagerSetProperty (Handle, propertyNameString.Handle, value.Handle))
						throw new Exception ("Failed to set property");
				}
			}
		}
Example #14
0
        internal OsxUsbData(IntPtr registry_entry)
        {
            // 1st approach - get IODeviceTree's parent locationID, then find by location ID
            /*string path = properties.GetStringValue ("DAMediaPath");
            IntPtr entry = IORegistryEntryFromPath (IntPtr.Zero, path);
            CFString s = new CFString ("locationID");
            IntPtr plane = new CFString ("IODeviceTree").Handle;
            IntPtr parent = IntPtr.Zero;
            IORegistryEntryGetParentEntry (entry, "IODeviceTree", out parent);
            if (parent != IntPtr.Zero) {
                IntPtr ptr = IORegistryEntryCreateCFProperty (parent, s.Handle, IntPtr.Zero, 0);
                CFShow (ptr);
            }*/
            // TODO recursive find

            // 2nd approach - walk the tree (which one?) up until we find
            // a idVendor - at worst, up to the root
            IntPtr cf_ref;

            // populate properties from the usb device info

            cf_ref = IOKit.GetUsbProperty (registry_entry, "idVendor");
            if (cf_ref != IntPtr.Zero) {
                Int32 num;
                CoreFoundation.CFNumberGetValue (cf_ref, 3, out num);
                VendorId = (uint) num;
            }

            cf_ref = IOKit.GetUsbProperty (registry_entry, "idProduct");
            if (cf_ref != IntPtr.Zero) {
                Int32 num;
                CoreFoundation.CFNumberGetValue (cf_ref, 3, out num);
                ProductId = (uint) num;
            }

            cf_ref = IOKit.GetUsbProperty (registry_entry, "USB Vendor Name");
            if (cf_ref != IntPtr.Zero) {
                VendorName = new CFString (cf_ref).ToString ();
            }

            cf_ref = IOKit.GetUsbProperty (registry_entry, "USB Product Name");
            if (cf_ref != IntPtr.Zero) {
                ProductName = new CFString (cf_ref).ToString ();
            }

            cf_ref = IOKit.GetUsbProperty (registry_entry, "USB Serial Number");
            if (cf_ref != IntPtr.Zero) {
                UsbSerial = new CFString (cf_ref).ToString ();
            }
        }
		public IntPtr GetIntPtrValue (string key)
		{
			using (var str = new CFString (key)) {
				return CFDictionaryGetValue (Handle, str.handle);
			}
		}
		public CFDictionary GetDictionaryValue (string key)
		{
			using (var str = new CFString (key)) {
				var ptr = CFDictionaryGetValue (Handle, str.handle);
				return ptr == IntPtr.Zero ? null : new CFDictionary (ptr);
			}
		}
Example #17
0
		public NSObject this[string key] {
			get {
				ThrowIfDisposed ();
				using (var keyString = new CFString (key)) {
					var propertyRef = IOHIDElementGetProperty (Handle, keyString.Handle);
					return Runtime.GetNSObject (propertyRef);
				}
			}
			set {
				ThrowIfDisposed ();
				using (var keyString = new CFString (key)) {
					if (!IOHIDElementSetProperty (Handle, keyString.Handle, value.Handle))
					    throw new Exception ("Failed to set property");
				}
			}
		}
Example #18
0
 public void SetProperty(CGSConnection target, string property, CFBoolean value)
 {
     var cfProperty = new CFString(property);
     CGSSetConnectionProperty(Handle, target.Handle, cfProperty.Handle, value.Handle);
 }
Example #19
0
		/// <summary>
		/// Initializes a new instance of the <see cref="IOKit.CFUUID"/> class from the specified string.
		/// </summary>
		/// <param name="uuid">String.</param>
		public CFUUID (string uuid)
		{
			using (var uuidCFString = new CFString (uuid)) {
				Handle = CFUUIDCreateFromString (NULL, uuidCFString.Handle);
			}
			if (Handle == IntPtr.Zero)
				throw new Exception ("Failed to create CFUUID");
			Initalize ();
		}
Example #20
0
		public string GlyphNameForGlyph (ushort glyph)
		{
			using (var s = new CFString (CGFontCopyGlyphNameForGlyph (handle, glyph), true))
				return (string) s;
		}
Example #21
0
		string GetStringValue ()
		{
			var stringRef = CFUUIDCreateString (NULL, Handle);
			using (var cfString = new CFString (stringRef)) {
				Release (stringRef);
				return cfString.ToString ();
			}
		}
Example #22
0
		public CFTypeRef CreateCFProperty (string key)
		{
			ThrowIfDisposed ();
			var keyAsCFString = new CFString (key);
			return IORegistryEntryCreateCFProperty (Handle, keyAsCFString.Handle, CFAllocator.Default.Handle, 0);
		}
Example #23
0
		public void SetCFProperty (string propertyName, INativeObject properties)
		{
			ThrowIfDisposed ();
			var propertyNameAsCFString = new CFString (propertyName);
			var result = IORegistryEntrySetCFProperty (Handle, propertyNameAsCFString.Handle, properties.Handle);
			ThrowIfError (result);
		}
Example #24
0
		public CFRunLoopExitReason RunInMode (string mode, double seconds, bool returnAfterSourceHandled)
		{
			if (mode == null)
				throw new ArgumentNullException ("mode");

			CFString s = new CFString (mode);

			var v = CFRunLoopRunInMode (s.Handle, seconds, returnAfterSourceHandled ? 1 : 0);
			s.Dispose ();

			return (CFRunLoopExitReason) v;
		}
		public string GetStringValue (string key)
		{
			using (var str = new CFString (key)) {
				return CFString.FetchString (CFDictionaryGetValue (Handle, str.handle));
			}
		}
Example #26
0
		static internal string GetFileSystemPath (IntPtr hcfurl)
		{
			using (var str = new CFString (CFURLCopyFileSystemPath (hcfurl, 0), true))
				return str.ToString ();
		}
		public long GetInt64Value (string key)
		{
			long value = 0;
			using (var str = new CFString (key)) {
				if (!CFNumberGetValue (CFDictionaryGetValue (Handle, str.Handle), /* kCFNumberSInt64Type */ 4, out value))
					throw new System.Collections.Generic.KeyNotFoundException (string.Format ("Key {0} not found", key));
				return value;
			}
		}
Example #28
0
		static public CFUrl FromUrlString (string url, CFUrl baseurl)
		{
			using (var str = new CFString (url)){
				return FromStringHandle (str.Handle, baseurl);
			}
		}
Example #29
0
		public NSObject this [string key] {
			get {
				ThrowIfDisposed ();
				if (key == null)
					throw new ArgumentNullException ("key");
				using (var keyString = new CFString (key)) {
					var result = IOHIDDeviceGetProperty (Handle, keyString.Handle);
					if (result == IntPtr.Zero)
						return null;
					return Runtime.GetNSObject (result);
				}
			}
			set {
				ThrowIfDisposed ();
				if (key == null)
					throw new ArgumentNullException ("key");
				using (var keyString = new CFString (key)) {
					if (!IOHIDDeviceSetProperty (Handle, keyString.Handle, value.Handle))
						throw new Exception ("Failed to set property");
				}
			}
		}