Added copyright headers
[src/xds/xds-agent.git] / webapp / src / app / @core-xds / services / sdk.service.ts
1 /**
2 * @license
3 * Copyright (C) 2017 "IoT.bzh"
4 * Author Sebastien Douheret <sebastien@iot.bzh>
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 *   http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19 import { Injectable, SecurityContext } from '@angular/core';
20 import { Observable } from 'rxjs/Observable';
21 import { BehaviorSubject } from 'rxjs/BehaviorSubject';
22
23 import { XDSAgentService } from '../services/xdsagent.service';
24
25 import 'rxjs/add/observable/throw';
26
27 export interface ISdk {
28     id: string;
29     profile: string;
30     version: string;
31     arch: number;
32     path: string;
33 }
34
35 @Injectable()
36 export class SdkService {
37     public Sdks$: Observable<ISdk[]>;
38
39     private _sdksList = [];
40     private current: ISdk;
41     private sdksSubject = <BehaviorSubject<ISdk[]>>new BehaviorSubject(this._sdksList);
42
43     constructor(private xdsSvr: XDSAgentService) {
44         this.current = null;
45         this.Sdks$ = this.sdksSubject.asObservable();
46
47         this.xdsSvr.XdsConfig$.subscribe(cfg => {
48             if (!cfg || cfg.servers.length < 1) {
49                 return;
50             }
51             // FIXME support multiple server
52             // cfg.servers.forEach(svr => {
53             this.xdsSvr.getSdks(cfg.servers[0].id).subscribe((s) => {
54                 this._sdksList = s;
55                 this.sdksSubject.next(s);
56             });
57         });
58     }
59
60     public setCurrent(s: ISdk) {
61         this.current = s;
62     }
63
64     public getCurrent(): ISdk {
65         return this.current;
66     }
67
68     public getCurrentId(): string {
69         if (this.current && this.current.id) {
70             return this.current.id;
71         }
72         return '';
73     }
74
75     public add(sdk: ISdk): Observable<ISdk> {
76       // TODO SEB
77       return Observable.throw('Not implement yet');
78     }
79
80     public delete(sdk: ISdk): Observable<ISdk> {
81       // TODO SEB
82       return Observable.throw('Not implement yet');
83     }
84 }