ConnectEvent() public method

public ConnectEvent ( PlayerEventHandler handler ) : void
handler PlayerEventHandler
return void
Example #1
0
        void IExtensionService.Initialize ()
        {
            try {
                Log.DebugFormat ("BansheeAwn. Starting {0}", Application.ActiveClient.ClientId);

                awn = DBus.Bus.Session.GetObject<IAvantWindowNavigator> ("com.google.code.Awn",
                        new DBus.ObjectPath ("/com/google/code/Awn"));

                // Dummy call to check that awn is really there
                awn.UnsetTaskIconByName ("banshee-dummy");

                service = ServiceManager.PlayerEngine;
                service.ConnectEvent (new PlayerEventHandler (this.OnEventChanged));

                Log.Debug ("BansheeAwn - Initialized");

            } catch (Exception ex) {
                Log.Exception ("BansheeAwn - Failed loading Awn Extension. ", ex);
                awn = null;
            }
        }
Example #2
0
        private void AssertTransition(System.Func <PlayerState?, PlayerEvent?, bool> ignore, System.Action action, params object [] states)
        {
            Log.DebugFormat("AssertTransition: {0}", String.Join(", ", states.Select(s => s.ToString()).ToArray()));
            int result_count = 0;
            var reset_event  = new ManualResetEvent(false);
            var handler      = new PlayerEventHandler(a => {
                lock (states) {
                    if (result_count < states.Length)
                    {
                        var sca = a as PlayerEventStateChangeArgs;

                        var last_state = sca != null ? sca.Current : service.CurrentState;
                        var last_event = a.Event;

                        if (ignore != null && ignore(last_state, last_event))
                        {
                            Log.DebugFormat("   > ignoring {0}/{1}", last_event, last_state);
                            return;
                        }

                        if (sca == null)
                        {
                            Log.DebugFormat("   > {0}", a.Event);
                        }
                        else
                        {
                            Log.DebugFormat("   > {0}", last_state);
                        }

                        var evnt  = (states[result_count] as PlayerEvent?) ?? PlayerEvent.StateChange;
                        var state = states[result_count] as PlayerState?;

                        result_count++;
                        Assert.AreEqual(evnt, last_event);
                        if (state != null)
                        {
                            Assert.AreEqual(state, last_state);
                        }
                    }
                }
                reset_event.Set();
            });

            service.ConnectEvent(handler);

            if (action != null)
            {
                action();
            }

            while (result_count < states.Length)
            {
                reset_event.Reset();
                if (!reset_event.WaitOne(2000))
                {
                    Assert.Fail(String.Format("Waited 1s for state/event, didnt' happen"));
                    break;
                }
            }

            service.DisconnectEvent(handler);
        }
Example #3
0
        private void AssertTransition(System.Func <PlayerState?, PlayerEvent?, bool> ignore, System.Action action, params object [] states)
        {
            Log.DebugFormat("AssertTransition: {0}", String.Join(", ", states.Select(s => s.ToString()).ToArray()));

            foreach (var state in states)
            {
                if (state == null)
                {
                    throw new ArgumentException("states array cannot contain nulls");
                }
                if (state.GetType() != typeof(PlayerEvent) && state.GetType() != typeof(PlayerState))
                {
                    throw new ArgumentException("states array can only contain states or events, not " + state.GetType().FullName);
                }
            }

            int result_count = 0;
            var reset_event  = new ManualResetEvent(false);
            var handler      = new Action <PlayerEventArgs> (a => {
                lock (states) {
                    if (result_count < states.Length)
                    {
                        var sca = a as PlayerEventStateChangeArgs;

                        var last_state = sca != null ? sca.Current : service.CurrentState;
                        var last_event = a.Event;

                        if (ignore != null && ignore(last_state, last_event))
                        {
                            Log.DebugFormat("   > ignoring {0}/{1}", last_event, last_state);
                            return;
                        }

                        if (sca == null)
                        {
                            Log.DebugFormat("   > {0}", a.Event);
                        }
                        else
                        {
                            Log.DebugFormat("   > {0}", last_state);
                        }

                        var evnt  = (states[result_count] as PlayerEvent?) ?? PlayerEvent.StateChange;
                        var state = states[result_count] as PlayerState?;

                        var evnt_or_state_desc = (evnt == PlayerEvent.StateChange ?
                                                  evnt.ToString() + ">" + states[result_count].ToString() : evnt.ToString());
                        var last_evnt_or_state_desc = (last_event == PlayerEvent.StateChange ?
                                                       last_event.ToString() + ">" + sca.Current.ToString() : last_event.ToString());

                        Assert.That(last_event, Is.EqualTo(evnt),
                                    String.Format("Event[{0}] doesn't match (should be {1}, it was {2})",
                                                  result_count, evnt_or_state_desc, last_evnt_or_state_desc));
                        if (state != null)
                        {
                            Assert.That(last_state, Is.EqualTo(state), String.Format("State[{0}] doesn't match", result_count));
                        }

                        result_count++;
                    }
                }
                reset_event.Set();
            });

            AssertionException exception = null;
            var guarded_handler          = new PlayerEventHandler(args => {
                try {
                    handler(args);
                } catch (AssertionException ae) {
                    exception = ae;
                }
            });

            service.ConnectEvent(guarded_handler);

            if (action != null)
            {
                action();
            }

            const int seconds = 3;

            while (result_count < states.Length)
            {
                reset_event.Reset();
                if (!reset_event.WaitOne(TimeSpan.FromSeconds(seconds)))
                {
                    Assert.Fail(String.Format("Waited {0}s for state/event, didn't happen", seconds));
                    break;
                }
                if (exception != null)
                {
                    throw new AssertionException(exception.Message, exception);
                }
            }

            service.DisconnectEvent(guarded_handler);
        }
        public PlaybackControllerService ()
        {
            InstantiateStacks ();

            player_engine = ServiceManager.PlayerEngine;
            player_engine.PlayWhenIdleRequest += OnPlayerEnginePlayWhenIdleRequest;
            player_engine.ConnectEvent (OnPlayerEvent,
                PlayerEvent.RequestNextTrack |
                PlayerEvent.EndOfStream |
                PlayerEvent.StartOfStream |
                PlayerEvent.StateChange |
                PlayerEvent.Error,
                true);

            ServiceManager.SourceManager.ActiveSourceChanged += delegate {
                ITrackModelSource active_source = ServiceManager.SourceManager.ActiveSource as ITrackModelSource;
                if (active_source != null && source_auto_set_at == source_set_at && !player_engine.IsPlaying ()) {
                    Source = active_source;
                    source_auto_set_at = source_set_at;
                }
            };
        }
        void IExtensionService.Initialize()
        {
            try
            {

                Log.Debug("BansheeAwn. Starting..." + Banshee.ServiceStack.Application.ActiveClient.ClientId);

                awn = NDesk.DBus.Bus.Session.GetObject<IAvantWindowNavigator> ("com.google.code.Awn",
                                                              new NDesk.DBus.ObjectPath ("/com/google/code/Awn"));
                if (awn == null)
                    throw new NullReferenceException();
                service = ServiceManager.PlayerEngine;

                service.ConnectEvent(new PlayerEventHandler(this.OnEventChanged));

                Log.Debug("BansheeAwn - Initialized");

            }
            catch (Exception ex)
            {
                Log.Debug("BansheeAwn - Failed loading Awn Extension. " + ex.Message);
            }
        }