1 //******************************************************************
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
23 #include "CloudResource.h"
25 #include "OCPlatform.h"
26 #include "ESException.h"
27 #include "OCResource.h"
34 #define ES_CLOUD_RES_TAG "ES_CLOUD_RESOURCE"
36 static const char ES_BASE_RES_URI[] = "/oic/res";
38 CloudResource::CloudResource(std::shared_ptr< OC::OCResource > resource)
40 m_ocResource = resource;
43 void CloudResource::provisionProperties(const CloudProp& cloudProp)
45 OIC_LOG (DEBUG, ES_CLOUD_RES_TAG, "provisionProperties IN");
47 OCRepresentation provisioningRepresentation = cloudProp.toOCRepresentation();
49 m_ocResource->post(OC_RSRVD_ES_RES_TYPE_PROV, BATCH_INTERFACE,
50 provisioningRepresentation, QueryParamsMap(),
52 void(const HeaderOptions& headerOptions,
53 const OCRepresentation& rep, const int eCode) >(
54 std::bind(&CloudResource::onCloudProvResponse, this,
55 std::placeholders::_1, std::placeholders::_2,
56 std::placeholders::_3)), OC::QualityOfService::HighQos);
58 OIC_LOG (DEBUG, ES_CLOUD_RES_TAG, "provisionProperties OUT");
61 void CloudResource::onCloudProvResponse(const HeaderOptions& /*headerOptions*/,
62 const OCRepresentation& /*rep*/, const int eCode)
64 OIC_LOG_V (DEBUG, ES_CLOUD_RES_TAG, "onCloudProvResponse : eCode = %d",
67 if (eCode > OCStackResult::OC_STACK_RESOURCE_CHANGED)
69 ESResult result = ESResult::ES_ERROR;
71 OIC_LOG(DEBUG, ES_CLOUD_RES_TAG,"onCloudProvResponse : onCloudProvResponse is failed ");
73 if(eCode == OCStackResult::OC_STACK_COMM_ERROR)
75 OIC_LOG_V (DEBUG, ES_CLOUD_RES_TAG,
76 "can't receive any response from Enrollee by a timeout threshold.");
77 result = ESResult::ES_COMMUNICATION_ERROR;
80 std::shared_ptr< CloudPropProvisioningStatus > provStatus = std::make_shared<
81 CloudPropProvisioningStatus >(result);
82 m_cloudPropProvStatusCb(provStatus);
86 OIC_LOG(DEBUG, ES_CLOUD_RES_TAG,"onCloudProvResponse : onCloudProvResponse is success ");
87 std::shared_ptr< CloudPropProvisioningStatus > provStatus =
88 std::make_shared<CloudPropProvisioningStatus >(ESResult::ES_OK);
89 m_cloudPropProvStatusCb(provStatus);
93 void CloudResource::registerCloudPropProvisioningStatusCallback(
94 const CloudPropProvStatusCb callback)
96 m_cloudPropProvStatusCb = callback;