Java SDK and Eclipse plugin for simulator.
[platform/upstream/iotivity.git] / service / simulator / java / sdk / src / org / oic / simulator / SimulatorManager.java
1 /*
2  * Copyright 2015 Samsung Electronics All Rights Reserved.
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.oic.simulator;
18
19 import org.oic.simulator.clientcontroller.IFindResourceListener;
20 import org.oic.simulator.serviceprovider.IResourceModelChangedListener;
21 import org.oic.simulator.serviceprovider.SimulatorResourceServer;
22
23 /**
24  * This class provides a set of methods for creation, discovery and deletion of
25  * resources.
26  */
27 public class SimulatorManager {
28
29     /**
30      * API for creating a resource from a RAML configuration file whose path is
31      * given as a parameter.
32      *
33      * @param configPath
34      *            Path to RAML configuration file.
35      * @param listener
36      *            Listener for receiving notifications whenever there is a
37      *            change in the resource model.
38      * 
39      * @return {@link SimulatorResourceServer} - Created resource on success,
40      *         otherwise null.
41      * 
42      * @throws InvalidArgsException
43      *             Thrown if the input parameters are empty.
44      * @throws SimulatorException
45      *             Thrown for other errors.
46      */
47     public static SimulatorResourceServer createResource(String configPath,
48             IResourceModelChangedListener listener)
49             throws InvalidArgsException, SimulatorException {
50         SimulatorResourceServer simulatorResourceServerObj;
51         simulatorResourceServerObj = SimulatorManagerNativeInterface
52                 .createResource(configPath, listener);
53         return simulatorResourceServerObj;
54     }
55
56     /**
57      * API for creating a set of resources from a RAML configuration file whose
58      * path is given as a parameter.
59      *
60      * @param configPath
61      *            Path to RAML configuration file.
62      * @param count
63      *            Number of resources to be created.
64      * @param listener
65      *            Listener for receiving notifications whenever there is a
66      *            change in the resource model.
67      * 
68      * @return Returns an array of {@link SimulatorResourceServer} objects one
69      *         for each created resource on success, otherwise null.
70      * 
71      * @throws InvalidArgsException
72      *             Thrown if the input parameters are empty.
73      * @throws SimulatorException
74      *             Thrown for other errors.
75      */
76     public static SimulatorResourceServer[] createResource(String configPath,
77             int count, IResourceModelChangedListener listener)
78             throws InvalidArgsException, SimulatorException {
79         SimulatorResourceServer[] simulatorResourceServers;
80         simulatorResourceServers = SimulatorManagerNativeInterface
81                 .createResources(configPath, count, listener);
82         return simulatorResourceServers;
83     }
84
85     /**
86      * API for deleting a specific resource.
87      *
88      * @param resource
89      *            {@link SimulatorResourceServer} object of the resource to be
90      *            deleted.
91      *
92      * @throws InvalidArgsException
93      *             Thrown if the input parameter is empty.
94      * @throws SimulatorException
95      *             Thrown for other errors.
96      */
97     public static void deleteResource(SimulatorResourceServer resource)
98             throws InvalidArgsException, SimulatorException {
99         SimulatorManagerNativeInterface.deleteResource(resource);
100     }
101
102     /**
103      * API for deleting either all the resources or resources of a specific
104      * type. Ex: If resourceType is oic.light, all resources of oic.light type
105      * will be deleted. If resourceType is null, then all of the resources will
106      * be deleted.
107      *
108      * @param resourceType
109      *            Type of resource to be deleted.
110      *
111      * @throws InvalidArgsException
112      *             Thrown if the input parameter is empty.
113      * @throws SimulatorException
114      *             Thrown for other errors.
115      */
116     public static void deleteResources(String resourceType)
117             throws InvalidArgsException, SimulatorException {
118         SimulatorManagerNativeInterface.deleteResources(resourceType);
119     }
120
121     /**
122      * API for discovering all types of resources in the network. Callback is
123      * called when a resource is discovered in the network.
124      *
125      * @param listener
126      *            Interface to receive the discovered remote resources.
127      * 
128      * @throws InvalidArgsException
129      *             Thrown if the input parameter is empty.
130      * @throws SimulatorException
131      *             Thrown for other errors.
132      */
133     public static void findResource(IFindResourceListener listener)
134             throws InvalidArgsException, SimulatorException {
135         SimulatorManagerNativeInterface.findResource(listener);
136     }
137
138     /**
139      * API for discovering specific type of resources in the network. Callback
140      * is called when a resource is discovered in the network.
141      *
142      * @param resourceType
143      *            Required resource type
144      * @param listener
145      *            Interface to receive the discovered remote resources.
146      * 
147      * @throws InvalidArgsException
148      *             Thrown if the input parameter is empty.
149      * @throws SimulatorException
150      *             Thrown for other errors.
151      */
152     public static void findResources(String resourceType,
153             IFindResourceListener listener) throws InvalidArgsException,
154             SimulatorException {
155         SimulatorManagerNativeInterface.findResources(resourceType, listener);
156     }
157
158     /**
159      * API to set the listener for receiving log messages.
160      *
161      * @param logger
162      *            {@link ILogger} to receive the log messages.
163      */
164     public static void setLogger(ILogger logger) {
165         SimulatorManagerNativeInterface.setLogger(logger);
166     }
167
168     /**
169      * API to set the device information.
170      * 
171      * @param deviceInfo
172      *            Device information.
173      */
174     public static void setDeviceInfo(String deviceInfo) {
175         SimulatorManagerNativeInterface.setDeviceInfo(deviceInfo);
176     }
177
178     /**
179      * API to get the device information asynchronously via the listener.
180      * 
181      * @param listener
182      *            Interface for receiving the device information.
183      */
184     public static void getDeviceInfo(IDeviceInfo listener) {
185         SimulatorManagerNativeInterface.getDeviceInfo(listener);
186     }
187
188     /**
189      * API to set the platform information.
190      * 
191      * @param platformInfo
192      *            {@link PlatformInfo} - Platform information.
193      */
194     public static void setPlatformInfo(PlatformInfo platformInfo) {
195         SimulatorManagerNativeInterface.setPlatformInfo(platformInfo);
196     }
197
198     /**
199      * API to get the platform information asynchronously via the listener.
200      * 
201      * @param listener
202      *            Interface for receiving the platform information.
203      */
204     public static void getPlatformInfo(IPlatformInfo listener) {
205         SimulatorManagerNativeInterface.getPlatformInfo(listener);
206     }
207 }