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 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 (); } }
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"); } }
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); } }
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 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)); } }
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); } }
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); }
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 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 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; }
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; } }
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 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); } }
static public CFUrl FromUrlString(string url, CFUrl baseurl) { using (var str = new CFString(url)){ return(FromStringHandle(str.Handle, baseurl)); } }
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 GlyphNameForGlyph (ushort glyph) { using (var s = new CFString (CGFontCopyGlyphNameForGlyph (handle, glyph), true)) return (string) s; }
public string GetStringValue(string key) { using (var str = new CFString(key)) { return(CFString.FetchString(CFDictionaryGetValue(Handle, str.Handle))); } }
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); } }
public override string ToString () { using (var str = new CFString (CFURLGetString (handle))) { return str.ToString (); } }
/// <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 (); }
public void SetCFProperty (string name, INativeObject value) { ThrowIfDisposed (); var nameCFString = new CFString (name); var result = IOConnectSetCFProperty (Handle, nameCFString.Handle, value.Handle); ThrowIfError (result); }
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"); } } }
public override string ToString() { using (var str = new CFString(CFURLGetString(handle))) { return(str.ToString()); } }
public void SetProperty(CGSConnection target, string property, CFBoolean value) { var cfProperty = new CFString(property); CGSSetConnectionProperty(Handle, target.Handle, cfProperty.Handle, value.Handle); }
public ushort GetGlyphWithGlyphName (string s) { using (var cs = new CFString (s)){ return CGFontGetGlyphWithGlyphName (handle, cs.handle); } }
public IntPtr GetIntPtrValue(string key) { using (var str = new CFString(key)) { return(CFDictionaryGetValue(Handle, str.Handle)); } }
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); } }
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); } }
string GetStringValue () { var stringRef = CFUUIDCreateString (NULL, Handle); using (var cfString = new CFString (stringRef)) { Release (stringRef); return cfString.ToString (); } }
static internal string GetFileSystemPath(IntPtr hcfurl) { using (var str = new CFString(CFURLCopyFileSystemPath(hcfurl, 0), true)) return(str.ToString()); }
static internal string GetFileSystemPath (IntPtr hcfurl) { using (var str = new CFString (CFURLCopyFileSystemPath (hcfurl, 0), true)) return str.ToString (); }
public CFTypeRef CreateCFProperty (string key) { ThrowIfDisposed (); var keyAsCFString = new CFString (key); return IORegistryEntryCreateCFProperty (Handle, keyAsCFString.Handle, CFAllocator.Default.Handle, 0); }
static public CFUrl FromUrlString (string url, CFUrl baseurl) { using (var str = new CFString (url)){ return FromStringHandle (str.Handle, baseurl); } }
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; } }
public bool ContainsKey(string key) { using (var str = new CFString(key)) { return(CFDictionaryContainsKey(Handle, str.Handle)); } }
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"); } } }