ThrowOcException(JNI_EXCEPTION, "OnDeviceInfoListenet not found");\r
}\r
deviceInfoMapLock.unlock();\r
+}
+
+JniOnPlatformInfoListener* AddOnPlatformInfoListener(JNIEnv* env, jobject jListener)
+{
+ JniOnPlatformInfoListener *onPlatformInfoListener = NULL;
+
+ platformInfoMapLock.lock();
+
+ for (auto it = onPlatformInfoListenerMap.begin(); it != onPlatformInfoListenerMap.end(); ++it)
+ {
+ if (env->IsSameObject(jListener, it->first))
+ {
+ auto refPair = it->second;
+ onPlatformInfoListener = refPair.first;
+ refPair.second++;
+ it->second = refPair;
+ onPlatformInfoListenerMap.insert(*it);
+ LOGD("OnPlatformInfoListener: ref. count incremented");
+ break;
+ }
+ }
+
+ if (!onPlatformInfoListener)
+ {
+ onPlatformInfoListener = new JniOnPlatformInfoListener(env, jListener, RemoveOnPlatformInfoListener);
+ jobject jgListener = env->NewGlobalRef(jListener);
+
+ onPlatformInfoListenerMap.insert(std::pair < jobject, std::pair < JniOnPlatformInfoListener*,
+ int >> (jgListener, std::pair<JniOnPlatformInfoListener*, int>(onPlatformInfoListener, 1)));
+ LOGI("OnPlatformInfoListener: new listener");
+ }
+
+ platformInfoMapLock.unlock();
+ return onPlatformInfoListener;
+}
+
+void RemoveOnPlatformInfoListener(JNIEnv* env, jobject jListener)
+{
+ platformInfoMapLock.lock();
+ bool isFound = false;
+ for (auto it = onPlatformInfoListenerMap.begin(); it != onPlatformInfoListenerMap.end(); ++it)
+ {
+ if (env->IsSameObject(jListener, it->first))
+ {
+ auto refPair = it->second;
+ if (refPair.second > 1)
+ {
+ refPair.second--;
+ it->second = refPair;
+ onPlatformInfoListenerMap.insert(*it);
+ LOGI("OnPlatformInfoListener: ref. count decremented");
+ }
+ else
+ {
+ env->DeleteGlobalRef(it->first);
+ JniOnPlatformInfoListener* listener = refPair.first;
+ delete listener;
+ onPlatformInfoListenerMap.erase(it);
+
+ LOGI("OnPlatformInfoListener removed");
+ }
+
+ isFound = true;
+ break;
+ }
+ }
+
+ if (!isFound)
+ {
+ ThrowOcException(JNI_EXCEPTION, "OnPlatformInfoListenet not found");
+ }
+ platformInfoMapLock.unlock();
}\r
\r
JniOnPresenceListener* AddOnPresenceListener(JNIEnv* env, jobject jListener)\r
/*\r
* Class: org_iotivity_base_OcPlatform\r
* Method: configure\r
-* Signature: (IILjava/lang/String;IILjava/lang/String;)V
+* Signature: (IILjava/lang/String;II)V\r
*/\r
JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_configure\r
(JNIEnv *env, jclass clazz, jint jServiceType, jint jModeType, jstring jIpAddress, jint jPort,
if (OC_STACK_OK != result)\r
{\r
ThrowOcException(result, "Find device has failed");\r
+ }
+ }
+ catch (OCException& e)
+ {
+ LOGE("%s", e.reason().c_str());
+ ThrowOcException(OC_STACK_ERROR, e.reason().c_str());
+ }
+}
+
+/*
+* Class: org_iotivity_base_OcPlatform
+* Method: getPlatformInfo0
+* Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnPlatformFoundListener;)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_getPlatformInfo0
+(JNIEnv *env, jclass clazz, jstring jHost, jstring jResourceUri, jint jConnectivityType, jobject jListener)
+{
+ LOGD("OcPlatform_getPlatformInfo0");
+ std::string host;
+ if (jHost)
+ {
+ host = env->GetStringUTFChars(jHost, NULL);
+ }
+ std::string resourceUri;
+ if (jResourceUri)
+ {
+ resourceUri = env->GetStringUTFChars(jResourceUri, NULL);
+ }
+ if (!jListener)
+ {
+ ThrowOcException(OC_STACK_INVALID_PARAM, "onPlatformFoundListener cannot be null");
+ return;
+ }
+ JniOnPlatformInfoListener *onPlatformInfoListener = AddOnPlatformInfoListener(env, jListener);
+
+ FindPlatformCallback findPlatformCallback = [onPlatformInfoListener](const OCRepresentation& ocRepresentation)
+ {
+ onPlatformInfoListener->foundPlatformCallback(ocRepresentation);
+ };
+
+ try
+ {
+ OCStackResult result = OCPlatform::getPlatformInfo(
+ host,
+ resourceUri,
+ JniUtils::getConnectivityType(env, static_cast<int>(jConnectivityType)),
+ findPlatformCallback);
+
+ if (OC_STACK_OK != result)
+ {
+ ThrowOcException(result, "Find platform has failed");
+ }
+ }
+ catch (OCException& e)
+ {
+ LOGE("%s", e.reason().c_str());
+ ThrowOcException(OC_STACK_ERROR, e.reason().c_str());
+ }
+}
+
+/*
+* Class: org_iotivity_base_OcPlatform
+* Method: getPlatformInfo1
+* Signature: (Ljava/lang/String;Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnPlatformFoundListener;I)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_getPlatformInfo1
+(JNIEnv *env, jclass clazz, jstring jHost, jstring jResourceUri, jint jConnectivityType, jobject jListener, jint jQoS)
+{
+ LOGD("OcPlatform_getPlatformInfo1");
+ std::string host;
+ if (jHost)
+ {
+ host = env->GetStringUTFChars(jHost, NULL);
+ }
+ std::string resourceUri;
+ if (jResourceUri)
+ {
+ resourceUri = env->GetStringUTFChars(jResourceUri, NULL);
+ }
+ if (!jListener)
+ {
+ ThrowOcException(OC_STACK_INVALID_PARAM, "onPlatformFoundListener cannot be null");
+ return;
+ }
+ JniOnDeviceInfoListener *onDeviceInfoListener = AddOnDeviceInfoListener(env, jListener);
+
+ FindDeviceCallback findDeviceCallback = [onDeviceInfoListener](const OCRepresentation& ocRepresentation)
+ {
+ onDeviceInfoListener->foundDeviceCallback(ocRepresentation);
+ };
+
+ try
+ {
+ OCStackResult result = OCPlatform::getPlatformInfo(
+ host,
+ resourceUri,
+ JniUtils::getConnectivityType(env, static_cast<int>(jConnectivityType)),
+ findDeviceCallback,
+ JniUtils::getQOS(env, static_cast<int>(jQoS)));
+
+ if (OC_STACK_OK != result)
+ {
+ ThrowOcException(result, "Find platform has failed");
}\r
}\r
catch (OCException& e)\r
}\r
JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, jResource);\r
if (!resource) return nullptr;\r
-\r
+ LOGD("OcPlatform_registerResource1");
OCResourceHandle resourceHandle;\r
try\r
{\r
+ LOGD("OcPlatform_registerResource2");
OCStackResult result = OCPlatform::registerResource(\r
resourceHandle,\r
resource->getOCResource());\r
+ LOGD("OcPlatform_registerResource3");
\r
if (OC_STACK_OK != result)\r
{\r
ThrowOcException(OC_STACK_ERROR, e.reason().c_str());\r
return nullptr;\r
}\r
-\r
+ LOGD("OcPlatform_registerResource4");
JniOcResourceHandle* jniHandle = new JniOcResourceHandle(resourceHandle);\r
jlong handle = reinterpret_cast<jlong>(jniHandle);\r
jobject jResourceHandle = env->NewObject(g_cls_OcResourceHandle, g_mid_OcResourceHandle_N_ctor, handle);\r
+ LOGD("OcPlatform_registerResource5");
if (!jResourceHandle)\r
{\r
LOGE("Failed to create OcResourceHandle");\r
\r
/*\r
* Class: org_iotivity_base_OcPlatform\r
+* Method: registerPlatformInfo0
+* Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
+*/
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_registerPlatformInfo0
+(JNIEnv *env,
+jclass clazz,
+jstring jPlatformID,
+jstring jManufacturerName,
+jstring jManufacturerUrl,
+jstring jModelNumber,
+jstring jDateOfManufacture,
+jstring jPlatformVersion,
+jstring jOperatingSystemVersion,
+jstring jHardwareVersion,
+jstring jFirmwareVersion,
+jstring jSupportUrl,
+jstring jSystemTime)
+{
+ LOGI("OcPlatform_registerPlatformInfo");
+
+
+ std::string platformID;
+ std::string manufacturerName;
+ std::string manufacturerUrl;
+ std::string modelNumber;
+ std::string dateOfManufacture;
+ std::string platformVersion;
+ std::string operatingSystemVersion;
+ std::string hardwareVersion;
+ std::string firmwareVersion;
+ std::string supportUrl;
+ std::string systemTime;
+
+ if (jPlatformID)
+ {
+ platformID = env->GetStringUTFChars(jPlatformID, NULL);
+ }
+ if (jManufacturerName)
+ {
+ manufacturerName = env->GetStringUTFChars(jManufacturerName, NULL);
+ }
+ if (jManufacturerUrl)
+ {
+ manufacturerUrl = env->GetStringUTFChars(jManufacturerUrl, NULL);
+ }
+ if (jModelNumber)
+ {
+ modelNumber = env->GetStringUTFChars(jModelNumber, NULL);
+ }
+ if (jDateOfManufacture)
+ {
+ dateOfManufacture = env->GetStringUTFChars(jDateOfManufacture, NULL);
+ }
+ if (jPlatformVersion)
+ {
+ platformVersion = env->GetStringUTFChars(jPlatformVersion, NULL);
+ }
+ if (jOperatingSystemVersion)
+ {
+ operatingSystemVersion = env->GetStringUTFChars(jOperatingSystemVersion, NULL);
+ }
+ if (jHardwareVersion)
+ {
+ hardwareVersion = env->GetStringUTFChars(jHardwareVersion, NULL);
+ }
+ if (jFirmwareVersion)
+ {
+ firmwareVersion = env->GetStringUTFChars(jFirmwareVersion, NULL);
+ }
+ if (jSupportUrl)
+ {
+ supportUrl = env->GetStringUTFChars(jSupportUrl, NULL);
+ }
+ if (jSystemTime)
+ {
+ systemTime = env->GetStringUTFChars(jSystemTime, NULL);
+ }
+
+ OCPlatformInfo platformInfo;
+ try
+ {
+ DuplicateString(&platformInfo.platformID, platformID);
+ DuplicateString(&platformInfo.manufacturerName, manufacturerName);
+ DuplicateString(&platformInfo.manufacturerUrl, manufacturerUrl);
+ DuplicateString(&platformInfo.modelNumber, modelNumber);
+ DuplicateString(&platformInfo.dateOfManufacture, dateOfManufacture);
+ DuplicateString(&platformInfo.platformVersion, platformVersion);
+ DuplicateString(&platformInfo.operatingSystemVersion, operatingSystemVersion);
+ DuplicateString(&platformInfo.hardwareVersion, hardwareVersion);
+ DuplicateString(&platformInfo.firmwareVersion, firmwareVersion);
+ DuplicateString(&platformInfo.supportUrl, supportUrl);
+ DuplicateString(&platformInfo.systemTime, systemTime);
+ }
+ catch (std::exception &e)
+ {
+ ThrowOcException(JNI_EXCEPTION, "Failed to construct platform info");
+ return;
+ }
+
+ // __android_log_print(ANDROID_LOG_INFO, "Rahul", "platformID = %s", platformID);
+ try
+ {
+ OCStackResult result = OCPlatform::registerPlatformInfo(platformInfo);
+
+ delete platformInfo.platformID;
+ delete platformInfo.manufacturerName;
+ delete platformInfo.manufacturerUrl;
+ delete platformInfo.modelNumber;
+ delete platformInfo.dateOfManufacture;
+ delete platformInfo.platformVersion;
+ delete platformInfo.operatingSystemVersion;
+ delete platformInfo.hardwareVersion;
+ delete platformInfo.firmwareVersion;
+ delete platformInfo.supportUrl;
+ delete platformInfo.systemTime;
+
+ if (OC_STACK_OK != result)
+ {
+ ThrowOcException(result, "Failed to register platform info");
+ return;
+ }
+ }
+ catch (OCException& e)
+ {
+ LOGE("Error is due to %s", e.reason().c_str());
+ ThrowOcException(OC_STACK_ERROR, e.reason().c_str());
+ }
+
+
+
+}
+
+/*
+* Class: org_iotivity_base_OcPlatform
* Method: unregisterResource0\r
* Signature: (Lorg/iotivity/base/OcResourceHandle;)V\r
*/\r
LOGE("Failed to create OcPresenceHandle");\r
delete jniPresenceHandle;\r
}\r
-\r
return jPresenceHandle;\r
}\r
\r