public void getAclIdByDeviceListener(int result, String aclId);
}
+ public interface CreateAclIdListener {
+ public void createAclIdListener(int result, String aclId);
+ }
+
public interface GetIndividualAclInfoListener {
public void getIndividualAclInfoListener(int result);
}
GetAclIdByDeviceListener cloudAclIdGetByDeviceHandler) throws OcException;
/**
+ * Method to create ACL ID
+ * @param ownerid owner ID for which the Acl ID is created
+ * @param deviceId device ID for which the Acl ID is requested
+ * @param cloudcreateAclId function called by the stack on completion of request.
+ * @throws OcException Indicates failure getting ACL ID for the device.
+ * Use OcException.GetErrorCode() for more details.
+ */
+ public native void createAclId(String ownerId, String deviceId,
+ CreateAclIdListener cloudcreateAclId) throws OcException;
+
+ /**
* Method to get ACL information about the given Acl ID
* @param aclId ACL ID for which the Acl information is requested
* @param cloudAclIndividualGetInfoHandler function called by the stack on completion of request.
SharedPreferences settingPreference;
OcCloudProvisioning ocCloudProvisioning;
String acl_Id;
+ String createacl_Id = null;
OcCloudProvisioning.GetAclIdByDeviceListener getAclIdByDeviceListener =
new OcCloudProvisioning.GetAclIdByDeviceListener() {
@Override
}
}
};
+
+ OcCloudProvisioning.CreateAclIdListener createAclIdListener =
+ new OcCloudProvisioning.CreateAclIdListener() {
+ @Override
+ public void createAclIdListener(int result, String aclId) {
+ Log.d(TAG, "Inside createAclIdListener ");
+ if (result == 0) {
+ createacl_Id = aclId;
+ logMessage("Acl Id by create aclid !!" + createacl_Id);
+ } else {
+ logMessage("Error: Acl Id by create aclid failed !!");
+ }
+ }
+ };
private OcAccountManager mAccountManager;
private String filePath = "";
private TextView mEventsTextView;
editor.putString("IP", StringConstants.DEFAULT_COAP_DERVER_IP);
editor.putString("PORT", StringConstants.DEFAULT_COAP_DERVER_PORT);
editor.putString("DEVICEID", StringConstants.DEFAULT_DEVICE_ID);
+ editor.putString("OWNERID", StringConstants.DEFAULT_OWNER_ID);
editor.putString("SERIALNUMBER", StringConstants.DEFAULT_SERIAL_NUMBER);
editor.commit();
}
private void getAclId() {
try {
- logMessage("getAclId");
- logMessage("\tdeviceId= " + settingPreference.getString("DEVICEID", ""));
- ocCloudProvisioning.getAclIdByDevice(settingPreference.getString("DEVICEID", ""), getAclIdByDeviceListener);
+ if(createacl_Id == null)
+ {
+ ocCloudProvisioning.createAclId(settingPreference.getString("OWNERID", ""),
+ settingPreference.getString("DEVICEID", ""), createAclIdListener);
+ }
+ else{
+ ocCloudProvisioning.getAclIdByDevice(settingPreference.getString("DEVICEID", ""),
+ getAclIdByDeviceListener);
+ }
} catch (OcException e) {
e.printStackTrace();
}
public interface StringConstants {
public static final String DEFAULT_DEVICE_ID = "9cfbeb8e-5a1e-4d1c-9d01-2ae6fdb";
+ public static final String DEFAULT_OWNER_ID = "123e4567-e89b-12d3-a456-4266554";
public static final String DEFAULT_SERIAL_NUMBER = "1234";
public static final String COAP_TCP = "coap+tcp://";
--- /dev/null
+/*
+* //******************************************************************
+* //
+* // Copyright 2017 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 "JniCreateAciIdListener.h"
+
+JniCreateAclIdListener::JniCreateAclIdListener(JNIEnv *env, jobject jListener,
+ RemoveCallback removeListener)
+{
+ m_jwListener = env->NewWeakGlobalRef(jListener);
+ m_createAclIDListener = removeListener;
+}
+
+JniCreateAclIdListener::~JniCreateAclIdListener()
+{
+ LOGI("~JniCreateAclIdListener()");
+ if (m_jwListener)
+ {
+ jint ret = JNI_ERR;
+ JNIEnv *env = GetJNIEnv(ret);
+ if (nullptr == env)
+ {
+ return;
+ }
+ env->DeleteWeakGlobalRef(m_jwListener);
+ if (JNI_EDETACHED == ret)
+ {
+ g_jvm->DetachCurrentThread();
+ }
+ }
+}
+
+void JniCreateAclIdListener::CreateAclIdListenerCB(int result, std::string aclID)
+{
+ 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;
+ }
+
+ jmethodID midL = env->GetMethodID(clsL, "createAclIdListener", "(ILjava/lang/String;)V");
+ if (!midL)
+ {
+ checkExAndRemoveListener(env);
+ if (JNI_EDETACHED == ret)
+ {
+ g_jvm->DetachCurrentThread();
+ }
+ return;
+ }
+ jstring jStr = env-> NewStringUTF(aclID.c_str());
+ if (!jStr)
+ {
+ checkExAndRemoveListener(env);
+ if (JNI_EDETACHED == ret)
+ {
+ g_jvm->DetachCurrentThread();
+ }
+ return;
+
+ }
+ env->CallVoidMethod(jListener, midL, (jint)result, jStr);
+ if (env->ExceptionCheck())
+ {
+ LOGE("Java exception is thrown");
+ }
+ checkExAndRemoveListener(env);
+ if (JNI_EDETACHED == ret)
+ {
+ g_jvm->DetachCurrentThread();
+ }
+}
+
+void JniCreateAclIdListener::checkExAndRemoveListener(JNIEnv* env)
+{
+ if (env->ExceptionCheck())
+ {
+ jthrowable ex = env->ExceptionOccurred();
+ env->ExceptionClear();
+ m_createAclIDListener(env, m_jwListener);
+ env->Throw((jthrowable)ex);
+ }
+ else
+ {
+ m_createAclIDListener(env, m_jwListener);
+ }
+}
+
--- /dev/null
+/*
+* //******************************************************************
+* //
+* // Copyright 2017 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 "JniOcStack.h"
+
+/* Header for class org_iotivity_base_OcCloudProvisioning_CreateAclId */
+#ifndef _Included_org_iotivity_base_OcCloudProvisioning_JniCreateAclId
+#define _Included_org_iotivity_base_OcCloudProvisioning_JniCreateAclId
+
+typedef std::function<void(JNIEnv* env, jobject jListener)> RemoveCallback;
+
+class JniCreateAclIdListener
+{
+ public:
+ JniCreateAclIdListener(JNIEnv *env, jobject jListener,
+ RemoveCallback removeListener);
+ ~JniCreateAclIdListener();
+
+ void CreateAclIdListenerCB(int result, std::string aclID);
+
+ private:
+ RemoveCallback m_createAclIDListener;
+ jweak m_jwListener;
+ void checkExAndRemoveListener(JNIEnv* env);
+};
+#endif
return resultListener;
}
+JniCreateAclIdListener* JniOcCloudProvisioning::CreateAclListener(JNIEnv* env,
+ jobject jListener)
+{
+ JniCreateAclIdListener *resultListener = NULL;
+ createresultMapLock.lock();
+
+ for (auto it = createresultMap.begin(); it != createresultMap.end(); ++it)
+ {
+ if (env->IsSameObject(jListener, it->first))
+ {
+ auto refPair = it->second;
+ resultListener = refPair.first;
+ refPair.second++;
+ it->second = refPair;
+ createresultMap.insert(*it);
+ LOGD("CreateACLID Listener: ref. count incremented");
+ break;
+ }
+ }
+ if (!resultListener)
+ {
+ resultListener = new JniCreateAclIdListener(env, jListener,
+ RemoveCallback(std::bind(&JniOcCloudProvisioning::RemoveCreateAclIdListener,
+ this, PH::_1, PH::_2)));
+ jobject jgListener = env->NewGlobalRef(jListener);
+
+ createresultMap.insert(std::pair < jobject, std::pair < JniCreateAclIdListener*,
+ int >> (jgListener, std::pair<JniCreateAclIdListener*, int>(resultListener, 1)));
+ LOGD("CreateACLID Listener: new listener");
+ }
+ createresultMapLock.unlock();
+ return resultListener;
+}
+
void JniOcCloudProvisioning::RemoveGetAclByDeviceIdListener(JNIEnv* env, jobject jListener)
{
aclresultMapLock.lock();
}
aclresultMapLock.unlock();
}
+
+void JniOcCloudProvisioning::RemoveCreateAclIdListener(JNIEnv* env, jobject jListener)
+{
+ createresultMapLock.lock();
+
+ for (auto it = createresultMap.begin(); it != createresultMap.end(); ++it)
+ {
+ if (env->IsSameObject(jListener, it->first))
+ {
+ auto refPair = it->second;
+ if (refPair.second > 1)
+ {
+ refPair.second--;
+ it->second = refPair;
+ createresultMap.insert(*it);
+ LOGI("CreateACLID Listener: ref. count decremented");
+ }
+ else
+ {
+ env->DeleteGlobalRef(it->first);
+ JniCreateAclIdListener* listener = refPair.first;
+ delete listener;
+ createresultMap.erase(it);
+ LOGI("CreateACLID Listener removed");
+ }
+ break;
+ }
+ }
+ createresultMapLock.unlock();
+}
+
JniOcCloudProvisioning * Create_native_object(JNIEnv *env, jobject thiz)
{
jstring jip = (jstring)env->CallObjectMethod(thiz, g_mid_OcCloudProvisioning_getIP);
return m_sharedCloudObject->getAclIdByDevice(deviceId, aclIdResponseCallBack);
}
+
+OCStackResult JniOcCloudProvisioning::createAclId(JNIEnv* env, std::string ownerId,
+ std::string deviceID, jobject jListener)
+{
+ JniCreateAclIdListener *resultListener = CreateAclListener(env, jListener);
+
+ AclIdResponseCallBack aclIdResponseCallBack = [resultListener](OCStackResult result,
+ std::string aclId)
+ {
+ resultListener->CreateAclIdListenerCB(result, aclId);
+ };
+
+ return m_sharedCloudObject->createAclId(ownerId, deviceID, aclIdResponseCallBack);
+}
/*
* Class: org_iotivity_base_OcCloudProvisioning
* Method: requestCertificate
/*
* Class: org_iotivity_base_OcCloudProvisioning
+ * Method: createAclId
+ * Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcCloudProvisioning/CreateAclIdListener;)V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcCloudProvisioning_createAclId
+ (JNIEnv *env, jobject thiz, jstring jownerId, jstring jdeviceId, jobject jListener)
+{
+ LOGD("OcCloudProvisioning_createAclId");
+ if (!jListener)
+ {
+ ThrowOcException(OC_STACK_INVALID_CALLBACK, "Listener cannot be null");
+ return;
+ }
+
+ if (!jownerId)
+ {
+ ThrowOcException(OC_STACK_INVALID_PARAM, "ownerId can not be null");
+ return;
+ }
+
+ if (!jdeviceId)
+ {
+ ThrowOcException(OC_STACK_INVALID_PARAM, "deviceID can not be null");
+ return;
+ }
+
+ JniOcCloudProvisioning *cloud = JniOcCloudProvisioning::getJniOcCloudProvisioningPtr(env, thiz);
+ if (!cloud)
+ {
+ LOGD("OcCloudProvisioning_createAclId, No native object, creating now");
+ cloud = Create_native_object(env, thiz);
+ if (!cloud)
+ {
+ ThrowOcException(OC_STACK_ERROR, "OcCloudProvisioning_createAclId,"
+ "Can not Create Native object");
+ return;
+ }
+ }
+
+ const char *ownerstr = env->GetStringUTFChars(jownerId, NULL);
+ if (!ownerstr || env->ExceptionCheck())
+ {
+ ThrowOcException(OC_STACK_ERROR,"OcCloudProvisioning_createAclId");
+ return;
+ }
+ std::string ownerId(ownerstr);
+ env->ReleaseStringUTFChars(jownerId, ownerstr);
+
+ const char *str = env->GetStringUTFChars(jdeviceId, NULL);
+ if (!str || env->ExceptionCheck())
+ {
+ ThrowOcException(OC_STACK_ERROR,"OcCloudProvisioning_createAclId");
+ return;
+ }
+ std::string deviceId(str);
+ env->ReleaseStringUTFChars(jdeviceId, str);
+
+ try
+ {
+ OCStackResult result = cloud->createAclId(env, ownerId, deviceId, jListener);
+ if (OC_STACK_OK != result)
+ {
+ ThrowOcException(result, "OcCloudProvisioning_createAclId");
+ return;
+ }
+ }
+ catch (OCException& e)
+ {
+ LOGE("%s", e.reason().c_str());
+ ThrowOcException(e.code(), e.reason().c_str());
+ }
+ return;
+}
+
+/*
+ * Class: org_iotivity_base_OcCloudProvisioning
* Method: getIndividualAclInfo
* Signature: (Ljava/lang/String;Lorg/iotivity/base/OcCloudProvisioning/GetIndividualAclInfoListener;)V
*/
#include "OCCloudProvisioning.hpp"
#include "JniOcCloudResultListener.h"
#include "JniGetAclIdByDeviceListener.h"
+#include "JniCreateAciIdListener.h"
#include <mutex>
static JniOcCloudProvisioning* getJniOcCloudProvisioningPtr(JNIEnv *env, jobject thiz);
JniOcCloudResultListener* AddCloudResultListener(JNIEnv* env, jobject jListener);
JniGetAclIdByDeviceListener* AddGetAclByDeviceListener(JNIEnv* env, jobject jListener);
+ JniCreateAclIdListener* CreateAclListener(JNIEnv* env, jobject jListener);
void RemoveCloudResultListener(JNIEnv* env, jobject jListener);
void RemoveGetAclByDeviceIdListener(JNIEnv*, jobject);
+ void RemoveCreateAclIdListener(JNIEnv*, jobject);
OCStackResult requestCertificate(JNIEnv* env, jobject jListener);
OCStackResult getAclIdByDevice(JNIEnv*, std::string, jobject);
+ OCStackResult createAclId(JNIEnv*, std::string, std::string, jobject);
OCStackResult getIndividualAclInfo(JNIEnv*, jobject, std::string &);
OCStackResult getCRL(JNIEnv* env, jobject jListener);
OCStackResult postCRL(JNIEnv* env, const std::string& thisUpdate,
private:
std::map<jobject, std::pair<JniOcCloudResultListener*, int>> resultMap;
std::map<jobject, std::pair<JniGetAclIdByDeviceListener*, int>> aclresultMap;
+ std::map<jobject, std::pair<JniCreateAclIdListener*, int>> createresultMap;
std::mutex resultMapLock;
std::mutex aclresultMapLock;
+ std::mutex createresultMapLock;
std::shared_ptr<OCCloudProvisioning>m_sharedCloudObject;
};
/*
* Class: org_iotivity_base_OcCloudProvisioning
+ * Method: createAclId
+ * Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcCloudProvisioning/CreateAclId;)V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcCloudProvisioning_createAclId
+ (JNIEnv *, jobject, jstring, jstring, jobject);
+
+/*
+ * Class: org_iotivity_base_OcCloudProvisioning
* Method: getIndividualAclInfo
* Signature: (Ljava/lang/String;Lorg/iotivity/base/OcCloudProvisioning/GetIndividualAclInfoListener;)V
*/
if env.get('WITH_CLOUD'):
ocstack_files += [
'JniOcAccountManager.cpp',
+ 'JniCreateAciIdListener.cpp',
'JniOcCloudResultListener.cpp',
'JniGetAclIdByDeviceListener.cpp'
]
-//****************************************************************\r
-//\r
-// Copyright 2016 Samsung Electronics All Rights Reserved.\r
-//\r
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
-//\r
-// Licensed under the Apache License, Version 2.0 (the "License");\r
-// you may not use this file except in compliance with the License.\r
-// You may obtain a copy of the License at\r
-//\r
-// http://www.apache.org/licenses/LICENSE-2.0\r
-//\r
-// Unless required by applicable law or agreed to in writing, software\r
-// distributed under the License is distributed on an "AS IS" BASIS,\r
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-// See the License for the specific language governing permissions and\r
-// limitations under the License.\r
-//\r
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
-\r
-#ifndef OC_CLOUD_PROVISIONING_CXX_H_\r
-#define OC_CLOUD_PROVISIONING_CXX_H_\r
-\r
-#include <thread>\r
-\r
-#include "occloudprovisioning.h"\r
-#include "OCApi.h"\r
-#include "OCPlatform_impl.h"\r
-#include "CAManager.h"\r
-\r
-namespace OC\r
-{\r
- typedef std::function<void(OCStackResult result, void *data)> ResponseCallBack;\r
- typedef std::function<void(OCStackResult result, std::string aclId)> AclIdResponseCallBack;\r
-\r
- /**\r
- * Context to be passed to the underlying stack. This is passed back as argument\r
- * to the callback function\r
- */\r
- struct CloudProvisionContext\r
- {\r
- ResponseCallBack callback;\r
- CloudProvisionContext(ResponseCallBack cb) : callback(cb){}\r
- };\r
-\r
- struct AclIdContext\r
- {\r
- AclIdResponseCallBack callback;\r
- AclIdContext(AclIdResponseCallBack cb) : callback(cb){}\r
- };\r
-\r
- class OCCloudProvisioning\r
- {\r
-\r
- private:\r
- OCDevAddr m_devAddr;\r
- public:\r
-\r
- /**\r
- * API to construct the CloudProvisioning\r
- * @param ipAddr address of the cloud server\r
- * @param port port of the cloud server\r
- */\r
- OCCloudProvisioning(std::string& ipAddr, uint16_t port);\r
- ~OCCloudProvisioning();\r
-\r
- void setIpAddr(std::string& ipAddr)\r
- {\r
- memcpy(m_devAddr.addr, ipAddr.c_str(), MAX_ADDR_STR_SIZE);\r
- }\r
-\r
- void setPort(uint16_t port)\r
- {\r
- m_devAddr.port = port;\r
- }\r
-\r
- /**\r
- * API to Request a certificate from the cloud\r
- * @param callback function called by the stack on completion of request\r
- * @return ::OC_STACK_OK on Success and other values otherwise\r
- */\r
- OCStackResult requestCertificate(ResponseCallBack callback);\r
-\r
- /**\r
- * API to get ACL ID for the device\r
- * @param deviceId device ID for which the Acl ID is requested\r
- * @param callback function called by the stack on completion of request\r
- * @return ::OC_STACK_OK on Success and other values otherwise\r
- */\r
- OCStackResult getAclIdByDevice(const std::string& deviceId, AclIdResponseCallBack callback);\r
-\r
- /**\r
- * API to get ACL information about the given Acl ID\r
- * @param aclId ACL ID for which the Acl information is requested\r
- * @param callback function called by the stack on completion of request\r
- * @return ::OC_STACK_OK on Success and other values otherwise\r
- */\r
- OCStackResult getIndividualAclInfo(const std::string& aclId, ResponseCallBack callback);\r
-\r
- /**\r
- * API to get certificate revocation list\r
- * @param callback function called by the stack on completion of request\r
- * @return ::OC_STACK_OK on Success and other values otherwise\r
- */\r
- OCStackResult getCRL(ResponseCallBack callback);\r
-\r
- /**\r
- * API to post the certificate revocation list to cloud\r
- * @param thisUpdate thisUpdate [mandatory param]\r
- * @param nextUpdate nextUpdate [mandatory param]\r
- * @param crl revocation list [optional]\r
- * @param serialNumbers [optional]\r
- * @param callback function called by the stack on completion of request\r
- * @return ::OC_STACK_OK on Success and other values otherwise\r
- */\r
- OCStackResult postCRL(const std::string& thisUpdate,\r
- const std::string& nextUpdate,\r
- const OCByteString *crl,\r
- const stringArray_t *serialNumbers,\r
- ResponseCallBack callback);\r
-\r
- /**\r
- * Common callback wrapper for all the callback functions.\r
- * @param ctx user context passed to the request API\r
- * @param result result of the request performed\r
- * @param data response data\r
- */\r
- static void callbackWrapper(void* ctx, OCClientResponse *response, void* data);\r
-\r
- /**\r
- * Callback wrapper for Acl ID get request\r
- * @param ctx user context passed to the request API\r
- * @param result result of the request performed\r
- * @param data AclID for the device\r
- */\r
- static void aclIdResponseWrapper(void* ctx, OCClientResponse *response, void* data);\r
- };\r
-}\r
-#endif //OC_CLOUD_PROVISIONING_CXX_H_\r
+//****************************************************************
+//
+// 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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#ifndef OC_CLOUD_PROVISIONING_CXX_H_
+#define OC_CLOUD_PROVISIONING_CXX_H_
+
+#include <thread>
+
+#include "occloudprovisioning.h"
+#include "OCApi.h"
+#include "OCPlatform_impl.h"
+#include "CAManager.h"
+
+namespace OC
+{
+ typedef std::function<void(OCStackResult result, void *data)> ResponseCallBack;
+ typedef std::function<void(OCStackResult result, std::string aclId)> AclIdResponseCallBack;
+
+ /**
+ * Context to be passed to the underlying stack. This is passed back as argument
+ * to the callback function
+ */
+ struct CloudProvisionContext
+ {
+ ResponseCallBack callback;
+ CloudProvisionContext(ResponseCallBack cb) : callback(cb){}
+ };
+
+ struct AclIdContext
+ {
+ AclIdResponseCallBack callback;
+ AclIdContext(AclIdResponseCallBack cb) : callback(cb){}
+ };
+
+ class OCCloudProvisioning
+ {
+
+ private:
+ OCDevAddr m_devAddr;
+ public:
+
+ /**
+ * API to construct the CloudProvisioning
+ * @param ipAddr address of the cloud server
+ * @param port port of the cloud server
+ */
+ OCCloudProvisioning(std::string& ipAddr, uint16_t port);
+ ~OCCloudProvisioning();
+
+ void setIpAddr(std::string& ipAddr)
+ {
+ memcpy(m_devAddr.addr, ipAddr.c_str(), MAX_ADDR_STR_SIZE);
+ }
+
+ void setPort(uint16_t port)
+ {
+ m_devAddr.port = port;
+ }
+
+ /**
+ * API to Request a certificate from the cloud
+ * @param callback function called by the stack on completion of request
+ * @return ::OC_STACK_OK on Success and other values otherwise
+ */
+ OCStackResult requestCertificate(ResponseCallBack callback);
+
+ /**
+ * API to get ACL ID for the device
+ * @param deviceId device ID for which the Acl ID is requested
+ * @param callback function called by the stack on completion of request
+ * @return ::OC_STACK_OK on Success and other values otherwise
+ */
+ OCStackResult getAclIdByDevice(const std::string& deviceId,
+ AclIdResponseCallBack callback);
+
+ /**
+ * API to create ACL ID for the device
+ * @param ownerId owner ID for which the Acl ID is to be created
+ * @param deviceId device ID for which the Acl ID is requested
+ * @param endPoint cloud host and port
+ * @return ::OC_STACK_OK on Success and other values otherwise
+ */
+ OCStackResult createAclId(const std::string& ownerId, const std::string& deviceId,
+ AclIdResponseCallBack callback);
+
+ /**
+ * API to get ACL information about the given Acl ID
+ * @param aclId ACL ID for which the Acl information is requested
+ * @param callback function called by the stack on completion of request
+ * @return ::OC_STACK_OK on Success and other values otherwise
+ */
+ OCStackResult getIndividualAclInfo(const std::string& aclId, ResponseCallBack callback);
+
+ /**
+ * API to get certificate revocation list
+ * @param callback function called by the stack on completion of request
+ * @return ::OC_STACK_OK on Success and other values otherwise
+ */
+ OCStackResult getCRL(ResponseCallBack callback);
+
+ /**
+ * API to post the certificate revocation list to cloud
+ * @param thisUpdate thisUpdate [mandatory param]
+ * @param nextUpdate nextUpdate [mandatory param]
+ * @param crl revocation list [optional]
+ * @param serialNumbers [optional]
+ * @param callback function called by the stack on completion of request
+ * @return ::OC_STACK_OK on Success and other values otherwise
+ */
+ OCStackResult postCRL(const std::string& thisUpdate,
+ const std::string& nextUpdate,
+ const OCByteString *crl,
+ const stringArray_t *serialNumbers,
+ ResponseCallBack callback);
+
+ /**
+ * Common callback wrapper for all the callback functions.
+ * @param ctx user context passed to the request API
+ * @param result result of the request performed
+ * @param data response data
+ */
+ static void callbackWrapper(void* ctx, OCClientResponse *response, void* data);
+
+ /**
+ * Callback wrapper for Acl ID get request
+ * @param ctx user context passed to the request API
+ * @param result result of the request performed
+ * @param data AclID for the device
+ */
+ static void aclIdResponseWrapper(void* ctx, OCClientResponse *response, void* data);
+ };
+}
+#endif //OC_CLOUD_PROVISIONING_CXX_H_
return result;
}
+ OCStackResult OCCloudProvisioning::createAclId(const std::string& ownerId, const std::string& deviceId,
+ AclIdResponseCallBack callback)
+ {
+ if (!callback)
+ {
+ oclog() <<"Result callback can't be null";
+ return OC_STACK_INVALID_CALLBACK;
+ }
+
+ OCStackResult result;
+ auto cLock = OCPlatform_impl::Instance().csdkLock().lock();
+
+ if (cLock)
+ {
+ AclIdContext *context = new AclIdContext(callback);
+
+ std::lock_guard<std::recursive_mutex> lock(*cLock);
+ result = OCCloudAclIdCreate(static_cast<void*>(context), ownerId.c_str(),
+ deviceId.c_str(), &m_devAddr,
+ &OCCloudProvisioning::aclIdResponseWrapper);
+ }
+ else
+ {
+ oclog() <<"Mutex not found";
+ result = OC_STACK_ERROR;
+ }
+ return result;
+ }
+
OCStackResult OCCloudProvisioning::getCRL(ResponseCallBack callback)
{
if (!callback)