jdk_env.Clean(cmdBuildExamples,
'#/java/examples-android/devicediscoveryserver/build/')
jdk_env.Clean(cmdBuildExamples,
- '#/java/examples-android/DirectPairing/build/')
- jdk_env.Clean(cmdBuildExamples,
'#/java/examples-android/fridgeclient/build/')
jdk_env.Clean(cmdBuildExamples,
'#/java/examples-android/fridgegroupclient/build/')
+++ /dev/null
-/*
- * //******************************************************************
- * //
- * // Copyright 2016 Samsung Electronics All Rights Reserved.
- * //
- * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- * //
- * // Licensed under the Apache License, Version 2.0 (the "License");
- * // you may not use this file except in compliance with the License.
- * // You may obtain a copy of the License at
- * //
- * // http://www.apache.org/licenses/LICENSE-2.0
- * //
- * // Unless required by applicable law or agreed to in writing, software
- * // distributed under the License is distributed on an "AS IS" BASIS,
- * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * // See the License for the specific language governing permissions and
- * // limitations under the License.
- * //
- * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- */
-
-package org.iotivity.base;
-
-import java.util.List;
-import java.util.EnumSet;
-import java.util.Map;
-import java.util.Arrays;
-import java.util.ArrayList;
-
-public class OcDirectPairDevice {
-
-
- private long mNativeHandle;
- private String mdeviceID;
- private String mHost;
-
- private OcDirectPairDevice(long nativeHandle) {
- this.mNativeHandle = nativeHandle;
- }
-
- public OcDirectPairDevice(String deviceID) {
- this.mdeviceID = deviceID;
- }
-
- public String getDevId() {
- return this.mdeviceID;
- }
-
- public native String getHost();
-
- public List<Integer> getPairingMethodList() {
- int [] intList = this.getPairingMethods();
- List<Integer> prmList = new ArrayList<Integer>();
- for (int i = 0; i < intList.length; i++) {
- prmList.add(intList[i]);
- }
- return prmList;
- }
-
- private native int[] getPairingMethods();
-
- /**
- * Method to get the connectivity type of this resource
- *
- * @return EnumSet OcConnectivityType connectivity type set
- */
- public EnumSet<OcConnectivityType> getConnectivityTypeSet() {
- return OcConnectivityType.convertToEnumSet(
- this.getConnectivityTypeN()
- );
- }
-
- private native int getConnectivityTypeN();
-
-
- /**
- * Method to get list of all paired devices for a given device.
- *
- * @param getDirectPairedListener Callback function, which will receive the list of direct paired devices.
- * @throws OcException Indicate failure to list paired devices.
- * Use OcException.GetErrorCode() for more details.
- */
-
- public native void getDirectPairedDevices(GetDirectPairedListener getDirectPairedListener) throws OcException;
-
- public interface GetDirectPairedListener {
- public void getDirectPairedListener(List<String> ocPairedDeviceList);
- }
-
- /**
- * Method to perform direct pairing between two devices.
- *
- * @param peer the peer device
- * @param pmSel direct pairing Method Type ( DP_NOT_ALLOWED, DP_PRE_CONFIGURED, DP_RANDOM_PIN )
- * @param pinNumber pairing pin number
- * @param directPairingListener Callback function, which will be called after
- * completion of direct pairing.
- * @throws OcException Indicate failure to perform direct pairing between devices.
- * Use OcException.GetErrorCode() for more details.
- */
- public native void doDirectPairing(OcDirectPairDevice peer,
- OcPrmType pmSel, String pinNumber,
- DirectPairingListener directPairingListener) throws OcException;
-
-
- public interface DirectPairingListener {
- public void directPairingListener(String devId, int result);
- }
-
- @Override
- public String toString() {
- return this.mdeviceID;
- }
-}
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>\r
-<classpath>\r
- <classpathentry kind="src" path="src"/>\r
- <classpathentry kind="src" path="gen"/>\r
- <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>\r
- <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>\r
- <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>\r
- <classpathentry kind="output" path="bin/classes"/>\r
-</classpath>\r
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<module external.linked.project.id=":DirectPairing" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="examples" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
- <component name="FacetManager">
- <facet type="android-gradle" name="Android-Gradle">
- <configuration>
- <option name="GRADLE_PROJECT_PATH" value=":DirectPairing" />
- </configuration>
- </facet>
- <facet type="android" name="Android">
- <configuration>
- <option name="SELECTED_BUILD_VARIANT" value="debug" />
- <option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
- <option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
- <option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
- <option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugAndroidTest" />
- <option name="COMPILE_JAVA_TEST_TASK_NAME" value="compileDebugAndroidTestSources" />
- <afterSyncTasks>
- <task>generateDebugAndroidTestSources</task>
- <task>generateDebugSources</task>
- </afterSyncTasks>
- <option name="ALLOW_USER_CONFIGURATION" value="false" />
- <option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
- <option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
- <option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />
- <option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
- </configuration>
- </facet>
- </component>
- <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
- <output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
- <output-test url="file://$MODULE_DIR$/build/intermediates/classes/androidTest/debug" />
- <exclude-output />
- <content url="file://$MODULE_DIR$">
- <sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
- <sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
- <sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
- <sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
- <sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
- <sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/debug" type="java-resource" />
- <sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
- <sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
- <sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
- <sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
- <sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" />
- <sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/androidTest/debug" type="java-test-resource" />
- <sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
- <sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
- <sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
- <sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
- <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
- <sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
- <sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
- <sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
- <sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
- <sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
- <sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
- <sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
- <sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/coverage-instrumented-classes" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/libs" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
- <excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
- <excludeFolder url="file://$MODULE_DIR$/build/outputs" />
- <excludeFolder url="file://$MODULE_DIR$/build/reports" />
- <excludeFolder url="file://$MODULE_DIR$/build/test-results" />
- <excludeFolder url="file://$MODULE_DIR$/build/tmp" />
- </content>
- <orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
- <orderEntry type="sourceFolder" forTests="false" />
- <orderEntry type="library" exported="" name="iotivity-base-armeabi-release-" level="project" />
- <orderEntry type="library" exported="" name="android-android-21" level="project" />
- </component>
-</module>
+++ /dev/null
-apply plugin: 'com.android.application'
-
-android {
- compileSdkVersion 21
- buildToolsVersion "20.0.0"
-
- defaultConfig {
- applicationId "org.iotivity.base.examples.DirectPairing"
- minSdkVersion 21
- targetSdkVersion 21
- versionCode 1
- versionName "1.0"
- }
- buildTypes {
- release {
- minifyEnabled false
- proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
- }
- }
- lintOptions {
- abortOnError false
- }
-}
-repositories {
- flatDir {
- dirs "../../iotivity-android/build/outputs/aar/"
- }
-}
-
-try {
- dependencies {
- compile ":iotivity-base-${TARGET_ARCH}-${RELEASE}@aar"
- }
-} catch (all) {
- print "${ERROR_MSG}"
- assert all
-}
-
+++ /dev/null
-# This file is automatically generated by Android Tools.
-# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
-#
-# This file must be checked in Version Control Systems.
-#
-# To customize properties used by the Ant build system edit
-# "ant.properties", and override values to adapt the script to your
-# project structure.
-#
-# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
-#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
-
-# Project target.
-target=android-23
-android.library.reference.1=../appcompat_v7
+++ /dev/null
-<?xml version="1.0" encoding="utf-8"?>
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="org.iotivity.base.examples.DirectPairing"
- android:versionCode="1"
- android:versionName="1.0" >
-
- <uses-sdk
- android:minSdkVersion="19"
- android:targetSdkVersion="21" />
- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
- <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
-
- <application
- android:allowBackup="true"
- android:icon="@drawable/ic_launcher"
- android:label="@string/app_name"
- android:theme="@style/AppTheme" >
- <activity
- android:name=".MainActivity"
- android:label="@string/app_name" >
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
-
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- </application>
-
-</manifest>
+++ /dev/null
-/*
- * //******************************************************************
- * //
- * // Copyright 2016 Samsung Electronics All Rights Reserved.
- * //
- * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- * //
- * // Licensed under the Apache License, Version 2.0 (the "License");
- * // you may not use this file except in compliance with the License.
- * // You may obtain a copy of the License at
- * //
- * // http://www.apache.org/licenses/LICENSE-2.0
- * //
- * // Unless required by applicable law or agreed to in writing, software
- * // distributed under the License is distributed on an "AS IS" BASIS,
- * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * // See the License for the specific language governing permissions and
- * // limitations under the License.
- * //
- * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- */
-
-package org.iotivity.base.examples.DirectPairing;
-
-import android.content.Context;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.BaseExpandableListAdapter;
-import android.widget.ImageView;
-import android.widget.TextView;
-
-import org.iotivity.base.examples.DirectPairing.Led;
-
-import java.util.List;
-
-public class ExpandableListAdapter extends BaseExpandableListAdapter {
- private List<String> mGroupList;
- private List<Object> mChilditemsList;
- private Context mContext;
-
- public ExpandableListAdapter(List<String> groupList, List<Object> childitemsList,
- Context context) {
- super();
- this.mContext = context;
- this.mGroupList = groupList;
- this.mChilditemsList = childitemsList;
- }
-
- @Override
- public int getGroupCount() {
- return mGroupList.size();
- }
-
- @Override
- public int getChildrenCount(int groupPosition) {
- return 1;
- }
-
- @Override
- public Object getGroup(int groupPosition) {
- return mGroupList.get(groupPosition);
- }
-
- @Override
- public Object getChild(int groupPosition, int childPosition) {
- return this.mChilditemsList.get(childPosition);
- }
-
- @Override
- public long getGroupId(int groupPosition) {
- return groupPosition;
- }
-
- @Override
- public long getChildId(int groupPosition, int childPosition) {
- return childPosition;
- }
-
- @Override
- public boolean hasStableIds() {
- return false;
- }
-
- @Override
- public View getGroupView(int groupPosition, boolean isExpanded,
- View convertView, ViewGroup parent) {
-
- String data = (String) getGroup(groupPosition);
- if (convertView == null) {
- LayoutInflater infalInflater = (LayoutInflater) this.mContext
- .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- convertView = infalInflater.inflate(R.layout.list_group, null);
- }
-
- ImageView img = (ImageView) convertView.findViewById(R.id.image);
- if (isExpanded) {
- img.setImageResource(R.drawable.arrow_down);
-
- } else {
- img.setImageResource(R.drawable.arrow_right);
- }
-
- TextView groupText = (TextView) convertView.findViewById(R.id.title);
- groupText.setText(mGroupList.get(groupPosition));
-
- return convertView;
- }
-
- @Override
- public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
- View convertView, ViewGroup parent) {
- LayoutInflater inflater = (LayoutInflater) mContext
- .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- convertView = inflater.inflate(R.layout.list_item, parent, false);
-
- Led ledResource = (Led) getChild(groupPosition, childPosition);
- TextView textItem = (TextView) convertView
- .findViewById(R.id.textViewItem);
- TextView textSource = (TextView) convertView
- .findViewById(R.id.textViewSource);
- TextView textStatus = (TextView) convertView
- .findViewById(R.id.textViewStatus);
- textStatus.setText("URI:" + "/a/led");
- textItem.setText("State: " + ledResource.getState());
- textSource.setText("Power: " + ledResource.getPower());
-
- return convertView;
-
- }
-
- @Override
- public boolean isChildSelectable(int groupPosition, int childPosition) {
- return true;
- }
-
-}
+++ /dev/null
-/*
- * //******************************************************************
- * //
- * // Copyright 2016 Samsung Electronics All Rights Reserved.
- * //
- * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- * //
- * // Licensed under the Apache License, Version 2.0 (the "License");
- * // you may not use this file except in compliance with the License.
- * // You may obtain a copy of the License at
- * //
- * // http://www.apache.org/licenses/LICENSE-2.0
- * //
- * // Unless required by applicable law or agreed to in writing, software
- * // distributed under the License is distributed on an "AS IS" BASIS,
- * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * // See the License for the specific language governing permissions and
- * // limitations under the License.
- * //
- * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- */
-package org.iotivity.base.examples.DirectPairing;
-
-/**
- * Led
- * <p/>
- * This class is used by simpleclient to create an object and update the values depending
- * on the server response
- */
-public class Led {
- private boolean mState;
- private int mPower;
- private String mUri;
-
- // constructor
- public Led() {
- mState = false;
- mPower = 0;
- mUri = "";
- }
-
- // accessor methods
- public boolean getState() {
- return mState;
- }
-
- public void setState(boolean state) {
- mState = state;
- }
-
- public int getPower() {
- return mPower;
- }
-
- public void setPower(int power) {
- mPower = power;
- }
-
- public String getUri() {
- return mUri;
- }
-
- public void setUri(String uri) {
- mUri = uri;
- }
-}
+++ /dev/null
-/*
- * //******************************************************************
- * //
- * // Copyright 2016 Samsung Electronics All Rights Reserved.
- * //
- * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- * //
- * // Licensed under the Apache License, Version 2.0 (the "License");
- * // you may not use this file except in compliance with the License.
- * // You may obtain a copy of the License at
- * //
- * // http://www.apache.org/licenses/LICENSE-2.0
- * //
- * // Unless required by applicable law or agreed to in writing, software
- * // distributed under the License is distributed on an "AS IS" BASIS,
- * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * // See the License for the specific language governing permissions and
- * // limitations under the License.
- * //
- * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- */
-package org.iotivity.base.examples.DirectPairing;
-
-import android.app.Activity;
-import android.app.AlertDialog;
-import android.app.ProgressDialog;
-import android.content.DialogInterface;
-import android.content.SharedPreferences;
-import android.graphics.Color;
-import android.os.AsyncTask;
-import android.os.Bundle;
-import android.os.Environment;
-import android.preference.PreferenceManager;
-import android.text.InputFilter;
-import android.util.Log;
-import android.view.View;
-import android.widget.AdapterView;
-import android.widget.AdapterView.OnItemClickListener;
-import android.widget.ArrayAdapter;
-import android.widget.Button;
-import android.widget.CompoundButton;
-import android.widget.EditText;
-import android.widget.ExpandableListView;
-import android.widget.ExpandableListView.OnGroupExpandListener;
-import android.widget.LinearLayout;
-import android.widget.ListView;
-import android.widget.Switch;
-import android.widget.Toast;
-
-import org.iotivity.base.ModeType;
-import org.iotivity.base.OcDirectPairDevice;
-import org.iotivity.base.OcException;
-import org.iotivity.base.OcHeaderOption;
-import org.iotivity.base.OcPlatform;
-import org.iotivity.base.OcPrmType;
-import org.iotivity.base.OcProvisioning;
-import org.iotivity.base.OcRepresentation;
-import org.iotivity.base.OcResource;
-import org.iotivity.base.PlatformConfig;
-import org.iotivity.base.QualityOfService;
-import org.iotivity.base.ServiceType;
-import org.iotivity.base.examples.DirectPairing.Led;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.nio.channels.FileChannel;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-
-public class MainActivity extends Activity {
- private static final int BUFFER_SIZE = 1024;
- private static final String TAG = "DirectPairing: ";
- private static int selected = -1;
- private int[] pList;
- private Button save;
- private int prmType;
- private EditText pinText;
- private Led ledResource;
- private ListView mListView;
- private String filePath = "";
- private OcResource led = null;
- private Switch discoverButton;
- private List<String> resourceInterfaces;
- private ArrayAdapter<String> arrayAdapter;
- private List<Object> onGetResponseList;
- private ExpandableListAdapter exlistAdapter;
- OcResource.OnGetListener onGetListener = new OcResource.OnGetListener() {
- @Override
- public synchronized void onGetCompleted(List<OcHeaderOption> headerOptionList,
- OcRepresentation ocRepresentation) {
- onGetResponseList = new ArrayList<Object>();
- ledResource.setState(ocRepresentation.getValueBool("state"));
- ledResource.setPower(ocRepresentation.getValueInt("power"));
- ledResource.setUri(ocRepresentation.getUri());
- runOnUiThread(new Runnable() {
- public void run() {
- onGetResponseList.add(ledResource);
- exlistAdapter.notifyDataSetChanged();
- }
- });
-
- Log.d(TAG, "Got a response from " + ocRepresentation.getUri() +
- " " + ocRepresentation.getValueBool("state") + " "
- + ocRepresentation.getValueInt("power") + " " +
- ocRepresentation.getValueString("name"));
- }
-
- @Override
- public synchronized void onGetFailed(Throwable throwable) {
- Log.d(TAG, "GET request has failed");
- Log.e(TAG, throwable.toString());
- }
- };
- private ExpandableListView mPairedListDisplay;
- private ArrayAdapter<OcDirectPairDevice> adapter;
- private List<String> pairedList;
- private List<OcDirectPairDevice> discoveredListObj;
- OcPlatform.DirectPairingListener doDPListener = new OcPlatform.DirectPairingListener() {
- @Override
- public void onDirectPairingListener(String devId, int result) {
- Log.d(TAG, "Inside getDPListener");
- if (result == StringConstants.SUCCES_CODE) {
- pairedList.clear();
- pairedList.add(devId);
- onGetResponseList.add(new Led());
- runOnUiThread(new Runnable() {
- public void run() {
- mPairedListDisplay.setAdapter(exlistAdapter);
- int pos = mListView.getCheckedItemPosition();
- if (pos != ListView.INVALID_POSITION && discoveredListObj.size() != 0) {
- discoveredListObj.remove(pos);
- adapter.notifyDataSetChanged();
- }
- }
- });
- Log.d(TAG, "direct pair successfull for " + devId);
- } else {
- Log.d(TAG, "direct pairing failed");
- runOnUiThread(new Runnable() {
- public void run() {
- Toast.makeText(getApplicationContext(),
- "Direct Pairing Failed", Toast.LENGTH_SHORT).show();
- }
- });
- }
- exportCBOR();
- }
- };
- private List<OcDirectPairDevice> discoveredPairableDevices;
- OcPlatform.FindDirectPairingListener finddirectPairing =
- new OcPlatform.FindDirectPairingListener() {
- @Override
- public void onFindDirectPairingListener(List<OcDirectPairDevice> direcPairingDevice) {
- Log.d(TAG, "find direct pairable successfull ");
- discoveredListObj.clear();
- discoveredPairableDevices =
- new ArrayList<OcDirectPairDevice>(direcPairingDevice);
- for (int i = 0; i < direcPairingDevice.size(); i++) {
- OcDirectPairDevice dpPairDevice = direcPairingDevice.get(i);
- Log.d(TAG, "getHost from Find Direct Pairing " + dpPairDevice.getHost());
- discoveredListObj.add(dpPairDevice);
- }
-
- runOnUiThread(new Runnable() {
- public void run() {
- mListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
- mListView.setAdapter(adapter);
- discoverButton.setChecked(false);
- }
- });
- }
- };
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
-
- onGetResponseList = new ArrayList<Object>();
- discoveredListObj = new ArrayList<OcDirectPairDevice>();
- pairedList = new ArrayList<String>();
-
- ledResource = new Led();
-
- mListView = (ListView) findViewById(R.id.list_view);
- discoverButton = (Switch) findViewById(R.id.discover);
- mPairedListDisplay = (ExpandableListView) findViewById(R.id.list_view_paired_list);
-
-
- filePath = getFilesDir().getPath() + "/"; // data/data/<package>/files/
- //copy CBOR file when application runs first time
- SharedPreferences wmbPreference = PreferenceManager.getDefaultSharedPreferences(this);
- boolean isFirstRun = wmbPreference.getBoolean("FIRSTRUN", true);
- if (isFirstRun) {
- copyCborFromAsset();
- SharedPreferences.Editor editor = wmbPreference.edit();
- editor.putBoolean("FIRSTRUN", false);
- editor.commit();
- }
-
- initOICStack();
-
- adapter = new ArrayAdapter<OcDirectPairDevice>(this,
- android.R.layout.simple_list_item_single_choice,
- discoveredListObj);
-
- arrayAdapter = new ArrayAdapter<String>(
- MainActivity.this,
- android.R.layout.select_dialog_singlechoice);
-
- save = (Button) findViewById(R.id.saveDiscovered);
-
- save.setEnabled(false);
- save.setBackgroundColor(Color.GRAY);
-
- resourceInterfaces = new LinkedList<>();
- resourceInterfaces.add(OcPlatform.DEFAULT_INTERFACE);
-
- exlistAdapter = new ExpandableListAdapter(pairedList, onGetResponseList,
- MainActivity.this);
- mPairedListDisplay.setAdapter(exlistAdapter);
-
- // to expand only a single group item.
- mPairedListDisplay.setOnGroupExpandListener(new OnGroupExpandListener() {
- int previousGroup = -1;
-
- @Override
- public void onGroupExpand(int groupPosition) {
- Log.d(TAG, "Calling GET api on mResource");
- try {
- if (null != led) led.get(new HashMap<String, String>(), onGetListener);
- } catch (OcException e) {
- Log.d(TAG, "Error in GET calls");
- Log.e(TAG, e.getMessage());
- }
-
- if (groupPosition != previousGroup)
- mPairedListDisplay.collapseGroup(previousGroup);
-
- previousGroup = groupPosition;
- }
- });
-
- save.setOnClickListener(new View.OnClickListener() {
-
- @Override
- public void onClick(View v) {
-
- AlertDialog.Builder alertPinDialog =
- new AlertDialog.Builder(MainActivity.this);
- alertPinDialog.setTitle("PIN");
- alertPinDialog.setMessage("Enter Pin");
-
- pinText = new EditText(MainActivity.this);
- int maxLength = 8;
- InputFilter[] fArray = new InputFilter[1];
- fArray[0] = new InputFilter.LengthFilter(maxLength);
- pinText.setFilters(fArray);
- pinText.setMaxLines(1);
- LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
- LinearLayout.LayoutParams.MATCH_PARENT,
- LinearLayout.LayoutParams.MATCH_PARENT);
- pinText.setLayoutParams(lp);
- alertPinDialog.setView(pinText);
- alertPinDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- selected = -1;
- final AlertDialog alertPrmTypeDialog = new AlertDialog.Builder
- (MainActivity.this)
- .setSingleChoiceItems(arrayAdapter, -1,
- new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- selected = which;
- prmType = pList[which];
- Log.d(TAG, " prmType " + prmType);
- }
- })
- .setTitle("Select Direct Pair Method")
- .setPositiveButton("OK", null)
- .setNegativeButton("CANCEL", null)
- .create();
-
- alertPrmTypeDialog.setOnShowListener(
- new DialogInterface.OnShowListener() {
- @Override
- public void onShow(DialogInterface dialog) {
- Button ok =
- alertPrmTypeDialog
- .getButton(AlertDialog.BUTTON_POSITIVE);
-
- Button cancel =
- alertPrmTypeDialog
- .getButton(AlertDialog.BUTTON_NEGATIVE);
-
- ok.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- int pos = mListView.getCheckedItemPosition();
- if (selected == -1) {
- Toast.makeText(getApplicationContext(),
- "Please Select A Value",
- Toast.LENGTH_SHORT).show();
- } else if (pos != ListView.INVALID_POSITION) {
- if (!discoveredListObj.isEmpty()) {
- try {
- OcDirectPairDevice peer =
- (OcDirectPairDevice)
- discoveredListObj.
- get(pos);
- OcPlatform.doDirectPairing(peer,
- OcPrmType.convertOcPrmType(prmType),
- pinText.getText().toString(),
- doDPListener);
- } catch (OcException e) {
- Log.d(TAG, "do Direct Pairing error: "
- + e.getMessage());
- Log.e(TAG, e.getMessage());
- }
-
- alertPrmTypeDialog.dismiss();
- } else {
- alertPrmTypeDialog.dismiss();
- }
- }
- }
- });
-
- cancel.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- alertPrmTypeDialog.dismiss();
- }
- });
- }
- });
-
- alertPrmTypeDialog.show();
- }
- });
- alertPinDialog.show();
- }
- });
-
- mListView.setOnItemClickListener(new OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView adapt, View view, int position, long itemId) {
- save.setEnabled(true);
- save.setBackgroundColor(Color.parseColor("#13AEF4"));
- OcDirectPairDevice dpPairDevice =
- (OcDirectPairDevice) adapt.getItemAtPosition(position);
- Log.d(TAG, "DevId On List Item Clicked " + dpPairDevice.getDevId());
- List<Integer> pTypeList = dpPairDevice.getPairingMethodList();
- pList = new int[pTypeList.size()];
- Iterator<Integer> iterator = pTypeList.iterator();
- for(int k = 0; k < pList.length; k++){
- pList[k]=iterator.next().intValue();
- }
- arrayAdapter.clear();
- for (int j = 0; j < pList.length; j++) {
- Log.d(TAG, " List Item Value " + pList[j]);
- OcPrmType prmTy = OcPrmType.convertOcPrmType(pList[j]);
- arrayAdapter.add(prmTy.name());
- }
- }
- });
-
- discoverButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- if (isChecked) {
- save.setEnabled(false);
- save.setBackgroundColor(Color.GRAY);
- new GetDiscoveredItems().execute();
- }
- }
- });
-
- }
-
- @Override
- public void onDestroy() {
- super.onDestroy();
- closeIOCStack();
- }
-
- /**
- * Copy svr db CBOR dat file from assets folder to app data files dir
- */
- private void copyCborFromAsset() {
- InputStream inputStream = null;
- OutputStream outputStream = null;
- int length;
- byte[] buffer = new byte[BUFFER_SIZE];
- try {
- inputStream = getAssets().open(StringConstants.OIC_CLIENT_CBOR_DB_FILE);
- File file = new File(filePath);
- //check files directory exists
- if (!(file.exists() && file.isDirectory())) {
- file.mkdirs();
- }
- outputStream = new FileOutputStream(filePath +
- StringConstants.OIC_CLIENT_CBOR_DB_FILE);
- while ((length = inputStream.read(buffer)) != -1) {
- outputStream.write(buffer, 0, length);
- }
- } catch (NullPointerException e) {
- Log.d(TAG, "Null pointer exception " + e.getMessage());
- Log.e(TAG, e.getMessage());
- } catch (FileNotFoundException e) {
- Log.d(TAG, "CBOR svr db file not found " + e.getMessage());
- Log.e(TAG, e.getMessage());
- } catch (IOException e) {
- Log.d(TAG, StringConstants.OIC_CLIENT_CBOR_DB_FILE + " file copy failed");
- Log.e(TAG, e.getMessage());
- } finally {
- if (inputStream != null) {
- try {
- inputStream.close();
- } catch (IOException e) {
- Log.e(TAG, e.getMessage());
- }
- }
- if (outputStream != null) {
- try {
- outputStream.close();
- } catch (IOException e) {
- Log.e(TAG, e.getMessage());
- }
- }
- }
- }
-
- void exportCBOR() {
- try {
- File sd = Environment.getExternalStorageDirectory();
- File data = Environment.getDataDirectory();
- if (sd.canWrite()) {
- String currentDBPath = "/data/data/" + getPackageName() +
- "/files/" + StringConstants.OIC_CLIENT_CBOR_DB_FILE;
- File currentDB = new File(currentDBPath);
- File backupDB = new File(sd, StringConstants.OIC_CLIENT_CBOR_DB_FILE);
- if (currentDB.exists()) {
- FileChannel src = new FileInputStream(currentDB).getChannel();
- FileChannel dst = new FileOutputStream(backupDB).getChannel();
- dst.transferFrom(src, 0, src.size());
- src.close();
- dst.close();
- }
- }
- } catch (Exception e) {
- Log.e(TAG, e.getMessage());
- }
- }
-
- /**
- * configure OIC platform and call findResource
- */
- private void initOICStack() {
- //create platform config
- PlatformConfig cfg = new PlatformConfig(this, ServiceType.IN_PROC, ModeType.CLIENT_SERVER,
- "0.0.0.0", // bind to all available interfaces
- 0,
- QualityOfService.LOW, filePath + StringConstants.OIC_CLIENT_CBOR_DB_FILE);
- OcPlatform.Configure(cfg);
- try {
- /*
- * Initialize DataBase
- */
- String sqlDbPath = getFilesDir().getAbsolutePath().replace("files", "databases") +
- File.separator;
- File file = new File(sqlDbPath);
- //check files directory exists
- if (!(file.isDirectory())) {
- file.mkdirs();
- Log.d(TAG, "Sql db directory created at " + sqlDbPath);
- }
- Log.d(TAG, "Sql db directory exists at " + sqlDbPath);
- OcProvisioning.provisionInit(sqlDbPath + StringConstants.OIC_SQL_DB_FILE);
- } catch (OcException e) {
- Log.d(TAG, "provisionInit error: " + e.getMessage());
- Log.e(TAG, e.getMessage());
- }
- }
-
- private void closeIOCStack() {
- try {
- /*
- * Close DataBase
- */
- OcProvisioning.provisionClose();
- } catch (OcException e) {
- Log.d(TAG, "provisionClose error: " + e.getMessage());
- Log.e(TAG, e.getMessage());
- }
- }
-
- class GetDiscoveredItems extends AsyncTask<Void, Void, List<String>> {
-
- ProgressDialog pDialog;
-
- @Override
- protected void onPreExecute() {
- pDialog = new ProgressDialog(MainActivity.this);
- pDialog.setMessage("Getting Discovered Items");
- pDialog.setCancelable(false);
- pDialog.setCanceledOnTouchOutside(false);
- pDialog.show();
- }
-
- ;
-
- @Override
- protected List<String> doInBackground(Void... params) {
- try {
- OcPlatform.findDirectPairingDevices(5, finddirectPairing);
- } catch (OcException e) {
- Log.e(TAG, e.getMessage());
- }
- return null;
- }
-
- @Override
- protected void onPostExecute(List<String> discoveredItems) {
- pDialog.dismiss();
- for (Iterator iterator = discoveredListObj.iterator(); iterator.hasNext(); ) {
- OcDirectPairDevice ledResource = (OcDirectPairDevice) iterator.next();
- List<String> lightTypes = new LinkedList<>();
- lightTypes.add("core.led");
- try {
- Log.d(TAG, "Constructing Led Resource");
- led = OcPlatform.constructResourceObject(ledResource.getHost(),
- "/a/led", ledResource.getConnectivityTypeSet(),
- false, //isObservable
- lightTypes,
- resourceInterfaces);
- Log.d(TAG, "Constructed Led Resource");
- } catch (OcException e) {
- Log.e(TAG, e.getMessage());
- }
- }
- }
-
- }
-}
+++ /dev/null
-/*
- * //******************************************************************
- * //
- * // Copyright 2016 Samsung Electronics All Rights Reserved.
- * //
- * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- * //
- * // Licensed under the Apache License, Version 2.0 (the "License");
- * // you may not use this file except in compliance with the License.
- * // You may obtain a copy of the License at
- * //
- * // http://www.apache.org/licenses/LICENSE-2.0
- * //
- * // Unless required by applicable law or agreed to in writing, software
- * // distributed under the License is distributed on an "AS IS" BASIS,
- * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * // See the License for the specific language governing permissions and
- * // limitations under the License.
- * //
- * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- */
-package org.iotivity.base.examples.DirectPairing;
-
-public interface StringConstants {
-
- public static final int NUMBER_ZERO = 0;
- public static final int DISCOVERY_TIMEOUT_10 = 10;
- public static final int DISCOVERY_TIMEOUT_20 = 20;
- public static final int SUCCES_CODE = 0;
- public static final String DEFAULT_ROWNER_ID = "61646d69-6e44-6576-6963-655555494430";
- public static final String DEFAULT_RESOURCES = "*";
- public static final String DEFAULT_RECURRENCES = "Daily";
- public static final String DEFAULT_PERIOD = "12-12-16";
- public static final int DEFAULT_PERMISSION = 31;
- public static final String OIC_CLIENT_CBOR_DB_FILE = "oic_svr_db_client_directpairing.dat";
- public static final String MESSAGE = "message";
- public static final String OIC_SQL_DB_FILE = "Pdm.db";
- public static final int CREDENTIAL_TYPE = 1;
- public static final int OWNER_PSK_LENGTH_128 = 128 / 8;
-}
+++ /dev/null
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"\r
- xmlns:tools="http://schemas.android.com/tools"\r
- android:layout_width="match_parent"\r
- android:layout_height="match_parent"\r
- android:orientation="vertical"\r
- android:paddingBottom="@dimen/activity_vertical_margin"\r
- android:paddingLeft="@dimen/activity_horizontal_margin"\r
- android:paddingRight="@dimen/activity_horizontal_margin"\r
- android:paddingTop="@dimen/activity_vertical_margin"\r
- tools:context="com.example.iot.MainActivity" >\r
-\r
- <LinearLayout\r
- android:layout_width="match_parent"\r
- android:layout_height="wrap_content"\r
- android:weightSum="1" >\r
-\r
- <TextView\r
- android:layout_width="wrap_content"\r
- android:layout_height="wrap_content"\r
- android:layout_weight="0.75"\r
- android:gravity="center"\r
- android:text="@string/discover_items"\r
- android:textSize="18sp" />\r
-\r
- <Switch\r
- android:id="@+id/discover"\r
- android:layout_width="wrap_content"\r
- android:layout_height="wrap_content"\r
- android:layout_weight="0.25" />\r
- </LinearLayout>\r
-\r
- <View\r
- android:layout_width="match_parent"\r
- android:layout_height="2dp"\r
- android:background="#13AEF4" />\r
-\r
- <ListView\r
- android:id="@+id/list_view"\r
- android:layout_width="match_parent"\r
- android:layout_height="250dp" />\r
-\r
- <View\r
- android:layout_width="match_parent"\r
- android:layout_height="2dp"\r
- android:background="#13AEF4" />\r
-\r
- <RelativeLayout\r
- android:id="@+id/relLay"\r
- android:layout_width="fill_parent"\r
- android:layout_height="wrap_content"\r
- android:orientation="horizontal"\r
- android:padding="15dp" >\r
-\r
- <Button\r
- android:id="@+id/saveDiscovered"\r
- android:layout_width="90dp"\r
- android:layout_height="30dp"\r
- android:layout_centerInParent="true"\r
- android:background="#13AEF4"\r
- android:text="Save"\r
- android:textColor="#FFFFFF" />\r
- </RelativeLayout>\r
-\r
- <View\r
- android:layout_width="match_parent"\r
- android:layout_height="2dp"\r
- android:background="#13AEF4" />\r
-\r
- <TextView\r
- android:layout_width="match_parent"\r
- android:layout_height="wrap_content"\r
- android:layout_gravity="center_vertical"\r
- android:paddingLeft="50dp"\r
- android:text="@string/paired_list"\r
- android:textSize="18sp" />\r
-\r
- <View\r
- android:layout_width="match_parent"\r
- android:layout_height="2dp"\r
- android:background="#13AEF4" />\r
-\r
- <ExpandableListView\r
- android:id="@+id/list_view_paired_list"\r
- android:layout_width="fill_parent"\r
- android:layout_height="200dp"\r
- android:paddingTop="5dp"\r
- android:groupIndicator="@null" >\r
- </ExpandableListView>\r
-\r
- <View\r
- android:layout_width="match_parent"\r
- android:layout_height="2dp"\r
- android:background="#13AEF4" />\r
-\r
-</LinearLayout>
\ No newline at end of file
+++ /dev/null
-<?xml version="1.0" encoding="utf-8"?>
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal"
- android:padding="10dp" >
-
- <TextView
- android:id="@+id/textView"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Discovered Items"
- android:layout_centerVertical="true"
- android:layout_gravity="center_vertical"
- android:textColor="#545454"
- android:textSize="15sp" />
-
- <LinearLayout
- android:id="@+id/linearLay"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentRight="true"
- android:layout_centerVertical="true" >
-
- <CheckBox
- android:id="@+id/checkBox"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_centerVertical="true"
- android:layout_gravity="center_vertical"
- android:layout_marginRight="10dp" />
- </LinearLayout>
-
-</RelativeLayout>
\ No newline at end of file
+++ /dev/null
-<selector xmlns:android="http://schemas.android.com/apk/res/android">\r
-Â <item android:drawable="@drawable/arrow_right" android:state_empty="true"></item>\r
-Â Â Â Â <item android:drawable="@drawable/arrow_down" android:state_expanded="true"></item>\r
-Â Â Â Â <item android:drawable="@drawable/arrow_right"></item>\r
-\r
-</selector>
\ No newline at end of file
+++ /dev/null
-<?xml version="1.0" encoding="utf-8"?>\r
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"\r
- android:layout_width="fill_parent"\r
- android:layout_height="40dp"\r
- android:background="#ffffff"\r
- android:orientation="horizontal" >\r
-\r
- <TextView\r
- android:id="@+id/title"\r
- android:layout_width="wrap_content"\r
- android:layout_height="40dp"\r
- android:layout_weight="0.9"\r
- android:gravity="center_vertical"\r
- android:paddingLeft="40dp"\r
- android:text="Items"\r
- android:textColor="#040404"\r
- android:textSize="16sp"\r
- android:textStyle="bold"\r
- android:typeface="sans" />\r
-\r
- <ImageView\r
- android:id="@+id/image"\r
- android:layout_width="wrap_content"\r
- android:layout_height="20dp"\r
- android:layout_gravity="center_vertical"\r
- android:layout_weight="0.1" />\r
-\r
-</LinearLayout>
\ No newline at end of file
+++ /dev/null
-<?xml version="1.0" encoding="utf-8"?>\r
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"\r
- android:layout_width="fill_parent"\r
- android:layout_height="wrap_content"\r
- android:orientation="vertical" >\r
-\r
- <TextView\r
- android:id="@+id/textViewItem"\r
- android:layout_width="wrap_content"\r
- android:layout_height="wrap_content"\r
- android:gravity="center_vertical"\r
- android:paddingLeft="50dp"\r
- android:text="Paired Items"\r
- android:textColor="#545454"\r
- android:textSize="15sp" />\r
-\r
- <TextView\r
- android:id="@+id/textViewSource"\r
- android:layout_below="@id/textViewItem"\r
- android:layout_width="wrap_content"\r
- android:layout_height="wrap_content"\r
- android:gravity="center_vertical"\r
- android:paddingLeft="50dp"\r
- android:text="Paired Source"\r
- android:textColor="#545454"\r
- android:textSize="15sp" />\r
-\r
- <TextView\r
- android:id="@+id/textViewStatus"\r
- android:layout_below="@id/textViewSource"\r
- android:layout_width="wrap_content"\r
- android:layout_height="wrap_content"\r
- android:gravity="center_vertical"\r
- android:paddingLeft="50dp"\r
- android:text="Paired Status"\r
- android:textColor="#545454"\r
- android:textSize="15sp" />\r
-\r
-</RelativeLayout>
\ No newline at end of file
+++ /dev/null
-<menu xmlns:android="http://schemas.android.com/apk/res/android"\r
- xmlns:app="http://schemas.android.com/apk/res-auto"\r
- xmlns:tools="http://schemas.android.com/tools"\r
- tools:context="org.iotivity.base.examples.MainActivity" >\r
-\r
- <item\r
- android:id="@+id/action_settings"\r
- android:orderInCategory="100"\r
- android:title="@string/action_settings"/>\r
-\r
-</menu>\r
+++ /dev/null
-<resources>\r
-\r
- <!--\r
- Base application theme for API 11+. This theme completely replaces
- AppBaseTheme from res/values/styles.xml on API 11+ devices.\r
- -->\r
- <style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">\r
- <!-- API 11 theme customizations can go here. -->\r
- </style>\r
-\r
-</resources>\r
+++ /dev/null
-<resources>\r
-\r
- <!--\r
- Base application theme for API 14+. This theme completely replaces
- AppBaseTheme from BOTH res/values/styles.xml and
- res/values-v11/styles.xml on API 14+ devices.\r
- -->\r
- <style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">\r
- <!-- API 14 theme customizations can go here. -->\r
- </style>\r
-\r
-</resources>\r
+++ /dev/null
-<resources>\r
-\r
- <!--\r
- Example customization of dimensions originally defined in res/values/dimens.xml
- (such as screen margins) for screens with more than 820dp of available width. This
- would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively).\r
- -->\r
- <dimen name="activity_horizontal_margin">64dp</dimen>\r
-\r
-</resources>\r
+++ /dev/null
-<resources>\r
-\r
- <!-- Default screen margins, per the Android Design guidelines. -->\r
- <dimen name="activity_horizontal_margin">16dp</dimen>\r
- <dimen name="activity_vertical_margin">16dp</dimen>\r
-\r
-</resources>\r
+++ /dev/null
-<?xml version="1.0" encoding="utf-8"?>
-<resources>\r
-\r
- <string name="app_name">DirectPairingClient</string>\r
- <string name="discover_items">Discover Resources</string>
- <string name="paired_items">Paired Resources</string>
- <string name="paired_list">Direct Paired Resources</string>\r
- <string name="action_settings">Settings</string>\r
-\r
-</resources>\r
+++ /dev/null
-<resources>\r
-\r
- <!--\r
- Base application theme, dependent on API level. This theme is replaced
- by AppBaseTheme from res/values-vXX/styles.xml on newer devices.\r
- -->\r
- <style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">\r
- <!--\r
- Theme customizations available in newer API levels can go in
- res/values-vXX/styles.xml, while customizations related to
- backward-compatibility can go here.\r
- -->\r
- </style>\r
-\r
- <!-- Application theme. -->\r
- <style name="AppTheme" parent="AppBaseTheme">\r
- <!-- All customizations that are NOT specific to a particular API-level can go here. -->\r
- </style>\r
-\r
-</resources>\r
include ':simpleserver', ':simpleclient', ':fridgeserver', ':fridgeclient', ':guiclient', ':presenceserver', ':presenceclient', ':devicediscoveryclient', ':devicediscoveryserver', ':groupclient', ':groupserver', ':fridgegroupclient', ':fridgegroupserver'
SECURED=System.getProperty('SECURE')
if(SECURED== "1"){
- include ':provisioningclient', ':DirectPairing'
+ include ':provisioningclient'
}
if(SECURED== "1" && WITH_TCP== "1" && WITH_CLOUD== "1"){
include ':cloudprovisioningclient'
throws OcException;
/**
- * Method to find all devices which are eligible for direct pairing and return the list.
- *
- * @param timeout timeout for discovering direct pair devices.
- * @param onFindDirectPairingListener Callback function, which will receive the list of direct
- * pairable devices.
- * @throws OcException
- */
- public static native void findDirectPairingDevices(int timeout,
- FindDirectPairingListener onFindDirectPairingListener) throws OcException;
-
- /**
- * Method to get list of all paired devices for a given device.
- *
- * @param onGetDirectPairedListener Callback function, which will receive the list of direct
- * paired devices.
- * @throws OcException
- */
- public native void getDirectPairedDevices(GetDirectPairedListener onGetDirectPairedListener)
- throws OcException;
-
- /**
- * Method to perform direct pairing between two devices.
- *
- * @param peer Target peer
- * @param prmType Pairing Method to be used for Pairing
- * @param pin pin
- * @param onDirectPairingListener Callback function, which will be called after
- * completion of direct pairing.
- * @throws OcException
- */
- public static void doDirectPairing(
- OcDirectPairDevice peer,
- OcPrmType prmType,
- String pin,
- DirectPairingListener onDirectPairingListener) throws OcException {
-
- OcPlatform.doDirectPairing0(
- peer,
- prmType.getValue(),
- pin,
- onDirectPairingListener
- );
- }
-
- private static native void doDirectPairing0(OcDirectPairDevice peer,
- int pmSel, String pinNumber, DirectPairingListener onDirectPairingListener)
- throws OcException;
-
- /**
- * An FindDirectPairingListener can be registered via the OcPlatform.findDirectPairingDevices call.
- * Event listeners are notified asynchronously
- */
- public interface FindDirectPairingListener {
- public void onFindDirectPairingListener(List<OcDirectPairDevice> ocPairedDeviceList);
- }
-
- /**
- * Listerner to Get List of already Direct Paired devices.
- * An GetDirectPairedListener can be registered via the OcPlatform.getDirectPairedDevices call.
- * Event listeners are notified asynchronously
- */
- public interface GetDirectPairedListener {
- public void onGetDirectPairedListener(List<OcDirectPairDevice> ocPairedDeviceList);
- }
-
- /**
- * Listner to get result of doDirectPairing.
- * An DirectPairingListener can be registered via the OcPlatform.doDirectPairing call.
- * Event listeners are notified asynchronously
- */
- public interface DirectPairingListener {
- public void onDirectPairingListener(String devId, int result);
- }
-
- /**
* An OnResourceFoundListener can be registered via the OcPlatform.findResource call.
* Event listeners are notified asynchronously
*/
throws OcException;
/**
- * Method to find all devices which are eligible for direct pairing and return the list.
- *
- * @param timeout timeout for discovering direct pair devices.
- * @param onFindDirectPairingListener Callback function, which will receive the list of direct
- * pairable devices.
- * @throws OcException
- */
- public static native void findDirectPairingDevices(int timeout,
- FindDirectPairingListener onFindDirectPairingListener) throws OcException;
-
- /**
- * Method to get list of all paired devices for a given device.
- *
- * @param onGetDirectPairedListener Callback function, which will receive the list of direct
- * paired devices.
- * @throws OcException
- */
- public native void getDirectPairedDevices(GetDirectPairedListener onGetDirectPairedListener)
- throws OcException;
-
- /**
- * Method to perform direct pairing between two devices.
- *
- * @param peer Target peer
- * @param prmType Pairing Method to be used for Pairing
- * @param pin pin
- * @param onDirectPairingListener Callback function, which will be called after
- * completion of direct pairing.
- * @throws OcException
- */
- public static void doDirectPairing(
- OcDirectPairDevice peer,
- OcPrmType prmType,
- String pin,
- DirectPairingListener onDirectPairingListener) throws OcException {
-
- OcPlatform.doDirectPairing0(
- peer,
- prmType.getValue(),
- pin,
- onDirectPairingListener
- );
- }
-
- private static native void doDirectPairing0(OcDirectPairDevice peer,
- int pmSel, String pinNumber, DirectPairingListener onDirectPairingListener)
- throws OcException;
-
- /**
- * An FindDirectPairingListener can be registered via the OcPlatform.findDirectPairingDevices call.
- * Event listeners are notified asynchronously
- */
- public interface FindDirectPairingListener {
- public void onFindDirectPairingListener(List<OcDirectPairDevice> ocPairedDeviceList);
- }
-
- /**
- * Listerner to Get List of already Direct Paired devices.
- * An GetDirectPairedListener can be registered via the OcPlatform.getDirectPairedDevices call.
- * Event listeners are notified asynchronously
- */
- public interface GetDirectPairedListener {
- public void onGetDirectPairedListener(List<OcDirectPairDevice> ocPairedDeviceList);
- }
-
- /**
- * Listner to get result of doDirectPairing.
- * An DirectPairingListener can be registered via the OcPlatform.doDirectPairing call.
- * Event listeners are notified asynchronously
- */
- public interface DirectPairingListener {
- public void onDirectPairingListener(String devId, int result);
- }
-
- /**
* An OnResourceFoundListener can be registered via the OcPlatform.findResource call.
* Event listeners are notified asynchronously
*/
+++ /dev/null
-/*
-* //******************************************************************
-* //
-* // Copyright 2016 Samsung Electronics All Rights Reserved.
-* //
-* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-* //
-* // Licensed under the Apache License, Version 2.0 (the "License");
-* // you may not use this file except in compliance with the License.
-* // You may obtain a copy of the License at
-* //
-* // http://www.apache.org/licenses/LICENSE-2.0
-* //
-* // Unless required by applicable law or agreed to in writing, software
-* // distributed under the License is distributed on an "AS IS" BASIS,
-* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* // See the License for the specific language governing permissions and
-* // limitations under the License.
-* //
-* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-*/
-
-#include "JniOcDirectPairDevice.h"
-#include "OCDirectPairing.h"
-#include "OCDirectPairing.h"
-using namespace OC;
-namespace PH = std::placeholders;
-
-JniOcDirectPairDevice::JniOcDirectPairDevice(std::shared_ptr<OC::OCDirectPairing> directPairingDevice)
- : m_sharedDirectPairDevice(directPairingDevice)
-{
-}
-
-JniOcDirectPairDevice::~JniOcDirectPairDevice()
-{
- LOGD("~JniOcDirectPairDevice()");
- m_sharedDirectPairDevice = nullptr;
-}
-
-std::string JniOcDirectPairDevice::getHost()
-{
- return m_sharedDirectPairDevice->getHost();
-}
-
-std::vector<OCPrm_t> JniOcDirectPairDevice::getPairingMethods()
-{
-
- return m_sharedDirectPairDevice->getPairingMethods();
-}
-
-OCConnectivityType JniOcDirectPairDevice::connectivityType()
-{
- return m_sharedDirectPairDevice->getConnType();
-}
-
-JniOcDirectPairDevice* JniOcDirectPairDevice::getJniOcDirectPairDevicePtr(JNIEnv *env, jobject thiz)
-{
- JniOcDirectPairDevice *dpDev = GetHandle<JniOcDirectPairDevice>(env, thiz);
- if (env->ExceptionCheck())
- {
- LOGE("Failed to get native handle from OcDirectPairingDevice");
- }
- if (!dpDev)
- {
- ThrowOcException(JNI_NO_NATIVE_POINTER, "");
- }
- return dpDev;
-}
-std::shared_ptr<OC::OCDirectPairing> JniOcDirectPairDevice::getPtr()
-{
- return m_sharedDirectPairDevice;
-}
-
-JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcDirectPairDevice_getHost
-(JNIEnv *env, jobject thiz)
-{
-
- LOGD("OcDirectPairing_getHost");
-
- JniOcDirectPairDevice* device = JniOcDirectPairDevice::getJniOcDirectPairDevicePtr(env,thiz);
- if (!device)
- {
- return nullptr;
- }
-
- std::string dev = device->getHost();
- return env->NewStringUTF(dev.c_str());
-}
-
-JNIEXPORT jintArray JNICALL Java_org_iotivity_base_OcDirectPairDevice_getPairingMethods
- (JNIEnv *env, jobject thiz)
-{
-
- LOGD("OcDirectPairing_getPairingMethods");
-
- std::vector<jint> pairingMethodList;
- JniOcDirectPairDevice* device = JniOcDirectPairDevice::getJniOcDirectPairDevicePtr(env,thiz);
- if (!device)
- {
- return nullptr;
- }
-
- std::vector<OCPrm_t> pairingMethods = device->getPairingMethods();
- return JniOcDirectPairDevice::JconvertIntVectorToJavaList(env,pairingMethods);
-}
-
-
-jintArray JniOcDirectPairDevice::JconvertIntVectorToJavaList(JNIEnv *env, std::vector<OCPrm_t> &vector)
-{
-
- jsize len = static_cast<jsize>(vector.size());
-
- jintArray intArray = env->NewIntArray(len);
- if (!intArray)
- {
- return nullptr;
- }
-
- env->SetIntArrayRegion(intArray, (jsize)0, len, (const jint*)&vector[0]);
-
- if (env->ExceptionCheck())
- {
- LOGE("ArrayIndexOutOfBoundsException in JconvertIntVectorToJavaList");
- }
- return intArray;
-}
-
-/*
-* Class: org_iotivity_base_OcDirectPairDevice
-* Method: getConnectivityTypeN
-* Signature: ()I
-*/
-JNIEXPORT jint JNICALL Java_org_iotivity_base_OcDirectPairDevice_getConnectivityTypeN
-(JNIEnv *env, jobject thiz)
-{
- LOGD("OcDirectPairDevice_getConnectivityType");
- JniOcDirectPairDevice* device = JniOcDirectPairDevice::getJniOcDirectPairDevicePtr(env,thiz);
- if (!device)
- {
- return -1;
- }
-
- OCConnectivityType connectivityType = device->connectivityType();
- return static_cast<jint>(connectivityType);
-}
+++ /dev/null
-/*
-* //******************************************************************
-* //
-* // Copyright 2016 Samsung Electronics All Rights Reserved.
-* //
-* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-* //
-* // Licensed under the Apache License, Version 2.0 (the "License");
-* // you may not use this file except in compliance with the License.
-* // You may obtain a copy of the License at
-* //
-* // http://www.apache.org/licenses/LICENSE-2.0
-* //
-* // Unless required by applicable law or agreed to in writing, software
-* // distributed under the License is distributed on an "AS IS" BASIS,
-* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* // See the License for the specific language governing permissions and
-* // limitations under the License.
-* //
-* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-*/
-
-#include "JniOcStack.h"
-#include "JniOnDPDevicesFoundListener.h"
-#include "OCDirectPairing.h"
-#include <mutex>
-
-#ifndef _Included_org_iotivity_base_OcDirectPairDevice
-#define _Included_org_iotivity_base_OcDirectPairDevice
-
-class JniOcDirectPairDevice
-{
- public:
- JniOcDirectPairDevice(std::shared_ptr<OC::OCDirectPairing> directPairingDevice);
- ~JniOcDirectPairDevice();
-
- static JniOcDirectPairDevice* getJniOcDirectPairDevicePtr(JNIEnv *env, jobject thiz);
- static jintArray JconvertIntVectorToJavaList(JNIEnv *env, std::vector<OCPrm_t> &vector);
-
- std::shared_ptr<OC::OCDirectPairing> getPtr();
- std::string getHost();
- std::vector<OCPrm_t> getPairingMethods();
- OCConnectivityType connectivityType();
-
- private:
- std::shared_ptr<OC::OCDirectPairing> m_sharedDirectPairDevice;
-};
-
-/* DO NOT EDIT THIS FILE BEYOND THIS LINE - it is machine generated */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
- /*
- * Class: org_iotivity_base_OcDirectPairDevice
- * Method: getDirectPairedDevices
- * Signature: (Lorg/iotivity/base/OcDirectPairDevice/GetDirectPairedListener;)V
- */
- JNIEXPORT void JNICALL Java_org_iotivity_base_OcDirectPairDevice_getDirectPairedDevices
- (JNIEnv *, jobject, jobject);
-
- /*
- * Class: org_iotivity_base_OcDirectPairDevice
- * Method: getHost
- * Signature: ()Ljava/lang/String;
- */
- JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcDirectPairDevice_getHost
- (JNIEnv *, jobject);
-
- /*
- * Class: org_iotivity_base_OcDirectPairDevice
- * Method: getPairingMethods
- * Signature: ()Ljava/util/List;
- */
- JNIEXPORT jintArray JNICALL Java_org_iotivity_base_OcDirectPairDevice_getPairingMethods
- (JNIEnv *, jobject);
-
- /*
- * Class: org_iotivity_base_OcDirectPairDevice
- * Method: doDirectPairing
- * Signature: (Lorg/iotivity/base/OcDirectPairDevice;Lorg/iotivity/base/OcPrmType;
- * Ljava/lang/String;Lorg/iotivity/base/OcDirectPairDevice/DirectPairingListener;)V
- */
- JNIEXPORT void JNICALL Java_org_iotivity_base_OcDirectPairDevice_doDirectPairing
- (JNIEnv *, jobject, jobject, jint, jstring, jobject);
-
- /*
- * Class: org_iotivity_base_OcDirectPairDevice
- * Method: getConnectivityTypeN
- * Signature: ()I
- */
- JNIEXPORT jint JNICALL Java_org_iotivity_base_OcDirectPairDevice_getConnectivityTypeN
- (JNIEnv *env, jobject thiz);
-
-#ifdef __cplusplus
-}
-#endif
-#endif
-
#include "JniOcPresenceHandle.h"
#include "JniOcResourceResponse.h"
#include "JniOcSecurity.h"
-#include "JniOcDirectPairDevice.h"
#include "JniUtils.h"
#include "ocpayload.h"
#include "RDClient.h"
observeMapLock.unlock();
}
-JniOnDPDevicesFoundListener* AddOnDPDevicesFoundListener(JNIEnv* env, jobject jListener)
-{
- JniOnDPDevicesFoundListener *onDPDeviceListener = nullptr;
-
- dpDevicesFoundListenerMapLock.lock();
-
- for (auto it = onDPDevicesFoundListenerMap.begin(); it !=
- onDPDevicesFoundListenerMap.end(); ++it)
- {
- if (env->IsSameObject(jListener, it->first))
- {
- auto refPair = it->second;
- onDPDeviceListener = refPair.first;
- refPair.second++;
- it->second = refPair;
- onDPDevicesFoundListenerMap.insert(*it);
- LOGD("onDPDeviceListener: ref. count incremented");
- break;
- }
- }
- if (!onDPDeviceListener)
- {
- onDPDeviceListener = new JniOnDPDevicesFoundListener(env, jListener,
- RemoveOnDPDevicesFoundListener);
- jobject jgListener = env->NewGlobalRef(jListener);
- onDPDevicesFoundListenerMap.insert(
- std::pair<jobject, std::pair<JniOnDPDevicesFoundListener*, int>>(
- jgListener,
- std::pair<JniOnDPDevicesFoundListener*, int>(onDPDeviceListener, 1)));
- LOGI("onDPDeviceListener: new listener");
- }
- dpDevicesFoundListenerMapLock.unlock();
- return onDPDeviceListener;
-}
-
-void RemoveOnDPDevicesFoundListener(JNIEnv* env, jobject jListener)
-{
- dpDevicesFoundListenerMapLock.lock();
- bool isFound = false;
- for (auto it = onDPDevicesFoundListenerMap.begin(); it !=
- onDPDevicesFoundListenerMap.end(); ++it)
- {
- if (env->IsSameObject(jListener, it->first))
- {
- auto refPair = it->second;
- if (refPair.second > 1)
- {
- refPair.second--;
- it->second = refPair;
- onDPDevicesFoundListenerMap.insert(*it);
- LOGI("onDPDeviceListener: ref. count decremented");
- }
- else
- {
- env->DeleteGlobalRef(it->first);
- JniOnDPDevicesFoundListener* listener = refPair.first;
- delete listener;
- onDPDevicesFoundListenerMap.erase(it);
- LOGI("onDPDeviceListener is removed");
- }
- isFound = true;
- break;
- }
- }
- if (!isFound)
- {
- ThrowOcException(JNI_EXCEPTION, "onDPDeviceListener not found");
- }
- dpDevicesFoundListenerMapLock.unlock();
-}
-
-JniOnDirectPairingListener* AddOnDirectPairingListener(JNIEnv* env, jobject jListener)
-{
- JniOnDirectPairingListener *onDirectPairingListener = nullptr;
-
- directPairingListenerMapLock.lock();
-
- for (auto it = directPairingListenerMap.begin(); it !=
- directPairingListenerMap.end(); ++it)
- {
- if (env->IsSameObject(jListener, it->first))
- {
- auto refPair = it->second;
- onDirectPairingListener = refPair.first;
- refPair.second++;
- it->second = refPair;
- directPairingListenerMap.insert(*it);
- LOGD("onDirectPairingListener: ref. count incremented");
- break;
- }
- }
- if (!onDirectPairingListener)
- {
- onDirectPairingListener = new JniOnDirectPairingListener(env, jListener,
- RemoveOnDirectPairingListener);
- jobject jgListener = env->NewGlobalRef(jListener);
- directPairingListenerMap.insert(
- std::pair<jobject, std::pair<JniOnDirectPairingListener*, int>>(
- jgListener,
- std::pair<JniOnDirectPairingListener*, int>(onDirectPairingListener, 1)));
- LOGI("onDirectPairingListener: new listener");
- }
- directPairingListenerMapLock.unlock();
- return onDirectPairingListener;
-}
-
-void RemoveOnDirectPairingListener(JNIEnv* env, jobject jListener)
-{
- directPairingListenerMapLock.lock();
- bool isFound = false;
- for (auto it = directPairingListenerMap.begin(); it !=
- directPairingListenerMap.end(); ++it)
- {
- if (env->IsSameObject(jListener, it->first))
- {
- auto refPair = it->second;
- if (refPair.second > 1)
- {
- refPair.second--;
- it->second = refPair;
- directPairingListenerMap.insert(*it);
- LOGI("onDirectPairingListener: ref. count decremented");
- }
- else
- {
- env->DeleteGlobalRef(it->first);
- JniOnDirectPairingListener* listener = refPair.first;
- delete listener;
- directPairingListenerMap.erase(it);
- LOGI("onDirectPairingListener is removed");
- }
- isFound = true;
- break;
- }
- }
- if (!isFound)
- {
- ThrowOcException(JNI_EXCEPTION, "onDirectPairingListener not found");
- }
- directPairingListenerMapLock.unlock();
-}
-
/*
* Class: org_iotivity_base_OcPlatform
* Method: configure
}
/*
- * Class: org_iotivity_base_OcPlatform
- * Method: findDirectPairingDevices
- * Signature: (ILorg/iotivity/base/OcPlatform/FindDirectPairingListener;)V
- */
-JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_findDirectPairingDevices
- (JNIEnv * env, jclass clazz, jint jTimeout, jobject jListener)
-{
- OC_UNUSED(clazz);
- LOGD("OcPlatform_findDirectPairingDevices");
- if (jTimeout > USHRT_MAX)
- {
- ThrowOcException(OC_STACK_INVALID_PARAM, "timeout exceeds max timeout.");
- return;
- }
- if (!jListener)
- {
- ThrowOcException(OC_STACK_INVALID_PARAM, "onDPDevicesFoundListener cannot be null");
- return;
- }
- JniOnDPDevicesFoundListener *onDPDevsFoundListener = AddOnDPDevicesFoundListener(env,
- jListener);
-
- GetDirectPairedCallback getDirectPairedCallback =
- [onDPDevsFoundListener](PairedDevices pairingDevList)
- {
- onDPDevsFoundListener->directPairingDevicesCallback(pairingDevList,
- DPFunc::FIND_DIRECT_PAIRED_DEV_LIST);
- };
-
-
- try
- {
- OCStackResult result = OCPlatform::findDirectPairingDevices(
- static_cast<unsigned short>(jTimeout), getDirectPairedCallback);
- if (OC_STACK_OK != result)
- {
- ThrowOcException(result, "OCPlatform::findDirectPairingDevices has failed");
- return;
- }
- }
- catch (OCException& e)
- {
- LOGE("%s", e.reason().c_str());
- ThrowOcException(e.code(), e.reason().c_str());
- }
-}
-
-/*
- * Class: org_iotivity_base_OcPlatform
- * Method: getDirectPairedDevices
- * Signature: (Lorg/iotivity/base/OcDirectPairDevice/GetDirectPairedListener;)V
- */
-JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_getDirectPairedDevices
-(JNIEnv *env, jclass jclazz, jobject jListener)
-{
- OC_UNUSED(jclazz);
- LOGD("OcPlatform_getDirectPairedDevices");
-
- if (!jListener)
- {
- ThrowOcException(OC_STACK_INVALID_PARAM, "getPairedDevList Callback cannot be null");
- return;
- }
- JniOnDPDevicesFoundListener *onGetPairedDevicesListener = AddOnDPDevicesFoundListener(env,
- jListener);
-
- GetDirectPairedCallback getDirectPairedCallback =
- [onGetPairedDevicesListener](PairedDevices pairedDevList)
- {
- onGetPairedDevicesListener->directPairingDevicesCallback(pairedDevList,
- DPFunc::GET_PAIRED_DEV_LIST);
- };
-
- try
- {
- OCStackResult result = OCPlatform::getDirectPairedDevices(getDirectPairedCallback);
- if (OC_STACK_OK != result)
- {
- ThrowOcException(result, "OcDirectPairDevice_getDirectPairedDevices");
- return;
- }
- }
- catch (OCException& e)
- {
- LOGE("%s", e.reason().c_str());
- ThrowOcException(e.code(), e.reason().c_str());
- }
-}
-
-/*
- * Class: org_iotivity_base_OcPlatform
- * Method: doDirectPairing
- * Signature: (Lorg/iotivity/base/OcDirectPairDevice;Lorg/iotivity/base/OcPrmType;
- * Ljava/lang/String;Lorg/iotivity/base/OcDirectPairDevice/DirectPairingListener;)V
- */
-JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_doDirectPairing0
-(JNIEnv *env, jclass clazz, jobject jpeer, jint jprmType, jstring jpin, jobject jListener)
-{
- OC_UNUSED(clazz);
- LOGD("OcPlatform_doDirectPairing");
-
- if (!jListener)
- {
- ThrowOcException(OC_STACK_INVALID_PARAM, "doDirectPairing Callback cannot be null");
- return;
- }
- if (!jpeer)
- {
- ThrowOcException(OC_STACK_INVALID_PARAM, "Peer cannot be null");
- return;
- }
-
- JniOnDirectPairingListener *onDirectPairingListener = AddOnDirectPairingListener(env,
- jListener);
-
- DirectPairingCallback DirectPairingCB =
- [onDirectPairingListener](std::shared_ptr<OCDirectPairing> dpDev, OCStackResult result)
- {
- onDirectPairingListener->doDirectPairingCB(dpDev, result);
- };
-
- JniOcDirectPairDevice *dev = JniOcDirectPairDevice::getJniOcDirectPairDevicePtr(env, jpeer);
-
- if (!dev)
- {
- return ;
- }
- std::string pin = env->GetStringUTFChars(jpin, 0);
-
- try
- {
- OCStackResult result = OCPlatform::doDirectPairing(dev->getPtr(), (OCPrm_t)jprmType,
- pin, DirectPairingCB);
- if (OC_STACK_OK != result)
- {
- ThrowOcException(result, "OcPlatform_oDirectPairing");
- return;
- }
- }
- catch (OCException& e)
- {
- LOGE("%s", e.reason().c_str());
- ThrowOcException(e.code(), e.reason().c_str());
- }
-}
-
-/*
* Class: org_iotivity_base_OcPlatform
* Method: getDeviceInfo0
* Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnDeviceFoundListener;)V
#include "JniOnResourcesFoundListener.h"
#include "JniOnDeviceInfoListener.h"
#include "JniOnPlatformInfoListener.h"
-#include "JniOnDPDevicesFoundListener.h"
-#include "JniOnDirectPairingListener.h"
#include "JniOnPresenceListener.h"
#include "JniOnObserveListener.h"
JniOnObserveListener* AddOnObserveListener(JNIEnv* env, jobject jListener);
void RemoveOnObserveListener(JNIEnv* env, jobject jListener);
-JniOnDPDevicesFoundListener* AddOnDPDevicesFoundListener(JNIEnv* env, jobject jListener);
-void RemoveOnDPDevicesFoundListener(JNIEnv* env, jobject jListener);
-
-JniOnDirectPairingListener* AddOnDirectPairingListener(JNIEnv* env, jobject jListener);
-void RemoveOnDirectPairingListener(JNIEnv* env, jobject jListener);
-
std::map<jobject, std::pair<JniOnResourceFoundListener*, int>> onResourceFoundListenerMap;
std::map<jobject, std::pair<JniOnResourcesFoundListener*, int>> onResourcesFoundListenerMap;
std::map<jobject, std::pair<JniOnDeviceInfoListener*, int>> onDeviceInfoListenerMap;
std::map<jobject, std::pair<JniOnPlatformInfoListener*, int>> onPlatformInfoListenerMap;
std::map<jobject, std::pair<JniOnPresenceListener*, int>> onPresenceListenerMap;
std::map<jobject, std::pair<JniOnObserveListener*, int>> onObserveListenerMap;
-std::map<jobject, std::pair<JniOnDPDevicesFoundListener*, int>> onDPDevicesFoundListenerMap;
-std::map<jobject, std::pair<JniOnDirectPairingListener*, int>> directPairingListenerMap;
std::mutex resourceFoundMapLock;
std::mutex resourcesFoundMapLock;
std::mutex platformInfoMapLock;
std::mutex presenceMapLock;
std::mutex observeMapLock;
-std::mutex dpDevicesFoundListenerMapLock;
-std::mutex directPairingListenerMapLock;
#ifdef __cplusplus
extern "C" {
(JNIEnv *, jclass, jobject);
/*
- * Class: org_iotivity_base_OcPlatform
- * Method: findDirectPairingDevices
- * Signature: (ILorg/iotivity/base/OcPlatform/FindDirectPairingListener;)V
- */
- JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_findDirectPairingDevices
- (JNIEnv *, jclass, jint, jobject);
-
- /*
- * Class: org_iotivity_base_OcPlatform
- * Method: getDirectPairedDevices
- * Signature: (Lorg/iotivity/base/OcDirectPairDevice/GetDirectPairedListener;)V
- */
- JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_getDirectPairedDevices
- (JNIEnv *, jclass, jobject);
-
- /*
- * Class: org_iotivity_base_OcPlatform
- * Method: doDirectPairing
- * Signature: (Lorg/iotivity/base/OcDirectPairDevice;Lorg/iotivity/base/OcPrmType;
- * Ljava/lang/String;Lorg/iotivity/base/OcDirectPairDevice/DirectPairingListener;)V
- */
- JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_doDirectPairing0
- (JNIEnv *, jclass, jobject, jint, jstring, jobject);
-
- /*
* Class: org_iotivity_base_OcPlatform
* Method: constructAccountManagerObject0
* Signature: (Ljava/lang/String;I)Lorg/iotivity/base/OcAccountManager;
return ret;
}
-OCStackResult JniOcSecureResource::provisionDirectPairing(JNIEnv* env, jobjectArray jpdacls,
- jobject jListener, std::string pin, std::vector<int> prms, int edp)
-{
- OCStackResult ret;
- JniProvisionResultListner *resultListener = AddProvisionResultListener(env, jListener);
-
- jsize len = env->GetArrayLength(jpdacls);
-
- OicSecPconf_t *pconf = nullptr;
- OicSecPdAcl_t *head = nullptr;
-
- for (jsize i = 0; i < len; ++i)
- {
- OicSecPdAcl_t *pdacl = new OicSecPdAcl_t;
- if (!pdacl)
- {
- return OC_STACK_NO_MEMORY;
- }
-
- memset(pdacl, 0, sizeof(OicSecPdAcl_t));
- pdacl->next = nullptr;
-
- jobject jpdacl = env->GetObjectArrayElement(jpdacls, i);
-
- if (OC_STACK_OK != JniSecureUtils::convertJavaPdACLToOCAcl(env, jpdacl, pdacl))
- {
- delete pdacl;
- return OC_STACK_ERROR;
- }
-
- pdacl->next = head;
- head = pdacl;
- }
-
- pconf = new OicSecPconf_t;
- memset(pconf, 0, sizeof(OicSecPconf_t));
- pconf->edp = (edp != 0);
- pconf->prmLen = prms.size();
- pconf->prm = new OicSecPrm_t[pconf->prmLen];
- pconf->pddevLen = 0;
-
- for (size_t i = 0 ; i < prms.size(); i++)
- pconf->prm[i] = (OicSecPrm_t)prms[i];
-
- memcpy(pconf->pin.val, pin.c_str(), DP_PIN_LENGTH);
- pconf->pdacls = head;
-
- ResultCallBack resultCallback = [head, resultListener, pconf, prms]
- (PMResultList_t *result, int hasError)
- {
- OicSecPdAcl_t *tmp1, *tmp2;
- tmp1 = head;
- while (tmp1)
- {
- tmp2 = tmp1->next;
- delete tmp1;
- tmp1 = tmp2;
- }
-
- delete[] pconf->prm;
- delete pconf;
- resultListener->ProvisionResultCallback(result, hasError, ListenerFunc::PROVISIONDIRECTPAIRING);
- };
-
- ret = m_sharedSecureResource->provisionDirectPairing(pconf, resultCallback);
-
- if (ret != OC_STACK_OK)
- {
- OicSecPdAcl_t *tmp1, *tmp2;
- tmp1 = head;
- while (tmp1)
- {
- tmp2 = tmp1->next;
- delete tmp1;
- tmp1 = tmp2;
- }
-
- delete[] pconf->prm;
- delete pconf;
- }
- return ret;
-}
-
OCStackResult JniOcSecureResource::provisionPairwiseDevices(JNIEnv* env, jint type, jint keySize,
jobject _acl1, jobject _device2, jobject _acl2, jobject jListener)
{
/*
* Class: org_iotivity_base_OcSecureResource
- * Method: provisionDirectPairing
- * Signature: (Ljava/lang/String;[Lorg/iotivity/base/OicSecPdAcl;ILorg/iotivity/base/OcSecureResource/ProvisionDirectPairingListener;I)V
- */
-JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_provisionDirectPairing
-(JNIEnv *env, jobject thiz, jstring jpin, jobjectArray pdacls, jintArray jprmType,
- jint jedp, jobject jListener)
-{
- LOGD("OcSecureResource_provisionDirectPairing");
- if (!jListener)
- {
- ThrowOcException(OC_STACK_INVALID_CALLBACK, "Invalid Callback");
- return;
- }
- if (!pdacls || !jpin || ! jprmType)
- {
- ThrowOcException(OC_STACK_INVALID_PARAM, "Invalid Parameters");
- return;
- }
- std::string pin = env->GetStringUTFChars(jpin, nullptr);
-
- JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz);
- if (!secureResource)
- {
- ThrowOcException(OC_STACK_ERROR, "getJniOcSecureResourcePtr failed");
- return;
- }
-
- const jsize len = env->GetArrayLength(jprmType);
- jint* ints = env->GetIntArrayElements(jprmType, nullptr);
- std::vector<int> value;
- for (jsize i = 0; i < len; ++i)
- {
- value.push_back(static_cast<int>(ints[i]));
- }
- env->ReleaseIntArrayElements(jprmType, ints, JNI_ABORT);
-
- try
- {
- OCStackResult result = secureResource->provisionDirectPairing(env, pdacls, jListener,
- pin, value, static_cast<int>(jedp));
- if (OC_STACK_OK != result)
- {
- ThrowOcException(result, "OcSecureResource_provisionDirectPairing");
- return;
- }
- }
- catch (OCException& e)
- {
- LOGE("%s", e.reason().c_str());
- ThrowOcException(e.code(), e.reason().c_str());
- }
-}
-
-/*
- * Class: org_iotivity_base_OcSecureResource
* Method: selectMOTMethod0
* Signature: (ILorg/iotivity/base/OcSecureResource/SelectOTMMethodListener;)V
*/
jobject jListener);
OCStackResult unlinkDevices(JNIEnv* env, jobject device2, jobject jListener);
OCStackResult removeDevice(JNIEnv* env, jint timeout, jobject jListener);
- OCStackResult provisionDirectPairing(JNIEnv* env, jobjectArray jpdacls,jobject jListener,
- std::string pin, std::vector<int> prms, int edp);
OCStackResult selectMOTMethod(JNIEnv* env, jint oxmSel, jobject jListener);
OCStackResult changeMOTMode(JNIEnv* env, jint momType, jobject jListener);
OCStackResult addPreconfigPIN(JNIEnv* env, std::string pin, int size);
/*
* Class: org_iotivity_base_OcSecureResource
- * Method: provisionDirectPairing
- * Signature: (Ljava/lang/Object;Lorg/iotivity/base/OcSecureResource/ProvisionDirectPairingListener;)V
- */
-JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_provisionDirectPairing
- (JNIEnv *, jobject, jstring, jobjectArray, jintArray, jint, jobject);
-
-/*
- * Class: org_iotivity_base_OcSecureResource
* Method: getLinkedDevices
* Signature: ()Ljava/util/List;
*/
jclass g_cls_OcOicSecAcl_resr = nullptr;
jclass g_cls_OcOicSecAcl_validity = nullptr;
jclass g_cls_OcOicSecPdAcl = nullptr;
-jclass g_cls_OcDirectPairDevice = nullptr;
#ifdef WITH_CLOUD
jclass g_cls_OcAccountManager = nullptr;
jmethodID g_mid_OcResourceIdentifier_N_ctor = nullptr;
jmethodID g_mid_OcProvisionResult_ctor = nullptr;
jmethodID g_mid_OcSecureResource_ctor = nullptr;
-jmethodID g_mid_OcDirectPairDevice_ctor = nullptr;
-jmethodID g_mid_OcDirectPairDevice_dev_ctor = nullptr;
#ifdef WITH_CLOUD
jmethodID g_mid_OcAccountManager_ctor = nullptr;
#endif
g_mid_OcProvisionResult_ctor = env->GetMethodID(g_cls_OcProvisionResult, "<init>", "(Ljava/lang/String;I)V");
VERIFY_VARIABLE_NULL(g_mid_OcProvisionResult_ctor);
- //OcDirectPairDevice
- clazz = env->FindClass("org/iotivity/base/OcDirectPairDevice");
- VERIFY_VARIABLE_NULL(clazz);
- g_cls_OcDirectPairDevice = (jclass)env->NewGlobalRef(clazz);
- g_mid_OcDirectPairDevice_ctor = env->GetMethodID(g_cls_OcDirectPairDevice, "<init>", "(J)V");
- VERIFY_VARIABLE_NULL(g_mid_OcDirectPairDevice_ctor);
-
- g_mid_OcDirectPairDevice_dev_ctor = env->GetMethodID(g_cls_OcDirectPairDevice, "<init>", "(Ljava/lang/String;)V");
- VERIFY_VARIABLE_NULL(g_mid_OcDirectPairDevice_dev_ctor);
- env->DeleteLocalRef(clazz);
-
#ifdef WITH_CLOUD
//OcAccountManager
clazz = env->FindClass("org/iotivity/base/OcAccountManager");
env->DeleteGlobalRef(g_cls_OcResourceIdentifier);
env->DeleteGlobalRef(g_cls_OcSecureResource);
env->DeleteGlobalRef(g_cls_OcProvisionResult);
- env->DeleteGlobalRef(g_cls_OcDirectPairDevice);
env->DeleteGlobalRef(g_cls_byte1DArray);
env->DeleteGlobalRef(g_cls_byte2DArray);
env->DeleteGlobalRef(g_cls_byte3DArray);
+++ /dev/null
-/*
-* //******************************************************************
-* //
-* // Copyright 2016 Samsung Electronics All Rights Reserved.
-* //
-* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-* //
-* // Licensed under the Apache License, Version 2.0 (the "License");
-* // you may not use this file except in compliance with the License.
-* // You may obtain a copy of the License at
-* //
-* // http://www.apache.org/licenses/LICENSE-2.0
-* //
-* // Unless required by applicable law or agreed to in writing, software
-* // distributed under the License is distributed on an "AS IS" BASIS,
-* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* // See the License for the specific language governing permissions and
-* // limitations under the License.
-* //
-* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-*/
-#include "JniOnDPDevicesFoundListener.h"
-#include "JniOcDirectPairDevice.h"
-#include "OCApi.h"
-using namespace OC;
-
-JniOnDPDevicesFoundListener::JniOnDPDevicesFoundListener(JNIEnv *env, jobject jListener,
- RemoveListenerCallback removeListenerCallback)
-{
- m_jwListener = env->NewWeakGlobalRef(jListener);
- m_removeListenerCallback = removeListenerCallback;
-}
-
-jobject JniOnDPDevicesFoundListener::convertdpDevVectorToJavaList(JNIEnv *env, PairedDevices DPdevList)
-{
- jobject jResultList = env->NewObject(g_cls_LinkedList, g_mid_LinkedList_ctor);
- if (!jResultList)
- {
- return nullptr;
- }
-
- for (size_t i = 0; i < DPdevList.size(); ++i)
- {
- JniOcDirectPairDevice *device = new JniOcDirectPairDevice(DPdevList.at(i));
- if (!device)
- {
- return nullptr;
- }
-
- jstring jStr = env->NewStringUTF(((DPdevList.at(i))->getDeviceID()).c_str());
- if (!jStr)
- {
- return nullptr;
- }
- jobject jresult = env->NewObject(g_cls_OcDirectPairDevice,
- g_mid_OcDirectPairDevice_dev_ctor,jStr);
- if (!jresult)
- {
- return nullptr;
- }
-
- SetHandle<JniOcDirectPairDevice>(env, jresult, device);
-
- env->CallBooleanMethod(jResultList, g_mid_LinkedList_add_object, jresult);
- if (env->ExceptionCheck())
- {
- return nullptr;
- }
- env->DeleteLocalRef(jresult);
- env->DeleteLocalRef(jStr);
- }
- return jResultList;
-}
-
-JniOnDPDevicesFoundListener::~JniOnDPDevicesFoundListener()
-{
- LOGI("~JniOnDPDevicesFoundListener()");
- if (m_jwListener)
- {
- jint ret = JNI_ERR;
- JNIEnv *env = GetJNIEnv(ret);
- if (nullptr == env)
- {
- return;
- }
- env->DeleteWeakGlobalRef(m_jwListener);
- m_jwListener = nullptr;
- if (JNI_EDETACHED == ret)
- {
- g_jvm->DetachCurrentThread();
- }
- }
-}
-
-void JniOnDPDevicesFoundListener::directPairingDevicesCallback(PairedDevices paringDevicesList, DPFunc func)
-{
- jint ret = JNI_ERR;
- JNIEnv *env = GetJNIEnv(ret);
- if (nullptr == env)
- {
- return;
- }
-
- jobject jListener = env->NewLocalRef(m_jwListener);
- if (!jListener)
- {
- checkExAndRemoveListener(env);
- if (JNI_EDETACHED == ret)
- {
- g_jvm->DetachCurrentThread();
- }
- return;
- }
-
- jclass clsL = env->GetObjectClass(jListener);
-
- if (!clsL)
- {
- checkExAndRemoveListener(env);
- if (JNI_EDETACHED == ret)
- {
- g_jvm->DetachCurrentThread();
- }
- return;
- }
-
- jobject jpairingDevicesList = convertdpDevVectorToJavaList(env, paringDevicesList);
- std::string calledFunc;
- switch (func)
- {
- case DPFunc::FIND_DIRECT_PAIRED_DEV_LIST:
- {
- calledFunc = "onFindDirectPairingListener";
- }
- break;
- case DPFunc::GET_PAIRED_DEV_LIST:
- {
- calledFunc = "onGetDirectPairedListener";
- }
- break;
- default:
- {
- checkExAndRemoveListener(env);
- if (JNI_EDETACHED == ret)
- {
- g_jvm->DetachCurrentThread();
- }
- }
- return;
- }
-
- jmethodID midL = env->GetMethodID(clsL, calledFunc.c_str(), "(Ljava/util/List;)V");
-
- if (!midL)
- {
- checkExAndRemoveListener(env);
- if (JNI_EDETACHED == ret)
- {
- g_jvm->DetachCurrentThread();
- }
- return;
- }
-
- env->CallVoidMethod(jListener, midL, jpairingDevicesList);
- if (env->ExceptionCheck())
- {
- LOGE("Java exception is thrown");
- }
-
- checkExAndRemoveListener(env);
- if (JNI_EDETACHED == ret)
- {
- g_jvm->DetachCurrentThread();
- }
-}
-
-void JniOnDPDevicesFoundListener::checkExAndRemoveListener(JNIEnv* env)
-{
- if (env->ExceptionCheck())
- {
- jthrowable ex = env->ExceptionOccurred();
- env->ExceptionClear();
- m_removeListenerCallback(env, m_jwListener);
- env->Throw((jthrowable)ex);
- }
- else
- {
- m_removeListenerCallback(env, m_jwListener);
- }
-}
+++ /dev/null
-/*
-* //******************************************************************
-* //
-* // Copyright 2016 Samsung Electronics All Rights Reserved.
-* //
-* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-* //
-* // Licensed under the Apache License, Version 2.0 (the "License");
-* // you may not use this file except in compliance with the License.
-* // You may obtain a copy of the License at
-* //
-* // http://www.apache.org/licenses/LICENSE-2.0
-* //
-* // Unless required by applicable law or agreed to in writing, software
-* // distributed under the License is distributed on an "AS IS" BASIS,
-* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* // See the License for the specific language governing permissions and
-* // limitations under the License.
-* //
-* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-*/
-#include <jni.h>
-#include "OCDirectPairing.h"
-#include "OCApi.h"
-#include "JniOcStack.h"
-
-#ifndef _Included_org_iotivity_base_OcPlatform_JniOnDPDevicesFoundListener
-#define _Included_org_iotivity_base_OcPlatform_JniOnDPDevicesFoundListener
-
-enum class DPFunc
-{
- FIND_DIRECT_PAIRED_DEV_LIST = 1,
- GET_PAIRED_DEV_LIST,
-};
-
-class JniOnDPDevicesFoundListener
-{
-public:
- JniOnDPDevicesFoundListener(JNIEnv *env, jobject jListener,
- RemoveListenerCallback removeListenerCallback);
- ~JniOnDPDevicesFoundListener();
-
- jobject convertdpDevVectorToJavaList(JNIEnv *env, OC::PairedDevices DPdevList);
- void directPairingDevicesCallback(OC::PairedDevices paringDevicesList, DPFunc);
-
-private:
- RemoveListenerCallback m_removeListenerCallback;
- jweak m_jwListener;
- void checkExAndRemoveListener(JNIEnv* env);
-};
-#endif
+++ /dev/null
-/*
-* //******************************************************************
-* //
-* // Copyright 2016 Samsung Electronics All Rights Reserved.
-* //
-* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-* //
-* // Licensed under the Apache License, Version 2.0 (the "License");
-* // you may not use this file except in compliance with the License.
-* // You may obtain a copy of the License at
-* //
-* // http://www.apache.org/licenses/LICENSE-2.0
-* //
-* // Unless required by applicable law or agreed to in writing, software
-* // distributed under the License is distributed on an "AS IS" BASIS,
-* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* // See the License for the specific language governing permissions and
-* // limitations under the License.
-* //
-* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-*/
-#include "JniOnDirectPairingListener.h"
-#include "JniOcDirectPairDevice.h"
-#include "OCDirectPairing.h"
-#include "OCApi.h"
-using namespace OC;
-
-JniOnDirectPairingListener::JniOnDirectPairingListener(JNIEnv *env, jobject jListener,
- RemoveListenerCallback removeListenerCallback)
-{
- m_jwListener = env->NewWeakGlobalRef(jListener);
- m_removeListenerCallback = removeListenerCallback;
-}
-
-
-JniOnDirectPairingListener::~JniOnDirectPairingListener()
-{
- LOGI("~JniOnDirectPairingListener()");
- if (m_jwListener)
- {
- jint ret = JNI_ERR;
- JNIEnv *env = GetJNIEnv(ret);
- if (nullptr == env)
- {
- return;
- }
- env->DeleteWeakGlobalRef(m_jwListener);
- m_jwListener = nullptr;
- if (JNI_EDETACHED == ret)
- {
- g_jvm->DetachCurrentThread();
- }
- }
-}
-
-void JniOnDirectPairingListener::doDirectPairingCB(std::shared_ptr<OC::OCDirectPairing> dpDev,
- OCStackResult result)
-{
- jint ret = JNI_ERR;
- JNIEnv *env = GetJNIEnv(ret);
- if (nullptr == env)
- {
- return;
- }
-
- jobject jListener = env->NewLocalRef(m_jwListener);
- if (!jListener)
- {
- checkExAndRemoveListener(env);
- if (JNI_EDETACHED == ret)
- {
- g_jvm->DetachCurrentThread();
- }
- return;
- }
-
- jclass clsL = env->GetObjectClass(jListener);
- if (!clsL)
- {
- checkExAndRemoveListener(env);
- if (JNI_EDETACHED == ret)
- {
- g_jvm->DetachCurrentThread();
- }
- return;
- }
-
- JniOcDirectPairDevice *device = new JniOcDirectPairDevice(dpDev);
- if (!device)
- {
- return;
- }
-
- jstring jStr = env->NewStringUTF((dpDev->getDeviceID()).c_str());
- if (!jStr)
- {
- checkExAndRemoveListener(env);
- if (JNI_EDETACHED == ret)
- {
- g_jvm->DetachCurrentThread();
- }
- return;
- }
-
- jobject jresult = env->NewObject(g_cls_OcDirectPairDevice, g_mid_OcDirectPairDevice_ctor);
- if (!jresult)
- {
- checkExAndRemoveListener(env);
- if (JNI_EDETACHED == ret)
- {
- g_jvm->DetachCurrentThread();
- }
- return;
- }
-
- SetHandle<JniOcDirectPairDevice>(env, jresult, device);
-
- jint jres = static_cast<jint>(result);
-
- jmethodID midL = env->GetMethodID(clsL, "onDirectPairingListener", "(Ljava/lang/String;I)V");
-
- if (!midL)
- {
- checkExAndRemoveListener(env);
- if (JNI_EDETACHED == ret)
- {
- g_jvm->DetachCurrentThread();
- }
- return;
- }
-
- env->CallVoidMethod(jListener, midL, jStr, jres);
- if (env->ExceptionCheck())
- {
- LOGE("Java exception is thrown");
- }
-
- checkExAndRemoveListener(env);
-
- if (JNI_EDETACHED == ret)
- {
- g_jvm->DetachCurrentThread();
- }
-}
-
-void JniOnDirectPairingListener::checkExAndRemoveListener(JNIEnv* env)
-{
- if (env->ExceptionCheck())
- {
- jthrowable ex = env->ExceptionOccurred();
- env->ExceptionClear();
- m_removeListenerCallback(env, m_jwListener);
- env->Throw((jthrowable)ex);
- }
- else
- {
- m_removeListenerCallback(env, m_jwListener);
- }
-}
+++ /dev/null
-/*
-* //******************************************************************
-* //
-* // Copyright 2016 Samsung Electronics All Rights Reserved.
-* //
-* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-* //
-* // Licensed under the Apache License, Version 2.0 (the "License");
-* // you may not use this file except in compliance with the License.
-* // You may obtain a copy of the License at
-* //
-* // http://www.apache.org/licenses/LICENSE-2.0
-* //
-* // Unless required by applicable law or agreed to in writing, software
-* // distributed under the License is distributed on an "AS IS" BASIS,
-* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* // See the License for the specific language governing permissions and
-* // limitations under the License.
-* //
-* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-*/
-#include <jni.h>
-#include "OCDirectPairing.h"
-#include "JniOcStack.h"
-
-#ifndef _Included_org_iotivity_base_OcPlatform_JniOnDirectPairingListener
-#define _Included_org_iotivity_base_OcPlatform_JniOnDirectPairingListener
-
-class JniOnDirectPairingListener
-{
-public:
- JniOnDirectPairingListener(JNIEnv *env, jobject jListener,
- RemoveListenerCallback removeListenerCallback);
- ~JniOnDirectPairingListener();
-
- void doDirectPairingCB(std::shared_ptr<OC::OCDirectPairing>, OCStackResult);
-
-private:
- RemoveListenerCallback m_removeListenerCallback;
- jweak m_jwListener;
- void checkExAndRemoveListener(JNIEnv* env);
-};
-#endif
'JniOcResource.cpp',
'JniOcResourceIdentifier.cpp',
'JniOcSecurity.cpp',
- 'JniOnDPDevicesFoundListener.cpp',
- 'JniOnDirectPairingListener.cpp',
- 'JniOcDirectPairDevice.cpp',
'JniOnPublishResourceListener.cpp',
'JniOnDeleteResourceListener.cpp',
'JniOcRDClient.cpp',