src/rest-python/rest-python.service.ts
The REST Python (URL) Service provides generation of the URL end points of the REST Python server. Aided by dependency injection between services, this service builds URL structures so that a Device Manager can infer its Domain's end point, a Device can infer the Device Manager's end point, and so on.
Properties |
Methods |
Accessors |
constructor(config: IRestPythonConfig)
|
||||||||
Defined in src/rest-python/rest-python.service.ts:49
|
||||||||
Constructor
Parameters :
|
Private baseRestUrl | ||||||||||||||||
baseRestUrl(parentUrl: string, subPath?: string, target?: string)
|
||||||||||||||||
Defined in src/rest-python/rest-python.service.ts:191
|
||||||||||||||||
Creates a URL from the parent's and some new end point details.
Parameters :
Returns :
string
|
Private baseWebsocketUrl | ||||||||||||
baseWebsocketUrl(parentUrl: string, subPath?: string)
|
||||||||||||
Defined in src/rest-python/rest-python.service.ts:176
|
||||||||||||
Returns a websocket URL from the provided URL and path
Parameters :
Returns :
string
|
bulkioSocketUrl | ||||||||
bulkioSocketUrl(portUrl: string)
|
||||||||
Defined in src/rest-python/rest-python.service.ts:151
|
||||||||
URL for a port's BULKIO WebSocket interface (if applicable)
Parameters :
Returns :
string
|
componentUrl |
componentUrl(parentUrl: string, componentId?: string)
|
Defined in src/rest-python/rest-python.service.ts:136
|
URL for a Component listing or a specific instance
Returns :
string
|
deviceManagerUrl |
deviceManagerUrl(parentUrl: string, deviceManagerId?: string)
|
Defined in src/rest-python/rest-python.service.ts:116
|
URL for a Device Manager listing or a specific instance
Returns :
string
|
deviceUrl |
deviceUrl(parentUrl: string, deviceId?: string)
|
Defined in src/rest-python/rest-python.service.ts:121
|
URL for a Device listing or a specific instance
Returns :
string
|
domainUrl |
domainUrl(parentUrl: string, domainId?: string)
|
Defined in src/rest-python/rest-python.service.ts:106
|
URL for the/a Domain's interface
Returns :
string
|
eventChannelsUrl |
eventChannelsUrl()
|
Defined in src/rest-python/rest-python.service.ts:101
|
URL for the Event Channels listing
Returns :
string
|
eventSocketUrl |
eventSocketUrl()
|
Defined in src/rest-python/rest-python.service.ts:167
|
URL for subscribing to Event Channels (WebSocket)
Returns :
string
|
fileSystemUrl |
fileSystemUrl(parentUrl: string, path?: string)
|
Defined in src/rest-python/rest-python.service.ts:111
|
URL for a FIle System interface
Returns :
string
|
portUrl |
portUrl(parentUrl: string, portId?: string)
|
Defined in src/rest-python/rest-python.service.ts:146
|
URL for a Port listing or a specific instance
Returns :
string
|
propertyUrl | ||||||||
propertyUrl(parentUrl: string)
|
||||||||
Defined in src/rest-python/rest-python.service.ts:141
|
||||||||
URL for the properties listing on an interface
Parameters :
Returns :
string
|
redhawkSocketUrl |
redhawkSocketUrl()
|
Defined in src/rest-python/rest-python.service.ts:162
|
URL of the REDHAWK (Domain) Listener WebSocket (i.e., Domains coming and going)
Returns :
string
|
redhawkUrl |
redhawkUrl()
|
Defined in src/rest-python/rest-python.service.ts:96
|
URL for the REDHAWK interface
Returns :
string
|
serviceUrl |
serviceUrl(parentUrl: string, serviceId?: string)
|
Defined in src/rest-python/rest-python.service.ts:126
|
URL for a Service listing or a specific instance
Returns :
string
|
setConfiguration | ||||||||
setConfiguration(config: IRestPythonConfig)
|
||||||||
Defined in src/rest-python/rest-python.service.ts:62
|
||||||||
Reconfigure the REST-Python Service to a new service address
Parameters :
Returns :
void
|
waveformUrl |
waveformUrl(parentUrl: string, waveformId?: string)
|
Defined in src/rest-python/rest-python.service.ts:131
|
URL for a Waveform listing or a specific instance
Returns :
string
|
Private _apiUrl |
_apiUrl:
|
Type : string
|
Defined in src/rest-python/rest-python.service.ts:27
|
REST Python API URL (top-level endpoint) |
Private _changed |
_changed:
|
Default value : new Subject<void>()
|
Defined in src/rest-python/rest-python.service.ts:30
|
Subject for indicating if the REST configuration changed at runtime |
Private _host |
_host:
|
Type : string
|
Defined in src/rest-python/rest-python.service.ts:23
|
REST Python host address |
Private _port |
_port:
|
Type : number
|
Defined in src/rest-python/rest-python.service.ts:25
|
REST Python host port |
baseUrl |
getbaseUrl()
|
Defined in src/rest-python/rest-python.service.ts:33
|
Base URL of the REST Python Service
Returns :
string
|
changed$ |
getchanged$()
|
Defined in src/rest-python/rest-python.service.ts:40
|
Be notified when the REST Python Service's URL changes in any way.
Returns :
Observable<void>
|
host |
gethost()
|
Defined in src/rest-python/rest-python.service.ts:43
|
The configured host address for the REST-Python server
Returns :
string
|
port |
getport()
|
Defined in src/rest-python/rest-python.service.ts:46
|
The configured port for the REST-Python server
Returns :
number
|
apiUrl |
getapiUrl()
|
Defined in src/rest-python/rest-python.service.ts:49
|
The configured API URL for the REST-Python server
Returns :
string
|
import {
Optional,
Inject,
Injectable
} from '@angular/core';
import { Subject } from 'rxjs/Subject';
import { Observable } from 'rxjs/Observable';
import {
IRestPythonConfig,
REST_PYTHON_CONFIG
} from './rest-python-config';
/**
* The REST Python (URL) Service provides generation of the URL end points of the
* REST Python server. Aided by dependency injection between services, this service
* builds URL structures so that a Device Manager can infer its Domain's end point,
* a Device can infer the Device Manager's end point, and so on.
*/
@Injectable()
export class RestPythonService {
/** REST Python host address */
private _host: string;
/** REST Python host port */
private _port: number;
/** REST Python API URL (top-level endpoint) */
private _apiUrl: string;
/** Subject for indicating if the REST configuration changed at runtime */
private _changed = new Subject<void>();
/** Base URL of the REST Python Service */
private get baseUrl(): string {
return this.host + ':' + this.port + this.apiUrl;
}
/**
* Be notified when the REST Python Service's URL changes in any way.
*/
get changed$(): Observable<void> { return this._changed.asObservable(); }
/** The configured host address for the REST-Python server */
get host(): string { return this._host; }
/** The configured port for the REST-Python server */
get port(): number { return this._port; }
/** The configured API URL for the REST-Python server */
get apiUrl(): string { return this._apiUrl; }
/**
* Constructor
* @param config The REST Python Configuration
*/
constructor(@Optional() @Inject(REST_PYTHON_CONFIG) config: IRestPythonConfig) {
this.setConfiguration(config);
}
/**
* Reconfigure the REST-Python Service to a new service address
*/
setConfiguration(config: IRestPythonConfig) {
let changed = false;
config = config || {};
if (config.host !== undefined && config.host !== this.host) {
changed = true;
this._host = config.host;
} else if (this.host === undefined) {
changed = true;
this._host = window.location.hostname;
}
if (config.port !== undefined && config.port !== this.port) {
changed = true;
this._port = config.port;
} else if (this.port === undefined) {
changed = true;
this._port = 8080;
}
if (config.apiUrl !== undefined && config.apiUrl !== this.apiUrl) {
changed = true;
this._apiUrl = config.apiUrl;
} else if (this.apiUrl === undefined) {
changed = true;
this._apiUrl = '/redhawk/rest';
}
if (changed === true) {
this._changed.next();
}
}
/** URL for the REDHAWK interface */
redhawkUrl(): string {
return this.baseRestUrl('');
}
/** URL for the Event Channels listing */
eventChannelsUrl(): string {
return this.baseRestUrl('/events/');
}
/** URL for the/a Domain's interface */
domainUrl(parentUrl: string, domainId?: string): string {
return this.baseRestUrl(parentUrl, '/domains', domainId);
}
/** URL for a FIle System interface */
fileSystemUrl(parentUrl: string, path?: string): string {
return this.baseRestUrl(parentUrl, '/fs', path);
}
/** URL for a Device Manager listing or a specific instance */
deviceManagerUrl(parentUrl: string, deviceManagerId?: string): string {
return this.baseRestUrl(parentUrl, '/deviceManagers', deviceManagerId);
}
/** URL for a Device listing or a specific instance */
deviceUrl(parentUrl: string, deviceId?: string): string {
return this.baseRestUrl(parentUrl, '/devices', deviceId);
}
/** URL for a Service listing or a specific instance */
serviceUrl(parentUrl: string, serviceId?: string): string {
return this.baseRestUrl(parentUrl, '/services', serviceId);
}
/** URL for a Waveform listing or a specific instance */
waveformUrl(parentUrl: string, waveformId?: string): string {
return this.baseRestUrl(parentUrl, '/applications', waveformId);
}
/** URL for a Component listing or a specific instance */
componentUrl(parentUrl: string, componentId?: string): string {
return this.baseRestUrl(parentUrl, '/components', componentId);
}
/** URL for the properties listing on an interface */
propertyUrl(parentUrl: string): string {
return this.baseRestUrl(parentUrl, '/properties');
}
/** URL for a Port listing or a specific instance */
portUrl(parentUrl: string, portId?: string): string {
return this.baseRestUrl(parentUrl, '/ports', portId);
}
/** URL for a port's BULKIO WebSocket interface (if applicable) */
bulkioSocketUrl(portUrl: string): string {
// Pop service off the front, if present.
let baseUrlRE = new RegExp(this.baseUrl.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&'));
let svcRE = /^https?\:\/{1,2}/i;
portUrl = portUrl.replace(baseUrlRE, '');
portUrl = portUrl.replace(svcRE, '');
return this.baseWebsocketUrl(portUrl, '/bulkio');
}
/** URL of the REDHAWK (Domain) Listener WebSocket (i.e., Domains coming and going) */
redhawkSocketUrl(): string {
return this.baseWebsocketUrl('/redhawk');
}
/** URL for subscribing to Event Channels (WebSocket) */
eventSocketUrl(): string {
return this.baseWebsocketUrl('/events');
}
/**
* Returns a websocket URL from the provided URL and path
* @param parentUrl The parent (service) URL
* @param [subPath] A sub-path to extend on the URL
*/
private baseWebsocketUrl(parentUrl: string, subPath?: string): string {
let path = ((window.location.protocol === 'https:') ? 'wss:' : 'ws:') + '//';
path += this.baseUrl + parentUrl;
if (subPath) {
path += subPath;
}
return path;
}
/**
* Creates a URL from the parent's and some new end point details.
* @param parentUrl The parent (service's) URL
* @param [subPath] A sub-path extending off the parent's URL
* @param [target] A REST end point combining the above URL elements.
*/
private baseRestUrl(parentUrl: string, subPath?: string, target?: string): string {
let server = window.location.protocol + '//' + this.baseUrl;
if (parentUrl.lastIndexOf(server) >= 0) {
server = ''; // Already added.
}
if (subPath) {
if (target) {
return server + parentUrl + subPath + '/' + target;
}
return server + parentUrl + subPath;
}
return server + parentUrl;
}
}