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