protected DeviceConnection DoConnect(RootDescriptor descriptor, string deviceUuid, DataTypeResolverDlgt dataTypeResolver, bool useHttpKeepAlive = true)
 {
     lock (_cpData.SyncObj)
     {
         DeviceConnection connection = new DeviceConnection(this, descriptor, deviceUuid, _cpData, dataTypeResolver, useHttpKeepAlive);
         _connectedDevices.Add(deviceUuid, connection);
         return(connection);
     }
 }
    public ServerSettingsProxy RegisterServerSettingsProxy(DeviceConnection connection)
    {
      CpService serverSettingsStub = connection.Device.FindServiceByServiceId(Consts.SERVERSETTINGS_SERVICE_ID);

      if (serverSettingsStub == null)
        throw new NotSupportedException("ServerSettingsProxy not supported by this UPnP device.");

      ServerSettingsProxy settingsProxy = new ServerSettingsProxy(serverSettingsStub);
      return settingsProxy;
    }
    public static FanArtServiceProxy RegisterFanArtServiceProxy(DeviceConnection connection)
    {
      CpService fanArtStub = connection.Device.FindServiceByServiceId(Consts.FANART_SERVICE_ID);

      if (fanArtStub == null)
        throw new NotSupportedException("FanArtService not supported by this UPnP device.");

      FanArtServiceProxy fanArtProxy = new FanArtServiceProxy(fanArtStub);
      return fanArtProxy;
    }
 protected void DoDisconnect(DeviceConnection connection, bool unsubscribeEvents)
 {
     lock (_cpData.SyncObj)
     {
         string deviceUUID = connection.DeviceUUID;
         if (!_connectedDevices.ContainsKey(deviceUUID))
         {
             throw new ArgumentException(string.Format("This control point instance doesn't manage the given device connection for device '{0}'",
                                                       connection.DeviceUUID));
         }
         DoDisconnect(deviceUUID, unsubscribeEvents);
     }
 }
    private void OnBackendServerConnected(DeviceConnection connection)
    {
      ServerDescriptor serverDescriptor = ServerDescriptor.GetMPBackendServerDescriptor(connection.RootDescriptor);
      if (serverDescriptor == null)
      {
        ServiceRegistration.Get<ILogger>().Warn("ServerConnectionManager: Could not connect to home server - Unable to verify UPnP root descriptor");
        return;
      }
      SystemName preferredLink = serverDescriptor.GetPreferredLink();
      ServiceRegistration.Get<ILogger>().Info("ServerConnectionManager: Connected to home server '{0}' at host '{1}' (IP address: '{2}')", serverDescriptor.MPBackendServerUUID, preferredLink.HostName, preferredLink.Address);
      lock (_syncObj)
      {
        _isHomeServerConnected = true;
        SaveLastHomeServerData(serverDescriptor);
      }

      ServerConnectionMessaging.SendServerConnectionStateChangedMessage(ServerConnectionMessaging.MessageType.HomeServerConnected);
      ServiceRegistration.Get<IThreadPool>().Add(CompleteServerConnection);
    }
 public ClientConnection(UPnPControlPoint controlPoint, DeviceConnection connection, ClientDescriptor clientDescriptor)
 {
   _controlPoint = controlPoint;
   _connection = connection;
   _clientDescriptor = clientDescriptor;
   _connection.DeviceDisconnected += OnUPnPDeviceDisconnected;
   try
   {
     CpService ccsStub = connection.Device.FindServiceByServiceId(UPnPTypesAndIds.CLIENT_CONTROLLER_SERVICE_ID);
     if (ccsStub == null)
       throw new InvalidDataException("ClientController service not found in device '{0}' of type '{1}:{2}'",
           clientDescriptor.MPFrontendServerUUID,
           UPnPTypesAndIds.FRONTEND_SERVER_DEVICE_TYPE, UPnPTypesAndIds.FRONTEND_SERVER_DEVICE_TYPE_VERSION);
     lock (_connection.CPData.SyncObj)
       _clientController = new UPnPClientControllerServiceProxy(ccsStub);
     // TODO: other services
   }
   catch (Exception)
   {
     _connection.DeviceDisconnected -= OnUPnPDeviceDisconnected;
     throw;
   }
 }
 void OnUPnPDeviceDisconnected(DeviceConnection connection)
 {
   _clientController = null;
   InvokeClientDeviceDisconnected(this);
 }
 /// <summary>
 /// Disconnects the connected device specified by the given <paramref name="connection"/> instance.
 /// </summary>
 /// <param name="connection">Connection instance to disconnect. Must be maintained by this instance, i.e. must have been
 /// returned by method <see cref="Connect"/> of this instance.</param>
 public void Disconnect(DeviceConnection connection)
 {
   DoDisconnect(connection, true);
 }
    public NativeTvProxy RegisterNativeTvProxy(DeviceConnection connection)
    {
      CpService tvStub = connection.Device.FindServiceByServiceId(Consts.SLIMTV_SERVICE_ID);

      if (tvStub == null)
        throw new NotSupportedException("NativeTvService not supported by this UPnP device.");

      NativeTvProxy tvProxy = new NativeTvProxy(tvStub);
      return tvProxy;
    }
Beispiel #10
0
    /// <summary>
    /// Build the graph.
    /// </summary>
    public override void BuildGraph()
    {
      try
      {
        if (_graphState != GraphState.Idle)
        {
          Log.Log.Info("DRI CC: device already initialised");
          return;
        }

        bool useKeepAlive = !_isCetonDevice;
        Log.Log.Info("DRI CC: connect to device, keep-alive = {0}", useKeepAlive);
        _deviceConnection = _controlPoint.Connect(_descriptor.RootDescriptor, _descriptor.DeviceUUID, ResolveDataType, useKeepAlive);

        // services
        Log.Log.Debug("DRI CC: setup services");
        _tunerService = new TunerService(_deviceConnection.Device);
        _fdcService = new FdcService(_deviceConnection.Device);
        _auxService = new AuxService(_deviceConnection.Device);
        _encoderService = new EncoderService(_deviceConnection.Device);
        _casService = new CasService(_deviceConnection.Device);
        _muxService = new MuxService(_deviceConnection.Device);
        _securityService = new SecurityService(_deviceConnection.Device);
        _diagService = new DiagService(_deviceConnection.Device);
        _avTransportService = new AvTransportService(_deviceConnection.Device);
        _connectionManagerService = new ConnectionManagerService(_deviceConnection.Device);

        Log.Log.Debug("DRI CC: subscribe services");
        _stateVariableDelegate = new StateVariableChangedDlgt(OnStateVariableChanged);
        _tunerService.SubscribeStateVariables(_stateVariableDelegate);
        _auxService.SubscribeStateVariables(_stateVariableDelegate);
        _encoderService.SubscribeStateVariables(_stateVariableDelegate);
        _casService.SubscribeStateVariables(_stateVariableDelegate);
        _securityService.SubscribeStateVariables(_stateVariableDelegate);
        _avTransportService.SubscribeStateVariables(_stateVariableDelegate);
        _connectionManagerService.SubscribeStateVariables(_stateVariableDelegate);

        // Give time for the device to notify us about initial state variable values.
        // Attempting to continue with other actions now can overload the puny device
        // processors.
        Thread.Sleep(2000);

        int rcsId = -1;
        _connectionManagerService.PrepareForConnection(string.Empty, string.Empty, -1, UpnpConnectionDirection.Output, out _connectionId, out _avTransportId, out rcsId);
        Log.Log.Debug("DRI CC: PrepareForConnection, connection ID = {0}, AV transport ID = {1}", _connectionId, _avTransportId);

        // Check that the device is not already in use.
        if (IsTunerInUse())
        {
          throw new TvExceptionGraphBuildingFailed("DRI CC: tuner appears to be in use");
        }

        ReadDeviceInfo();

        Log.Log.Info("DRI CC: build graph");
        _graphBuilder = (IFilterGraph2)new FilterGraph();
        _capBuilder = (ICaptureGraphBuilder2)new CaptureGraphBuilder2();
        _capBuilder.SetFiltergraph(_graphBuilder);
        _rotEntry = new DsROTEntry(_graphBuilder);
        AddTsWriterFilterToGraph();
        AddStreamSourceFilter();

        // This shouldn't be required, but it enables us to reuse TvCardDvbBase
        // and use CI menus for delivering messages from the CableCARD to the
        // user.
        _conditionalAccess = new ConditionalAccess(null, null, null, this);

        _graphState = GraphState.Created;
      }
      catch (Exception)
      {
        Dispose();
        throw;
      }
    }
 void OnUPnPDeviceDisconnected(DeviceConnection connection)
 {
   IEnumerable<UPnPServiceProxyBase> servicesToDispose;
   lock (_networkTracker.SharedControlPointData.SyncObj)
   {
     _connection = null;
     _contentDirectoryService = null;
     _resourceInformationService = null;
     _serverControllerService = null;
     servicesToDispose = _additionalServices;
     _additionalServices.Clear();
   }
   // Dispose all additional services if possible, to allow proper shutdown and cleanup
   foreach (UPnPServiceProxyBase service in servicesToDispose)
   {
     IDisposable disposable = service as IDisposable;
     if (disposable == null)
       continue;
     try
     {
       disposable.Dispose();
     }
     catch (Exception e)
     {
       ServiceRegistration.Get<ILogger>().Warn("UPnPClientControlPoint: Error disposing additional service '{0}'", service, e);
     }
   }
   InvokeBackendServerDeviceDisconnected(connection);
 }
 protected void InvokeBackendServerDeviceDisconnected(DeviceConnection connection)
 {
   BackendServerDisconnectedDlgt dlgt = BackendServerDisconnected;
   if (dlgt != null)
     dlgt(connection);
 }
 protected void DoDisconnect(DeviceConnection connection, bool unsubscribeEvents)
 {
   lock (_cpData.SyncObj)
   {
     string deviceUUID = connection.DeviceUUID;
     if (!_connectedDevices.ContainsKey(deviceUUID))
       throw new ArgumentException(string.Format("This control point instance doesn't manage the given device connection for device '{0}'",
           connection.DeviceUUID));
     DoDisconnect(deviceUUID, unsubscribeEvents);
   }
 }
    protected void TryConnect(RootDescriptor rootDescriptor)
    {
      DeviceConnection connection;
      string deviceUuid;
      lock (_networkTracker.SharedControlPointData.SyncObj)
      {
        if (_connection != null)
          return;
        DeviceDescriptor rootDeviceDescriptor = DeviceDescriptor.CreateRootDeviceDescriptor(rootDescriptor);
        DeviceDescriptor backendServerDescriptor = rootDeviceDescriptor.FindFirstDevice(
            UPnPTypesAndIds.BACKEND_SERVER_DEVICE_TYPE, UPnPTypesAndIds.BACKEND_SERVER_DEVICE_TYPE_VERSION);
        if (backendServerDescriptor == null)
          return;
        deviceUuid = backendServerDescriptor.DeviceUUID;
        string friendlyName = backendServerDescriptor.FriendlyName;
        SystemName system = new SystemName(new Uri(rootDescriptor.SSDPRootEntry.PreferredLink.DescriptionLocation).Host);
        if (deviceUuid == _homeServerSystemId)
          ServiceRegistration.Get<ILogger>().Debug("UPnPClientControlPoint: Found MP2 home server '{0}' (system ID '{1}') at host '{2}' (IP address: '{3}')",
              friendlyName, deviceUuid, system.HostName, system.Address);
        else
        {
          ServiceRegistration.Get<ILogger>().Debug("UPnPClientControlPoint: Found foreign MP2 server '{0}' (system ID '{1}') at host '{2}' (IP address: '{3}')",
              friendlyName, deviceUuid, system.HostName, system.Address);
          return;
        }
        try
        {
          connection = _connection = _controlPoint.Connect(rootDescriptor, deviceUuid, UPnPExtendedDataTypes.ResolveDataType);
        }
        catch (Exception e)
        {
          ServiceRegistration.Get<ILogger>().Warn("UPnPClientControlPoint: Error connecting to UPnP MP2 backend server '{0}'", e, deviceUuid);
          return;
        }
      }
      connection.DeviceDisconnected += OnUPnPDeviceDisconnected;
      try
      {
        CpService cdsStub = connection.Device.FindServiceByServiceId(UPnPTypesAndIds.CONTENT_DIRECTORY_SERVICE_ID);
        if (cdsStub == null)
          throw new InvalidDataException("ContentDirectory service not found in device '{0}' of type '{1}:{2}'",
              deviceUuid, UPnPTypesAndIds.BACKEND_SERVER_DEVICE_TYPE, UPnPTypesAndIds.BACKEND_SERVER_DEVICE_TYPE_VERSION);
        CpService risStub = connection.Device.FindServiceByServiceId(UPnPTypesAndIds.RESOURCE_INFORMATION_SERVICE_ID);
        if (risStub == null)
          throw new InvalidDataException("ResourceAccess service not found in device '{0}' of type '{1}:{2}'",
              deviceUuid, UPnPTypesAndIds.BACKEND_SERVER_DEVICE_TYPE, UPnPTypesAndIds.BACKEND_SERVER_DEVICE_TYPE_VERSION);
        CpService scsStub = connection.Device.FindServiceByServiceId(UPnPTypesAndIds.SERVER_CONTROLLER_SERVICE_ID);
        if (scsStub == null)
          throw new InvalidDataException("ServerController service not found in device '{0}' of type '{1}:{2}'",
              deviceUuid, UPnPTypesAndIds.BACKEND_SERVER_DEVICE_TYPE, UPnPTypesAndIds.BACKEND_SERVER_DEVICE_TYPE_VERSION);
        CpService updmStub = connection.Device.FindServiceByServiceId(UPnPTypesAndIds.USER_PROFILE_DATA_MANAGEMENT_SERVICE_ID);
        if (updmStub == null)
          throw new InvalidDataException("UserProfileDataManagement service not found in device '{0}' of type '{1}:{2}'",
              deviceUuid, UPnPTypesAndIds.BACKEND_SERVER_DEVICE_TYPE, UPnPTypesAndIds.BACKEND_SERVER_DEVICE_TYPE_VERSION);
        lock (_networkTracker.SharedControlPointData.SyncObj)
        {
          _contentDirectoryService = new UPnPContentDirectoryServiceProxy(cdsStub);
          _resourceInformationService = new UPnPResourceInformationServiceProxy(risStub);
          _serverControllerService = new UPnPServerControllerServiceProxy(scsStub);
          _userProfileDataManagementService = new UPnPUserProfileDataManagementServiceProxy(updmStub);
        }

        ICollection<UPnPServiceProxyBase> additionalServices = new List<UPnPServiceProxyBase>();
        foreach (AdditionalServiceRegisterDlgt additionalServiceRegistration in _additionalServiceRegistrations)
        {
          try
          {
            additionalServices.Add(additionalServiceRegistration(connection));
          }
          catch (Exception e)
          {
            ServiceRegistration.Get<ILogger>().Warn("UPnPClientControlPoint: Error registering user service for UPnP MP2 backend server '{0}'", e, deviceUuid);
          }
        }
        lock (_networkTracker.SharedControlPointData.SyncObj)
          _additionalServices = additionalServices;
      }
      catch (Exception e)
      {
        ServiceRegistration.Get<ILogger>().Warn("UPnPClientControlPoint: Error connecting to services of UPnP MP2 backend server '{0}'", e, deviceUuid);
        connection.DeviceDisconnected -= OnUPnPDeviceDisconnected;
        _controlPoint.Disconnect(deviceUuid);
        return;
      }
      InvokeBackendServerDeviceConnected(connection);
    }
 protected DeviceConnection DoConnect(RootDescriptor descriptor, string deviceUuid, DataTypeResolverDlgt dataTypeResolver, bool useHttpKeepAlive = true)
 {
   lock (_cpData.SyncObj)
   {
     DeviceConnection connection = new DeviceConnection(this, descriptor, deviceUuid, _cpData, dataTypeResolver, useHttpKeepAlive);
     _connectedDevices.Add(deviceUuid, connection);
     return connection;
   }
 }
Beispiel #16
0
    public override void Dispose()
    {
      if (_eventSignalLock != null)
      {
        _eventSignalLock.Close();
        _eventSignalLock = null;
      }

      base.Dispose();

      RemoveStreamSourceFilter();
      if (_mpeg2TransportStream != null)
      {
        DsUtils.FreeAMMediaType(_mpeg2TransportStream);
        _mpeg2TransportStream = null;
      }
      if (_tunerService != null)
      {
        _tunerService.Dispose();
        _tunerService = null;
      }
      if (_fdcService != null)
      {
        _fdcService.Dispose();
        _fdcService = null;
      }
      if (_auxService != null)
      {
        _auxService.Dispose();
        _auxService = null;
      }
      if (_encoderService != null)
      {
        _encoderService.Dispose();
        _encoderService = null;
      }
      if (_casService != null)
      {
        _casService.Dispose();
        _casService = null;
      }
      if (_muxService != null)
      {
        _muxService.Dispose();
        _muxService = null;
      }
      if (_securityService != null)
      {
        _securityService.Dispose();
        _securityService = null;
      }
      if (_diagService != null)
      {
        _diagService.Dispose();
        _diagService = null;
      }
      if (_avTransportService != null)
      {
        if (_gotTunerControl && _transportState != UpnpAvTransportState.STOPPED)
        {
          _avTransportService.Stop((uint)_avTransportId);
          _transportState = UpnpAvTransportState.STOPPED;
        }
        _avTransportService.Dispose();
        _avTransportService = null;
      }
      if (_connectionManagerService != null)
      {
        _connectionManagerService.ConnectionComplete(_connectionId);
        _connectionManagerService.Dispose();
        _connectionManagerService = null;
      }

      if (_deviceConnection != null)
      {
        _deviceConnection.Disconnect();
        _deviceConnection = null;
      }
      _gotTunerControl = false;
    }
 private void OnBackendServerDisconnected(DeviceConnection connection)
 {
   lock (_syncObj)
     _isHomeServerConnected = false;
   ServerConnectionMessaging.SendServerConnectionStateChangedMessage(ServerConnectionMessaging.MessageType.HomeServerDisconnected);
 }
 void OnBackendServerDisconnected(DeviceConnection connection)
 {
   lock (_syncObj)
     _isHomeServerConnected = false;
   IImporterWorker importerWorker = ServiceRegistration.Get<IImporterWorker>();
   importerWorker.Suspend();
   UpdateCurrentlyImportingShares(null); // Mark all shares as not being imported
   ServerConnectionMessaging.SendServerConnectionStateChangedMessage(ServerConnectionMessaging.MessageType.HomeServerDisconnected);
 }
 /// <summary>
 /// Disconnects the connected device specified by the given <paramref name="connection"/> instance.
 /// </summary>
 /// <param name="connection">Connection instance to disconnect. Must be maintained by this instance, i.e. must have been
 /// returned by method <see cref="Connect"/> of this instance.</param>
 public void Disconnect(DeviceConnection connection)
 {
     DoDisconnect(connection, true);
 }