Initial merge-commit of the OIC code. Should successfully do discovery for single...
[platform/upstream/iotivity.git] / csdk / android / OCLib / src / com / oc / OCServer.java
1 //******************************************************************
2 //
3 // Copyright 2014 Intel Corporation All Rights Reserved.
4 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
5
6 package com.oc;
7
8 /**
9  * This represents a running open connection server.
10  * 
11  * WARNING: This may change to an interface so that we may transition to a factory pattern
12  * 
13  */
14 public class OCServer {
15   private native void jniRegisterResource(OCObject object, String url);
16
17   private native void jniUnregisterResource(OCObject object);
18
19   private native void jniStartOCServer();
20
21   private native void jniStopOCServer();
22
23   private native OCDiscovery jniGetDiscoverySingleton();
24
25   /**
26    * Constructor for OCService.
27    */
28   public OCServer() {}
29
30   /**
31    * This registers a security model for access control to resources under this service.
32    * 
33    * @param model - Security Model required for access to this service and control/view of it's
34    *        services.
35    */
36   public void setSecurityModel(OCSecurityModel model) {
37     // Todo: Pat, What will we do here?
38   }
39
40   /**
41    * Registers a resource with the service.
42    * 
43    * @param object - The OCObject that handles the resource requests
44    * @param url - The URL under the resource.
45    * @param accessControl - The access control handler that determines whether the remote device is
46    *        allowed to access this resource. If NULL, all access is granted.
47    */
48   public void registerResource(OCObject object, String url/* TODO: , AccessControl accessControl */) {
49     jniRegisterResource(object, url);
50   }
51
52   /**
53    * Unregisters a resource with the service.
54    * 
55    * @param object - The OCObject to be unregistered.
56    */
57   public void unregisterResource(OCObject object) {
58     jniUnregisterResource(object);
59   }
60
61   /**
62    * Starts the open connectivity service.
63    * 
64    * Thread-Safety: TODO Determine if it is going to be safe to call in a UI thread
65    */
66   public void start() {
67     jniStartOCServer();
68   }
69
70   /**
71    * Stops the open connectivity service.
72    * 
73    * Thread-Safety: TODO Determine if it is going to be safe to call in a UI thread
74    */
75   public void stop() {
76     jniStopOCServer();
77   }
78
79   /**
80    * Retrieves access to discovery APIs via the Discovery Singleton delegated by the SDK. Delegation
81    * is limited to just one singleton per OCServer object.
82    * 
83    * @return Returns an object which permits access to the open connectivity discovery APIs to just
84    *         one discovery singleton object.
85    * 
86    * @throws //TODO throws an exception when the discovery singleton has already been checked out.
87    */
88   public OCDiscovery getDiscoverySingleton() {
89     return jniGetDiscoverySingleton();
90   }
91 }