2 *******************************************************************
4 * Copyright 2015 Samsung Electronics All Rights Reserved.
6 *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
23 package org.iotivity.base;
25 import java.util.List;
26 import java.util.EnumSet;
29 public class OcSecureResource {
31 private OcSecureResource(long nativeHandle) {
32 this.mNativeHandle = nativeHandle;
36 * Method to Start Ownership Transfer of an un-owned device.
38 * @param DoOwnershipTransferListener Callback function, which will be called after
39 * completion of ownership Transfer.
42 public native void doOwnershipTransfer(DoOwnershipTransferListener doOwnershipTransferListener)
46 * Method removes device credential from all devices in subnet
49 * @param RemoveDeviceListener Callback function, which will be called after
50 * completion of removing device.
53 public native void removeDevice(int timeout, RemoveDeviceListener removeDeviceListener)
57 * Method removes the credential & relationship between the two devices.
59 * @param jobject Second device
60 * @param UnlinkDevicesListener Callback function, which will be called after
61 * completion of removing device.
64 public native void unlinkDevices(Object device2, UnlinkDevicesListener unlinkDevicesListener)
68 * Method removes the credential & relationship between the two devices.
70 * @param EnumSet<CredType> OR'ed Cred Types
71 * @param KeySize keySize
72 * @param Object Second device
73 * @param ProvisionCredentialsListener Callback function, which will be called after
74 * completion of removing device.
77 public void provisionCredentials(EnumSet<CredType> credTypeSet, KeySize keysize, Object device2,
78 ProvisionCredentialsListener provisionCredentialsListener) throws OcException {
81 for (CredType credType : CredType.values()) {
82 if (credTypeSet.contains(credType))
83 credTypeInt |= credType.getValue();
85 this.provisionCredentials1(credTypeInt, keysize.getValue(),
86 device2, provisionCredentialsListener);
88 private native void provisionCredentials1(int type, int keySize, Object device2,
89 ProvisionCredentialsListener provisionCredentialsListener)
93 * Method send ACL information to resource.
96 * @param ProvisionAclListener Callback function, which will be called after
97 * completion of removing device.
100 public native void provisionACL(Object acl, ProvisionAclListener provisionACLListener)
105 * Method provisions credentials between two devices and ACLs for the devices who
108 * @param EnumSet<CredType> OR'ed Cred Types
109 * @param KeySize keySize
110 * @param Object First acl
111 * @param Object Second device
112 * @param Object Second acl
113 * @param ProvisionPairwiseDevicesListener Callback function, which will be called after
114 * completion of removing device.
115 * @throws OcException
117 public void provisionPairwiseDevices(EnumSet<CredType> credTypeSet, KeySize keysize, Object acl1,
118 Object device2, Object acl2,
119 ProvisionPairwiseDevicesListener provisionPairwiseDevicesListener) throws OcException {
122 for (CredType credType : CredType.values()) {
123 if (credTypeSet.contains(credType))
124 credTypeInt |= credType.getValue();
126 this.provisionPairwiseDevices1(credTypeInt, keysize.getValue(), acl1, device2,
127 acl2, provisionPairwiseDevicesListener);
129 private native void provisionPairwiseDevices1(int type, int keySize, Object acl1,
130 Object device2, Object acl2,
131 ProvisionPairwiseDevicesListener provisionPairwiseDevicesListener) throws OcException;
134 * doOwnershipTransferListener can be registered with doOwnershipTransfer
136 * Listener notified asynchronously.
138 public interface DoOwnershipTransferListener {
139 public void doOwnershipTransferListener(List<ProvisionResult> provisionResultList,
144 * removeDeviceListener can be registered with removeDeviceListener
146 * Listener notified asynchronously.
148 public interface RemoveDeviceListener {
149 public void removeDeviceListener(List<ProvisionResult> provisionResultList,
154 * unlinkDevicesListener can be registered with unlinkDevicesListener
156 * Listener notified asynchronously.
158 public interface UnlinkDevicesListener {
159 public void unlinkDevicesListener(List<ProvisionResult> provisionResultList,
164 * provisionCredentialsListener can be registered with provisionCredentialsListener
166 * Listener notified asynchronously.
168 public interface ProvisionCredentialsListener {
169 public void provisionCredentialsListener(List<ProvisionResult> provisionResultList,
174 * provisionAclListener can be registered with provisionAclListener
176 * Listener notified asynchronously.
178 public interface ProvisionAclListener {
179 public void provisionAclListener(List<ProvisionResult> provisionResultList,
184 * provisionPairwiseDevicesListener can be registered with provisionPairwiseDevicesListener
186 * Listener notified asynchronously.
188 public interface ProvisionPairwiseDevicesListener {
189 public void provisionPairwiseDevicesListener(List<ProvisionResult> provisionResultList,
193 /** Method to get List of device ID of devices linked with invoking device.
195 * @return Sring List List of device id's of linked devices.
197 public native List<String> getLinkedDevices();
200 * Method to get IP address of sercure discovered device.
201 * @return Stringified IP address.
203 public native String getIpAddr();
206 * Method to get device id of a device.
207 * @return Device ID of the selected device.
209 public native String getDeviceID();
212 * Method to get device status (ON/OFF) of a device.
216 public DeviceStatus getDeviceStatus() throws OcException {
217 return DeviceStatus.convertDeviceStatus(this.deviceStatus());
219 public native int deviceStatus() throws OcException;
222 * Method to get device ownership (OWNED/UNOWNED) status.
223 * @return OWNED/UNOWNED
226 public OwnedStatus getOwnedStatus() throws OcException {
227 return OwnedStatus.convertOwnedStatus(this.ownedStatus());
229 public native int ownedStatus() throws OcException;
232 protected void finalize() throws Throwable {
237 private native void dispose();
239 private long mNativeHandle;