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
129 * Constructor with OCRepresentation object. This is used for JNI communication.
131 CloudProp(const OCRepresentation &rep)
138 * Set CloudServer resource properties to be delivered to Enrollee
140 * @param authCode Auth code issued by OAuth2.0-compatible account server
141 * @param authProvider Auth provider ID
142 * @param ciServer Cloud interface server URL which an Enrollee is going to registered
144 void setCloudProp(string authCode, string authProvider, string ciServer)
146 m_rep.setValue(OC_RSRVD_ES_AUTHCODE, authCode);
147 m_rep.setValue(OC_RSRVD_ES_AUTHPROVIDER, authProvider);
148 m_rep.setValue(OC_RSRVD_ES_CISERVER, ciServer);
152 * Set CloudServer's UUID
154 * @param cloudID Cloud Interface server's UUID
156 void setCloudID(string cloudID)
162 * Get an auth code to be delivered.
164 * @return an auth code to be delivered.
166 std::string getAuthCode() const
168 if(m_rep.hasAttribute(OC_RSRVD_ES_AUTHCODE))
170 return m_rep.getValue<std::string>(OC_RSRVD_ES_AUTHCODE);
172 return std::string("");
176 * Get an auth provider which issued an auth code
178 * @return an auth provider which issued an auth code
180 std::string getAuthProvider() const
182 if(m_rep.hasAttribute(OC_RSRVD_ES_AUTHPROVIDER))
184 return m_rep.getValue<std::string>(OC_RSRVD_ES_AUTHPROVIDER);
186 return std::string("");
190 * Get a CI server to be delivered
192 * @return a CI server to be delivered
194 std::string getCiServer() const
196 if(m_rep.hasAttribute(OC_RSRVD_ES_CISERVER))
198 return m_rep.getValue<std::string>(OC_RSRVD_ES_CISERVER);
200 return std::string("");
204 * Get a CI server's Uuid to be delivered
206 * @return a CI server's Uuid to be delivered
208 std::string getCloudID() const
214 * Get OCRepresentation object
216 * @return OCRepresentation object
218 const OCRepresentation &toOCRepresentation() const
223 OCRepresentation m_rep;
224 std::string m_cloudID;
228 * @brief Data class stored for Device property provisioning which includes a WiFi
229 * and device configuration provisioning
241 * Constructor with OCRepresentation object. This is used for JNI communication.
243 DeviceProp(const OCRepresentation &rep)
249 * Set WiFi resource properties to be delivered to Enrollee
251 * @param ssid Ssid of the Enroller
252 * @param pwd Pwd of the Enrolle
253 * @param authtype Auth type of the Enroller
254 * @param enctype Encryption type of the Enroller
259 void setWiFiProp(string ssid, string pwd, WIFI_AUTHTYPE authtype, WIFI_ENCTYPE enctype)
261 m_rep.setValue(OC_RSRVD_ES_SSID, ssid);
262 m_rep.setValue(OC_RSRVD_ES_CRED, pwd);
263 m_rep.setValue(OC_RSRVD_ES_AUTHTYPE, authtype);
264 m_rep.setValue(OC_RSRVD_ES_ENCTYPE, enctype);
268 * Set DevConf resource properties to be delivered to Enrollee
270 * @param language IETF language tag using ISO 639X
271 * @param country ISO Country Code (ISO 3166-1 Alpha-2)
273 void setDevConfProp(string language, string country)
275 m_rep.setValue(OC_RSRVD_ES_LANGUAGE, language);
276 m_rep.setValue(OC_RSRVD_ES_COUNTRY, country);
280 * Get a SSID of Enroller
282 * @return a SSID of enroller
284 std::string getSsid() const
286 if(m_rep.hasAttribute(OC_RSRVD_ES_SSID))
288 return m_rep.getValue<std::string>(OC_RSRVD_ES_SSID);
290 return std::string("");
294 * Get a password of Enroller
296 * @return a password of enroller
298 std::string getPassword() const
300 if(m_rep.hasAttribute(OC_RSRVD_ES_CRED))
302 return m_rep.getValue<std::string>(OC_RSRVD_ES_CRED);
304 return std::string("");
308 * Get an auth type of Enroller
310 * @return an auth type of enroller
314 WIFI_AUTHTYPE getAuthType() const
316 if(m_rep.hasAttribute(OC_RSRVD_ES_AUTHTYPE))
318 return static_cast<WIFI_AUTHTYPE>(m_rep.getValue<int>(OC_RSRVD_ES_AUTHTYPE));
324 * Get an encryption type of Enroller
326 * @return an encryption type of enroller
330 WIFI_ENCTYPE getEncType() const
332 if(m_rep.hasAttribute(OC_RSRVD_ES_ENCTYPE))
334 return static_cast<WIFI_ENCTYPE>(m_rep.getValue<int>(OC_RSRVD_ES_ENCTYPE));
340 * Get a language to be set. A language is expressed in IETF language tag
343 * @return a language to be set
345 std::string getLanguage() const
347 if(m_rep.hasAttribute(OC_RSRVD_ES_LANGUAGE))
349 return m_rep.getValue<std::string>(OC_RSRVD_ES_LANGUAGE);
351 return std::string("");
355 * Get a country to be set. A country is expressed in ISO Country Code
356 * (ISO 3166-1 Alpha-2)
358 * @return a country to be set
360 std::string getCountry() const
362 if(m_rep.hasAttribute(OC_RSRVD_ES_COUNTRY))
364 return m_rep.getValue<std::string>(OC_RSRVD_ES_COUNTRY);
366 return std::string("");
370 * Get OCRepresentation object
372 * @return OCRepresentation object
374 const OCRepresentation &toOCRepresentation() const
380 OCRepresentation m_rep;
384 * @brief Provisioning state in cloud server property provisioning.
388 ES_CLOUD_PROVISIONING_ERROR = -1, /**< An error in cloud provisioning happens **/
389 ES_CLOUD_PROVISIONING_SUCCESS, /**< Cloud provisioning is successfully done **/
390 ES_CLOUD_ENROLLEE_FOUND, /**< An enrollee is found in a given network **/
391 ES_CLOUD_ENROLLEE_NOT_FOUND /**< NO enrollee is found in a given network **/
395 * Security Provisioning Status
397 class SecProvisioningStatus
400 SecProvisioningStatus(string deviceUUID, ESResult result) :
401 m_devUUID(deviceUUID), m_result(result)
405 const string getDeviceUUID()
410 ESResult getESResult()
420 * @breif This provide a set of getter APIs from received response for getConfiguration().
421 * Received information includes a device name, WiFi supported mode, and frequency.
422 * Additionally, you can know if Enrollee can be access to cloud server with this
430 * The expected OCRepresentation is one for collection resource and has several child
431 * OCRepresentation object corresponding to WiFi, DevConf, and CloudServer resource's
434 EnrolleeConf(const OCRepresentation& rep)
438 std::vector<OCRepresentation> children = rep.getChildren();
440 for(auto child = children.begin(); child != children.end(); ++child)
442 if(child->getUri().find(OC_RSRVD_ES_URI_WIFI) != std::string::npos)
446 else if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
448 m_DevConfRep = *child;
450 else if(child->getUri().find(OC_RSRVD_ES_URI_CLOUDSERVER) != std::string::npos)
458 * Get a device name of Enrollee. It is Device's human-friendly name like device model
461 * @return a device name of Enrollee
463 std::string getDeviceName() const
465 if(m_DevConfRep.hasAttribute(OC_RSRVD_ES_DEVNAME))
466 return m_DevConfRep.getValue<std::string>(OC_RSRVD_ES_DEVNAME);
467 return std::string("");
471 * Get a set of WiFi supported modes of Enrollee
473 * @return a set of WiFi supported modes of Enrollee
477 vector<WIFI_MODE> getWiFiModes() const
479 vector<WIFI_MODE> modes;
482 if(m_WiFiRep.hasAttribute(OC_RSRVD_ES_SUPPORTEDWIFIMODE))
484 for(auto it : m_WiFiRep.getValue
485 <std::vector<int>>(OC_RSRVD_ES_SUPPORTEDWIFIMODE))
487 modes.push_back(static_cast<WIFI_MODE>(it));
494 * Get a WiFi supported frequency of Enrollee
496 * @return a WiFi supported frequency of Enrollee
500 WIFI_FREQ getWiFiFreq() const
502 if(m_WiFiRep.hasAttribute(OC_RSRVD_ES_SUPPORTEDWIFIFREQ))
503 return static_cast<WIFI_FREQ>(
504 m_WiFiRep.getValue<int>(OC_RSRVD_ES_SUPPORTEDWIFIFREQ));
505 return WIFI_FREQ_NONE;
509 * Get an accessibility to cloud server of an Enrollee
511 * @return an accessibility to cloud server of an Enrollee
513 bool isCloudAccessible() const
515 if(m_CloudRep.getUri().find(OC_RSRVD_ES_URI_CLOUDSERVER) != std::string::npos)
523 * Get OCRepresentation object
525 * @return OCRepresentation object
527 const OCRepresentation& getProvResRep()
533 OCRepresentation m_ProvRep, m_WiFiRep, m_DevConfRep, m_CloudRep;
537 * Status object for getStatus API. This object is given to application
538 * when a response for GET request to provisioning resource at Enrollee is arrived.
539 * It returns a result of the API and requested data delivered in the response which includes
540 * a provisioning status and last error code stored in Enrollee.
542 * @see EnrolleeStatus
544 class GetEnrolleeStatus
547 GetEnrolleeStatus(ESResult result, const EnrolleeStatus& status) :
548 m_result(result), m_enrolleeStatus(status)
552 ESResult getESResult()
557 const EnrolleeStatus& getEnrolleeStatus()
559 return m_enrolleeStatus;
564 EnrolleeStatus m_enrolleeStatus;
568 * Status object for getConfiguration API. This object is given to application
569 * when a response for GET request to provisioning resource at Enrollee is arrived.
570 * It returns a result of the API and requested data delivered in the response which includes
571 * WiFi configuration and device configuration stored in Enrollee.
575 class GetConfigurationStatus
578 GetConfigurationStatus(ESResult result, const EnrolleeConf& conf) :
579 m_result(result), m_enrolleeConf(conf)
583 ESResult getESResult()
588 const EnrolleeConf& getEnrolleeConf()
590 return m_enrolleeConf;
595 EnrolleeConf m_enrolleeConf;
599 * Status object for provisionDeviceProperties API. This object is given to application
600 * when a response for GET request to provisioning resource at Enrollee is arrived.
601 * It returns a result of the request.
603 class DevicePropProvisioningStatus
606 DevicePropProvisioningStatus(ESResult result) :
611 ESResult getESResult()
622 * Status object for provisionCloudProperties API. This object is given to application
623 * when a response for GET request to provisioning resource at Enrollee is arrived.
624 * It returns a result of the request and status of this provisioning. The status provides
625 * an information if the enrollee is found in a given network and the provisioning is
628 class CloudPropProvisioningStatus
631 CloudPropProvisioningStatus(ESResult result, ESCloudProvState state) :
632 m_result(result), m_esCloudState(state)
636 ESResult getESResult()
641 ESCloudProvState getESCloudState()
643 return m_esCloudState;
648 ESCloudProvState m_esCloudState;
652 * Callback function definition for providing Enrollee status
654 typedef function< void(shared_ptr< GetEnrolleeStatus >) > GetStatusCb;
657 * Callback function definition for providing Enrollee configuration status
659 typedef function< void(shared_ptr< GetConfigurationStatus >) > GetConfigurationStatusCb;
662 * Callback function definition for providing Enrollee device property provisioning status
664 typedef function< void(shared_ptr< DevicePropProvisioningStatus >) > DevicePropProvStatusCb;
667 * Callback function definition for providing Enrollee cloud property provisioning status
669 typedef function< void(shared_ptr< CloudPropProvisioningStatus >) > CloudPropProvStatusCb;
672 * Callback function definition for providing Enrollee security provisioning status
674 typedef function< void(shared_ptr<SecProvisioningStatus>) > SecurityProvStatusCb;
677 * Callback definition to be invoked when the security stack expects a pin from application
679 typedef function< void(string&) > SecurityPinCb;
682 * Callback definition to be invoked when the stack expects a db path
684 typedef function< void(string&) > SecProvisioningDbPathCb;
688 #endif //WITH_ARDUINO
690 #endif //ES_COMMON_RICH_H_