Gaurav Agrawal | a4338f6 | 2017-03-07 17:08:26 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present 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 | */ |
| 16 | |
| 17 | package org.onosproject.yang; |
| 18 | |
| 19 | import com.google.common.annotations.Beta; |
| 20 | import org.apache.felix.scr.annotations.Activate; |
| 21 | import org.apache.felix.scr.annotations.Component; |
| 22 | import org.apache.felix.scr.annotations.Deactivate; |
| 23 | import org.apache.felix.scr.annotations.Reference; |
| 24 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 25 | import org.apache.felix.scr.annotations.Service; |
| 26 | import org.onosproject.core.CoreService; |
Gaurav Agrawal | a4338f6 | 2017-03-07 17:08:26 +0530 | [diff] [blame] | 27 | import org.onosproject.yang.model.YangModel; |
| 28 | import org.onosproject.yang.runtime.CompositeData; |
| 29 | import org.onosproject.yang.runtime.CompositeStream; |
| 30 | import org.onosproject.yang.runtime.ModelRegistrationParam; |
| 31 | import org.onosproject.yang.runtime.RuntimeContext; |
| 32 | import org.onosproject.yang.runtime.YangModelRegistry; |
| 33 | import org.onosproject.yang.runtime.YangRuntimeService; |
| 34 | import org.onosproject.yang.runtime.YangSerializer; |
| 35 | import org.onosproject.yang.runtime.YangSerializerRegistry; |
| 36 | import org.onosproject.yang.runtime.impl.DefaultYangModelRegistry; |
| 37 | import org.onosproject.yang.runtime.impl.DefaultYangRuntimeHandler; |
| 38 | import org.onosproject.yang.runtime.impl.DefaultYangSerializerRegistry; |
| 39 | import org.slf4j.Logger; |
| 40 | import org.slf4j.LoggerFactory; |
| 41 | |
| 42 | import java.util.Set; |
| 43 | |
| 44 | /** |
| 45 | * Represents implementation of YANG runtime manager. |
| 46 | */ |
| 47 | @Beta |
| 48 | @Service |
| 49 | @Component(immediate = true) |
| 50 | public class YangRuntimeManager implements YangModelRegistry, |
| 51 | YangSerializerRegistry, YangRuntimeService { |
| 52 | |
| 53 | private static final String APP_ID = "org.onosproject.yang"; |
| 54 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 55 | |
| 56 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 57 | protected CoreService coreService; |
| 58 | |
Thomas Vachuska | 6803401 | 2017-03-07 14:04:53 -0800 | [diff] [blame^] | 59 | private DefaultYangModelRegistry modelRegistry; |
| 60 | private DefaultYangSerializerRegistry serializerRegistry; |
| 61 | private DefaultYangRuntimeHandler runtimeService; |
Gaurav Agrawal | a4338f6 | 2017-03-07 17:08:26 +0530 | [diff] [blame] | 62 | |
| 63 | @Activate |
| 64 | public void activate() { |
| 65 | coreService.registerApplication(APP_ID); |
| 66 | serializerRegistry = new DefaultYangSerializerRegistry(); |
| 67 | modelRegistry = new DefaultYangModelRegistry(); |
Thomas Vachuska | 6803401 | 2017-03-07 14:04:53 -0800 | [diff] [blame^] | 68 | runtimeService = new DefaultYangRuntimeHandler(serializerRegistry, modelRegistry); |
| 69 | log.info("Started"); |
Gaurav Agrawal | a4338f6 | 2017-03-07 17:08:26 +0530 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | @Deactivate |
| 73 | public void deactivate() { |
Thomas Vachuska | 6803401 | 2017-03-07 14:04:53 -0800 | [diff] [blame^] | 74 | log.info("Stopped"); |
Gaurav Agrawal | a4338f6 | 2017-03-07 17:08:26 +0530 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | |
| 78 | @Override |
| 79 | public void registerModel(ModelRegistrationParam p) { |
| 80 | modelRegistry.registerModel(p); |
| 81 | } |
| 82 | |
| 83 | @Override |
| 84 | public void unregisterModel(ModelRegistrationParam p) { |
| 85 | modelRegistry.unregisterModel(p); |
| 86 | } |
| 87 | |
| 88 | @Override |
| 89 | public Set<YangModel> getModels() { |
| 90 | return modelRegistry.getModels(); |
| 91 | } |
| 92 | |
| 93 | @Override |
| 94 | public void registerSerializer(YangSerializer ys) { |
| 95 | serializerRegistry.registerSerializer(ys); |
| 96 | } |
| 97 | |
| 98 | @Override |
| 99 | public void unregisterSerializer(YangSerializer ys) { |
| 100 | serializerRegistry.unregisterSerializer(ys); |
| 101 | } |
| 102 | |
| 103 | @Override |
| 104 | public Set<YangSerializer> getSerializers() { |
| 105 | return serializerRegistry.getSerializers(); |
| 106 | } |
| 107 | |
| 108 | @Override |
| 109 | public CompositeData decode(CompositeStream cs, RuntimeContext rc) { |
Thomas Vachuska | 6803401 | 2017-03-07 14:04:53 -0800 | [diff] [blame^] | 110 | return runtimeService.decode(cs, rc); |
Gaurav Agrawal | a4338f6 | 2017-03-07 17:08:26 +0530 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | @Override |
| 114 | public CompositeStream encode(CompositeData cd, RuntimeContext rc) { |
Thomas Vachuska | 6803401 | 2017-03-07 14:04:53 -0800 | [diff] [blame^] | 115 | return runtimeService.encode(cd, rc); |
Gaurav Agrawal | a4338f6 | 2017-03-07 17:08:26 +0530 | [diff] [blame] | 116 | } |
| 117 | } |