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
130 CloudProp(const CloudProp& cloudProp) :
131 m_rep(cloudProp.toOCRepresentation()),
132 m_cloudID(cloudProp.getCloudID()),
133 m_credID(cloudProp.getCredID())
137 CloudProp(const CloudProp&& cloudProp) :
138 m_rep(std::move(cloudProp.toOCRepresentation())),
139 m_cloudID(cloudProp.getCloudID()),
140 m_credID(cloudProp.getCredID())
145 * Constructor with OCRepresentation object. This is used for JNI communication.
147 CloudProp(const OCRepresentation &rep)
154 * Set CloudServer resource properties to be delivered to Enrollee
156 * @param authCode Auth code issued by OAuth2.0-compatible account server
157 * @param authProvider Auth provider ID
158 * @param ciServer Cloud interface server URL which an Enrollee is going to registered
160 void setCloudProp(string authCode, string authProvider, string ciServer)
162 m_rep.setValue(OC_RSRVD_ES_AUTHCODE, authCode);
163 m_rep.setValue(OC_RSRVD_ES_AUTHPROVIDER, authProvider);
164 m_rep.setValue(OC_RSRVD_ES_CISERVER, ciServer);
168 * Set CloudServer's UUID
170 * @param cloudID Cloud Interface server's UUID
172 void setCloudID(string cloudID)
178 * Set CloudServer's credential ID of certificate
180 * @param credID Cloud Interface server's credential ID of certificate
182 void setCredID(int credID)
188 * Get an auth code to be delivered.
190 * @return an auth code to be delivered.
192 std::string getAuthCode() const
194 if(m_rep.hasAttribute(OC_RSRVD_ES_AUTHCODE))
196 return m_rep.getValue<std::string>(OC_RSRVD_ES_AUTHCODE);
198 return std::string("");
202 * Get an auth provider which issued an auth code
204 * @return an auth provider which issued an auth code
206 std::string getAuthProvider() const
208 if(m_rep.hasAttribute(OC_RSRVD_ES_AUTHPROVIDER))
210 return m_rep.getValue<std::string>(OC_RSRVD_ES_AUTHPROVIDER);
212 return std::string("");
216 * Get a CI server to be delivered
218 * @return a CI server to be delivered
220 std::string getCiServer() const
222 if(m_rep.hasAttribute(OC_RSRVD_ES_CISERVER))
224 return m_rep.getValue<std::string>(OC_RSRVD_ES_CISERVER);
226 return std::string("");
230 * Get a CI server's Uuid to be delivered
232 * @return a CI server's Uuid to be delivered
234 std::string getCloudID() const
240 * Get a CI server's credential ID of certificate
242 * @return a CI server's credential ID of certificated
244 int getCredID() const
250 * Get OCRepresentation object
252 * @return OCRepresentation object
254 const OCRepresentation &toOCRepresentation() const
259 OCRepresentation m_rep;
260 std::string m_cloudID;
265 * @brief Data class stored for Device property provisioning which includes a WiFi
266 * and device configuration provisioning
279 DeviceProp(const DeviceProp& deviceProp) :
280 m_rep(deviceProp.toOCRepresentation())
284 DeviceProp(const DeviceProp&& deviceProp) :
285 m_rep(std::move(deviceProp.toOCRepresentation()))
290 * Constructor with OCRepresentation object. This is used for JNI communication.
292 DeviceProp(const OCRepresentation &rep)
298 * Set WiFi resource properties to be delivered to Enrollee
300 * @param ssid Ssid of the Enroller
301 * @param pwd Pwd of the Enrolle
302 * @param authtype Auth type of the Enroller
303 * @param enctype Encryption type of the Enroller
308 void setWiFiProp(string ssid, string pwd, WIFI_AUTHTYPE authtype, WIFI_ENCTYPE enctype)
310 m_rep.setValue(OC_RSRVD_ES_SSID, ssid);
311 m_rep.setValue(OC_RSRVD_ES_CRED, pwd);
312 m_rep.setValue(OC_RSRVD_ES_AUTHTYPE, authtype);
313 m_rep.setValue(OC_RSRVD_ES_ENCTYPE, enctype);
317 * Set DevConf resource properties to be delivered to Enrollee
319 * @param language IETF language tag using ISO 639X
320 * @param country ISO Country Code (ISO 3166-1 Alpha-2)
322 void setDevConfProp(string language, string country, string location)
324 m_rep.setValue(OC_RSRVD_ES_LANGUAGE, language);
325 m_rep.setValue(OC_RSRVD_ES_COUNTRY, country);
326 m_rep.setValue(OC_RSRVD_ES_LOCATION, location);
330 * Get a SSID of Enroller
332 * @return a SSID of enroller
334 std::string getSsid() const
336 if(m_rep.hasAttribute(OC_RSRVD_ES_SSID))
338 return m_rep.getValue<std::string>(OC_RSRVD_ES_SSID);
340 return std::string("");
344 * Get a password of Enroller
346 * @return a password of enroller
348 std::string getPassword() const
350 if(m_rep.hasAttribute(OC_RSRVD_ES_CRED))
352 return m_rep.getValue<std::string>(OC_RSRVD_ES_CRED);
354 return std::string("");
358 * Get an auth type of Enroller
360 * @return an auth type of enroller
364 WIFI_AUTHTYPE getAuthType() const
366 if(m_rep.hasAttribute(OC_RSRVD_ES_AUTHTYPE))
368 return static_cast<WIFI_AUTHTYPE>(m_rep.getValue<int>(OC_RSRVD_ES_AUTHTYPE));
374 * Get an encryption type of Enroller
376 * @return an encryption type of enroller
380 WIFI_ENCTYPE getEncType() const
382 if(m_rep.hasAttribute(OC_RSRVD_ES_ENCTYPE))
384 return static_cast<WIFI_ENCTYPE>(m_rep.getValue<int>(OC_RSRVD_ES_ENCTYPE));
390 * Get a language to be set. A language is expressed in IETF language tag
393 * @return a language to be set
395 std::string getLanguage() const
397 if(m_rep.hasAttribute(OC_RSRVD_ES_LANGUAGE))
399 return m_rep.getValue<std::string>(OC_RSRVD_ES_LANGUAGE);
401 return std::string("");
405 * Get a country to be set. A country is expressed in ISO Country Code
406 * (ISO 3166-1 Alpha-2)
408 * @return a country to be set
410 std::string getCountry() const
412 if(m_rep.hasAttribute(OC_RSRVD_ES_COUNTRY))
414 return m_rep.getValue<std::string>(OC_RSRVD_ES_COUNTRY);
416 return std::string("");
420 * Get a location to be set. A location is GPS information
422 * @return a country to be set
424 std::string getLocation() const
426 if(m_rep.hasAttribute(OC_RSRVD_ES_LOCATION))
428 return m_rep.getValue<std::string>(OC_RSRVD_ES_LOCATION);
430 return std::string("");
434 * Get OCRepresentation object
436 * @return OCRepresentation object
438 const OCRepresentation &toOCRepresentation() const
444 OCRepresentation m_rep;
448 * Security Provisioning Status
450 class SecProvisioningStatus
453 SecProvisioningStatus(string deviceUUID, ESResult result) :
454 m_devUUID(deviceUUID), m_result(result)
458 const string getDeviceUUID()
463 ESResult getESResult()
473 * @breif This provide a set of getter APIs from received response for getConfiguration().
474 * Received information includes a device name, WiFi supported mode, and frequency.
475 * Additionally, you can know if Enrollee can be access to cloud server with this
483 * The expected OCRepresentation is one for collection resource and has several child
484 * OCRepresentation object corresponding to WiFi, DevConf, and CloudServer resource's
487 EnrolleeConf(const OCRepresentation& rep) :
492 EnrolleeConf(const EnrolleeConf& enrolleeConf) :
493 m_ProvRep(enrolleeConf.getProvResRep())
497 EnrolleeConf(const EnrolleeConf&& enrolleeConf) :
498 m_ProvRep(std::move(enrolleeConf.getProvResRep()))
503 * Get a device name of Enrollee. It is Device's human-friendly name like device model
506 * @return a device name of Enrollee
508 std::string getDeviceName() const
510 std::vector<OCRepresentation> children = m_ProvRep.getChildren();
511 for(auto child = children.begin(); child != children.end(); ++child)
513 if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
515 if(child->hasAttribute(OC_RSRVD_ES_DEVNAME))
517 return child->getValue<std::string>(OC_RSRVD_ES_DEVNAME);
521 return std::string("");
525 * Get a model number of Enrollee.
527 * @return a model number of Enrollee
529 std::string getModelNumber() const
531 std::vector<OCRepresentation> children = m_ProvRep.getChildren();
532 for(auto child = children.begin(); child != children.end(); ++child)
534 if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
536 if(child->hasAttribute(OC_RSRVD_ES_MODELNUMBER))
538 return child->getValue<std::string>(OC_RSRVD_ES_MODELNUMBER);
542 return std::string("");
546 * Get a set of WiFi supported modes of Enrollee
548 * @return a set of WiFi supported modes of Enrollee
552 vector<WIFI_MODE> getWiFiModes() const
554 vector<WIFI_MODE> modes;
557 std::vector<OCRepresentation> children = m_ProvRep.getChildren();
558 for(auto child = children.begin(); child != children.end(); ++child)
560 if(child->getUri().find(OC_RSRVD_ES_URI_WIFI) != std::string::npos)
562 if(child->hasAttribute(OC_RSRVD_ES_SUPPORTEDWIFIMODE))
564 for(auto it : child->getValue
565 <std::vector<int>>(OC_RSRVD_ES_SUPPORTEDWIFIMODE))
567 modes.push_back(static_cast<WIFI_MODE>(it));
576 * Get a WiFi supported frequency of Enrollee
578 * @return a WiFi supported frequency of Enrollee
582 WIFI_FREQ getWiFiFreq() const
584 std::vector<OCRepresentation> children = m_ProvRep.getChildren();
585 for(auto child = children.begin(); child != children.end(); ++child)
587 if(child->getUri().find(OC_RSRVD_ES_URI_WIFI) != std::string::npos)
589 if(child->hasAttribute(OC_RSRVD_ES_SUPPORTEDWIFIFREQ))
591 return static_cast<WIFI_FREQ>(
592 child->getValue<int>(OC_RSRVD_ES_SUPPORTEDWIFIFREQ));
596 return WIFI_FREQ_NONE;
600 * Get an accessibility to cloud server of an Enrollee
602 * @return an accessibility to cloud server of an Enrollee
604 bool isCloudAccessible() const
606 std::vector<OCRepresentation> children = m_ProvRep.getChildren();
607 for(auto child = children.begin(); child != children.end(); ++child)
609 if(child->getUri().find(OC_RSRVD_ES_URI_CLOUDSERVER) != std::string::npos)
618 * Get OCRepresentation object
620 * @return OCRepresentation object
622 const OCRepresentation& getProvResRep() const
628 OCRepresentation m_ProvRep;
632 * Status object for getStatus API. This object is given to application
633 * when a response for GET request to provisioning resource at Enrollee is arrived.
634 * It returns a result of the API and requested data delivered in the response which includes
635 * a provisioning status and last error code stored in Enrollee.
637 * @see EnrolleeStatus
639 class GetEnrolleeStatus
645 GetEnrolleeStatus(ESResult result, const EnrolleeStatus& status) :
646 m_result(result), m_enrolleeStatus(status)
651 * Get a result of getting provisioning status and last error code of Enrollee
653 * @return a result of getting provisioning status and last error code of Enrollee
657 ESResult getESResult()
663 * Get Enrollee's status and last error code properties
665 * @return Enrollee's status and last error code properties
667 * @see EnrolleeStatus
669 const EnrolleeStatus& getEnrolleeStatus()
671 return m_enrolleeStatus;
676 EnrolleeStatus m_enrolleeStatus;
680 * Status object for getConfiguration API. This object is given to application
681 * when a response for GET request to provisioning resource at Enrollee is arrived.
682 * It returns a result of the API and requested data delivered in the response which includes
683 * WiFi configuration and device configuration stored in Enrollee.
687 class GetConfigurationStatus
693 GetConfigurationStatus(ESResult result, const EnrolleeConf& conf) :
694 m_result(result), m_enrolleeConf(conf)
699 * Get a result of getting preconfiguration of Enrollee
701 * @return a result of preconfiguration of Enrollee
705 ESResult getESResult()
711 * Get Enrollee's pre-configuration properties
713 * @return Enrollee's pre-configuration properties
717 EnrolleeConf& getEnrolleeConf()
719 return m_enrolleeConf;
724 EnrolleeConf m_enrolleeConf;
728 * Status object for provisionDeviceProperties API. This object is given to application
729 * when a response for GET request to provisioning resource at Enrollee is arrived.
730 * It returns a result of the request.
732 class DevicePropProvisioningStatus
738 DevicePropProvisioningStatus(ESResult result) :
744 * Get a result of Device property provisioning
746 * @return a result of Device property provisioning
750 ESResult getESResult()
760 * Status object for provisionCloudProperties API. This object is given to application
761 * when a response for GET request to provisioning resource at Enrollee is arrived.
762 * It returns a result of the request and status of this provisioning. The status provides
763 * an information if the enrollee is found in a given network and the provisioning is
766 class CloudPropProvisioningStatus
772 CloudPropProvisioningStatus(ESResult result) :
778 * Get a result of Cloud property provisioning
780 * @return a result of Cloud property provisioning
784 ESResult getESResult()
794 * Callback function definition for providing Enrollee status
796 typedef function< void(shared_ptr< GetEnrolleeStatus >) > GetStatusCb;
799 * Callback function definition for providing Enrollee configuration status
801 typedef function< void(shared_ptr< GetConfigurationStatus >) > GetConfigurationStatusCb;
804 * Callback function definition for providing Enrollee device property provisioning status
806 typedef function< void(shared_ptr< DevicePropProvisioningStatus >) > DevicePropProvStatusCb;
809 * Callback function definition for providing Enrollee cloud property provisioning status
811 typedef function< void(shared_ptr< CloudPropProvisioningStatus >) > CloudPropProvStatusCb;
814 * Callback function definition for providing Enrollee security provisioning status
816 typedef function< void(shared_ptr<SecProvisioningStatus>) > SecurityProvStatusCb;
819 * Callback definition to be invoked when the security stack expects a pin from application
821 typedef function< void(string&) > SecurityPinCb;
824 * Callback definition to be invoked when the stack expects a db path
826 typedef function< void(string&) > SecProvisioningDbPathCb;
830 #endif //WITH_ARDUINO
832 #endif //ES_COMMON_RICH_H_