Displaying and editing the complex value types for attributes.
[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 java.util.Vector;
20
21 import org.oic.simulator.client.FindResourceListener;
22 import org.oic.simulator.server.SimulatorResource;
23
24 /**
25  * This class provides a set of methods for creation, discovery and deletion of
26  * resources.
27  */
28 public class SimulatorManager {
29
30     private SimulatorManager() {
31     }
32
33     /**
34      * API for creating a resource from a RAML configuration file.
35      *
36      * @param configPath
37      *            Path to RAML configuration file.
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 native SimulatorResource createResource(String configPath)
48             throws InvalidArgsException, SimulatorException;
49
50     /**
51      * API for creating a set of resources from a RAML configuration file.
52      *
53      * @param configPath
54      *            Path to RAML configuration file.
55      * @param count
56      *            Number of resources to be created.
57      *
58      * @return Returns an array of {@link SimulatorResourceServer} objects one
59      *         for each created resource on success, otherwise null.
60      *
61      * @throws InvalidArgsException
62      *             Thrown if the input parameters are empty.
63      * @throws SimulatorException
64      *             Thrown for other errors.
65      */
66     public static Vector<SimulatorResource> createResource(String configPath,
67             int count) throws InvalidArgsException, SimulatorException {
68         return createResources(configPath, count);
69     };
70
71     /**
72      * API for creating a resource either single or collection type.
73      *
74      * @param configPath
75      *            Path to RAML configuration file.
76      *
77      * @return {@link SimulatorResourceServer} - Created resource on success,
78      *         otherwise null.
79      *
80      * @throws InvalidArgsException
81      *             Thrown if the input parameters are empty.
82      * @throws SimulatorException
83      *             Thrown for other errors.
84      */
85     public static SimulatorResource createResource(SimulatorResource.Type type,
86             String name, String uri, String resourceType)
87             throws InvalidArgsException, SimulatorException {
88         SimulatorResource resource = null;
89         if (type == SimulatorResource.Type.SINGLE)
90             resource = createSingleResource(name, uri, resourceType);
91         else
92             resource = createCollectionResource(name, uri, resourceType);
93         return resource;
94     }
95
96     /**
97      * API for discovering all types of resources in the network. Callback is
98      * called when a resource is discovered in the network.
99      *
100      * @param listener
101      *            Interface to receive the discovered remote resources.
102      *
103      * @throws InvalidArgsException
104      *             Thrown if the input parameter is empty.
105      * @throws SimulatorException
106      *             Thrown for other errors.
107      */
108     public static void findResource(FindResourceListener listener)
109             throws InvalidArgsException, SimulatorException {
110         searchResource(null, listener);
111     }
112
113     /**
114      * API for discovering specific type of resources in the network. Callback
115      * is called when a resource is discovered in the network.
116      *
117      * @param resourceType
118      *            Required resource type
119      * @param listener
120      *            Interface to receive the discovered remote resources.
121      *
122      * @throws InvalidArgsException
123      *             Thrown if the input parameter is empty.
124      * @throws SimulatorException
125      *             Thrown for other errors.
126      */
127     public static void findResource(String resourceType,
128             FindResourceListener listener) throws InvalidArgsException,
129             SimulatorException {
130         if (null == resourceType || resourceType.isEmpty()) {
131             throw new InvalidArgsException(
132                     SimulatorResult.SIMULATOR_INVALID_PARAM,
133                     "Invalid resource type!");
134         }
135
136         searchResource(resourceType, listener);
137     }
138
139     /**
140      * API to set the device information.
141      *
142      * @param deviceInfo
143      *            Device information.
144      */
145     public static native void setDeviceInfo(String deviceInfo)
146             throws InvalidArgsException, SimulatorException;
147
148     /**
149      * API to search for devices in the network.
150      *
151      * @param hostUri
152      *            URI of the host device.
153      * @param listener
154      *            Listener for receiving the device information.
155      */
156     public static native void findDevices(String hostUri,
157             DeviceListener listener) throws InvalidArgsException,
158             SimulatorException;
159
160     /**
161      * API to set the platform information.
162      *
163      * @param platformInfo
164      *            {@link PlatformInfo} - Platform information.
165      */
166     public static native void setPlatformInfo(PlatformInfo platformInfo)
167             throws InvalidArgsException, SimulatorException;
168
169     /**
170      * API to find all devices' platform information in the network.
171      *
172      * @param hostUri
173      *            URI of the host device.
174      * @param listener
175      *            Listener for receiving the platform information.
176      */
177     public static native void getPlatformInformation(String hostUri,
178             PlatformListener listener) throws InvalidArgsException,
179             SimulatorException;
180
181     /**
182      * API to set the listener for receiving log messages.
183      *
184      * @param logger
185      *            {@link ILogger} to receive the log messages.
186      */
187     public static native void setLogger(ILogger logger)
188             throws SimulatorException;
189
190     private static native Vector<SimulatorResource> createResources(
191             String configPath, int count);
192
193     private static native SimulatorResource createSingleResource(String name,
194             String uri, String resourceType);
195
196     private static native SimulatorResource createCollectionResource(
197             String name, String uri, String resourceType);
198
199     private static native void searchResource(String resourceType,
200             FindResourceListener listener);
201 }