Add an API to cloud provisioning with a given OCResource object
authorJihun Ha <jihun.ha@samsung.com>
Tue, 27 Dec 2016 05:22:00 +0000 (14:22 +0900)
committerUze Choi <uzchoi@samsung.com>
Wed, 28 Dec 2016 07:36:00 +0000 (07:36 +0000)
When a user wants to do cloud provisioning with a specific OCResource object,
the added API can be used and expected that a resource discovery in a current
connectivity for cloud provisioning is skipped.

Change-Id: Ic93da14b39e7576e413442b00db28ed3a6fc4890
Signed-off-by: Jihun Ha <jihun.ha@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/15947
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Heewon Park <h_w.park@samsung.com>
Reviewed-by: Senthil Kumar G S <senthil.gs@samsung.com>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/easy-setup/mediator/richsdk/inc/RemoteEnrollee.h
service/easy-setup/mediator/richsdk/src/EasySetup.cpp
service/easy-setup/mediator/richsdk/src/RemoteEnrollee.cpp

index 5f1008f..450b151 100755 (executable)
@@ -59,6 +59,7 @@ namespace OIC
              *
              * @param callback will give the requested status
              *
+             * @throws ESInvalidParameterException If callback is null.
              * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call.
              *
              * @see GetStatusCb
@@ -70,6 +71,7 @@ namespace OIC
              *
              * @param callback will give the requested configuration
              *
+             * @throws ESInvalidParameterException If callback is null.
              * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call.
              *
              * @see GetConfigurationStatusCb
@@ -81,6 +83,7 @@ namespace OIC
              *
              * @param callback will give the result if the security provisioning succeeds or fails for some reasons
              *
+             * @throws ESInvalidParameterException If callback is null.
              * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call.
              *
              * @see SecurityProvStatusCb
@@ -94,6 +97,7 @@ namespace OIC
              *
              * @param callback will give the result if the security provisioning succeeds or fails for some reasons.
              *
+             * @throws ESInvalidParameterException If callback is null.
              * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call.
              *
              * @see SecurityProvStatusCb
@@ -108,6 +112,7 @@ namespace OIC
              * @param devProp a data structure storing the above information to be delivered
              * @param callback will give the result if the provisioning succeeds or fails
              *
+             * @throws ESInvalidParameterException If callback is null.
              * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call.
              *
              * @see DeviceProp
@@ -127,6 +132,7 @@ namespace OIC
              * @param cloudProp a data structure storing the above information to be delivered
              * @param callback will give the result if the provisioning succeeds or fails
              *
+             * @throws ESInvalidParameterException If callback is null.
              * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call.
              *
              * @see CloudProp
@@ -135,6 +141,26 @@ namespace OIC
             void provisionCloudProperties(const CloudProp& cloudProp,
                                               const CloudPropProvStatusCb callback);
 
+            /**
+             * Provision Cloud information to Enrollee, which includes Auth code, auth provider,
+             * Cloud interface server URL, and etc.
+             * Note that, this API is skipping finding Enrollee in a given network. Instead, an OCResource
+             * given as a first parameter will be considered to the Enrollee for cloud provisioning.
+             *
+             * @param resource an OCResource corresponding to a target Enrollee for cloud provisioning
+             * @param cloudProp a data structure storing the above information to be delivered
+             * @param callback will give the result if the provisioning succeeds or fails
+             *
+             * @throws ESInvalidParameterException If callback is null.
+             * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call.
+             *
+             * @see CloudProp
+             * @see CloudPropProvStatusCb
+             */
+            void provisionCloudProperties(const std::shared_ptr< OC::OCResource > resource,
+                                            const CloudProp& cloudProp,
+                                            const CloudPropProvStatusCb callback);
+
         private:
             RemoteEnrollee(const std::shared_ptr< OC::OCResource > resource);
 
index 73eab32..4fcc332 100755 (executable)
@@ -70,6 +70,7 @@ namespace OIC
                         OIC_LOG_V (DEBUG, EASYSETUP_TAG, "HOST: %s", resource->host().c_str());
                         OIC_LOG_V (DEBUG, EASYSETUP_TAG, "URI: %s", resource->uri().c_str());
                         OIC_LOG_V (DEBUG, EASYSETUP_TAG, "SID: %s", resource->sid().c_str());
+                        OIC_LOG_V (DEBUG, EASYSETUP_TAG, "CONNECTIVITY: %d", resource->connectivityType());
                         return std::shared_ptr< RemoteEnrollee > (new RemoteEnrollee(resource));
                     }
                 }
index f059aab..31ae394 100755 (executable)
@@ -425,6 +425,17 @@ namespace OIC
         void RemoteEnrollee::provisionCloudProperties(const CloudProp& cloudProp,
                                                             const CloudPropProvStatusCb callback)
         {
+            OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_TAG, "provisionCloudProperties w/o OCResource IN");
+
+            provisionCloudProperties(NULL, cloudProp, callback);
+
+            OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_TAG, "provisionCloudProperties w/o OCResource OUT");
+        }
+
+        void RemoteEnrollee::provisionCloudProperties(const std::shared_ptr< OC::OCResource > resource,
+                                                        const CloudProp& cloudProp,
+                                                        const CloudPropProvStatusCb callback)
+        {
             OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_TAG, "provisionCloudProperties IN");
 
             if(!callback)
@@ -441,11 +452,49 @@ namespace OIC
                 throw ESBadRequestException ("Invalid Cloud Provisiong Info.");
             }
 
-            try
+            if(resource)
             {
-                initCloudResource();
+                if(resource->getResourceTypes().at(0) != OC_RSRVD_ES_RES_TYPE_PROV ||
+                                resource->connectivityType() & CT_ADAPTER_TCP)
+                {
+                    OIC_LOG (ERROR, ES_REMOTE_ENROLLEE_TAG, "Given resource is not valid due to wrong rt or conntype");
+                    throw ESInvalidParameterException("A given OCResource is wrong");
+                }
+
+                auto interfaces = resource->getResourceInterfaces();
+                bool isFound = false;
+                for(auto interface : interfaces)
+                {
+                    if(interface.compare(BATCH_INTERFACE) == 0)
+                    {
+                        OIC_LOG (DEBUG, ES_REMOTE_ENROLLEE_TAG, "RemoteEnrollee object is succeessfully created");
+                        OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "HOST: %s", resource->host().c_str());
+                        OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "URI: %s", resource->uri().c_str());
+                        OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "SID: %s", resource->sid().c_str());
+                        OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "CONNECTIVITY: %d", resource->connectivityType());
+                        isFound = true;
+                    }
+                }
+
+                if(!isFound)
+                {
+                    throw ESInvalidParameterException("A given OCResource has no batch interface");
+                }
             }
 
+            try
+            {
+                if(resource == NULL)
+                {
+                    initCloudResource();
+                }
+                else
+                {
+                    OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_TAG, "Skip to find a provisioning resource");
+                    m_ocResource = resource;
+                    m_cloudResource = std::make_shared<CloudResource>(m_ocResource);
+                }
+            }
             catch (const std::exception& e)
             {
                 OIC_LOG_V(ERROR, ES_REMOTE_ENROLLEE_TAG,