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 * Security Provisioning Status
423 class SecProvisioningStatus
426 SecProvisioningStatus(string deviceUUID, ESResult result) :
427 m_devUUID(deviceUUID), m_result(result)
431 const string getDeviceUUID()
436 ESResult getESResult()
446 * @breif This provide a set of getter APIs from received response for getConfiguration().
447 * Received information includes a device name, WiFi supported mode, and frequency.
448 * Additionally, you can know if Enrollee can be access to cloud server with this
456 * The expected OCRepresentation is one for collection resource and has several child
457 * OCRepresentation object corresponding to WiFi, DevConf, and CloudServer resource's
460 EnrolleeConf(const OCRepresentation& rep) :
465 EnrolleeConf(const EnrolleeConf& enrolleeConf) :
466 m_ProvRep(enrolleeConf.getProvResRep())
470 EnrolleeConf(const EnrolleeConf&& enrolleeConf) :
471 m_ProvRep(std::move(enrolleeConf.getProvResRep()))
476 * Get a device name of Enrollee. It is Device's human-friendly name like device model
479 * @return a device name of Enrollee
481 std::string getDeviceName() const
483 std::vector<OCRepresentation> children = m_ProvRep.getChildren();
484 for(auto child = children.begin(); child != children.end(); ++child)
486 if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
488 if(child->hasAttribute(OC_RSRVD_ES_DEVNAME))
490 return child->getValue<std::string>(OC_RSRVD_ES_DEVNAME);
494 return std::string("");
498 * Get a model number of Enrollee.
500 * @return a model number of Enrollee
502 std::string getModelNumber() const
504 std::vector<OCRepresentation> children = m_ProvRep.getChildren();
505 for(auto child = children.begin(); child != children.end(); ++child)
507 if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
509 if(child->hasAttribute(OC_RSRVD_ES_MODELNUMBER))
511 return child->getValue<std::string>(OC_RSRVD_ES_MODELNUMBER);
515 return std::string("");
519 * Get a set of WiFi supported modes of Enrollee
521 * @return a set of WiFi supported modes of Enrollee
525 vector<WIFI_MODE> getWiFiModes() const
527 vector<WIFI_MODE> modes;
530 std::vector<OCRepresentation> children = m_ProvRep.getChildren();
531 for(auto child = children.begin(); child != children.end(); ++child)
533 if(child->getUri().find(OC_RSRVD_ES_URI_WIFI) != std::string::npos)
535 if(child->hasAttribute(OC_RSRVD_ES_SUPPORTEDWIFIMODE))
537 for(auto it : child->getValue
538 <std::vector<int>>(OC_RSRVD_ES_SUPPORTEDWIFIMODE))
540 modes.push_back(static_cast<WIFI_MODE>(it));
549 * Get a WiFi supported frequency of Enrollee
551 * @return a WiFi supported frequency of Enrollee
555 WIFI_FREQ getWiFiFreq() const
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_SUPPORTEDWIFIFREQ))
564 return static_cast<WIFI_FREQ>(
565 child->getValue<int>(OC_RSRVD_ES_SUPPORTEDWIFIFREQ));
569 return WIFI_FREQ_NONE;
573 * Get an accessibility to cloud server of an Enrollee
575 * @return an accessibility to cloud server of an Enrollee
577 bool isCloudAccessible() const
579 std::vector<OCRepresentation> children = m_ProvRep.getChildren();
580 for(auto child = children.begin(); child != children.end(); ++child)
582 if(child->getUri().find(OC_RSRVD_ES_URI_CLOUDSERVER) != std::string::npos)
591 * Get OCRepresentation object
593 * @return OCRepresentation object
595 const OCRepresentation& getProvResRep() const
601 OCRepresentation m_ProvRep;
605 * Status object for getStatus API. This object is given to application
606 * when a response for GET request to provisioning resource at Enrollee is arrived.
607 * It returns a result of the API and requested data delivered in the response which includes
608 * a provisioning status and last error code stored in Enrollee.
610 * @see EnrolleeStatus
612 class GetEnrolleeStatus
615 GetEnrolleeStatus(ESResult result, const EnrolleeStatus& status) :
616 m_result(result), m_enrolleeStatus(status)
620 ESResult getESResult()
625 const EnrolleeStatus& getEnrolleeStatus()
627 return m_enrolleeStatus;
632 EnrolleeStatus m_enrolleeStatus;
636 * Status object for getConfiguration API. This object is given to application
637 * when a response for GET request to provisioning resource at Enrollee is arrived.
638 * It returns a result of the API and requested data delivered in the response which includes
639 * WiFi configuration and device configuration stored in Enrollee.
643 class GetConfigurationStatus
646 GetConfigurationStatus(ESResult result, const EnrolleeConf& conf) :
647 m_result(result), m_enrolleeConf(conf)
651 ESResult getESResult()
656 EnrolleeConf& getEnrolleeConf()
658 return m_enrolleeConf;
663 EnrolleeConf m_enrolleeConf;
667 * Status object for provisionDeviceProperties API. This object is given to application
668 * when a response for GET request to provisioning resource at Enrollee is arrived.
669 * It returns a result of the request.
671 class DevicePropProvisioningStatus
674 DevicePropProvisioningStatus(ESResult result) :
679 ESResult getESResult()
689 * Status object for provisionCloudProperties API. This object is given to application
690 * when a response for GET request to provisioning resource at Enrollee is arrived.
691 * It returns a result of the request and status of this provisioning. The status provides
692 * an information if the enrollee is found in a given network and the provisioning is
695 class CloudPropProvisioningStatus
698 CloudPropProvisioningStatus(ESResult result) :
703 ESResult getESResult()
713 * Callback function definition for providing Enrollee status
715 typedef function< void(shared_ptr< GetEnrolleeStatus >) > GetStatusCb;
718 * Callback function definition for providing Enrollee configuration status
720 typedef function< void(shared_ptr< GetConfigurationStatus >) > GetConfigurationStatusCb;
723 * Callback function definition for providing Enrollee device property provisioning status
725 typedef function< void(shared_ptr< DevicePropProvisioningStatus >) > DevicePropProvStatusCb;
728 * Callback function definition for providing Enrollee cloud property provisioning status
730 typedef function< void(shared_ptr< CloudPropProvisioningStatus >) > CloudPropProvStatusCb;
733 * Callback function definition for providing Enrollee security provisioning status
735 typedef function< void(shared_ptr<SecProvisioningStatus>) > SecurityProvStatusCb;
738 * Callback definition to be invoked when the security stack expects a pin from application
740 typedef function< void(string&) > SecurityPinCb;
743 * Callback definition to be invoked when the stack expects a db path
745 typedef function< void(string&) > SecProvisioningDbPathCb;
749 #endif //WITH_ARDUINO
751 #endif //ES_COMMON_RICH_H_