#include <vector>
#endif
+#include "OCPlatform.h"
#include "ocstack.h"
#include "octypes.h"
+using namespace OC;
using namespace std;
// Defines
* @brief Properties of provisioning resource. It includes a provisioning status and last
* error code.
*/
- typedef struct
+ class EnrolleeStatus
{
- ProvStatus provStatus;
- ESErrorCode lastErrCode;
- } EnrolleeStatus;
+ public:
+
+ /**
+ * Constructor
+ */
+ EnrolleeStatus(const OCRepresentation& rep) { m_rep = rep; }
+
+ /**
+ * Get a provisioning status property of Enrollee.
+ *
+ * @return a provisioning status property of Enrollee
+ */
+ ProvStatus getProvStatus()
+ {
+ if(m_rep.hasAttribute(OC_RSRVD_ES_PROVSTATUS))
+ return static_cast<ProvStatus>(
+ m_rep.getValue<int>(OC_RSRVD_ES_PROVSTATUS));
+ return ES_STATE_INIT;
+ }
+
+ /**
+ * Get a last error code property of Enrollee.
+ *
+ * @return a last error code property of Enrollee.
+ */
+ ESErrorCode getLastErrCode()
+ {
+ if(m_rep.hasAttribute(OC_RSRVD_ES_LAST_ERRORCODE))
+ return static_cast<ESErrorCode>(
+ m_rep.getValue<int>(OC_RSRVD_ES_LAST_ERRORCODE));
+ return ES_ERRCODE_NO_ERROR;
+ }
+ protected:
+ OCRepresentation m_rep;
+ };
/**
- * @brief Data structure stored for Cloud server property provisioning
+ * @brief Data class stored for Cloud server property provisioning
*/
- typedef struct
+ class CloudProp
{
- string authCode; /**< Auth code issued by OAuth2.0-compatible account server **/
- string authProvider; /**< Auth provider ID **/
- string ciServer; /**< Cloud interface server URL which an Enrollee is going to registered **/
- } CloudProp;
+ public:
+
+ /**
+ * Constructor
+ */
+ CloudProp() {};
+
+ /**
+ * Constructor with OCRepresentation object. This is used for JNI communication.
+ */
+ CloudProp(const OCRepresentation &rep) { m_rep = rep; }
+
+ /**
+ * Set CloudServer resource properties to be delivered to Enrollee
+ *
+ * @param authCode Auth code issued by OAuth2.0-compatible account server
+ * @param authProvider Auth provider ID
+ * @param ciServer Cloud interface server URL which an Enrollee is going to registered
+ */
+ void setCloudProp(string authCode, string authProvider, string ciServer)
+ {
+ m_rep.setValue(OC_RSRVD_ES_AUTHCODE, authCode);
+ m_rep.setValue(OC_RSRVD_ES_AUTHPROVIDER, authProvider);
+ m_rep.setValue(OC_RSRVD_ES_CISERVER, ciServer);
+ }
+
+ /**
+ * Get an auth code to be delivered.
+ *
+ * @return an auth code to be delivered.
+ */
+ std::string getAuthCode()
+ {
+ if(m_rep.hasAttribute(OC_RSRVD_ES_AUTHCODE))
+ return m_rep.getValue<std::string>(OC_RSRVD_ES_AUTHCODE);
+ return std::string("");
+ }
+
+ /**
+ * Get an auth provider which issued an auth code
+ *
+ * @return an auth provider which issued an auth code
+ */
+ std::string getAuthProvider()
+ {
+ if(m_rep.hasAttribute(OC_RSRVD_ES_AUTHPROVIDER))
+ return m_rep.getValue<std::string>(OC_RSRVD_ES_AUTHPROVIDER);
+ return std::string("");
+ }
+
+ /**
+ * Get a CI server to be delivered
+ *
+ * @return a CI server to be delivered
+ */
+ std::string getCiServer()
+ {
+ if(m_rep.hasAttribute(OC_RSRVD_ES_CISERVER))
+ return m_rep.getValue<std::string>(OC_RSRVD_ES_CISERVER);
+ return std::string("");
+ }
+
+ /**
+ * Get OCRepresentation object
+ *
+ * @return OCRepresentation object
+ */
+ const OCRepresentation &toOCRepresentation() const
+ {
+ return m_rep;
+ }
+ protected:
+ OCRepresentation m_rep;
+ };
/**
- * @brief Data structure stored for Device property provisioning which includes a WiFi
+ * @brief Data class stored for Device property provisioning which includes a WiFi
* and device configuration provisioning
*/
- typedef struct
+ class DeviceProp
{
+ public:
+
+ /**
+ * Constructor
+ */
+ DeviceProp() {}
+
+ /**
+ * Constructor with OCRepresentation object. This is used for JNI communication.
+ */
+ DeviceProp(const OCRepresentation &rep) { m_rep = rep; }
+
/**
- * @brief Data structure stored for WiFi property provisioning
+ * Set WiFi resource properties to be delivered to Enrollee
+ *
+ * @param ssid Ssid of the Enroller
+ * @param pwd Pwd of the Enrolle
+ * @param authtype Auth type of the Enroller
+ * @param enctype Encryption type of the Enroller
+ *
+ * @see WIFI_AUTHTYPE
+ * @see WIFI_ENCTYPE
*/
- struct
+ void setWiFiProp(string ssid, string pwd, WIFI_AUTHTYPE authtype, WIFI_ENCTYPE enctype)
{
- string ssid; /**< Ssid of the Enroller **/
- string pwd; /**< Pwd of the Enroller **/
- WIFI_AUTHTYPE authtype; /**< Auth type of the Enroller **/
- WIFI_ENCTYPE enctype; /**< Encryption type of the Enroller **/
- } WIFI;
+ m_rep.setValue(OC_RSRVD_ES_SSID, ssid);
+ m_rep.setValue(OC_RSRVD_ES_CRED, pwd);
+ m_rep.setValue(OC_RSRVD_ES_AUTHTYPE, authtype);
+ m_rep.setValue(OC_RSRVD_ES_ENCTYPE, enctype);
+ }
/**
- * @brief Data structure stored for device configuration property provisioning
+ * Set DevConf resource properties to be delivered to Enrollee
+ *
+ * @param language IETF language tag using ISO 639X
+ * @param country ISO Country Code (ISO 3166-1 Alpha-2)
*/
- struct
+ void setDevConfProp(string language, string country)
{
- string language; /**< IETF language tag using ISO 639X **/
- string country; /**< ISO Country Code (ISO 3166-1 Alpha-2) **/
- } Device;
- } DeviceProp;
+ m_rep.setValue(OC_RSRVD_ES_LANGUAGE, language);
+ m_rep.setValue(OC_RSRVD_ES_COUNTRY, country);
+ }
- /**
- * @brief Data structure for received properties of device configuration resource
- */
- typedef struct
- {
- string name; /**< Device's human-friendly name like device model name **/
- string language; /**< IETF language tag using ISO 639X **/
- string country; /**< ISO Country Code (ISO 3166-1 Alpha-2) **/
- } DeviceConfig;
+ /**
+ * Get a SSID of Enroller
+ *
+ * @return a SSID of enroller
+ */
+ std::string getSsid()
+ {
+ if(m_rep.hasAttribute(OC_RSRVD_ES_SSID))
+ return m_rep.getValue<std::string>(OC_RSRVD_ES_SSID);
+ return std::string("");
+ }
- /**
- * @brief Data structure for received properties of WiFi resource
- */
- typedef struct
- {
- vector<WIFI_MODE> modes; /**< Supported WIFI mode like 802.11g and 802.11n **/
- WIFI_FREQ freq; /**< Supported WIFI frequency like 2.4G and 5G **/
- } WiFiConfig;
+ /**
+ * Get a password of Enroller
+ *
+ * @return a password of enroller
+ */
+ std::string getPassword()
+ {
+ if(m_rep.hasAttribute(OC_RSRVD_ES_CRED))
+ return m_rep.getValue<std::string>(OC_RSRVD_ES_CRED);
+ return std::string("");
+ }
+
+ /**
+ * Get an auth type of Enroller
+ *
+ * @return an auth type of enroller
+ *
+ * @see WIFI_AUTHTYPE
+ */
+ WIFI_AUTHTYPE getAuthType()
+ {
+ if(m_rep.hasAttribute(OC_RSRVD_ES_AUTHTYPE))
+ return static_cast<WIFI_AUTHTYPE>(m_rep.getValue<int>(OC_RSRVD_ES_AUTHTYPE));
+ return NONE_AUTH;
+ }
+
+ /**
+ * Get an encryption type of Enroller
+ *
+ * @return an encryption type of enroller
+ *
+ * @see WIFI_ENCTYPE
+ */
+ WIFI_ENCTYPE getEncType()
+ {
+ if(m_rep.hasAttribute(OC_RSRVD_ES_ENCTYPE))
+ return static_cast<WIFI_ENCTYPE>(m_rep.getValue<int>(OC_RSRVD_ES_ENCTYPE));
+ return NONE_ENC;
+ }
+
+ /**
+ * Get a language to be set. A language is expressed in IETF language tag
+ * using ISO 639X.
+ *
+ * @return a language to be set
+ */
+ std::string getLanguage()
+ {
+ if(m_rep.hasAttribute(OC_RSRVD_ES_LANGUAGE))
+ return m_rep.getValue<std::string>(OC_RSRVD_ES_LANGUAGE);
+ return std::string("");
+ }
+
+ /**
+ * Get a country to be set. A country is expressed in ISO Country Code
+ * (ISO 3166-1 Alpha-2)
+ *
+ * @return a country to be set
+ */
+ std::string getCountry()
+ {
+ if(m_rep.hasAttribute(OC_RSRVD_ES_COUNTRY))
+ return m_rep.getValue<std::string>(OC_RSRVD_ES_COUNTRY);
+ return std::string("");
+ }
+
+ /**
+ * Get OCRepresentation object
+ *
+ * @return OCRepresentation object
+ */
+ const OCRepresentation &toOCRepresentation() const
+ {
+ return m_rep;
+ }
+
+ protected:
+ OCRepresentation m_rep;
+ };
/**
* @brief Provisioning state in cloud server property provisioning.
};
/**
- * It comprises sets of WiFi and device configuration properties.
- * Additionally, it provides a variable, m_cloudable, to make app know if
- * the enrollee has a preference to register IoTivity cloud server.
+ * @breif This provide a set of getter APIs from received response for getConfiguration().
+ * Received information includes a device name, WiFi supported mode, and frequency.
+ * Additionally, you can know if Enrollee can be access to cloud server with this
+ * object.
*/
class EnrolleeConf
{
public:
- EnrolleeConf()
+ /**
+ * Constructor
+ * The expected OCRepresentation is one for collection resource and has several child
+ * OCRepresentation object corresponding to WiFi, DevConf, and CloudServer resource's
+ * representation.
+ */
+ EnrolleeConf(const OCRepresentation& rep)
{
- m_devConfig.name = nullptr;
- m_devConfig.language = nullptr;
- m_devConfig.country = nullptr;
- m_wifiConfig.freq = WIFI_FREQ_NONE;
- m_cloudable = false;
+ m_ProvRep = rep;
+
+ std::vector<OCRepresentation> children = rep.getChildren();
+
+ for(auto child = children.begin(); child != children.end(); ++child)
+ {
+ if(child->getUri().find(OC_RSRVD_ES_URI_WIFI) != std::string::npos)
+ {
+ m_WiFiRep = *child;
+ }
+ else if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
+ {
+ m_DevConfRep = *child;
+ }
+ else if(child->getUri().find(OC_RSRVD_ES_URI_CLOUDSERVER) != std::string::npos)
+ {
+ m_CloudRep = *child;
+ }
+ }
}
- EnrolleeConf(DeviceConfig devConfig, WiFiConfig wifiConfig, bool cloudable) :
- m_devConfig(devConfig), m_wifiConfig(wifiConfig), m_cloudable(cloudable)
+ /**
+ * Get a device name of Enrollee. It is Device's human-friendly name like device model
+ * name.
+ *
+ * @return a device name of Enrollee
+ */
+ std::string getDeviceName()
{
+ if(m_DevConfRep.hasAttribute(OC_RSRVD_ES_DEVNAME))
+ return m_DevConfRep.getValue<std::string>(OC_RSRVD_ES_DEVNAME);
+ return std::string("");
}
- const DeviceConfig& getDevConf() const
+ /**
+ * Get a set of WiFi supported modes of Enrollee
+ *
+ * @return a set of WiFi supported modes of Enrollee
+ *
+ * @see WIFI_MODE
+ */
+ vector<WIFI_MODE> getWiFiModes()
{
- return m_devConfig;
+ vector<WIFI_MODE> modes;
+ modes.clear();
+
+ if(m_WiFiRep.hasAttribute(OC_RSRVD_ES_SUPPORTEDWIFIMODE))
+ {
+ for(auto it : m_WiFiRep.getValue
+ <std::vector<int>>(OC_RSRVD_ES_SUPPORTEDWIFIMODE))
+ {
+ modes.push_back(static_cast<WIFI_MODE>(it));
+ }
+ }
+ return modes;
}
- const WiFiConfig& getWiFiConf() const
+ /**
+ * Get a WiFi supported frequency of Enrollee
+ *
+ * @return a WiFi supported frequency of Enrollee
+ *
+ * @see WIFI_FREQ
+ */
+ WIFI_FREQ getWiFiFreq()
{
- return m_wifiConfig;
+ if(m_WiFiRep.hasAttribute(OC_RSRVD_ES_SUPPORTEDWIFIFREQ))
+ return static_cast<WIFI_FREQ>(
+ m_WiFiRep.getValue<int>(OC_RSRVD_ES_SUPPORTEDWIFIFREQ));
+ return WIFI_FREQ_NONE;
}
- bool isCloudable() const
+ /**
+ * Get an accessibility to cloud server of an Enrollee
+ *
+ * @return an accessibility to cloud server of an Enrollee
+ */
+ bool isCloudAccessible()
{
- return m_cloudable;
+ if(m_CloudRep.getUri().find(OC_RSRVD_ES_URI_CLOUDSERVER) != std::string::npos)
+ {
+ return true;
+ }
+ return false;
}
- private:
- DeviceConfig m_devConfig;
- WiFiConfig m_wifiConfig;
- bool m_cloudable;
+ /**
+ * Get OCRepresentation object
+ *
+ * @return OCRepresentation object
+ */
+ const OCRepresentation& getProvResRep()
+ {
+ return m_ProvRep;
+ }
+
+ protected:
+ OCRepresentation m_ProvRep, m_WiFiRep, m_DevConfRep, m_CloudRep;
};
/**
class GetEnrolleeStatus
{
public:
- GetEnrolleeStatus()
- {
- }
-
GetEnrolleeStatus(ESResult result, const EnrolleeStatus& status) :
m_result(result), m_enrolleeStatus(status)
{
const int eCode);
void checkProvInformationCb(const HeaderOptions& headerOptions, const OCRepresentation& rep,
const int eCode);
- EnrolleeConf parseEnrolleeConfFromRepresentation(const OCRepresentation& rep);
- EnrolleeStatus parseEnrolleeStatusFromRepresentation(const OCRepresentation& rep);
};
}
}
{
OIC_LOG_V (DEBUG, ES_CLOUD_RES_TAG, "Enter provisionEnrollee.");
- OCRepresentation provisioningRepresentation;
-
- provisioningRepresentation.setValue(OC_RSRVD_ES_AUTHCODE, cloudProp.authCode);
- provisioningRepresentation.setValue(OC_RSRVD_ES_AUTHPROVIDER, cloudProp.authProvider);
- provisioningRepresentation.setValue(OC_RSRVD_ES_CISERVER, cloudProp.ciServer);
-
- OIC_LOG_V (DEBUG, ES_CLOUD_RES_TAG, "provisionEnrollee : authCode - %s",
- (cloudProp.authCode).c_str());
- OIC_LOG_V (DEBUG, ES_CLOUD_RES_TAG, "provisionEnrollee : authProvider - %s",
- (cloudProp.authProvider).c_str());
- OIC_LOG_V (DEBUG, ES_CLOUD_RES_TAG, "provisionEnrollee : ciServer - %s",
- (cloudProp.ciServer).c_str());
+ OCRepresentation provisioningRepresentation = cloudProp.toOCRepresentation();
m_ocResource->post(OC_RSRVD_ES_RES_TYPE_PROV, BATCH_INTERFACE,
provisioningRepresentation, QueryParamsMap(),
result = ESResult::ES_UNAUTHORIZED;
}
- EnrolleeStatus enrolleeStatus = {ES_STATE_INIT, ES_ERRCODE_NO_ERROR};
+ EnrolleeStatus enrolleeStatus(rep);
std::shared_ptr< GetEnrolleeStatus > getEnrolleeStatus = std::make_shared<
GetEnrolleeStatus >(ESResult::ES_ERROR, enrolleeStatus);
}
else
{
- EnrolleeStatus enrolleeStatus = parseEnrolleeStatusFromRepresentation(rep);
+ EnrolleeStatus enrolleeStatus(rep);
std::shared_ptr< GetEnrolleeStatus > getEnrolleeStatus = std::make_shared<
GetEnrolleeStatus >(ESResult::ES_OK, enrolleeStatus);
result = ESResult::ES_UNAUTHORIZED;
}
- EnrolleeConf enrolleeConf;
+ EnrolleeConf enrolleeConf(rep);
std::shared_ptr< GetConfigurationStatus > getConfigurationStatus = std::make_shared<
GetConfigurationStatus >(result, enrolleeConf);
m_getConfigurationStatusCb(getConfigurationStatus);
}
else
{
- EnrolleeConf enrolleeConf = parseEnrolleeConfFromRepresentation(rep);
+ EnrolleeConf enrolleeConf(rep);
std::shared_ptr< GetConfigurationStatus > getConfigurationStatus = std::make_shared<
GetConfigurationStatus >(ESResult::ES_OK, enrolleeConf);
if (result != OCStackResult::OC_STACK_OK)
{
- EnrolleeStatus enrolleeStatus = {ES_STATE_INIT, ES_ERRCODE_NO_ERROR};
+ EnrolleeStatus enrolleeStatus(rep);// = {ES_STATE_INIT, ES_ERRCODE_NO_ERROR};
std::shared_ptr< GetEnrolleeStatus > getEnrolleeStatus = std::make_shared<
GetEnrolleeStatus >(ESResult::ES_ERROR, enrolleeStatus);
if (result != OCStackResult::OC_STACK_OK)
{
- EnrolleeConf enrolleeConf;
+ EnrolleeConf enrolleeConf(rep);
std::shared_ptr< GetConfigurationStatus > getConfigurationStatus = std::make_shared<
GetConfigurationStatus >(ESResult::ES_ERROR, enrolleeConf);
m_getConfigurationStatusCb(getConfigurationStatus);
}
void EnrolleeResource::provisionEnrollee(const DeviceProp& deviceProp)
-
{
if (m_ocResource == nullptr)
{
}
OC::QueryParamsMap query;
- OC::OCRepresentation provisioningRepresentation;
-
- provisioningRepresentation.setValue(OC_RSRVD_ES_SSID, deviceProp.WIFI.ssid);
- provisioningRepresentation.setValue(OC_RSRVD_ES_CRED, deviceProp.WIFI.pwd);
- provisioningRepresentation.setValue(OC_RSRVD_ES_AUTHTYPE, deviceProp.WIFI.authtype);
- provisioningRepresentation.setValue(OC_RSRVD_ES_ENCTYPE, deviceProp.WIFI.enctype);
- provisioningRepresentation.setValue(OC_RSRVD_ES_LANGUAGE, deviceProp.Device.language);
- provisioningRepresentation.setValue(OC_RSRVD_ES_COUNTRY, deviceProp.Device.country);
-
- OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : ssid - %s",
- (deviceProp.WIFI.ssid).c_str());
- OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : pwd - %s",
- (deviceProp.WIFI.pwd).c_str());
- OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : authtype - %d",
- deviceProp.WIFI.authtype);
- OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : enctype - %d",
- deviceProp.WIFI.enctype);
- OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : language - %s",
- (deviceProp.Device.language).c_str());
- OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : country - %s",
- (deviceProp.Device.country).c_str());
+ OC::OCRepresentation provisioningRepresentation = deviceProp.toOCRepresentation();
m_ocResource->post(OC_RSRVD_ES_RES_TYPE_PROV, BATCH_INTERFACE,
provisioningRepresentation, QueryParamsMap(),
std::placeholders::_1, std::placeholders::_2,
std::placeholders::_3)));
}
-
- EnrolleeConf EnrolleeResource::parseEnrolleeConfFromRepresentation(const OCRepresentation& rep)
- {
- OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_RES_TAG, "Enter parseEnrolleeConfFromRepresentation");
-
- DeviceConfig devConf;
- WiFiConfig wifiConf;
- bool cloudable = false;
-
- std::vector<OCRepresentation> children = rep.getChildren();
-
- for(auto prop = children.begin(); prop != children.end(); ++prop)
- {
- if(prop->getUri().find(OC_RSRVD_ES_URI_WIFI) != std::string::npos)
- {
- OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_RES_TAG, "Find wifi resource");
- if(prop->hasAttribute(OC_RSRVD_ES_SUPPORTEDWIFIMODE)
- && prop->hasAttribute(OC_RSRVD_ES_SUPPORTEDWIFIFREQ))
- {
- std::vector<int> modes = prop->getValue<std::vector<int>>(OC_RSRVD_ES_SUPPORTEDWIFIMODE);
-
- for(auto mode = modes.begin(); mode != modes.end(); ++mode)
- {
- OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "OC_RSRVD_ES_SUPPORTEDWIFIMODE = %d",
- *mode);
- wifiConf.modes.push_back(static_cast<WIFI_MODE>(*mode));
- }
-
- wifiConf.freq = static_cast<WIFI_FREQ>(prop->getValue<int>(OC_RSRVD_ES_SUPPORTEDWIFIFREQ));
-
-
- OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "OC_RSRVD_ES_SUPPORTEDWIFIFREQ = %d",
- wifiConf.freq);
- }
- }
-
- else if(prop->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
- {
- OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_RES_TAG, "Find devconf");
- if(prop->hasAttribute(OC_RSRVD_ES_DEVNAME)
- && prop->hasAttribute(OC_RSRVD_ES_LANGUAGE)
- && prop->hasAttribute(OC_RSRVD_ES_COUNTRY))
- {
- //TODO:: setting DeviceID.
- //devInfo.id = devId;
- devConf.name = prop->getValue<std::string>(OC_RSRVD_ES_DEVNAME);
- devConf.language = prop->getValue<std::string>(OC_RSRVD_ES_LANGUAGE);
- devConf.country = prop->getValue<std::string>(OC_RSRVD_ES_COUNTRY);
-
- OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "OC_RSRVD_ES_DEVNAME = %s",
- devConf.name.c_str());
- OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "OC_RSRVD_ES_LANGUAGE = %s",
- devConf.language.c_str());
- OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "OC_RSRVD_ES_COUNTRY = %s",
- devConf.country.c_str());
- }
- }
-
- else if(prop->getUri().find(OC_RSRVD_ES_URI_CLOUDSERVER) != std::string::npos)
- {
- OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_RES_TAG, "Find cloudserver");
- cloudable = true;
- OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "cloudable = %d",
- cloudable);
- }
- }
-
- return EnrolleeConf(devConf, wifiConf, cloudable);
- }
-
- EnrolleeStatus EnrolleeResource::parseEnrolleeStatusFromRepresentation(const OCRepresentation& rep)
- {
- OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_RES_TAG, "Enter parseEnrolleeStatusFromRepresentation");
-
- EnrolleeStatus enrolleeStatus;
-
- if(rep.hasAttribute(OC_RSRVD_ES_PROVSTATUS))
- {
- enrolleeStatus.provStatus = static_cast<ProvStatus>(
- rep.getValue<int>(OC_RSRVD_ES_PROVSTATUS));
- }
-
- if(rep.hasAttribute(OC_RSRVD_ES_LAST_ERRORCODE))
- {
- enrolleeStatus.lastErrCode = static_cast<ESErrorCode>(
- rep.getValue<int>(OC_RSRVD_ES_LAST_ERRORCODE));
- }
-
- return enrolleeStatus;
- }
}
}
m_enrolleeResource->getConfiguration();
}
- void RemoteEnrollee::provisionDeviceProperties(const DeviceProp& devProp, DevicePropProvStatusCb callback)
+ void RemoteEnrollee::provisionDeviceProperties(const DeviceProp& deviceProp, DevicePropProvStatusCb callback)
{
OIC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Enter provisionDeviceProperties");
throw ESBadRequestException ("Device not created");
}
- if(devProp.WIFI.ssid.empty())
+ if(!deviceProp.toOCRepresentation().hasAttribute(OC_RSRVD_ES_SSID))
{
throw ESBadRequestException ("Invalid Provisiong Data.");
}
&RemoteEnrollee::devicePropProvisioningStatusHandler, this, std::placeholders::_1);
m_enrolleeResource->registerDevicePropProvStatusCallback(devicePropProvStatusCb);
- m_enrolleeResource->provisionEnrollee(devProp);
+ m_enrolleeResource->provisionEnrollee(deviceProp);
}
void RemoteEnrollee::initCloudResource()
m_cloudPropProvStatusCb = callback;
- if(cloudProp.authCode.empty()
- || cloudProp.authProvider.empty()
- || cloudProp.ciServer.empty())
+ if(!cloudProp.toOCRepresentation().hasAttribute(OC_RSRVD_ES_AUTHCODE) ||
+ !cloudProp.toOCRepresentation().hasAttribute(OC_RSRVD_ES_AUTHPROVIDER) ||
+ !cloudProp.toOCRepresentation().hasAttribute(OC_RSRVD_ES_CISERVER))
{
throw ESBadRequestException ("Invalid Cloud Provisiong Info.");
}
void printConfiguration(EnrolleeConf conf)
{
cout << "===========================================" << endl;
- DeviceConfig devConfig = conf.getDevConf();
- WiFiConfig wifiConfig = conf.getWiFiConf();
+ cout << "\tDevice Name : " << conf.getDeviceName() << endl;
- cout << "\tDeviceConfig.name : " << devConfig.name << endl;
- cout << "\tDeviceConfig.language : " << devConfig.language << endl;
- cout << "\tDeviceConfig.country : " << devConfig.country << endl;
-
- for(auto mode = wifiConfig.modes.begin(); mode != wifiConfig.modes.end(); ++mode)
+ for(auto it : conf.getWiFiModes())
{
- cout << "\tnetInfo.modes : " << static_cast<int>(*mode) << endl;
+ cout << "\tSupported WiFi modes : " << it << endl;
}
- cout << "\tnetInfo.freq : " << static_cast<int>(wifiConfig.freq) << endl;
+
+ cout << "\tSupported WiFi freq : " << static_cast<int>(conf.getWiFiFreq()) << endl;
+ cout << "\tCloud accessibility: " << conf.isCloudAccessible() << endl;
cout << "===========================================" << endl;
}
void printStatus(EnrolleeStatus status)
{
cout << "===========================================" << endl;
- cout << "\tEnrolleeStatus.provStatus : " << status.provStatus << endl;
- cout << "\tEnrolleeStatus.lastErrCode : " << status.lastErrCode << endl;
+ cout << "\tProvStatus : " << status.getProvStatus() << endl;
+ cout << "\tLastErrCode : " << status.getLastErrCode() << endl;
cout << "===========================================" << endl;
}
if(!remoteEnrollee)
return;
- DeviceProp deviceProp;
- deviceProp.WIFI.ssid = "Iotivity_SSID";
- deviceProp.WIFI.pwd = "Iotivity_PWD";
- deviceProp.WIFI.authtype = WPA2_PSK;
- deviceProp.WIFI.enctype = TKIP_AES;
- deviceProp.Device.language = "korean";
- deviceProp.Device.country = "Korea";
+ DeviceProp devProp;
+ devProp.setWiFiProp("Iotivity_SSID", "Iotivity_PWD", WPA2_PSK, TKIP_AES);
+ devProp.setDevConfProp("korean", "Korea");
try
{
- remoteEnrollee->provisionDeviceProperties(deviceProp, deviceProvisioningStatusCallback);
+ //remoteEnrollee->provisionDeviceProperties(deviceProp, deviceProvisioningStatusCallback);
+ remoteEnrollee->provisionDeviceProperties(devProp, deviceProvisioningStatusCallback);
}
catch (OCException &e)
{
return;
CloudProp cloudProp;
- cloudProp.authCode = "authCode";
- cloudProp.authProvider = "authProvider";
- cloudProp.ciServer = "ciServer";
+ cloudProp.setCloudProp("authCode", "authProvider", "ciServer");
try
{