Imported Upstream version 1.0.0
[platform/upstream/iotivity.git] / service / resource-container / android / resource-container / src / main / java / org / iotivity / service / resourcecontainer / RcsResourceContainer.java
1 /******************************************************************
2  *
3  * Copyright 2015 Samsung Electronics All Rights Reserved.
4  *
5  *
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  ******************************************************************/
20
21 /**
22  * @file
23  * This file contains the Resource Container APIs
24  */
25 package org.iotivity.service.resourcecontainer;
26
27 import java.util.List;
28 import java.util.Map;
29
30 // TODO null check for parameters
31 /**
32  * This class provides APIs for managing the container and bundles in the
33  * container.
34  */
35 public class RcsResourceContainer {
36
37     static {
38         System.loadLibrary("gnustl_shared");
39         System.loadLibrary("oc_logger");
40         System.loadLibrary("connectivity_abstraction");
41         System.loadLibrary("ca-interface");
42         System.loadLibrary("octbstack");
43         System.loadLibrary("oc");
44         System.loadLibrary("rcs_client");
45         System.loadLibrary("rcs_server");
46         System.loadLibrary("rcs_common");
47         System.loadLibrary("rcs_container");
48         System.loadLibrary("resource_container_jni");
49     }
50
51     private static RcsResourceContainer sInstance = new RcsResourceContainer();
52
53     private native void nativeStartContainer(String configFile);
54
55     private native void nativeStopContainer();
56
57     private native void nativeAddBundle(String bundleId, String bundleUri,
58             String bundlePath, String activator, Map<String, String> params);
59
60     private native void nativeRemoveBundle(String bundleId);
61
62     private native List<RcsBundleInfo> nativeListBundles();
63
64     private native void nativeStartBundle(String bundleId);
65
66     private native void nativeStopBundle(String bundleId);
67
68     private native void nativeAddResourceConfig(String bundleId,
69             String resourceUri, Map<String, String> params);
70
71     private native void nativeRemoveResourceConfig(String bundleId,
72             String resourceUri);
73
74     private native List<String> nativeListBundleResources(String bundleId);
75
76     /**
77      * API for getting the Instance of ResourceContainer class
78      *
79      */
80     public static RcsResourceContainer getInstance() {
81         return sInstance;
82     }
83
84     /**
85      * API for starting the Container
86      *
87      * <p>
88      * This API start the container with the provided Configuration file.
89      *
90      * @param configFile
91      *            configuration File that contains the Bundle/Bundles
92      *            information.
93      *
94      */
95     public void startContainer(String configFile) {
96         nativeStartContainer(configFile);
97     }
98
99     /**
100      * API for stopping the Container
101      */
102     public void stopContainer() {
103         nativeStopContainer();
104     }
105
106     /**
107      * API for getting the list of all bundles in the container
108      *
109      * @return list<RCSBundleInfo> -List of BundleInfo objects each associated
110      *         with a bundle
111      *
112      *         {@link RcsBundleInfo}
113      */
114     public List<RcsBundleInfo> listBundles() {
115         return nativeListBundles();
116     }
117
118     /**
119      * API for adding the bundle to the Container
120      *
121      * @param bundleId
122      *            Id of the Bundle
123      * @param bundleUri
124      *            Uri of the bundle
125      * @param bundlePath
126      *            Path of the bundle
127      * @param activator
128      *            Activation prefix for .so bundles, or activator class name for
129      *            .jar bundles
130      * @param params
131      *            key-value pairs in string form for other Bundle parameters
132      *
133      *            <p>
134      *            It is dynamic configuration
135      */
136     public void addBundle(String bundleId, String bundleUri, String bundlePath,
137             String activator, Map<String, String> params) {
138         nativeAddBundle(bundleId, bundleUri, bundlePath, activator, params);
139     }
140
141     /**
142      * API for removing the bundle from the container
143      *
144      * @param bundleId
145      *            Id of the Bundle
146      *
147      */
148     public void removeBundle(String bundleId) {
149         nativeRemoveBundle(bundleId);
150     }
151
152     /**
153      * API for starting the bundle.
154      *
155      * @param bundleId
156      *            Id of the Bundle
157      *
158      */
159     public void startBundle(String bundleId) {
160         nativeStartBundle(bundleId);
161     }
162
163     /**
164      * API for Stopping the bundle
165      *
166      * @param bundleId
167      *            Id of the Bundle
168      *
169      */
170     public void stopBundle(String bundleId) {
171         nativeStopBundle(bundleId);
172     }
173
174     /**
175      * API for adding the Resource configuration information to the bundle
176      *
177      * @param bundleId
178      *            Id of the Bundle
179      * @param resourceUri
180      *            URI of the resource
181      * @param params
182      *            key-value pairs in string form for other Bundle parameters
183      *
184      */
185     public void addResourceConfig(String bundleId, String resourceUri,
186             Map<String, String> params) {
187         nativeAddResourceConfig(bundleId, resourceUri, params);
188     }
189
190     /**
191      * API for removing the Resource configuration information from the bundle
192      *
193      * @param bundleId
194      *            Id of the Bundle
195      * @param resourceUri
196      *            URI of the resource
197      *
198      */
199     public void removeResourceConfig(String bundleId, String resourceUri) {
200         nativeRemoveResourceConfig(bundleId, resourceUri);
201     }
202
203     /**
204      * API for getting the list of Bundle Resources
205      *
206      * @param bundleId
207      *            Id of the Bundle
208      *
209      * @return List<String> All the bundle resources
210      */
211     public List<String> listBundleResources(String bundleId) {
212         return nativeListBundleResources(bundleId);
213     }
214 }