1 //******************************************************************
3 // Copyright 2016 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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #ifndef ES_COMMON_RICH_H_
22 #define ES_COMMON_RICH_H_
31 #include "OCPlatform.h"
46 * @brief Properties of provisioning resource. It includes a provisioning status and last
56 EnrolleeStatus(const OCRepresentation& rep)
61 EnrolleeStatus(const EnrolleeStatus& enrolleeStatus) :
62 m_rep(enrolleeStatus.getRepresentation())
66 EnrolleeStatus(const EnrolleeStatus&& enrolleeStatus) :
67 m_rep(std::move(enrolleeStatus.getRepresentation()))
72 * Get a provisioning status property of Enrollee.
74 * @return a provisioning status property of Enrollee
76 ProvStatus getProvStatus()
78 if(m_rep.hasAttribute(OC_RSRVD_ES_PROVSTATUS))
80 return static_cast<ProvStatus>(
81 m_rep.getValue<int>(OC_RSRVD_ES_PROVSTATUS));
87 * Get a last error code property of Enrollee.
89 * @return a last error code property of Enrollee.
91 ESErrorCode getLastErrCode()
93 if(m_rep.hasAttribute(OC_RSRVD_ES_LAST_ERRORCODE))
95 return static_cast<ESErrorCode>(
96 m_rep.getValue<int>(OC_RSRVD_ES_LAST_ERRORCODE));
98 return ES_ERRCODE_NO_ERROR;
102 * Get OCRepresentation object
104 * @return OCRepresentation object
106 const OCRepresentation& getRepresentation() const
111 OCRepresentation m_rep;
115 * @brief Data class stored for Cloud server property provisioning
128 CloudProp(const CloudProp& cloudProp) :
129 m_rep(cloudProp.toOCRepresentation()), m_cloudID(cloudProp.getCloudID())
133 CloudProp(const CloudProp&& cloudProp) :
134 m_rep(std::move(cloudProp.toOCRepresentation())), m_cloudID(cloudProp.getCloudID())
139 * Constructor with OCRepresentation object. This is used for JNI communication.
141 CloudProp(const OCRepresentation &rep)
148 * Set CloudServer resource properties to be delivered to Enrollee
150 * @param authCode Auth code issued by OAuth2.0-compatible account server
151 * @param authProvider Auth provider ID
152 * @param ciServer Cloud interface server URL which an Enrollee is going to registered
154 void setCloudProp(string authCode, string authProvider, string ciServer)
156 m_rep.setValue(OC_RSRVD_ES_AUTHCODE, authCode);
157 m_rep.setValue(OC_RSRVD_ES_AUTHPROVIDER, authProvider);
158 m_rep.setValue(OC_RSRVD_ES_CISERVER, ciServer);
162 * Set CloudServer's UUID
164 * @param cloudID Cloud Interface server's UUID
166 void setCloudID(string cloudID)
172 * Get an auth code to be delivered.
174 * @return an auth code to be delivered.
176 std::string getAuthCode() const
178 if(m_rep.hasAttribute(OC_RSRVD_ES_AUTHCODE))
180 return m_rep.getValue<std::string>(OC_RSRVD_ES_AUTHCODE);
182 return std::string("");
186 * Get an auth provider which issued an auth code
188 * @return an auth provider which issued an auth code
190 std::string getAuthProvider() const
192 if(m_rep.hasAttribute(OC_RSRVD_ES_AUTHPROVIDER))
194 return m_rep.getValue<std::string>(OC_RSRVD_ES_AUTHPROVIDER);
196 return std::string("");
200 * Get a CI server to be delivered
202 * @return a CI server to be delivered
204 std::string getCiServer() const
206 if(m_rep.hasAttribute(OC_RSRVD_ES_CISERVER))
208 return m_rep.getValue<std::string>(OC_RSRVD_ES_CISERVER);
210 return std::string("");
214 * Get a CI server's Uuid to be delivered
216 * @return a CI server's Uuid to be delivered
218 std::string getCloudID() const
224 * Get OCRepresentation object
226 * @return OCRepresentation object
228 const OCRepresentation &toOCRepresentation() const
233 OCRepresentation m_rep;
234 std::string m_cloudID;
238 * @brief Data class stored for Device property provisioning which includes a WiFi
239 * and device configuration provisioning
252 DeviceProp(const DeviceProp& deviceProp) :
253 m_rep(deviceProp.toOCRepresentation())
257 DeviceProp(const DeviceProp&& deviceProp) :
258 m_rep(std::move(deviceProp.toOCRepresentation()))
263 * Constructor with OCRepresentation object. This is used for JNI communication.
265 DeviceProp(const OCRepresentation &rep)
271 * Set WiFi resource properties to be delivered to Enrollee
273 * @param ssid Ssid of the Enroller
274 * @param pwd Pwd of the Enrolle
275 * @param authtype Auth type of the Enroller
276 * @param enctype Encryption type of the Enroller
281 void setWiFiProp(string ssid, string pwd, WIFI_AUTHTYPE authtype, WIFI_ENCTYPE enctype)
283 m_rep.setValue(OC_RSRVD_ES_SSID, ssid);
284 m_rep.setValue(OC_RSRVD_ES_CRED, pwd);
285 m_rep.setValue(OC_RSRVD_ES_AUTHTYPE, authtype);
286 m_rep.setValue(OC_RSRVD_ES_ENCTYPE, enctype);
290 * Set DevConf resource properties to be delivered to Enrollee
292 * @param language IETF language tag using ISO 639X
293 * @param country ISO Country Code (ISO 3166-1 Alpha-2)
295 void setDevConfProp(string language, string country, string location)
297 m_rep.setValue(OC_RSRVD_ES_LANGUAGE, language);
298 m_rep.setValue(OC_RSRVD_ES_COUNTRY, country);
299 m_rep.setValue(OC_RSRVD_ES_LOCATION, location);
303 * Get a SSID of Enroller
305 * @return a SSID of enroller
307 std::string getSsid() const
309 if(m_rep.hasAttribute(OC_RSRVD_ES_SSID))
311 return m_rep.getValue<std::string>(OC_RSRVD_ES_SSID);
313 return std::string("");
317 * Get a password of Enroller
319 * @return a password of enroller
321 std::string getPassword() const
323 if(m_rep.hasAttribute(OC_RSRVD_ES_CRED))
325 return m_rep.getValue<std::string>(OC_RSRVD_ES_CRED);
327 return std::string("");
331 * Get an auth type of Enroller
333 * @return an auth type of enroller
337 WIFI_AUTHTYPE getAuthType() const
339 if(m_rep.hasAttribute(OC_RSRVD_ES_AUTHTYPE))
341 return static_cast<WIFI_AUTHTYPE>(m_rep.getValue<int>(OC_RSRVD_ES_AUTHTYPE));
347 * Get an encryption type of Enroller
349 * @return an encryption type of enroller
353 WIFI_ENCTYPE getEncType() const
355 if(m_rep.hasAttribute(OC_RSRVD_ES_ENCTYPE))
357 return static_cast<WIFI_ENCTYPE>(m_rep.getValue<int>(OC_RSRVD_ES_ENCTYPE));
363 * Get a language to be set. A language is expressed in IETF language tag
366 * @return a language to be set
368 std::string getLanguage() const
370 if(m_rep.hasAttribute(OC_RSRVD_ES_LANGUAGE))
372 return m_rep.getValue<std::string>(OC_RSRVD_ES_LANGUAGE);
374 return std::string("");
378 * Get a country to be set. A country is expressed in ISO Country Code
379 * (ISO 3166-1 Alpha-2)
381 * @return a country to be set
383 std::string getCountry() const
385 if(m_rep.hasAttribute(OC_RSRVD_ES_COUNTRY))
387 return m_rep.getValue<std::string>(OC_RSRVD_ES_COUNTRY);
389 return std::string("");
393 * Get a location to be set. A location is GPS information
395 * @return a country to be set
397 std::string getLocation() const
399 if(m_rep.hasAttribute(OC_RSRVD_ES_MODELNUMBER))
401 return m_rep.getValue<std::string>(OC_RSRVD_ES_MODELNUMBER);
403 return std::string("");
407 * Get OCRepresentation object
409 * @return OCRepresentation object
411 const OCRepresentation &toOCRepresentation() const
417 OCRepresentation m_rep;
421 * @brief Provisioning state in cloud server property provisioning.
425 ES_CLOUD_PROVISIONING_ERROR = -1, /**< An error in cloud provisioning happens **/
426 ES_CLOUD_PROVISIONING_SUCCESS, /**< Cloud provisioning is successfully done **/
427 ES_CLOUD_ENROLLEE_FOUND, /**< An enrollee is found in a given network **/
428 ES_CLOUD_ENROLLEE_NOT_FOUND /**< NO enrollee is found in a given network **/
432 * Security Provisioning Status
434 class SecProvisioningStatus
437 SecProvisioningStatus(string deviceUUID, ESResult result) :
438 m_devUUID(deviceUUID), m_result(result)
442 const string getDeviceUUID()
447 ESResult getESResult()
457 * @breif This provide a set of getter APIs from received response for getConfiguration().
458 * Received information includes a device name, WiFi supported mode, and frequency.
459 * Additionally, you can know if Enrollee can be access to cloud server with this
467 * The expected OCRepresentation is one for collection resource and has several child
468 * OCRepresentation object corresponding to WiFi, DevConf, and CloudServer resource's
471 EnrolleeConf(const OCRepresentation& rep) :
476 EnrolleeConf(const EnrolleeConf& enrolleeConf) :
477 m_ProvRep(enrolleeConf.getProvResRep())
481 EnrolleeConf(const EnrolleeConf&& enrolleeConf) :
482 m_ProvRep(std::move(enrolleeConf.getProvResRep()))
487 * Get a device name of Enrollee. It is Device's human-friendly name like device model
490 * @return a device name of Enrollee
492 std::string getDeviceName() const
494 std::vector<OCRepresentation> children = m_ProvRep.getChildren();
495 for(auto child = children.begin(); child != children.end(); ++child)
497 if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
499 if(child->hasAttribute(OC_RSRVD_ES_DEVNAME))
501 return child->getValue<std::string>(OC_RSRVD_ES_DEVNAME);
505 return std::string("");
509 * Get a model number of Enrollee.
511 * @return a model number of Enrollee
513 std::string getModelNumber() const
515 std::vector<OCRepresentation> children = m_ProvRep.getChildren();
516 for(auto child = children.begin(); child != children.end(); ++child)
518 if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
520 if(child->hasAttribute(OC_RSRVD_ES_MODELNUMBER))
522 return child->getValue<std::string>(OC_RSRVD_ES_MODELNUMBER);
526 return std::string("");
530 * Get a set of WiFi supported modes of Enrollee
532 * @return a set of WiFi supported modes of Enrollee
536 vector<WIFI_MODE> getWiFiModes() const
538 vector<WIFI_MODE> modes;
541 std::vector<OCRepresentation> children = m_ProvRep.getChildren();
542 for(auto child = children.begin(); child != children.end(); ++child)
544 if(child->getUri().find(OC_RSRVD_ES_URI_WIFI) != std::string::npos)
546 if(child->hasAttribute(OC_RSRVD_ES_SUPPORTEDWIFIMODE))
548 for(auto it : child->getValue
549 <std::vector<int>>(OC_RSRVD_ES_SUPPORTEDWIFIMODE))
551 modes.push_back(static_cast<WIFI_MODE>(it));
560 * Get a WiFi supported frequency of Enrollee
562 * @return a WiFi supported frequency of Enrollee
566 WIFI_FREQ getWiFiFreq() const
568 std::vector<OCRepresentation> children = m_ProvRep.getChildren();
569 for(auto child = children.begin(); child != children.end(); ++child)
571 if(child->getUri().find(OC_RSRVD_ES_URI_WIFI) != std::string::npos)
573 if(child->hasAttribute(OC_RSRVD_ES_SUPPORTEDWIFIFREQ))
575 return static_cast<WIFI_FREQ>(
576 child->getValue<int>(OC_RSRVD_ES_SUPPORTEDWIFIFREQ));
580 return WIFI_FREQ_NONE;
584 * Get an accessibility to cloud server of an Enrollee
586 * @return an accessibility to cloud server of an Enrollee
588 bool isCloudAccessible() const
590 std::vector<OCRepresentation> children = m_ProvRep.getChildren();
591 for(auto child = children.begin(); child != children.end(); ++child)
593 if(child->getUri().find(OC_RSRVD_ES_URI_CLOUDSERVER) != std::string::npos)
602 * Get OCRepresentation object
604 * @return OCRepresentation object
606 const OCRepresentation& getProvResRep() const
612 OCRepresentation m_ProvRep;
616 * Status object for getStatus API. This object is given to application
617 * when a response for GET request to provisioning resource at Enrollee is arrived.
618 * It returns a result of the API and requested data delivered in the response which includes
619 * a provisioning status and last error code stored in Enrollee.
621 * @see EnrolleeStatus
623 class GetEnrolleeStatus
626 GetEnrolleeStatus(ESResult result, const EnrolleeStatus& status) :
627 m_result(result), m_enrolleeStatus(status)
631 ESResult getESResult()
636 const EnrolleeStatus& getEnrolleeStatus()
638 return m_enrolleeStatus;
643 EnrolleeStatus m_enrolleeStatus;
647 * Status object for getConfiguration API. This object is given to application
648 * when a response for GET request to provisioning resource at Enrollee is arrived.
649 * It returns a result of the API and requested data delivered in the response which includes
650 * WiFi configuration and device configuration stored in Enrollee.
654 class GetConfigurationStatus
657 GetConfigurationStatus(ESResult result, const EnrolleeConf& conf) :
658 m_result(result), m_enrolleeConf(conf)
662 ESResult getESResult()
667 EnrolleeConf& getEnrolleeConf()
669 return m_enrolleeConf;
674 EnrolleeConf m_enrolleeConf;
678 * Status object for provisionDeviceProperties API. This object is given to application
679 * when a response for GET request to provisioning resource at Enrollee is arrived.
680 * It returns a result of the request.
682 class DevicePropProvisioningStatus
685 DevicePropProvisioningStatus(ESResult result) :
690 ESResult getESResult()
700 * Status object for provisionCloudProperties API. This object is given to application
701 * when a response for GET request to provisioning resource at Enrollee is arrived.
702 * It returns a result of the request and status of this provisioning. The status provides
703 * an information if the enrollee is found in a given network and the provisioning is
706 class CloudPropProvisioningStatus
709 CloudPropProvisioningStatus(ESResult result, ESCloudProvState state) :
710 m_result(result), m_esCloudState(state)
714 ESResult getESResult()
719 ESCloudProvState getESCloudState()
721 return m_esCloudState;
726 ESCloudProvState m_esCloudState;
730 * Callback function definition for providing Enrollee status
732 typedef function< void(shared_ptr< GetEnrolleeStatus >) > GetStatusCb;
735 * Callback function definition for providing Enrollee configuration status
737 typedef function< void(shared_ptr< GetConfigurationStatus >) > GetConfigurationStatusCb;
740 * Callback function definition for providing Enrollee device property provisioning status
742 typedef function< void(shared_ptr< DevicePropProvisioningStatus >) > DevicePropProvStatusCb;
745 * Callback function definition for providing Enrollee cloud property provisioning status
747 typedef function< void(shared_ptr< CloudPropProvisioningStatus >) > CloudPropProvStatusCb;
750 * Callback function definition for providing Enrollee security provisioning status
752 typedef function< void(shared_ptr<SecProvisioningStatus>) > SecurityProvStatusCb;
755 * Callback definition to be invoked when the security stack expects a pin from application
757 typedef function< void(string&) > SecurityPinCb;
760 * Callback definition to be invoked when the stack expects a db path
762 typedef function< void(string&) > SecProvisioningDbPathCb;
766 #endif //WITH_ARDUINO
768 #endif //ES_COMMON_RICH_H_