Andorid(JNI) Implementation for Cloud Provisioning.
[platform/upstream/iotivity.git] / android / android_api / base / src / main / java / org / iotivity / base / OcCloudProvisioning.java
1 /*
2  *******************************************************************
3  *
4  * Copyright 2016 Samsung Electronics All Rights Reserved.
5  *
6  *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21  */
22
23 package org.iotivity.base;
24
25 import java.util.List;
26 import java.util.EnumSet;
27 import java.util.Map;
28 import java.util.ArrayList;
29
30
31
32 /**
33  * OcCloudProvisioning class is responsible for providing methods for cloud
34  * provisioning.
35  */
36 public class  OcCloudProvisioning {
37
38     private long    mNativeHandle;
39     private String mIp;
40     private int mPort;
41
42    /**
43     * API to construct the CloudProvisioning
44     *
45     * @param ipAddr address of the cloud server
46     * @param port port of the cloud server
47     */
48     public OcCloudProvisioning(String ip, int port) {
49         this.mIp = ip;
50         this.mPort = port;
51     }
52
53     public String getIP() {
54         return mIp;
55     }
56
57     public int getPort() {
58         return mPort;
59     }
60
61     private void setNativeHandle(long nativeHandle) {
62         this.mNativeHandle = nativeHandle;
63     }
64
65     public interface RequestCertificateListener {
66         public void requestCertificateListener(boolean result);
67     }
68
69     public interface GetAclIdByDeviceListener {
70         public void getAclIdByDeviceListener(boolean result,String aclId);
71     }
72
73     public interface GetIndividualAclInfoListener {
74         public void getIndividualAclInfoListener(boolean result);
75     }
76
77     public interface GetCRLListener {
78         public void getCRLListener(boolean result);
79     }
80
81     public interface PostCRLListener  {
82         public void postCRLListener(boolean result);
83     }
84
85    /**
86     * Method to Request a certificate from the cloud
87     * @param certificateIssueRequestListener function called by the stack on completion of request.
88     * @throws OcException
89     */
90     public native void requestCertificate(
91             RequestCertificateListener certificateIssueRequestListener) throws OcException;
92
93    /**
94     * Method to get ACL ID for the device
95     * @param deviceId device ID for which the Acl ID is requested
96     * @param cloudAclIdGetByDeviceHandler function called by the stack on completion of request.
97     * @throws OcException
98     */
99     public native void getAclIdByDevice(String deviceId,
100             GetAclIdByDeviceListener cloudAclIdGetByDeviceHandler) throws OcException;
101
102    /**
103     * Method to get ACL information about the given Acl ID
104     * @param aclId ACL ID for which the Acl information is requested
105     * @param cloudAclIndividualGetInfoHandler function called by the stack on completion of request.
106     * @throws OcException
107     */
108     public native void getIndividualAclInfo(String aclId,
109             GetIndividualAclInfoListener cloudAclIndividualGetInfoHandler) throws OcException;
110
111    /**
112     * Method to get certificate revocation list
113     * @param cloudGetCRLHandler function called by the stack on completion of request.
114     * @throws OcException
115     */
116     public native void getCRL(GetCRLListener cloudGetCRLHandler)
117             throws OcException;
118
119    /**
120     * Method to post the  certificate revocation list to cloud
121     * @param thisUpdate thisUpdate [mandatory param].
122     * @param nextUpdate nextUpdate [mandatory param].
123     * @param crl revocation list [optional].
124     * @param serialNumbers [optional].
125     * @param cloudPostCRLHandler function called by the stack on completion of request.
126     * @throws OcException
127     */
128     public void postCRL(String thisUpdate, String nextUpdate, String crl, ArrayList<String> serialNumbers,
129                                     PostCRLListener cloudPostCRLHandler) throws OcException
130     {
131         String[] serialNums = new String[serialNumbers.size()];
132         serialNums = serialNumbers.toArray(serialNums);
133         this.postCRL0(thisUpdate, nextUpdate, crl, serialNums, cloudPostCRLHandler);
134     }
135     public native void postCRL0(String thisUpdate, String nextUpdate, String crl, String[] serialNumbers,
136                                     PostCRLListener cloudPostCRLHandler) throws OcException;
137 }
138