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)
155 * Set CloudServer resource properties to be delivered to Enrollee
157 * @param authCode Auth code issued by OAuth2.0-compatible account server
158 * @param authProvider Auth provider ID
159 * @param ciServer Cloud interface server URL which an Enrollee is going to registered
161 void setCloudProp(string authCode, string authProvider, string ciServer)
163 m_rep.setValue(OC_RSRVD_ES_AUTHCODE, authCode);
164 m_rep.setValue(OC_RSRVD_ES_AUTHPROVIDER, authProvider);
165 m_rep.setValue(OC_RSRVD_ES_CISERVER, ciServer);
169 * Set CloudServer's UUID
171 * @param cloudID Cloud Interface server's UUID
173 void setCloudID(string cloudID)
179 * Set CloudServer's credential ID of certificate
181 * @param credID Cloud Interface server's credential ID of certificate
183 void setCredID(int credID)
189 * Get an auth code to be delivered.
191 * @return an auth code to be delivered.
193 std::string getAuthCode() const
195 if(m_rep.hasAttribute(OC_RSRVD_ES_AUTHCODE))
197 return m_rep.getValue<std::string>(OC_RSRVD_ES_AUTHCODE);
199 return std::string("");
203 * Get an auth provider which issued an auth code
205 * @return an auth provider which issued an auth code
207 std::string getAuthProvider() const
209 if(m_rep.hasAttribute(OC_RSRVD_ES_AUTHPROVIDER))
211 return m_rep.getValue<std::string>(OC_RSRVD_ES_AUTHPROVIDER);
213 return std::string("");
217 * Get a CI server to be delivered
219 * @return a CI server to be delivered
221 std::string getCiServer() const
223 if(m_rep.hasAttribute(OC_RSRVD_ES_CISERVER))
225 return m_rep.getValue<std::string>(OC_RSRVD_ES_CISERVER);
227 return std::string("");
231 * Get a CI server's Uuid to be delivered
233 * @return a CI server's Uuid to be delivered
235 std::string getCloudID() const
241 * Get a CI server's credential ID of certificate
243 * @return a CI server's credential ID of certificated
245 int getCredID() const
251 * Get OCRepresentation object
253 * @return OCRepresentation object
255 const OCRepresentation &toOCRepresentation() const
260 OCRepresentation m_rep;
261 std::string m_cloudID;
266 * @brief Data class stored for Device property provisioning which includes a WiFi
267 * and device configuration provisioning
280 DeviceProp(const DeviceProp& deviceProp) :
281 m_rep(deviceProp.toOCRepresentation())
285 DeviceProp(const DeviceProp&& deviceProp) :
286 m_rep(std::move(deviceProp.toOCRepresentation()))
291 * Constructor with OCRepresentation object. This is used for JNI communication.
293 DeviceProp(const OCRepresentation &rep)
299 * Set WiFi resource properties to be delivered to Enrollee
301 * @param ssid Ssid of the Enroller
302 * @param pwd Pwd of the Enrolle
303 * @param authtype Auth type of the Enroller
304 * @param enctype Encryption type of the Enroller
309 void setWiFiProp(string ssid, string pwd, WIFI_AUTHTYPE authtype, WIFI_ENCTYPE enctype)
311 m_rep.setValue(OC_RSRVD_ES_SSID, ssid);
312 m_rep.setValue(OC_RSRVD_ES_CRED, pwd);
313 m_rep.setValue(OC_RSRVD_ES_AUTHTYPE, authtype);
314 m_rep.setValue(OC_RSRVD_ES_ENCTYPE, enctype);
318 * Set DevConf resource properties to be delivered to Enrollee
320 * @param language IETF language tag using ISO 639X
321 * @param country ISO Country Code (ISO 3166-1 Alpha-2)
323 void setDevConfProp(string language, string country, string location)
325 m_rep.setValue(OC_RSRVD_ES_LANGUAGE, language);
326 m_rep.setValue(OC_RSRVD_ES_COUNTRY, country);
327 m_rep.setValue(OC_RSRVD_ES_LOCATION, location);
331 * Get a SSID of Enroller
333 * @return a SSID of enroller
335 std::string getSsid() const
337 if(m_rep.hasAttribute(OC_RSRVD_ES_SSID))
339 return m_rep.getValue<std::string>(OC_RSRVD_ES_SSID);
341 return std::string("");
345 * Get a password of Enroller
347 * @return a password of enroller
349 std::string getPassword() const
351 if(m_rep.hasAttribute(OC_RSRVD_ES_CRED))
353 return m_rep.getValue<std::string>(OC_RSRVD_ES_CRED);
355 return std::string("");
359 * Get an auth type of Enroller
361 * @return an auth type of enroller
365 WIFI_AUTHTYPE getAuthType() const
367 if(m_rep.hasAttribute(OC_RSRVD_ES_AUTHTYPE))
369 return static_cast<WIFI_AUTHTYPE>(m_rep.getValue<int>(OC_RSRVD_ES_AUTHTYPE));
375 * Get an encryption type of Enroller
377 * @return an encryption type of enroller
381 WIFI_ENCTYPE getEncType() const
383 if(m_rep.hasAttribute(OC_RSRVD_ES_ENCTYPE))
385 return static_cast<WIFI_ENCTYPE>(m_rep.getValue<int>(OC_RSRVD_ES_ENCTYPE));
391 * Get a language to be set. A language is expressed in IETF language tag
394 * @return a language to be set
396 std::string getLanguage() const
398 if(m_rep.hasAttribute(OC_RSRVD_ES_LANGUAGE))
400 return m_rep.getValue<std::string>(OC_RSRVD_ES_LANGUAGE);
402 return std::string("");
406 * Get a country to be set. A country is expressed in ISO Country Code
407 * (ISO 3166-1 Alpha-2)
409 * @return a country to be set
411 std::string getCountry() const
413 if(m_rep.hasAttribute(OC_RSRVD_ES_COUNTRY))
415 return m_rep.getValue<std::string>(OC_RSRVD_ES_COUNTRY);
417 return std::string("");
421 * Get a location to be set. A location is GPS information
423 * @return a country to be set
425 std::string getLocation() const
427 if(m_rep.hasAttribute(OC_RSRVD_ES_LOCATION))
429 return m_rep.getValue<std::string>(OC_RSRVD_ES_LOCATION);
431 return std::string("");
435 * Get OCRepresentation object
437 * @return OCRepresentation object
439 const OCRepresentation &toOCRepresentation() const
445 OCRepresentation m_rep;
449 * Security Provisioning Status
451 class SecProvisioningStatus
454 SecProvisioningStatus(string deviceUUID, ESResult result) :
455 m_devUUID(deviceUUID), m_result(result)
459 const string getDeviceUUID()
464 ESResult getESResult()
474 * @breif This provide a set of getter APIs from received response for getConfiguration().
475 * Received information includes a device name, WiFi supported mode, and frequency.
476 * Additionally, you can know if Enrollee can be access to cloud server with this
484 * The expected OCRepresentation is one for collection resource and has several child
485 * OCRepresentation object corresponding to WiFi, DevConf, and CloudServer resource's
488 EnrolleeConf(const OCRepresentation& rep) :
493 EnrolleeConf(const EnrolleeConf& enrolleeConf) :
494 m_ProvRep(enrolleeConf.getProvResRep())
498 EnrolleeConf(const EnrolleeConf&& enrolleeConf) :
499 m_ProvRep(std::move(enrolleeConf.getProvResRep()))
504 * Get a device name of Enrollee. It is Device's human-friendly name like device model
507 * @return a device name of Enrollee
509 std::string getDeviceName() const
511 std::vector<OCRepresentation> children = m_ProvRep.getChildren();
512 for(auto child = children.begin(); child != children.end(); ++child)
514 if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
516 if(child->hasAttribute(OC_RSRVD_ES_DEVNAME))
518 return child->getValue<std::string>(OC_RSRVD_ES_DEVNAME);
522 return std::string("");
526 * Get a model number of Enrollee.
528 * @return a model number of Enrollee
530 std::string getModelNumber() const
532 std::vector<OCRepresentation> children = m_ProvRep.getChildren();
533 for(auto child = children.begin(); child != children.end(); ++child)
535 if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
537 if(child->hasAttribute(OC_RSRVD_ES_MODELNUMBER))
539 return child->getValue<std::string>(OC_RSRVD_ES_MODELNUMBER);
543 return std::string("");
547 * Get a set of WiFi supported modes of Enrollee
549 * @return a set of WiFi supported modes of Enrollee
553 vector<WIFI_MODE> getWiFiModes() const
555 vector<WIFI_MODE> modes;
558 std::vector<OCRepresentation> children = m_ProvRep.getChildren();
559 for(auto child = children.begin(); child != children.end(); ++child)
561 if(child->getUri().find(OC_RSRVD_ES_URI_WIFI) != std::string::npos)
563 if(child->hasAttribute(OC_RSRVD_ES_SUPPORTEDWIFIMODE))
565 for(auto it : child->getValue
566 <std::vector<int>>(OC_RSRVD_ES_SUPPORTEDWIFIMODE))
568 modes.push_back(static_cast<WIFI_MODE>(it));
577 * Get a WiFi supported frequency of Enrollee
579 * @return a WiFi supported frequency of Enrollee
583 WIFI_FREQ getWiFiFreq() const
585 std::vector<OCRepresentation> children = m_ProvRep.getChildren();
586 for(auto child = children.begin(); child != children.end(); ++child)
588 if(child->getUri().find(OC_RSRVD_ES_URI_WIFI) != std::string::npos)
590 if(child->hasAttribute(OC_RSRVD_ES_SUPPORTEDWIFIFREQ))
592 return static_cast<WIFI_FREQ>(
593 child->getValue<int>(OC_RSRVD_ES_SUPPORTEDWIFIFREQ));
597 return WIFI_FREQ_NONE;
601 * Get an accessibility to cloud server of an Enrollee
603 * @return an accessibility to cloud server of an Enrollee
605 bool isCloudAccessible() const
607 std::vector<OCRepresentation> children = m_ProvRep.getChildren();
608 for(auto child = children.begin(); child != children.end(); ++child)
610 if(child->getUri().find(OC_RSRVD_ES_URI_CLOUDSERVER) != std::string::npos)
619 * Get OCRepresentation object
621 * @return OCRepresentation object
623 const OCRepresentation& getProvResRep() const
629 OCRepresentation m_ProvRep;
633 * Status object for getStatus API. This object is given to application
634 * when a response for GET request to provisioning resource at Enrollee is arrived.
635 * It returns a result of the API and requested data delivered in the response which includes
636 * a provisioning status and last error code stored in Enrollee.
638 * @see EnrolleeStatus
640 class GetEnrolleeStatus
646 GetEnrolleeStatus(ESResult result, const EnrolleeStatus& status) :
647 m_result(result), m_enrolleeStatus(status)
652 * Get a result of getting provisioning status and last error code of Enrollee
654 * @return a result of getting provisioning status and last error code of Enrollee
658 ESResult getESResult()
664 * Get Enrollee's status and last error code properties
666 * @return Enrollee's status and last error code properties
668 * @see EnrolleeStatus
670 const EnrolleeStatus& getEnrolleeStatus()
672 return m_enrolleeStatus;
677 EnrolleeStatus m_enrolleeStatus;
681 * Status object for getConfiguration API. This object is given to application
682 * when a response for GET request to provisioning resource at Enrollee is arrived.
683 * It returns a result of the API and requested data delivered in the response which includes
684 * WiFi configuration and device configuration stored in Enrollee.
688 class GetConfigurationStatus
694 GetConfigurationStatus(ESResult result, const EnrolleeConf& conf) :
695 m_result(result), m_enrolleeConf(conf)
700 * Get a result of getting preconfiguration of Enrollee
702 * @return a result of preconfiguration of Enrollee
706 ESResult getESResult()
712 * Get Enrollee's pre-configuration properties
714 * @return Enrollee's pre-configuration properties
718 EnrolleeConf& getEnrolleeConf()
720 return m_enrolleeConf;
725 EnrolleeConf m_enrolleeConf;
729 * Status object for provisionDeviceProperties API. This object is given to application
730 * when a response for GET request to provisioning resource at Enrollee is arrived.
731 * It returns a result of the request.
733 class DevicePropProvisioningStatus
739 DevicePropProvisioningStatus(ESResult result) :
745 * Get a result of Device property provisioning
747 * @return a result of Device property provisioning
751 ESResult getESResult()
761 * Status object for provisionCloudProperties API. This object is given to application
762 * when a response for GET request to provisioning resource at Enrollee is arrived.
763 * It returns a result of the request and status of this provisioning. The status provides
764 * an information if the enrollee is found in a given network and the provisioning is
767 class CloudPropProvisioningStatus
773 CloudPropProvisioningStatus(ESResult result) :
779 * Get a result of Cloud property provisioning
781 * @return a result of Cloud property provisioning
785 ESResult getESResult()
795 * Callback function definition for providing Enrollee status
797 typedef function< void(shared_ptr< GetEnrolleeStatus >) > GetStatusCb;
800 * Callback function definition for providing Enrollee configuration status
802 typedef function< void(shared_ptr< GetConfigurationStatus >) > GetConfigurationStatusCb;
805 * Callback function definition for providing Enrollee device property provisioning status
807 typedef function< void(shared_ptr< DevicePropProvisioningStatus >) > DevicePropProvStatusCb;
810 * Callback function definition for providing Enrollee cloud property provisioning status
812 typedef function< void(shared_ptr< CloudPropProvisioningStatus >) > CloudPropProvStatusCb;
815 * Callback function definition for providing Enrollee security provisioning status
817 typedef function< void(shared_ptr<SecProvisioningStatus>) > SecurityProvStatusCb;
820 * Callback definition to be invoked when the security stack expects a pin from application
822 typedef function< void(string&) > SecurityPinCb;
825 * Callback definition to be invoked when the stack expects a db path
827 typedef function< void(string&) > SecProvisioningDbPathCb;
831 #endif //WITH_ARDUINO
833 #endif //ES_COMMON_RICH_H_