private static void InternalLoadMatchDataCallback(IntPtr matchData, IntPtr error, IntPtr secondaryCallback) { if (PInvokeUtil.IsNull(secondaryCallback)) { return; } byte[] data = null; if (PInvokeUtil.IsNotNull(matchData)) { // Creating a one-time usage NSData binder, so no need to use the factory. using (var nsData = new NSData(matchData)) { var length = nsData.Length; if (length > 0) { data = nsData.GetBytes(length); } } } // A new NSError object is always created on native side, so no need // to check the binder pool for reusing an existing one. NSError nsError = PInvokeUtil.IsNotNull(error) ? new NSError(error) : null; PInvokeCallbackUtil.PerformInternalCallback( "GKTurnBasedMatch#InternalLoadMatchDataCallback", PInvokeCallbackUtil.Type.Temporary, data, nsError, secondaryCallback); }
private static void GetImageDataHolderFunc(int taskId, int frameCount, int frameWidth, int frameHeight, IntPtr pointerHolder) { if (frameCount <= 0 || PInvokeUtil.IsNull(pointerHolder)) { Debug.LogError("GetImageDataHolderFunc Error: Invalid buffer pointers from native side."); return; } // Create managed buffer for unmanaged code to fill data in. int frameSize = frameWidth * frameHeight; var buff = new Color32[frameCount][]; for (int i = 0; i < frameCount; i++) { buff[i] = new Color32[frameSize]; } var gcHandleArray = new GCHandle[frameCount]; var ptrArray = new IntPtr[frameCount]; for (int i = 0; i < buff.Length; i++) { gcHandleArray[i] = GCHandle.Alloc(buff[i], GCHandleType.Pinned); ptrArray[i] = gcHandleArray[i].AddrOfPinnedObject(); // fill the pointers sent by native code with the object pointer we've just pinned. } // Copy pointers to unmanaged holder. C._CopyPointerArray(pointerHolder, ptrArray, frameCount); // Cache GCHandles. DecodeTasks[taskId].imageDataHandles = gcHandleArray; }
private static void InternalMultipleMatchesCallback(IntPtr matches, IntPtr error, IntPtr secondaryCallback) { if (PInvokeUtil.IsNull(secondaryCallback)) { return; } GKTurnBasedMatch[] gkMatches = null; if (PInvokeUtil.IsNotNull(matches)) { // Creating a one-time usage NSArray binder, no need to use the factory. using (var nsArray = new NSArray <GKTurnBasedMatch>(matches)) { gkMatches = nsArray.ToArray(ptr => InteropObjectFactory <GKTurnBasedMatch> .FromPointer(ptr, p => new GKTurnBasedMatch(p))); } } // A new NSError object is always created on native side, so no need // to check the binder pool for reusing an existing one. NSError nsError = PInvokeUtil.IsNotNull(error) ? new NSError(error) : null; // Invoke consumer callback. PInvokeCallbackUtil.PerformInternalCallback( "GKTurnBasedMatch#InternalMultipleMatchesCallback", PInvokeCallbackUtil.Type.Temporary, gkMatches, nsError, secondaryCallback); }
private void Cleanup() { if (!PInvokeUtil.IsNull(mSelfPointer)) { ReleaseHandle(mSelfPointer); mSelfPointer = new HandleRef(this, IntPtr.Zero); } }
private static void InternalChooseBestHostingPlayerCallback(IntPtr player, IntPtr secondaryCallback) { if (PInvokeUtil.IsNull(secondaryCallback)) { return; } var gkPlayer = InteropObjectFactory <GKPlayer> .FromPointer(player, p => new GKPlayer(p)); PInvokeCallbackUtil.PerformInternalCallback( "GKMatch#InternalChooseBestHostingPlayerCallback", PInvokeCallbackUtil.Type.Temporary, gkPlayer, secondaryCallback); }
private static void InternalErrorOnlyCallback(IntPtr error, IntPtr secondaryCallback) { if (PInvokeUtil.IsNull(secondaryCallback)) { return; } NSError nsError = PInvokeUtil.IsNotNull(error) ? new NSError(error) : null; PInvokeCallbackUtil.PerformInternalCallback( "GKTurnBasedMatch#InternalErrorOnlyCallback", PInvokeCallbackUtil.Type.Temporary, nsError, secondaryCallback); }
private static void PlayerBoolCallback( /* InteropGKPlayer */ IntPtr playerPtr, bool boolArg, IntPtr secondaryCallback) { if (PInvokeUtil.IsNull(secondaryCallback)) { return; } var player = InteropObjectFactory <GKPlayer> .FromPointer(playerPtr, p => new GKPlayer(p)); PInvokeCallbackUtil.PerformInternalCallback( "GKMatchmaker#PlayerBoolCallback", PInvokeCallbackUtil.Type.Temporary, player, boolArg, secondaryCallback); }
/// <summary> /// Creates a NSString object from a pointer and release that pointer if required. /// </summary> /// <returns>The pointer.</returns> /// <param name="ptr">Ptr.</param> /// <param name="releasePointer">If set to <c>true</c> release pointer.</param> internal static NSString FromPointer(IntPtr ptr, bool releasePointer) { if (PInvokeUtil.IsNull(ptr)) { return(null); } var str = new NSString(ptr); if (releasePointer) { CFFunctions.CFRelease(ptr); } return(str); }
private static void IntErrorCallback( int intArg, /* InteropNSError */ IntPtr errorPtr, IntPtr secondaryCallback) { if (PInvokeUtil.IsNull(secondaryCallback)) { return; } var error = PInvokeUtil.IsNotNull(errorPtr) ? new NSError(errorPtr) : null; PInvokeCallbackUtil.PerformInternalCallback( "GKMatchmaker#IntErrorCallback", PInvokeCallbackUtil.Type.Temporary, intArg, error, secondaryCallback); }
private static void InternalSingleMatchCallback(IntPtr match, IntPtr error, IntPtr secondaryCallback) { if (PInvokeUtil.IsNull(secondaryCallback)) { return; } GKTurnBasedMatch gkMatch = InteropObjectFactory <GKTurnBasedMatch> .FromPointer(match, ptr => new GKTurnBasedMatch(ptr)); NSError nsError = PInvokeUtil.IsNotNull(error) ? new NSError(error) : null; PInvokeCallbackUtil.PerformInternalCallback( "GKTurnBasedMatch#InternalSingleMatchCallback", PInvokeCallbackUtil.Type.Temporary, gkMatch, nsError, secondaryCallback); }
private static void PlayersErrorCallback( /* InteropNSArray<GKPlayer> */ IntPtr playerArrayPtr, /* InteropNSError */ IntPtr errorPtr, IntPtr secondaryCallback) { if (PInvokeUtil.IsNull(secondaryCallback)) { return; } var array = InteropObjectFactory <NSArray <GKPlayer> > .FromPointer(playerArrayPtr, p => new NSArray <GKPlayer>(p)); var error = PInvokeUtil.IsNotNull(errorPtr) ? new NSError(errorPtr) : null; PInvokeCallbackUtil.PerformInternalCallback( "GKMatchmaker#PlayersErrorCallback", PInvokeCallbackUtil.Type.Temporary, array, error, secondaryCallback); }
private static void MatchErrorCallback( /* InteropGKMatch */ IntPtr matchPtr, /* InteropNSError */ IntPtr errorPtr, IntPtr secondaryCallback) { if (PInvokeUtil.IsNull(secondaryCallback)) { return; } var match = InteropObjectFactory <GKMatch> .FromPointer(matchPtr, p => new GKMatch(p)); var error = PInvokeUtil.IsNotNull(errorPtr) ? new NSError(errorPtr) : null; PInvokeCallbackUtil.PerformInternalCallback( "GKMatchmaker#MatchErrorCallback", PInvokeCallbackUtil.Type.Temporary, match, error, secondaryCallback); }
private static void InternalRequestAccessForEntityTypeCallback(bool granted, /* NSError */ IntPtr error, IntPtr secondaryCallback) { if (PInvokeUtil.IsNull(secondaryCallback)) { return; } NSError nsError = PInvokeUtil.IsNotNull(error) ? new NSError(error) : null; // Invoke consumer callback. PInvokeCallbackUtil.PerformInternalCallback( "CNContactStore#InternalRequestAccessForEntityTypeCallback", PInvokeCallbackUtil.Type.Temporary, granted, nsError, secondaryCallback); }
private static void WriteToSavedPhotosAlbumCallback( /* UIImage */ IntPtr imagePtr, /* InteropNSError */ IntPtr errorPtr, IntPtr secondaryCallback) { if (PInvokeUtil.IsNull(secondaryCallback)) { return; } var image = InteropObjectFactory <UIImage> .FromPointer(imagePtr, p => new UIImage(p)); var error = PInvokeUtil.IsNotNull(errorPtr) ? new NSError(errorPtr) : null; PInvokeCallbackUtil.PerformInternalCallback( "UIKitFunctions#WriteToSavedPhotosAlbumCallback", PInvokeCallbackUtil.Type.Temporary, image, error, secondaryCallback); }
private static void InternalLoadPhotoForSizeCallback(IntPtr photo, IntPtr error, IntPtr secondaryCallback) { if (PInvokeUtil.IsNull(secondaryCallback)) { return; } // Create the UIImage from the pointer. UIImage uiImage = InteropObjectFactory <UIImage> .FromPointer(photo, ptr => new UIImage(ptr)); // A new NSError object is always created on native side, so no need // to check the binder pool for reusing an existing one. NSError nsError = PInvokeUtil.IsNotNull(error) ? new NSError(error) : null; PInvokeCallbackUtil.PerformInternalCallback( "GKPlayer#InternalLoadPhotoForSizeCallback", PInvokeCallbackUtil.Type.Temporary, uiImage, nsError, secondaryCallback); }
private static void GetFrameMetadataHolderFunc(int taskId, int frameCount, IntPtr pointerHolder) { if (frameCount <= 0 || PInvokeUtil.IsNull(pointerHolder)) { Debug.LogError("GetFrameMetadataHolderFunc Error: Invalid buffer pointers from native side."); return; } var gcHandleArray = new GCHandle[frameCount]; var ptrArray = new IntPtr[frameCount]; for (int i = 0; i < frameCount; i++) { gcHandleArray[i] = GCHandle.Alloc(new GifFrameMetadata(), GCHandleType.Pinned); ptrArray[i] = gcHandleArray[i].AddrOfPinnedObject(); // fill the pointers sent by native code with the object pointer we've just pinned. } // Copy pointers to unmanaged holder. C._CopyPointerArray(pointerHolder, ptrArray, frameCount); // Cache GCHandles. DecodeTasks[taskId].frameMetadataHandles = gcHandleArray; }
private static void InternalEnumerateContactsBlock(/* CNContact */ IntPtr contact, out bool stop, IntPtr secondaryCallback) { if (PInvokeUtil.IsNull(secondaryCallback)) { stop = true; return; } CNContact ct = PInvokeUtil.IsNotNull(contact) ? new CNContact(contact) : null; // Invoke consumer callback. stop = PInvokeCallbackUtil.PerformInternalFunction <CNContact, bool>( "CNContactStore#InternalEnumerateContactsBlock", PInvokeCallbackUtil.Type.Permanent, // make sure the callback can be called repeatedly ct, secondaryCallback); // Release callback handle if stopping. if (stop) { PInvokeCallbackUtil.UnpinCallbackHandle(secondaryCallback); } }
private MediaResult CreateResult(PickerOperation operation, NSDictionary <NSString, iOSObjectProxy> info) { if (info == null) { return(null); } switch (Operation) { case PickerOperation.PickGallery: // User can either pick an image or a video NSURL pickedURL = null; if (TryGetUrl(info, UIImagePickerController.UIImagePickerControllerImageURL, out pickedURL)) { return(new MediaResult(MediaType.Image, null, pickedURL.AbsoluteString.UTF8String)); } else if (TryGetUrl(info, UIImagePickerController.UIImagePickerControllerMediaURL, out pickedURL)) { return(new MediaResult(MediaType.Video, null, pickedURL.AbsoluteString.UTF8String)); } else { return(null); } case PickerOperation.TakePicture: // Get the newly taken image, save it into the into user temporary folder and return the URL. // The image name will be "IMG_" + timestamp and format is JPG. UIImage picture = (UIImage)info.ValueForKey(UIImagePickerController.UIImagePickerControllerOriginalImage, ptr => PInvokeUtil.IsNull(ptr) ? null : new UIImage(ptr)); if (picture == null) { Debug.LogError("Couldn't get the taken picture."); return(null); } // Save the image into user temporary folder and return the URL. NSString tempDir = NSFileManager.NSTemporaryDirectory(); if (tempDir == null) { Debug.LogError("Couldn't find the path of user's temporary directory."); return(null); } // The image name is "IMG_" + timestamp and format is JPG. NSString pictureName = NSString.StringWithUTF8String("IMG_" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".jpg"); NSURL pictureURL = NSURL.FileURLWithPath(tempDir).URLByAppendingPathComponent(pictureName); if (pictureURL != null) { NSData imageData = UIFunctions.UIImageJPEGRepresentation(picture, 1f); NSFileManager.DefaultManager.CreateFileAtPath(pictureURL.Path, imageData, null); return(new MediaResult(MediaType.Image, null, pictureURL.AbsoluteString.UTF8String)); } else { return(null); } case PickerOperation.RecordVideo: NSURL videoURL = null; if (TryGetUrl(info, UIImagePickerController.UIImagePickerControllerMediaURL, out videoURL)) { return(new MediaResult(MediaType.Video, null, videoURL.AbsoluteString.UTF8String)); } else { return(null); } default: return(null); } }
protected bool IsDisposed() { return(PInvokeUtil.IsNull(mSelfPointer)); }