File

src/port/port.service.ts

Description

The Port Service provides unique interfaces to different types of ports through the 'ref' member. That member is a sub-service which may include REST callbacks for FEI ports vs. websocket controls for BULKIO.

Index

Properties
Methods
Accessors

Constructor

constructor(http: Http, restPython: RestPythonService, _wave: WaveformService, _device: DeviceService, _component: ComponentService)

Constructor NOTE: One of _wave, _device, or _component must be provided!

Parameters :
Name Type Optional Description
http Http

The HTTP service for server callbacks

restPython RestPythonService

The REST Python service for URL serialization

_wave WaveformService

The Waveform service that has this Port in it

_device DeviceService

The Device service that has this Port in it

_component ComponentService

The Component service that has this Port in it

Methods

modelUpdated
modelUpdated(model: Port)

Scans the model to determine the type of 'ref' to create for any subfeatures.

Parameters :
Name Type Optional Description
model Port

The new Port model from the recent refresh

Returns : void
setBaseUrl
setBaseUrl(url: string)

Internal, sets up the base URL

Parameters :
Name Type Optional Description
url string

Sets the base URL for this service

Returns : void
uniqueQuery$
uniqueQuery$()

Internal, initiates the server call that uniquely identifies this entity to retrieve its model.

Returns : Observable<Port>

Properties

Private _forceReconfigRef
_forceReconfigRef: boolean
Type : boolean

Flag for tracking upstream URI changes that impact the port if its unique ID does not appear to change.

Private _previousUniqueId
_previousUniqueId: string
Type : string

Cached previous Unique ID for managing a change in the ref

Private _ref
_ref: PortRef
Type : PortRef
Default value : null

The internal port "reference" controller

Protected parent
parent: WaveformService | DeviceService | ComponentService
Type : WaveformService | DeviceService | ComponentService

Reference to the parent service

Accessors

ref
getref()

The port's sub-reference interfaces. For BulkIO, this will be a BulkioRef giving connectPort and disconnectPort. For FEI, these will be interfaces that look like those defined in the associated IDL.

Use model.hasBulkioWebsocket to determine if this is a BulkioRef. Use model.isFEIControllable to determine if this is one of the FEI Refs.

Then use model.idl.type to determine the sub-type (either the data type of the BulkioRef, or the FeiXXXXRef ref type).

Returns : PortRef
import { Injectable, Optional } from '@angular/core';
import { Http }       from '@angular/http';
import { Observable } from 'rxjs/Observable';

// Model and Enumerations
import { Port, PortFEIIDLType } from '../models/index';

// URL Builder
import { RestPythonService } from '../rest-python/rest-python.module';

// Possible parent services
import { WaveformService } from '../waveform/waveform.module';
import { DeviceService } from '../device/device.module';
import { ComponentService } from '../component/component.module';

// And base service
import { BaseService } from '../base/index';

// Common port "ref" and the specific ones.
import {
    PortRef,
    BulkioRef,
    FeiAnalogTunerRef,
    FeiDigitalTunerRef,
    FeiGPSRef,
    FeiNavDataRef,
    FeiRFInfoRef,
    FeiRFSourceRef
} from './refs/index';

/**
 * The Port Service provides unique interfaces to different types of ports 
 * through the 'ref' member.  That member is a sub-service which may
 * include REST callbacks for FEI ports vs. websocket controls for BULKIO.
 */
@Injectable()
export class PortService extends BaseService<Port> {

    /** Reference to the parent service */
    protected parent: WaveformService | DeviceService | ComponentService;

    /** The internal port "reference" controller */
    private _ref: PortRef = null;
    /** Cached previous Unique ID for managing a change in the ref */
    private _previousUniqueId: string;

    /** 
     * Flag for tracking upstream URI changes that impact the port
     * if its unique ID does not appear to change.
     */
    private _forceReconfigRef: boolean;

    /**
     * Constructor
     * **NOTE:** One of _wave, _device, or _component must be provided!
     * 
     * @param http The HTTP service for server callbacks
     * @param restPython The REST Python service for URL serialization
     * @param [_wave] The Waveform service that has this Port in it
     * @param [_device] The Device service that has this Port in it
     * @param [_component] The Component service that has this Port in it
     */
    constructor(
        protected http: Http,
        protected restPython: RestPythonService,
        @Optional() _wave: WaveformService,
        @Optional() _device: DeviceService,
        @Optional() _component: ComponentService
    ) {
        super(http, restPython);
        this.modelUpdated(new Port());
        if (_wave) {
            if (_component) {
                this.parent = _component;
            } else {
                this.parent = _wave;
            }
        } else if (_device) {
            this.parent = _device;
        } else {
            console.error('Failed to provide a port bearing service');
        }
        // If the parent service changed, reconfigure.
        this.parent.configured$.subscribe(
            (cstat) => {
                if (cstat.uriChanged && cstat.success) {
                    this._forceReconfigRef = true;
                    this.reconfigure(this.uniqueId, cstat.uriChanged);
                }
            });
    }

    /**
     * The port's sub-reference interfaces.  For BulkIO, this will be a
     * BulkioRef giving connectPort and disconnectPort.  For FEI, these will
     * be interfaces that look like those defined in the associated IDL.
     *
     * Use model.hasBulkioWebsocket to determine if this is a BulkioRef.
     * Use model.isFEIControllable to determine if this is one of the FEI Refs.
     *
     * Then use model.idl.type to determine the sub-type (either the data type
     * of the BulkioRef, or the FeiXXXXRef ref type).
     */
    get ref(): PortRef { return this._ref; }

    /**
     * Internal, sets up the base URL
     * @param url Sets the base URL for this service
     */
    setBaseUrl(url: string): void {
        this._baseUrl = this.restPython.portUrl(this.parent.baseUrl, this.uniqueId);
    }

    /**
     * Internal, initiates the server call that uniquely identifies this entity
     * to retrieve its model.
     */
    uniqueQuery$(): Observable<Port> {
        return <Observable<Port>> this.parent.ports$(this.uniqueId);
    }

    /**
     * Scans the model to determine the type of 'ref' to create for any subfeatures.
     * @param model The new Port model from the recent refresh
     */
    modelUpdated(model: Port) {
        if (this._previousUniqueId !== this.uniqueId || this._forceReconfigRef) {
            this._forceReconfigRef = false;

            if (this._ref) {
                this._ref.release();
                this._ref = null;
            }

            if (model.hasBulkioWebsocket) {
                this._ref = new BulkioRef(this.baseUrl, this.restPython);
            } else if (model.isFEIControllable) {
                switch (model.idl.type) {
                    case PortFEIIDLType.AnalogTuner:
                        this._ref = new FeiAnalogTunerRef(this.baseUrl);
                        break;
                    case PortFEIIDLType.DigitalTuner:
                        this._ref = new FeiDigitalTunerRef(this.baseUrl);
                        break;
                    case PortFEIIDLType.GPS:
                        this._ref = new FeiGPSRef(this.baseUrl);
                        break;
                    case PortFEIIDLType.NavData:
                        this._ref = new FeiNavDataRef(this.baseUrl);
                        break;
                    case PortFEIIDLType.RFInfo:
                        this._ref = new FeiRFInfoRef(this.baseUrl);
                        break;
                    case PortFEIIDLType.RFSource:
                        this._ref = new FeiRFSourceRef(this.baseUrl);
                        break;
                    default:
                        console.warn('Provides (controllable) FEI port has unknown Port Type');
                        break;
                }
            }

            // Still not set? Use default.
            if (!this._ref) {
                this._ref = new PortRef(this.baseUrl);
            }

            // Set previousUniqueId to this one.
            this._previousUniqueId = this.uniqueId;
        }
        super.modelUpdated(model);
    }
}

results matching ""

    No results matching ""