Inheritance: INativeObject, IDisposable
Beispiel #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 ();
		}
Beispiel #2
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);
			}
		}
		static public string ToString (IntPtr pdfString)
		{
			if (pdfString == IntPtr.Zero)
				return null;
			
			using (var cfs = new CFString (CGPDFStringCopyTextString (pdfString), true)) {
				return cfs.ToString ();
			}
		}
Beispiel #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");
            }
        }
Beispiel #5
0
 public static void CreatePairWithSocketToHost(string host, int port,
                                               out CFReadStream readStream,
                                               out CFWriteStream writeStream)
 {
     using (var str = new CFString(host)) {
         IntPtr read, write;
         CFStreamCreatePairWithSocketToHost(
             IntPtr.Zero, str.Handle, port, out read, out write);
         readStream  = new CFReadStream(read);
         writeStream = new CFWriteStream(write);
     }
 }
Beispiel #6
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));
     }
 }
Beispiel #7
0
 static public 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));
     }
 }
Beispiel #8
0
        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);
            }
        }
Beispiel #9
0
        public CFRunLoopExitReason RunInMode(string mode, double interval, bool returnAfterSourceHandled)
        {
            CFString s = mode == null ? null : new CFString(mode);

            var v = CFRunLoopRunInMode(s == null ? IntPtr.Zero : s.Handle, interval, returnAfterSourceHandled ? 1 : 0);

            if (s != null)
            {
                s.Dispose();
            }

            return((CFRunLoopExitReason)v);
        }
Beispiel #10
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();
            }
        }
Beispiel #11
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);
        }
Beispiel #12
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;
        }
Beispiel #13
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;
            }
        }
Beispiel #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 ();
            }
        }
Beispiel #15
0
 public static string GetTypeDescription(IntPtr handle)
 {
     using (var s = new CFString(CFCopyDescription(handle)))
         return(s.ToString());
 }
		public bool ContainsKey (string key)
		{
			using (var str = new CFString (key)) {
				return CFDictionaryContainsKey (Handle, str.handle);
			}
		}
Beispiel #17
0
 static public CFUrl FromUrlString(string url, CFUrl baseurl)
 {
     using (var str = new CFString(url)){
         return(FromStringHandle(str.Handle, baseurl));
     }
 }
Beispiel #18
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;
		}
Beispiel #19
0
		public string GlyphNameForGlyph (ushort glyph)
		{
			using (var s = new CFString (CGFontCopyGlyphNameForGlyph (handle, glyph), true))
				return (string) s;
		}
Beispiel #20
0
 public string GetStringValue(string key)
 {
     using (var str = new CFString(key)) {
         return(CFString.FetchString(CFDictionaryGetValue(Handle, str.Handle)));
     }
 }
Beispiel #21
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);
     }
 }
Beispiel #22
0
		public override string ToString ()
		{
			using (var str = new CFString (CFURLGetString (handle))) {
				return str.ToString ();
			}
		}
Beispiel #23
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 ();
		}
Beispiel #24
0
		public void SetCFProperty (string name, INativeObject value)
		{
			ThrowIfDisposed ();
			var nameCFString = new CFString (name);
			var result = IOConnectSetCFProperty (Handle, nameCFString.Handle, value.Handle);
			ThrowIfError (result);
		}
Beispiel #25
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");
				}
			}
		}
Beispiel #26
0
 public override string ToString()
 {
     using (var str = new CFString(CFURLGetString(handle))) {
         return(str.ToString());
     }
 }
Beispiel #27
0
 public void SetProperty(CGSConnection target, string property, CFBoolean value)
 {
     var cfProperty = new CFString(property);
     CGSSetConnectionProperty(Handle, target.Handle, cfProperty.Handle, value.Handle);
 }
Beispiel #28
0
		public ushort GetGlyphWithGlyphName (string s)
		{
			using (var cs = new CFString (s)){
				return CGFontGetGlyphWithGlyphName (handle, cs.handle);
			}
		}
Beispiel #29
0
 public IntPtr GetIntPtrValue(string key)
 {
     using (var str = new CFString(key)) {
         return(CFDictionaryGetValue(Handle, str.Handle));
     }
 }
Beispiel #30
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");
				}
			}
		}
		public IntPtr GetIntPtrValue (string key)
		{
			using (var str = new CFString (key)) {
				return CFDictionaryGetValue (Handle, str.handle);
			}
		}
Beispiel #32
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 ();
			}
		}
		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);
			}
		}
Beispiel #34
0
		string GetStringValue ()
		{
			var stringRef = CFUUIDCreateString (NULL, Handle);
			using (var cfString = new CFString (stringRef)) {
				Release (stringRef);
				return cfString.ToString ();
			}
		}
Beispiel #35
0
 static internal string GetFileSystemPath(IntPtr hcfurl)
 {
     using (var str = new CFString(CFURLCopyFileSystemPath(hcfurl, 0), true))
         return(str.ToString());
 }
Beispiel #36
0
		static internal string GetFileSystemPath (IntPtr hcfurl)
		{
			using (var str = new CFString (CFURLCopyFileSystemPath (hcfurl, 0), true))
				return str.ToString ();
		}
Beispiel #37
0
		public CFTypeRef CreateCFProperty (string key)
		{
			ThrowIfDisposed ();
			var keyAsCFString = new CFString (key);
			return IORegistryEntryCreateCFProperty (Handle, keyAsCFString.Handle, CFAllocator.Default.Handle, 0);
		}
Beispiel #38
0
		static public CFUrl FromUrlString (string url, CFUrl baseurl)
		{
			using (var str = new CFString (url)){
				return FromStringHandle (str.Handle, baseurl);
			}
		}
Beispiel #39
0
		public void SetCFProperty (string propertyName, INativeObject properties)
		{
			ThrowIfDisposed ();
			var propertyNameAsCFString = new CFString (propertyName);
			var result = IORegistryEntrySetCFProperty (Handle, propertyNameAsCFString.Handle, properties.Handle);
			ThrowIfError (result);
		}
		public string GetStringValue (string key)
		{
			using (var str = new CFString (key)) {
				return CFString.FetchString (CFDictionaryGetValue (Handle, str.handle));
			}
		}
		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;
			}
		}
Beispiel #42
0
 public bool ContainsKey(string key)
 {
     using (var str = new CFString(key)) {
         return(CFDictionaryContainsKey(Handle, str.Handle));
     }
 }
Beispiel #43
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");
				}
			}
		}