示例#1
0
        public void TestChangingCallbackAddLocks()
        {
            var obj  = new DummyLockable(1);
            var obj2 = new DummyLockable(2);
            var obj3 = new DummyLockable(3);

            int callCount = 0;

            CallbackLock.CallbackLockHandler lockFunc = delegate
            {
                if (callCount == 0)
                {
                    callCount++;
                    return(new ILockable[] { obj2 });
                }

                callCount++;
                return(new ILockable[] { obj3, obj2 });
            };
            var lck = new CallbackLock(multiObjectLockFactory).Lock(lockFunc, null, obj);

            DefaultMultiObjectLock.IsLocked(obj).Should().BeTrue();
            DefaultMultiObjectLock.IsLocked(obj2).Should().BeTrue();
            DefaultMultiObjectLock.IsLocked(obj3).Should().BeTrue();

            lck.UnlockAll();

            DefaultMultiObjectLock.IsLocked(obj).Should().BeFalse();
            DefaultMultiObjectLock.IsLocked(obj2).Should().BeFalse();
            DefaultMultiObjectLock.IsLocked(obj3).Should().BeFalse();
        }
示例#2
0
        /// <summary>
        /// Update user states exposed to clients, if necessary.
        /// </summary>
        /// <param name="callbackLock">
        /// Lock used to delay all events until after we exit lock section.
        /// </param>
        private void UpdateUserStates(CallbackLock callbackLock)
        {
            this.userStatesAccumulator.Clear();

            // Add states for tracked users
            foreach (var trackingId in this.TrackedUserTrackingIds)
            {
                this.userStatesAccumulator.Add(trackingId, TrackedStateName);
            }

            if (this.EngagedUserTrackingId != SharedConstants.InvalidUserTrackingId)
            {
                // Engaged state supersedes all other states
                this.userStatesAccumulator[this.EngagedUserTrackingId] = EngagedStateName;
            }

            if (this.HaveUserStatesChanged())
            {
                var temporaryMap = this.publicUserStates;
                this.publicUserStates      = this.userStatesAccumulator;
                this.userStatesAccumulator = temporaryMap;

                var userStatesToSend = GetStateMappingEntryArray(this.publicUserStates);

                callbackLock.LockExit +=
                    () =>
                    this.SendUserStateChanged(
                        new UserStatesChangedEventMessage
                {
                    category   = EventCategory,
                    eventType  = UserStatesChangedEventType,
                    userStates = userStatesToSend
                });
            }
        }
示例#3
0
 /// <summary>
 /// Resets all state to the initial state, with no users remembered as engaged or tracked.
 /// </summary>
 public void Reset()
 {
     using (var callbackLock = new CallbackLock(this.lockObject))
     {
         this.activityMeter.Clear();
         this.TrackedUserTrackingIds.Clear();
         this.EngagedUserTrackingId = SharedConstants.InvalidUserTrackingId;
         this.SetPrimaryUserTrackingId(SharedConstants.InvalidUserTrackingId, callbackLock);
         this.UpdateUserStates(callbackLock);
     }
 }
示例#4
0
        public void TestEmptyListFromCallback()
        {
            var obj = new DummyLockable(1);

            CallbackLock.CallbackLockHandler lockFunc = custom => new ILockable[] {};
            var lck = new CallbackLock(multiObjectLockFactory).Lock(lockFunc, null, obj);

            DefaultMultiObjectLock.IsLocked(obj).Should().BeTrue();
            lck.UnlockAll();
            DefaultMultiObjectLock.IsLocked(obj).Should().BeFalse();
        }
        public IEnumerator  Connect()
        {
            var @lock = new CallbackLock();

            UM_InAppService.Client.Connect((connectionResult) => {
                @lock.Unlock();
                Assert.IsTrue(connectionResult.IsSucceeded);
            });

            yield return(@lock.WaitToUnlock());
        }
示例#6
0
        /// <summary>
        /// Update the primary user being tracked.
        /// </summary>
        /// <param name="candidateUserInfo">
        /// User information collection from which we will choose a primary user.
        /// </param>
        /// <param name="callbackLock">
        /// Lock used to delay all events until after we exit lock section.
        /// </param>
        private void UpdatePrimaryUser(IEnumerable <UserInfo> candidateUserInfo, CallbackLock callbackLock)
        {
            int  firstPrimaryUserCandidate      = SharedConstants.InvalidUserTrackingId;
            bool currentPrimaryUserStillPrimary = false;
            bool engagedUserIsPrimary           = false;

            var trackingIdsAvailable = new HashSet <int>();

            foreach (var userInfo in candidateUserInfo)
            {
                if (userInfo.SkeletonTrackingId == SharedConstants.InvalidUserTrackingId)
                {
                    continue;
                }

                trackingIdsAvailable.Add(userInfo.SkeletonTrackingId);

                foreach (var handPointer in userInfo.HandPointers)
                {
                    if (handPointer.IsPrimaryForUser)
                    {
                        if (this.PrimaryUserTrackingId == userInfo.SkeletonTrackingId)
                        {
                            // If the current primary user still has an active hand, we should continue to consider them the primary user.
                            currentPrimaryUserStillPrimary = true;
                        }
                        else if (SharedConstants.InvalidUserTrackingId == firstPrimaryUserCandidate)
                        {
                            // Else if this is the first user with an active hand, they are the alternative candidate for primary user.
                            firstPrimaryUserCandidate = userInfo.SkeletonTrackingId;
                        }

                        if (this.EngagedUserTrackingId == userInfo.SkeletonTrackingId)
                        {
                            engagedUserIsPrimary = true;
                        }
                    }
                }
            }

            // If engaged user has a primary hand, always pick that user as primary user.
            // If current primary user still has a primary hand, let them remain primary.
            // Otherwise default to first primary user candidate seen.
            int primaryUserTrackingId = engagedUserIsPrimary
                                            ? this.EngagedUserTrackingId
                                            : (currentPrimaryUserStillPrimary ? this.PrimaryUserTrackingId : firstPrimaryUserCandidate);

            this.SetPrimaryUserTrackingId(primaryUserTrackingId, callbackLock);
        }
        public IEnumerator SuccessfulPurchase()
        {
            if (Application.isEditor)
            {
                m_transactionLock         = new CallbackLock();
                m_Observer.OnTransaction += OnSuccessfuTransaction;

                UM_InAppService.Client.AddPayment(UM_InAppService.TEST_ITEM_PURCHASED);
                yield return(m_transactionLock.WaitToUnlock());

                m_Observer.OnTransaction -= OnSuccessfuTransaction;
            }

            yield return(null);
        }
示例#8
0
        public IEnumerator SaveScreenshot()
        {
            yield return(null);

            if (Application.isEditor)
            {
                var @lock   = new CallbackLock();
                var gallery = UM_Application.GalleryService;
                gallery.SaveScreenshot("example_scene.png", (result) => {
                    Assert.IsTrue(result.IsSucceeded);
                    @lock.Unlock();
                });

                yield return(@lock.WaitToUnlock());
            }
        }
示例#9
0
        /// <summary>
        /// Promote candidate user to be the engaged user.
        /// </summary>
        /// <param name="candidateTrackingId">
        /// Tracking Id of user to be promoted to engaged user.
        /// If tracking Id does not match the Id of one of the currently tracked users,
        /// no action is taken.
        /// </param>
        /// <returns>
        /// True if specified candidate could be confirmed as the new engaged user,
        /// false otherwise.
        /// </returns>
        public bool PromoteCandidateToEngaged(int candidateTrackingId)
        {
            bool isConfirmed = false;

            if ((candidateTrackingId != SharedConstants.InvalidUserTrackingId) && this.TrackedUserTrackingIds.Contains(candidateTrackingId))
            {
                using (var callbackLock = new CallbackLock(this.lockObject))
                {
                    this.EngagedUserTrackingId = candidateTrackingId;
                    this.UpdateUserStates(callbackLock);
                }

                isConfirmed = true;
            }

            return(isConfirmed);
        }
示例#10
0
        public IEnumerator PickImage()
        {
            yield return(null);

            var @lock = new CallbackLock();

            if (Application.isEditor)
            {
                var gallery = UM_Application.GalleryService;
                gallery.PickImage(1024, (result) => {
                    @lock.Unlock();
                    ValidateResult(result, UM_MediaType.Image);
                });
            }

            yield return(@lock.WaitToUnlock());
        }
示例#11
0
        public IEnumerator CamptureImage()
        {
            yield return(null);

            var @lock = new CallbackLock();

            if (Application.isEditor)
            {
                var cameraService = UM_Application.CameraService;
                cameraService.TakePicture(1024, (result) => {
                    @lock.Unlock();
                    ValidateResult(result, UM_MediaType.Image);
                });
            }

            yield return(@lock.WaitToUnlock());
        }
        public IEnumerator FailedPurchase()
        {
            //  if (Application.isEditor)
            //  {

            m_transactionLock         = new CallbackLock();
            m_Observer.OnTransaction += OnFailedTransaction;

            UM_InAppService.Client.AddPayment(UM_InAppService.TEST_ITEM_UNAVAILABLE);
            yield return(m_transactionLock.WaitToUnlock());

            m_Observer.OnTransaction -= OnFailedTransaction;

            // }

            yield return(null);
        }
示例#13
0
        public IEnumerator SaveImage()
        {
            yield return(null);

            if (Application.isEditor)
            {
                var @lock              = new CallbackLock();
                var gallery            = UM_Application.GalleryService;
                var sampleBlackTexture = SA_IconManager.GetIcon(Color.black, 32, 32);
                gallery.SaveImage(sampleBlackTexture, "sample_black_image.png", (result) => {
                    Assert.IsTrue(result.IsSucceeded);
                    @lock.Unlock();
                });

                yield return(@lock.WaitToUnlock());
            }
        }
示例#14
0
        public IEnumerator ShareToWhatsapp()
        {
            var @lock   = new CallbackLock();
            var client  = UM_SocialService.SharingClient;
            var builder = new UM_ShareDialogBuilder();

            //Juts generating smaple red tuxture with 32x32 resolution
            Texture2D sampleRedTexture = SA_IconManager.GetIcon(Color.red, 32, 32);

            builder.AddImage(sampleRedTexture);

            client.ShareToWhatsapp(builder, (result) => {
                @lock.Unlock();
                Assert.IsTrue(result.IsSucceeded);
            });

            yield return(@lock.WaitToUnlock());
        }
示例#15
0
        public IEnumerator RetrieveContacts()
        {
            var @lock  = new CallbackLock();
            var client = UM_Application.ContactsService;

            client.Retrieve((result) => {
                @lock.Unlock();
                Assert.IsTrue(result.IsSucceeded);
                Assert.IsTrue(result.Contacts.Count > 0);

                var contact = result.Contacts[0];
                Assert.NotNull(contact.Name);
                Assert.NotNull(contact.Phone);
                Assert.NotNull(contact.Email);
            });

            yield return(@lock.WaitToUnlock());
        }
示例#16
0
        internal void SetPrimaryUserTrackingId(int newId, CallbackLock callbackLock)
        {
            int oldId = this.PrimaryUserTrackingId;

            this.PrimaryUserTrackingId = newId;

            if (oldId != newId)
            {
                callbackLock.LockExit +=
                    () =>
                    this.SendUserStateChanged(
                        new UserTrackingIdChangedEventMessage
                {
                    category  = EventCategory,
                    eventType = PrimaryUserChangedEventType,
                    oldValue  = oldId,
                    newValue  = newId
                });
            }
        }
        public IEnumerator SystemShareDialog()
        {
            var @lock   = new CallbackLock();
            var client  = UM_SocialService.SharingClient;
            var builder = new UM_ShareDialogBuilder();

            builder.SetText("Hello world!");
            builder.SetUrl("https://stansassets.com/");

            //Juts generating smaple red tuxture with 32x32 resolution
            Texture2D sampleRedTexture = SA_IconManager.GetIcon(Color.red, 32, 32);

            builder.AddImage(sampleRedTexture);

            client.SystemSharingDialog(builder, (result) => {
                @lock.Unlock();
                Assert.IsTrue(result.IsSucceeded);
            });

            yield return(@lock.WaitToUnlock());
        }
        public IEnumerator MailDialog()
        {
            var @lock  = new CallbackLock();
            var client = UM_SocialService.SharingClient;
            var dialog = new UM_EmailDialogBuilder();

            dialog.SetSubject("Subject");
            dialog.SetText("Hello World!");
            dialog.SetUrl("https://stansassets.com/");

            //Juts generating smaple red tuxture with 32x32 resolution
            Texture2D sampleRedTexture = SA_IconManager.GetIcon(Color.red, 32, 32);

            dialog.AddImage(sampleRedTexture);
            dialog.AddRecipient("*****@*****.**");

            client.ShowSendMailDialog(dialog, (result) => {
                @lock.Unlock();
                Assert.IsTrue(result.IsSucceeded);
            });

            yield return(@lock.WaitToUnlock());
        }
示例#19
0
        /// <summary>
        /// Called whenever the set of tracked users has changed.
        /// </summary>
        /// <param name="trackedUserInfo">
        /// User information from which we'll update the set of tracked users and the primary user.
        /// </param>
        /// <param name="timestamp">
        /// Interaction frame timestamp corresponding to given user information.
        /// </param>
        public void UpdateUserInformation(IEnumerable <UserInfo> trackedUserInfo, long timestamp)
        {
            bool foundEngagedUser = false;
            int  firstTrackedUser = SharedConstants.InvalidUserTrackingId;

            using (var callbackLock = new CallbackLock(this.lockObject))
            {
                this.previousTrackedUserTrackingIds.Clear();
                var nextTrackedIds = this.previousTrackedUserTrackingIds;
                this.previousTrackedUserTrackingIds = this.TrackedUserTrackingIds;
                this.TrackedUserTrackingIds         = nextTrackedIds;

                var trackedUserInfoArray = trackedUserInfo as UserInfo[] ?? trackedUserInfo.ToArray();

                foreach (var userInfo in trackedUserInfoArray)
                {
                    if (userInfo.SkeletonTrackingId == SharedConstants.InvalidUserTrackingId)
                    {
                        continue;
                    }

                    if (this.EngagedUserTrackingId == userInfo.SkeletonTrackingId)
                    {
                        this.TrackedUserTrackingIds.Add(userInfo.SkeletonTrackingId);

                        foundEngagedUser = true;
                    }
                    else if (HasTrackedHands(userInfo) &&
                             (this.previousTrackedUserTrackingIds.Contains(userInfo.SkeletonTrackingId) ||
                              this.IsInactive(userInfo, timestamp)))
                    {
                        // Keep track of the non-engaged users we find that have at least one
                        // tracked hand pointer and also either (1) were previously tracked or
                        // (2) are not moving too much
                        this.TrackedUserTrackingIds.Add(userInfo.SkeletonTrackingId);

                        if (firstTrackedUser == SharedConstants.InvalidUserTrackingId)
                        {
                            // Consider the first non-engaged, stationary user as a candidate for engagement
                            firstTrackedUser = userInfo.SkeletonTrackingId;
                        }
                    }
                }

                // If engaged user was not found in list of candidate users, engaged user has become invalid.
                if (!foundEngagedUser)
                {
                    this.EngagedUserTrackingId = SharedConstants.InvalidUserTrackingId;
                }

                // Decide who should be the primary user, if anyone
                this.UpdatePrimaryUser(trackedUserInfoArray, callbackLock);

                // If there's a primary user, it is the preferred candidate for engagement.
                // Otherwise, the first tracked user seen is the preferred candidate.
                int candidateUserTrackingId = (this.PrimaryUserTrackingId != SharedConstants.InvalidUserTrackingId)
                                                  ? this.PrimaryUserTrackingId
                                                  : firstTrackedUser;

                // If there is a valid candidate user that is not already the engaged user
                if ((candidateUserTrackingId != SharedConstants.InvalidUserTrackingId) &&
                    (candidateUserTrackingId != this.EngagedUserTrackingId))
                {
                    // If there is currently no engaged user, or if candidate user is the
                    // primary user controlling interactions while the currently engaged user
                    // is not interacting
                    if ((this.EngagedUserTrackingId == SharedConstants.InvalidUserTrackingId) ||
                        (candidateUserTrackingId == this.PrimaryUserTrackingId))
                    {
                        this.PromoteCandidateToEngaged(candidateUserTrackingId);
                    }
                }

                // Update user states as the very last action, to include results from updates
                // performed so far
                this.UpdateUserStates(callbackLock);
            }
        }