1 //******************************************************************
3 // Copyright 2014 Intel Corporation All Rights Reserved.
4 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
8 import java.util.HashMap;
10 public class OCDiscovery {
11 static private native void jniFindResource(String host, HashMap<String, String> filter,
12 OCResourceResultHandler handler);
15 * Internal API for Service and Resource Discovery
17 * @param host - Host IP Address of a service to direct resource discovery query. If null or
18 * empty, performs service discovery OR resource discovery query to ALL group members.
19 * @param filter<String FilterType, String Value> - Filter Type - Can be one of two of the link
20 * format equivalent attribute types declared in table 7 of the
21 * OC-Lite-Product-Specification-V1 Document. Either "n" (i.e. Resource Name) or "rt"
22 * (i.e. Resource Type). Value - Can be any valid String that's defined to work with CoRE
23 * Link Attributes as defined in the RFC6690.
24 * @param handler - Handles callbacks, success states and failure states.
26 * Four modes of discovery defined as follows:
27 * (NULL/Empty, NULL/Empty) - Performs ALL service discovery AND ALL resource discovery.
28 * (NULL/Empty, Not Empty) - Performs query for a filtered/scoped/particular resource(s)
30 * (Not Empty, NULL/Empty) - Performs ALL resource discovery on a particular service.
31 * (Not Empty, Not Empty) - Performs query for a filtered/scoped/particular resource(s)
32 * from a particular service.
34 * Thread-Safety: TODO Determine if it is going to be safe to call in a UI thread
36 private void findResource(String host, HashMap<String, String> filter,
37 OCResourceResultHandler handler) {
38 /*** Have to make sure all values are valid so the pass down to JNI runs smoothly. ***/
39 String tempHost = host;
40 HashMap<String, String> tempFilter = filter;
45 tempFilter = new HashMap<String, String>();
46 tempFilter.put("", ""); // TODO: NOt sure if putting an empty key is necessary if the hashmap is empty.
48 // Todo: Throw exception if handler is invalid (i.e. null).
49 /*** Done ensuring all values are valid. ***/
50 jniFindResource(tempHost, tempFilter, handler);
54 * Queries the network for available resources.
56 * NOTE: This gets posted to a new thread so it doesn't hold the UI or network thread.
58 * @param serviceURL - The URL to the service. NULL for a broadcast/multicast.
59 * @param resourceType - The resource type filter. NULL for match any.
61 * @throws This may throw if the service is not started, network is bad, etc.
63 * Thread-Safety: TODO Determine if it is going to be safe to call in a UI thread
65 public void findResourceByType(String serviceURL, String resourceType,
66 OCResourceResultHandler handler) {
67 HashMap<String, String> filteredMap = new HashMap<String, String>();
68 filteredMap.put("rt", resourceType);
69 findResource(serviceURL, filteredMap, handler);