1 //******************************************************************
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
11 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
23 import java.util.HashMap;
25 public class OCDiscovery {
26 static private native void jniFindResource(String host, HashMap<String, String> filter,
27 OCResourceResultHandler handler);
30 * Internal API for Service and Resource Discovery
32 * @param host - Host IP Address of a service to direct resource discovery query. If null or
33 * empty, performs service discovery OR resource discovery query to ALL group members.
34 * @param filter<String FilterType, String Value> - Filter Type - Can be one of two of the link
35 * format equivalent attribute types declared in table 7 of the
36 * OC-Lite-Product-Specification-V1 Document. Either "n" (i.e. Resource Name) or "rt"
37 * (i.e. Resource Type). Value - Can be any valid String that's defined to work with CoRE
38 * Link Attributes as defined in the RFC6690.
39 * @param handler - Handles callbacks, success states and failure states.
41 * Four modes of discovery defined as follows:
42 * (NULL/Empty, NULL/Empty) - Performs ALL service discovery AND ALL resource discovery.
43 * (NULL/Empty, Not Empty) - Performs query for a filtered/scoped/particular resource(s)
45 * (Not Empty, NULL/Empty) - Performs ALL resource discovery on a particular service.
46 * (Not Empty, Not Empty) - Performs query for a filtered/scoped/particular resource(s)
47 * from a particular service.
49 * Thread-Safety: TODO Determine if it is going to be safe to call in a UI thread
51 private void findResource(String host, HashMap<String, String> filter,
52 OCResourceResultHandler handler) {
53 /*** Have to make sure all values are valid so the pass down to JNI runs smoothly. ***/
54 String tempHost = host;
55 HashMap<String, String> tempFilter = filter;
60 tempFilter = new HashMap<String, String>();
61 tempFilter.put("", ""); // TODO: NOt sure if putting an empty key is necessary if the hashmap is empty.
63 // Todo: Throw exception if handler is invalid (i.e. null).
64 /*** Done ensuring all values are valid. ***/
65 jniFindResource(tempHost, tempFilter, handler);
69 * Queries the network for available resources.
71 * NOTE: This gets posted to a new thread so it doesn't hold the UI or network thread.
73 * @param serviceURL - The URL to the service. NULL for a broadcast/multicast.
74 * @param resourceType - The resource type filter. NULL for match any.
76 * @throws This may throw if the service is not started, network is bad, etc.
78 * Thread-Safety: TODO Determine if it is going to be safe to call in a UI thread
80 public void findResourceByType(String serviceURL, String resourceType,
81 OCResourceResultHandler handler) {
82 HashMap<String, String> filteredMap = new HashMap<String, String>();
83 filteredMap.put("rt", resourceType);
84 findResource(serviceURL, filteredMap, handler);