blob: ebc4ed6755819207c76a774392da13cede24e3fd [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
2 * Copyright 2014 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070016package org.onlab.onos.core.impl;
17
18import org.apache.felix.scr.annotations.Activate;
19import org.apache.felix.scr.annotations.Component;
20import org.apache.felix.scr.annotations.Reference;
21import org.apache.felix.scr.annotations.ReferenceCardinality;
22import org.apache.felix.scr.annotations.Service;
23import org.onlab.onos.core.ApplicationId;
24import org.onlab.onos.core.ApplicationIdStore;
25import org.onlab.onos.core.CoreService;
26import org.onlab.onos.core.Version;
27import org.onlab.util.Tools;
28
29import java.io.File;
30import java.util.List;
31import java.util.Set;
32
33import static com.google.common.base.Preconditions.checkNotNull;
34
35/**
36 * Core service implementation.
37 */
38@Component
39@Service
40public class CoreManager implements CoreService {
41
42 private static final File VERSION_FILE = new File("../VERSION");
43 private static Version version = Version.version("1.0.0-SNAPSHOT");
44
45 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
46 protected ApplicationIdStore applicationIdStore;
47
48 @Activate
49 public void activate() {
50 List<String> versionLines = Tools.slurp(VERSION_FILE);
51 if (versionLines != null && !versionLines.isEmpty()) {
52 version = Version.version(versionLines.get(0));
53 }
54 }
55
56 @Override
57 public Version version() {
58 return version;
59 }
60
61 @Override
62 public Set<ApplicationId> getAppIds() {
63 return applicationIdStore.getAppIds();
64 }
65
66 @Override
67 public ApplicationId getAppId(Short id) {
68 return applicationIdStore.getAppId(id);
69 }
70
71 @Override
72 public ApplicationId registerApplication(String name) {
73 checkNotNull(name, "Application ID cannot be null");
74 return applicationIdStore.registerApplication(name);
75 }
76
77}