/// <summary>
            /// Destroys the video sink.
            /// </summary>
            /// <returns>
            /// MLResult.Result will be <c>MLResult.Code.Ok</c> if destroying all handles was successful.
            /// MLResult.Result will be <c>MLResult.Code.WebRTCResultInstanceNotCreated</c> if MLWebRTC instance was not created.
            /// MLResult.Result will be <c>MLResult.Code.WebRTCResultMismatchingHandle</c> if an incorrect handle was sent.
            /// </returns>
            public override MLResult Destroy()
            {
#if PLATFORM_LUMIN
                if (!MagicLeapNativeBindings.MLHandleIsValid(this.Handle))
                {
                    return(MLResult.Create(MLResult.Code.InvalidParam, "Handle is invalid."));
                }

                updateVideoEvent.WaitOne(250);
                this.SetStream(null);

                MLResult.Code resultCode = NativeBindings.MLWebRTCVideoSinkDestroy(this.Handle);
                DidNativeCallSucceed(resultCode, "MLWebRTCVideoSinkDestroy()");
                this.InvalidateHandle();
                MLWebRTC.Instance.sinks.Remove(this);

                return(MLResult.Create(resultCode));
#else
                return(new MLResult());
#endif
            }
Beispiel #2
0
 /// <summary>
 /// Checks whether the application has the specified privileges.
 /// This does not solicit consent from the end-user.
 /// </summary>
 /// <param name="privilegeId">The privilege to check for access.</param>
 /// <returns>
 /// MLResult.Result will be <c>MLResult.Code.PrivilegeGranted</c> if the privilege is granted.
 /// MLResult.Result will be <c>MLResult.Code.PrivilegeNotGranted</c> if the privilege is denied.
 /// MLResult.Result will be <c>MLResult.Code.UnspecifiedFailure</c> if the privilege system was not started.
 /// </returns>
 public static MLResult CheckPrivilege(MLPrivileges.Id privilegeId)
 {
     try
     {
         if (MLPrivileges.IsValidInstance())
         {
             MLResult.Code checkPrivilegeResult = NativeBindings.MLPrivilegesCheckPrivilege(privilegeId);
             return((checkPrivilegeResult == MLResult.Code.PrivilegeNotGranted) ? MLResult.Create(checkPrivilegeResult, "Privilege Denied or Not Yet Requested.") : MLResult.Create(checkPrivilegeResult));
         }
         else
         {
             MLPluginLog.ErrorFormat("MLPrivileges.CheckPrivilege failed. Reason: No Instance for MLPrivileges.");
             return(MLResult.Create(MLResult.Code.UnspecifiedFailure, "MLPrivileges.CheckPrivilege failed. Reason: No Instance for MLPrivileges."));
         }
     }
     catch (System.EntryPointNotFoundException)
     {
         MLPluginLog.Error("MLPrivileges.CheckPrivilege failed. Reason: API symbols not found");
         return(MLResult.Create(MLResult.Code.UnspecifiedFailure, "MLPrivileges.CheckPrivilege failed. Reason: API symbols not found."));
     }
 }
Beispiel #3
0
        /// <summary>
        /// Requests for the hand mesh and executes the callback when the request is done.
        /// </summary>
        /// <param name="callback">Callback to execute when the request is done.</param>
        /// <returns>
        /// MLResult.Result will be <c>MLResult.Code.Ok</c> if successful.
        /// MLResult.Result will be <c>MLResult.Code.InvalidParam</c> if failed due to internal invalid input parameter.
        /// </returns>
        public static MLResult RequestHandMesh(RequestHandMeshCallback callback)
        {
            if (callback == null)
            {
                MLPluginLog.ErrorFormat("MLHandMeshing.RequestHandMesh failed. Reason: Passed input callback is null");
                return(MLResult.Create(MLResult.Code.InvalidParam));
            }

            ulong requestHandle = MagicLeapNativeBindings.InvalidHandle;

            MLResult.Code resultCode = NativeBindings.MLHandMeshingRequestMesh(Instance.nativeTracker, ref requestHandle);
            if (resultCode != MLResult.Code.Ok)
            {
                MLPluginLog.ErrorFormat("MLHandMeshing.RequestHandMesh failed to request hand mesh. Reason: {0}", resultCode);
                return(MLResult.Create(resultCode));
            }

            Instance.pendingQueries.Add(new Query(requestHandle, callback));

            return(MLResult.Create(resultCode));
        }
        /// <summary>
        /// Initializes the image tracker.
        /// </summary>
        /// <returns>
        /// MLResult.Result will be <c>MLResult.Code.Ok</c> if successful.
        /// MLResult.Result will be <c>MLResult.Code.UnspecifiedFailure</c> if failed due to internal error.
        /// </returns>
        protected override MLResult StartAPI()
        {
            this.handle = MagicLeapNativeBindings.InvalidHandle;
            MLResult.Code resultCode = NativeBindings.MLImageTrackerCreate(ref this.trackerSettings, ref this.handle);
            MLResult      result     = MLResult.Create(resultCode);

            if (result.IsOk)
            {
                bool success = MagicLeapNativeBindings.MLHandleIsValid(this.handle);
                if (!success)
                {
                    MLPluginLog.Error("MLImageTracker.StartApi failed. Reason: Invalid image tracker this.handle.");
                }
            }
            else
            {
                MLPluginLog.ErrorFormat("MLImageTracker.StartApi failed to create image tracker this.handle. Reason: {0}", result);
            }

            return(result);
        }
        /// <summary>
        /// Internal call used to set the status of the Image Tracker.
        /// </summary>
        /// <param name="enabled">Used to enabled or disable Image Tracker to be enabled or disabled.</param>
        /// <returns>
        /// MLResult.Result will be <c>MLResult.Code.InvalidParam</c> if there were invalid trackerSettings when setting the Image Tracker status.
        /// MLResult.Result will be <c>MLResult.Code.Ok</c> if the Image Tracker status was updated successfully or if no change was needed.
        /// MLResult.Result will be <c>MLResult.Code.PrivilegeDenied</c> if there was a lack of privileges.
        /// MLResult.Result will be <c>MLResult.Code.UnspecifiedFailure</c> if there was an internal error.
        /// </returns>
        private MLResult SetTrackerStatusInternal(bool enabled)
        {
            if (this.trackerSettings.EnableTracker == enabled)
            {
                return(MLResult.Create(MLResult.Code.Ok, "No change needed"));
            }

            bool prevStatus = this.trackerSettings.EnableTracker;

            this.trackerSettings.EnableTracker = enabled;

            MLResult.Code resultCode = NativeBindings.MLImageTrackerUpdateSettings(this.handle, ref this.trackerSettings);
            MLResult      result     = MLResult.Create(resultCode);

            if (!result.IsOk)
            {
                this.trackerSettings.EnableTracker = prevStatus;
            }

            return(result);
        }
        /// <summary>
        /// Sets the Image Tracker's settings to match the provided settings.
        /// </summary>
        /// <param name="customSettings">The new MLImageTracker.Settings wanted.</param>
        /// <returns>
        /// MLResult.Result will be <c>MLResult.Code.Ok</c> if successfully updated the image tracker settings.
        /// MLResult.Result will be <c>MLResult.Code.InvalidParam</c> if failed to update the settings due to invalid input parameter.
        /// MLResult.Result will be <c>MLResult.Code.UnspecifiedFailure</c> if failed due to internal error.
        /// MLResult.Result will be <c>MLResult.Code.PrivilegeDenied</c> if failed to update the settings due to lack of privilege(s).
        /// </returns>
        public static MLResult UpdateTrackerSettings(MLImageTracker.Settings customSettings)
        {
            var currentSettings = GetCurrentTrackerSettings();

            if (currentSettings == customSettings)
            {
                return(MLResult.Create(MLResult.Code.Ok, "No change needed"));
            }

            Instance.trackerSettings = new NativeBindings.MLImageTrackerSettingsNative(customSettings);

            MLResult.Code resultCode = NativeBindings.MLImageTrackerUpdateSettings(Instance.handle, ref Instance.trackerSettings);
            MLResult      result     = MLResult.Create(resultCode);

            if (!result.IsOk)
            {
                Instance.trackerSettings = new NativeBindings.MLImageTrackerSettingsNative(currentSettings);
            }

            return(result);
        }
        /// <summary>
        /// Request the specified privilege asynchronously. This may solicit consent from the end-user.
        /// This async override uses Tasks instead of a callback.
        /// </summary>
        /// <param name="privilegeId">The privilege to request.</param>
        /// <returns>
        /// MLResult.Result will be <c>MLResult.Code.PrivilegeGranted</c> if the privilege is granted.
        /// MLResult.Result will be <c>MLResult.Code.PrivilegeNotGranted</c> if the privilege is denied.
        /// MLResult.Result will be <c>MLResult.Code.UnspecifiedFailure</c> if the privilege system was not started.
        /// </returns>
        private async Task <MLResult> RequestPrivilegeAsyncInternal(MLPrivileges.Id privilegeId)
        {
            var taskCompletionSource = new TaskCompletionSource <MLResult>();

            if (this.currentRequests.ContainsKey(privilegeId))
            {
                return(MLResult.Create(MLResult.Code.Ok));
            }

            IntPtr newRequest = IntPtr.Zero;

            MLResult.Code resultCode = NativeBindings.MLPrivilegesRequestPrivilegeAsync(privilegeId, ref newRequest);
            if (!MLResult.IsOK(resultCode))
            {
                return(MLResult.Create(resultCode));
            }

            RequestPrivilegeQuery newQuery = new RequestPrivilegeQuery((result, id) => taskCompletionSource.SetResult(result), newRequest, privilegeId);

            this.currentRequests.Add(privilegeId, newQuery);
            return(await taskCompletionSource.Task);
        }
                /// <summary>
                /// Destroys the Track and its associated media source.
                /// </summary>
                /// <returns>
                /// MLResult.Result will be <c>MLResult.Code.Ok</c> if destroying all handles was successful.
                /// MLResult.Result will be <c>MLResult.Code.WebRTCResultInstanceNotCreated</c> if MLWebRTC instance was not created.
                /// MLResult.Result will be <c>MLResult.Code.WebRTCResultMismatchingHandle</c> if an incorrect handle was sent.
                /// </returns>
                public virtual MLResult DestroyLocal()
                {
#if PLATFORM_LUMIN
                    if (!this.IsLocal)
                    {
                        return(MLResult.Create(MLResult.Code.InvalidParam, "Souce is not local."));
                    }

                    if (!MagicLeapNativeBindings.MLHandleIsValid(this.Handle))
                    {
                        return(MLResult.Create(MLResult.Code.InvalidParam, "Source handle is invalid."));
                    }

                    this.Cleanup();

                    MLResult.Code resultCode = MLResult.Code.Ok;

                    // If this is a local source then we need to explicitly remove it from it's associated connections.
                    foreach (MLWebRTC.PeerConnection connection in Instance.connections)
                    {
                        if (connection == this.ParentConnection)
                        {
                            connection.RemoveLocalTrack(this);
                            break;
                        }
                    }

                    MLWebRTC.Instance.localTracks.Remove(this);

                    resultCode = Source.NativeBindings.MLWebRTCSourceDestroy(this.Handle);
                    DidNativeCallSucceed(resultCode, "MLWebRTCSourceDestroy()");
                    this.Handle           = MagicLeapNativeBindings.InvalidHandle;
                    this.ParentConnection = null;

                    return(MLResult.Create(resultCode));
#else
                    return(new MLResult());
#endif
                }
        /// <summary>
        /// Request a subset of connections as manually selected by the user. The results are delivered via a callback
        /// </summary>
        /// <param name="maxSelectionAmount">Max number of connections to be selected. Min limit is 1.</param>
        /// <param name="userPrompt">Text prompt to be displayed to the user with selection dialog. The max length for the prompt is 40 characters.</param>
        /// <param name="defaultFilter">Type of filter applied by default to MLConnections list in selection dialog.</param>
        /// <returns>
        /// <para>MLResult.Result will be <c>MLResult.Code.Ok</c> if successfully submitted.</para>
        /// <para>MLResult.Result will be <c>MLResult.Code.PrivilegeDenied</c> if permissions haven't been granted to make this call.</para>
        /// </returns>
        public static MLResult GetSelection(uint maxSelectionAmount, string userPrompt, SelectionFilter defaultFilter)
        {
            if (MLConnections.IsValidInstance())
            {
                NativeBindings.SelectionArgs argsToSend = NativeBindings.SelectionArgs.Create(maxSelectionAmount, userPrompt, defaultFilter);

                MLResult.Code resultCode = NativeBindings.MLConnectionsRequestSelection(ref argsToSend, ref _instance.selectionHandle);
                MLResult      result     = MLResult.Create(resultCode);

                if (!result.IsOk)
                {
                    MLPluginLog.ErrorFormat("MLConnections.GetSelection failed to request a selection. Reason: {0}", result);
                }

                return(result);
            }
            else
            {
                MLPluginLog.ErrorFormat("MLConnections.GetSelection failed. Reason: No Instance for MLConnections");
                return(MLResult.Create(MLResult.Code.UnspecifiedFailure, "MLConnections.GetSelection failed. Reason: No Instance for MLConnections"));
            }
        }
Beispiel #10
0
            /// <summary>
            /// Call for querying the last known coarse/fine location.
            /// The accuracy field of the MLLocation.Location provides the estimate accuracy radius in meters.
            /// Returns the last known data on success and returns the last queried location data on failure. Latitude and Longitude of
            /// 0 should be assumed an Invalid Location.
            /// </summary>
            /// <param name="outLocation">Where to store the last known fine location. Only updates when getting the location succeeds. Latitude and Longitude of 0 should be assumed an Invalid Location.</param>
            /// <param name="isFine">Determines whether to query for fine location or coarse location.</param>
            /// <returns>
            /// MLResult.Result will be <c>MLResult.Code.Ok</c> if the location was queried successfully.
            /// MLResult.Result will be <c>MLResult.Code.UnspecifiedFailure</c> if there was an internal error.
            /// MLResult.Result will be <c>MLResult.Code.InvalidParam</c> if there was an invalid location.
            /// MLResult.Result will be <c>MLResult.Code.PrivilegeDenied</c> if there was a lack of privilege(s).
            /// MLResult.Result will be <c>MLResult.Code.LocationProviderNotFound</c> if there was no provider or an invalid request was made.
            /// MLResult.Result will be <c>MLResult.Code.LocationNetworkConnection</c> if there was no internet connection.
            /// MLResult.Result will be <c>MLResult.Code.LocationNoLocation</c> if the location could not be found.
            /// </returns>
            public static MLResult MLLocationGetLastLocation(out MLLocation.Location outLocation, bool isFine)
            {
                // The automatic marshaling was not working properly for this structure. TimeStamp was always 0. To solve this
                // we use an IntPtr that has the proper default values set.
                NativeBindings.LocationNative location = NativeBindings.LocationNative.Create();
                MLResult.Code resultCode;

                IntPtr myPointer = Marshal.AllocHGlobal(Marshal.SizeOf(location));

                Marshal.StructureToPtr(location, myPointer, false);

                try
                {
                    resultCode = isFine ? NativeBindings.MLLocationGetLastFineLocation(myPointer) : NativeBindings.MLLocationGetLastCoarseLocation(myPointer);

                    if (resultCode != MLResult.Code.Ok)
                    {
                        MLPluginLog.ErrorFormat("MLLocation.NativeBindings.MLLocationGetLastLocation failed to get location. Reason: {0}", resultCode);
                    }
                }
                catch (EntryPointNotFoundException)
                {
                    MLResult result = MLResult.Create(MLResult.Code.UnspecifiedFailure, "MLLocation API symbols not found.");
                    MLPluginLog.ErrorFormat("MLLocation.NativeBindings.MLLocationGetLastLocation failed to get location. Reason: {0}", result);
                    outLocation = new MLLocation.Location();
                    Marshal.FreeHGlobal(myPointer);
                    return(result);
                }

                location = (NativeBindings.LocationNative)Marshal.PtrToStructure(myPointer, typeof(NativeBindings.LocationNative));

                Marshal.FreeHGlobal(myPointer);

                MLResult finalResult = MLResult.Create(resultCode);

                outLocation = location.Data;

                return(finalResult);
            }
        /// <summary>
        /// Retrieves the closest known PCF of the types provided by the typesMask to the given position.
        /// </summary>
        /// <param name="position">The position of the object we want to anchor.</param>
        /// <param name="callback">Delegate used to return the resulting MLResult.Result and the closest found PCF.</param>
        /// <param name="typesMask">The bitmask of which PCF types to consider.</param>
        /// <param name="update">Determines if the PCF should have it's pose and state updated.</param>
        /// <returns>
        /// MLResult.Result will be <c>MLResult.Code.Ok</c> if a valid PCF was found.
        /// MLResult.Result will be <c>MLResult.Code.UnspecifiedFailure</c> if failed due to no API instance being found.
        /// </returns>
        public static MLResult FindClosestPCF(Vector3 position, OnFoundSinglePCFDelegate callback, PCF.Types typesMask = PCF.Types.SingleUserSingleSession | PCF.Types.SingleUserMultiSession | PCF.Types.MultiUserMultiSession, bool update = true)
        {
            if (MLPersistentCoordinateFrames.IsValidInstance())
            {
                QueryFilter queryFilter = QueryFilter.Create();
                queryFilter.TargetPoint = position;
                queryFilter.TypesMask   = typesMask;
                queryFilter.Sorted      = true;

                FindPCFsByFilter(queryFilter, update: update, callback: (MLResult.Code resultCode, List <PCF> pcfList) =>
                {
                    callback?.Invoke(resultCode, pcfList[0]);
                });

                return(MLResult.Create(MLResult.Code.Ok));
            }
            else
            {
                MLPluginLog.ErrorFormat("MLPersistentCoordinateFrames.FindClosestPCF failed. Reason: No Instance for MLPersistentCoordinateFrames.");
                return(MLResult.Create(MLResult.Code.UnspecifiedFailure, "MLPersistentCoordinateFrames.FindClosestPCF failed. Reason: No Instance for MLPersistentCoordinateFrames."));
            }
        }
        private MLResult InternalAdd(ref MLScreensWatchHistoryEntry entry, Texture2D thumbnailImage)
        {
            if (!entry.IsValid)
            {
                return(MLResult.Create(MLResult.Code.InvalidParam, "Invalid entry parameter"));
            }

            if (thumbnailImage != null && thumbnailImage.format != TextureFormat.RGB24)
            {
                return(MLResult.Create(MLResult.Code.InvalidParam, "Invalid thumbnail parameter format"));
            }

            MLScreensNativeBindings.MLScreensWatchHistoryEntryNative nativeEntry = MLScreensNativeBindings.MLScreensWatchHistoryEntryNative.Create();
            nativeEntry.Data = entry;

            MLImageNativeBindings.MLImageNative thumbnail =
                thumbnailImage == null ? _defaultGrayThumbnailImage : CreateThumbnailImage(thumbnailImage);
            MLResult.Code resultCode =
                MLScreensNativeBindings.MLScreensInsertWatchHistoryEntry(ref nativeEntry, ref thumbnail);

            if (thumbnail.Image != IntPtr.Zero && thumbnail.Image != _defaultGrayThumbnailImage.Image)
            {
                Marshal.FreeHGlobal(thumbnail.Image);
            }

            Marshal.FreeHGlobal(nativeEntry.Title);
            Marshal.FreeHGlobal(nativeEntry.Subtitle);
            Marshal.FreeHGlobal(nativeEntry.CustomData);

            var result = MLResult.Create(resultCode);

            if (result.IsOk)
            {
                entry.Id = nativeEntry.Id;
                _watchHistory.Add(entry.Id, entry);
            }

            return(result);
        }
Beispiel #13
0
        /// <summary>
        /// Retrieves the closest known PCF of the types provided by the typesMask to the given position.
        /// </summary>
        /// <param name="position">The position of the object we want to anchor.</param>
        /// <param name="pcf">Stores the resulting PCF.</param>
        /// <param name="typesMask">The bitmask of which PCF types to consider.</param>
        /// <param name="update">Determines if the PCF should have it's pose and state updated.</param>
        /// <returns>
        /// MLResult.Result will be <c>MLResult.Code.Ok</c> if a valid PCF was found.
        /// MLResult.Result will be <c>MLResult.Code.InvalidParam</c> if failed due to an invalid input parameter.
        /// MLResult.Result will be <c>MLResult.Code.PrivilegeDenied</c> if necessary privilege is missing.
        /// MLResult.Result will be <c>MLResult.Code.UnspecifiedFailure</c> if failed due to other internal error.
        /// MLResult.Result will be <c>MLResult.Code.PassableWorldLowMapQuality</c> if map quality is too low for content persistence. Continue building the map.
        /// MLResult.Result will be <c>MLResult.Code.PassableWorldUnableToLocalize</c> if currently unable to localize into any map. Continue building the map.
        /// </returns>
        public static MLResult FindClosestPCF(Vector3 position, out PCF pcf, PCF.Types typesMask = PCF.Types.SingleUserSingleSession | PCF.Types.SingleUserMultiSession | PCF.Types.MultiUserMultiSession, bool update = true)
        {
            pcf = null;

            if (MLPersistentCoordinateFrames.IsValidInstance())
            {
                QueryFilter queryFilter = QueryFilter.Create();
                queryFilter.TargetPoint = position;
                queryFilter.TypesMask   = typesMask;
                queryFilter.Sorted      = true;

                MLResult result = FindPCFsByFilter(queryFilter, out List <PCF> pcfList, update);

                if (!result.IsOk || pcfList.Count == 0)
                {
                    if (result.Result == MLResult.Code.PassableWorldLowMapQuality || result.Result == MLResult.Code.PassableWorldUnableToLocalize)
                    {
                        MLPluginLog.WarningFormat("Map quality not sufficient enough for MLPersistentCoordinateFrames.FindClosestPCF. Reason: {0}", result);
                    }
                    else
                    {
                        MLPluginLog.ErrorFormat("MLPersistentCoordinateFrames.FindClosestPCF failed. Reason: {0}", result);
                    }
                }
                else
                {
                    pcf = pcfList[0];
                }

                return(result);
            }
            else
            {
                MLPluginLog.ErrorFormat("MLPersistentCoordinateFrames.FindClosestPCF failed. Reason: No Instance for MLPersistentCoordinateFrames.");
                return(MLResult.Create(MLResult.Code.UnspecifiedFailure, "MLPersistentCoordinateFrames.FindClosestPCF failed. Reason: No Instance for MLPersistentCoordinateFrames."));
            }
        }
Beispiel #14
0
            /// <summary>
            /// Creates an initialized DataChannel object.
            /// </summary>
            /// <param name="connection">The connection to create the data channel with.</param>
            /// <param name="label">The label to give the data channel.</param>
            /// <param name="result">The MLResult object of the inner platform call(s).</param>
            /// <returns> An initialized DataChannel object.</returns>
            public static DataChannel CreateLocal(MLWebRTC.PeerConnection connection, out MLResult result, string label = "local")
            {
                DataChannel dataChannel = null;

                if (connection == null)
                {
                    result = MLResult.Create(MLResult.Code.InvalidParam, "PeerConnection is null.");
                    return(dataChannel);
                }

                ulong dataChannelHandle = MagicLeapNativeBindings.InvalidHandle;

                MLResult.Code resultCode = NativeBindings.MLWebRTCDataChannelCreate(connection.Handle, label, out dataChannelHandle);
                if (!DidNativeCallSucceed(resultCode, "MLWebRTCDataChannelCreate()"))
                {
                    result = MLResult.Create(resultCode);
                    return(dataChannel);
                }

                dataChannel = new DataChannel(dataChannelHandle)
                {
                    Label            = label,
                    ParentConnection = connection
                };

                resultCode = NativeBindings.SetCallbacks(dataChannel);

                if (!DidNativeCallSucceed(resultCode, "MLWebRTCDataChannelSetCallbacks()"))
                {
                    result = MLResult.Create(resultCode);
                    return(dataChannel);
                }

                connection.LocalDataChannels.Add(dataChannel);
                result = MLResult.Create(resultCode);
                return(dataChannel);
            }
Beispiel #15
0
        /// <summary>
        /// Open a secure browser window to perform an <c>oauth</c> authentication.
        /// Will open a special browser window that will be <c>laz</c> head locked to
        /// the user's head movement. The browser window will close once the
        /// authentication procedure has been completed.
        /// </summary>
        /// <param name="url">The <c>oauth</c> url to navigate to.</param>
        /// <param name="cancelUri">The cancel uri called by the browser when users cancels the window.</param>
        /// <param name="disallowHttp">Flag to set if http requests are not allowed. Default: false. If this is set to true and url points to http,
        /// the request will fail and the cancel uri callback will return the failure response.</param>
        /// <returns>
        /// MLResult.Result will be <c>MLResult.Code.Ok</c> if the browser <c>oauth</c> window opened correctly.
        /// MLResult.Result will be <c>MLResult.Code.UnspecifiedFailure</c> if the operation failed with an unspecified error.
        /// MLResult.Result will be <c>MLResult.Code.PrivilegeDenied*</c> if SecureBrowserWindow privilege is denied.
        /// MLResult.Result will be <c>MLResult.Code.Dispatch*</c> if a dispatch specific error occurred.
        /// </returns>
        public static MLResult OAuthOpenWindow(string url, string cancelUri, bool disallowHttp = false)
        {
            try
            {
                NativeBindings.OAuthOpenWindowRequest newRequest = NativeBindings.OAuthOpenWindowRequest.Create();
                newRequest.Url          = url;
                newRequest.CancelUri    = cancelUri;
                newRequest.DisallowHttp = disallowHttp;

                MLResult.Code resultCode = NativeBindings.MLDispatchOAuthOpenWindowEx(ref newRequest);

                return(MLResult.Create(resultCode));
            }
            catch (System.DllNotFoundException)
            {
                MLPluginLog.Error(DllNotFoundExceptionError);
                return(MLResult.Create(MLResult.Code.UnspecifiedFailure, DllNotFoundExceptionError));
            }
            catch (System.EntryPointNotFoundException)
            {
                MLPluginLog.Error("MLDispatch API symbols not found");
                return(MLResult.Create(MLResult.Code.UnspecifiedFailure, "MLDispatch API symbols not found"));
            }
        }
Beispiel #16
0
        public static MLResult FindClosestPCF(Vector3 position, Action <MLResult, MLPCF> callback)
        {
            if (callback == null)
            {
                MLResult result = MLResult.Create(MLResult.Code.InvalidParam);
                callback(result, null);
                return(result);
            }

            else
            {
                MLResult result = FindClosestPCF(position, out PCF pcf);
                if (result.IsOk)
                {
                    callback(result, (MLPCF)pcf);
                }
                else
                {
                    callback(result, null);
                }

                return(result);
            }
        }
Beispiel #17
0
        /// <summary>
        /// Unregister a unique schema for <c>OAuth</c> redirect handler.
        /// </summary>
        /// <param name="schema">A unique string that will match the redirect uri schema.</param>
        /// <returns>
        /// MLResult.Result will be <c>MLResult.Code.Ok</c> if the new schema has been registered correctly.
        /// MLResult.Result will be <c>MLResult.Code.UnspecifiedFailure</c> if the operation failed with an unspecified error.
        /// MLResult.Result will be <c>MLResult.Code.PrivilegeDenied</c> if SecureBrowserWindow privilege is denied.
        /// MLResult.Result will be <c>MLResult.Code.Dispatch*</c> if a dispatch specific error occurred.
        /// </returns>
        public static MLResult OAuthUnRegisterSchema(string schema)
        {
            try
            {
                MLResult.Code resultCode = NativeBindings.MLDispatchOAuthUnregisterSchema(schema);

                if (MLResult.IsOK(resultCode))
                {
                    oAuthCallbacks.Remove(schema.GetHashCode());
                }

                return(MLResult.Create(resultCode));
            }
            catch (System.DllNotFoundException)
            {
                MLPluginLog.Error(DllNotFoundExceptionError);
                return(MLResult.Create(MLResult.Code.UnspecifiedFailure, DllNotFoundExceptionError));
            }
            catch (System.EntryPointNotFoundException)
            {
                MLPluginLog.Error("MLDispatch API symbols not found");
                return(MLResult.Create(MLResult.Code.UnspecifiedFailure, "MLDispatch API symbols not found"));
            }
        }
        /// <summary>
        /// Request real world quad surfaces.
        /// Callback will never be called while request is still pending.
        /// </summary>
        /// <param name="queryParams">All values are required, omitting values may result in unexpected behavior.</param>
        /// <param name="callback">
        /// Callback used to report query results.
        /// Callback MLResult code will never be <c>MLResult.Code.Pending</c>.
        /// </param>
        /// <returns>
        /// MLResult.Result will be <c>MLResult.Code.Ok</c> if successful.
        /// MLResult.Result will be <c>MLResult.Code.InvalidParam</c> if failed due to invalid input parameter.
        /// MLResult.Result will be <c>MLResult.Code.UnspecifiedFailure</c> if failed due to internal error.
        /// </returns>
        public static MLResult GetPlanes(QueryParams queryParams, QueryResultsDelegate callback)
        {
            if (MLPlanes.IsValidInstance())
            {
                _instance.ValidateQueryParams(ref queryParams);

                // Required flag by the CAPI, has to be set or errors will occur.
                queryParams.Flags |= QueryFlags.Polygons;

                // Don't allow null callbacks to be registered.
                if (callback == null)
                {
                    MLPluginLog.Error("MLPlanes.GetPlanes failed. Reason: Passed input callback is null.");
                    return(MLResult.Create(MLResult.Code.InvalidParam));
                }

                return(_instance.BeginPlaneQuery(queryParams, callback));
            }
            else
            {
                MLPluginLog.ErrorFormat("MLPlanes.GetPlanes failed. Reason: No Instance for MLPlanes");
                return(MLResult.Create(MLResult.Code.UnspecifiedFailure, "MLPlanes.GetPlanes failed. Reason: No Instance for MLPlanes"));
            }
        }
        /// <summary>
        /// Starts the screens object requests, Must be called to receive screens data from
        /// the underlying system
        /// </summary>
        protected override MLResult StartAPI()
        {
            MLResult.Code resultCode = MLScreensNativeBindings.MLScreensGetWatchHistoryList(ref _watchHistoryList);
            var           result     = MLResult.Create(resultCode);

            if (!result.IsOk)
            {
                MLPluginLog.ErrorFormat("MLScreens.StartAPI failed to retrieve saved screen information. Reason: {0}", result);
                return(result);
            }

            PopulateWatchHistory();
            resultCode = MLScreensNativeBindings.MLScreensReleaseWatchHistoryList(ref _watchHistoryList);
            result     = MLResult.Create(resultCode);
            if (!result.IsOk)
            {
                MLPluginLog.ErrorFormat("MLScreens.StartAPI failed to clean screens data. Reason: {0}", result);
                return(result);
            }

            _defaultGrayThumbnailImage = CreateGrayThumbnailImage();

            return(result);
        }
 /// <summary>
 /// Requests a connection parameter update.
 /// </summary>
 /// <param name="priority">A specific connection priority</param>
 /// <returns>Returns <c>MLResult.Code.Ok</c> on success or an error on failure.</returns>
 public MLResult RequestConnectionPriority(ConnectionPriority priority)
 {
     return(MLResult.Create(NativeBindings.MLBluetoothGattRequestConnectionPriority(priority)));
 }
 /// <summary>
 /// Enables or disables notifications/indications for a given characteristic
 /// The values for the client characteristic configuration descriptor to start or stop the notification or indication.
 /// Enable notification: { 0x01, 0x00}.
 /// Enable indication: {0x02, 0x0}.
 /// Disable: {0x00, 0x00}.
 /// </summary>
 /// <param name="characteristic">Characteristic to be notified of</param>
 /// <param name="enabled">Enabled state</param>
 /// <returns>Returns <c>MLResult.Code.Ok</c> on success or an error on failure.</returns>
 public static MLResult EnableCharacteristicNotification(Characteristic characteristic, bool enabled)
 {
     return(MLResult.Create(NativeBindings.EnableCharacteristicNotification(characteristic, enabled)));
 }
 /// <summary>
 /// Writes the value of a given descriptor to the connected device
 /// </summary>
 /// <param name="descriptor">The descriptor to write to the remote device</param>
 /// <returns>Returns <c>MLResult.Code.Ok</c> on success or an error on failure.</returns>
 public static MLResult WriteDescriptor(Descriptor descriptor)
 {
     return(MLResult.Create(NativeBindings.WriteDescriptor(descriptor)));
 }
 /// <summary>
 /// Reads the requested descriptor from the connected remote device
 /// </summary>
 /// <param name="descriptor">The descriptor to read from the remote device</param>
 /// <returns>Returns <c>MLResult.Code.Ok</c> on success or an error on failure.</returns>
 public static MLResult ReadDescriptor(ref Descriptor descriptor)
 {
     return(MLResult.Create(NativeBindings.ReadDescriptor(ref descriptor)));
 }
 /// <summary>
 /// Writes a given characteristic and its value to the connected remote device
 /// </summary>
 /// <param name="characteristic">The characteristic to write on the remote device</param>
 /// <returns>Returns <c>MLResult.Code.Ok</c> on success or an error on failure.</returns>
 public static MLResult WriteCharacteristic(Characteristic characteristic)
 {
     return(MLResult.Create(NativeBindings.WriteCharacteristic(characteristic)));
 }
 /// <summary>
 /// Reads the requested characteristic from the connected remote device
 /// </summary>
 /// <param name="characteristic">The characteristic to read from the remote device</param>
 /// <returns>Returns <c>MLResult.Code.Ok</c> on success or an error on failure.</returns>
 public static MLResult ReadCharacteristic(ref Characteristic characteristic)
 {
     return(MLResult.Create(NativeBindings.ReadCharacteristic(ref characteristic)));
 }
 /// <summary>
 /// Reads the RSSI for a connected remote device. The <c>on_gatt_read_remote_rssi</c> callback will
 /// be invoked when the RSSI value has been read.
 /// </summary>
 /// <returns>Returns <c>MLResult.Code.Ok</c> on success or an error on failure.</returns>
 public static MLResult ReadRemoteRssi()
 {
     return(MLResult.Create(NativeBindings.MLBluetoothGattReadRemoteRssi()));
 }
 /// <summary>
 /// Discovers GATT services offered by a remote device.
 /// </summary>
 /// <returns>Returns <c>MLResult.Code.Ok</c> on success or an error on failure.</returns>
 public static MLResult DiscoverServices()
 {
     return(MLResult.Create(NativeBindings.MLBluetoothGattDiscoverServices()));
 }
 /// <summary>
 /// Disconnect the <c>Gatt</c> device.
 /// </summary>
 /// <returns>Returns <c>MLResult.Code.Ok</c> on success or an error on failure.</returns>
 public static MLResult GattDisconnect()
 {
     return(MLResult.Create(NativeBindings.MLBluetoothGattDisconnect()));
 }
 /// <summary>
 /// Stop scanning for Bluetooth LE devices
 /// </summary>
 /// <returns>MLResultCode.Ok on success, or failure</returns>
 public static MLResult StopScan()
 {
     return(MLResult.Create(NativeBindings.MLBluetoothLeStopScan()));
 }
 /// <summary>
 /// Updates connection interval.
 /// </summary>
 /// <param name="priority">A specific connection priority</param>
 /// <returns>Returns <c>MLResult.Code.Ok</c> on success or an error on failure.</returns>
 public static MLResult UpdateConnectionInterval(MLBluetoothLE.ConnectionPriority priority)
 {
     return(MLResult.Create(NativeBindings.MLBluetoothGattRequestConnectionPriority(priority)));
 }