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) { m_rep = rep; }
58 EnrolleeStatus(const EnrolleeStatus& enrolleeStatus) :
59 m_rep(enrolleeStatus.getRepresentation())
63 EnrolleeStatus(const EnrolleeStatus&& enrolleeStatus) :
64 m_rep(std::move(enrolleeStatus.getRepresentation()))
69 * Get a provisioning status property of Enrollee.
71 * @return a provisioning status property of Enrollee
73 ProvStatus getProvStatus()
75 if(m_rep.hasAttribute(OC_RSRVD_ES_PROVSTATUS))
76 return static_cast<ProvStatus>(
77 m_rep.getValue<int>(OC_RSRVD_ES_PROVSTATUS));
82 * Get a last error code property of Enrollee.
84 * @return a last error code property of Enrollee.
86 ESErrorCode getLastErrCode()
88 if(m_rep.hasAttribute(OC_RSRVD_ES_LAST_ERRORCODE))
89 return static_cast<ESErrorCode>(
90 m_rep.getValue<int>(OC_RSRVD_ES_LAST_ERRORCODE));
91 return ES_ERRCODE_NO_ERROR;
95 * Get OCRepresentation object
97 * @return OCRepresentation object
99 const OCRepresentation& getRepresentation() const
104 OCRepresentation m_rep;
108 * @brief Data class stored for Cloud server property provisioning
120 * Constructor with OCRepresentation object. This is used for JNI communication.
122 CloudProp(const OCRepresentation &rep)
129 * Set CloudServer resource properties to be delivered to Enrollee
131 * @param authCode Auth code issued by OAuth2.0-compatible account server
132 * @param authProvider Auth provider ID
133 * @param ciServer Cloud interface server URL which an Enrollee is going to registered
135 void setCloudProp(string authCode, string authProvider, string ciServer)
137 m_rep.setValue(OC_RSRVD_ES_AUTHCODE, authCode);
138 m_rep.setValue(OC_RSRVD_ES_AUTHPROVIDER, authProvider);
139 m_rep.setValue(OC_RSRVD_ES_CISERVER, ciServer);
143 * Set CloudServer's UUID
145 * @param cloudID Cloud Interface server's UUID
147 void setCloudID(string cloudID)
153 * Get an auth code to be delivered.
155 * @return an auth code to be delivered.
157 std::string getAuthCode()
159 if(m_rep.hasAttribute(OC_RSRVD_ES_AUTHCODE))
160 return m_rep.getValue<std::string>(OC_RSRVD_ES_AUTHCODE);
161 return std::string("");
165 * Get an auth provider which issued an auth code
167 * @return an auth provider which issued an auth code
169 std::string getAuthProvider()
171 if(m_rep.hasAttribute(OC_RSRVD_ES_AUTHPROVIDER))
172 return m_rep.getValue<std::string>(OC_RSRVD_ES_AUTHPROVIDER);
173 return std::string("");
177 * Get a CI server to be delivered
179 * @return a CI server to be delivered
181 std::string getCiServer()
183 if(m_rep.hasAttribute(OC_RSRVD_ES_CISERVER))
184 return m_rep.getValue<std::string>(OC_RSRVD_ES_CISERVER);
185 return std::string("");
189 * Get a CI server's Uuid to be delivered
191 * @return a CI server's Uuid to be delivered
193 std::string getCloudID() const
199 * Get OCRepresentation object
201 * @return OCRepresentation object
203 const OCRepresentation &toOCRepresentation() const
208 OCRepresentation m_rep;
209 std::string m_cloudID;
213 * @brief Data class stored for Device property provisioning which includes a WiFi
214 * and device configuration provisioning
226 * Constructor with OCRepresentation object. This is used for JNI communication.
228 DeviceProp(const OCRepresentation &rep) { m_rep = rep; }
231 * Set WiFi resource properties to be delivered to Enrollee
233 * @param ssid Ssid of the Enroller
234 * @param pwd Pwd of the Enrolle
235 * @param authtype Auth type of the Enroller
236 * @param enctype Encryption type of the Enroller
241 void setWiFiProp(string ssid, string pwd, WIFI_AUTHTYPE authtype, WIFI_ENCTYPE enctype)
243 m_rep.setValue(OC_RSRVD_ES_SSID, ssid);
244 m_rep.setValue(OC_RSRVD_ES_CRED, pwd);
245 m_rep.setValue(OC_RSRVD_ES_AUTHTYPE, authtype);
246 m_rep.setValue(OC_RSRVD_ES_ENCTYPE, enctype);
250 * Set DevConf resource properties to be delivered to Enrollee
252 * @param language IETF language tag using ISO 639X
253 * @param country ISO Country Code (ISO 3166-1 Alpha-2)
255 void setDevConfProp(string language, string country)
257 m_rep.setValue(OC_RSRVD_ES_LANGUAGE, language);
258 m_rep.setValue(OC_RSRVD_ES_COUNTRY, country);
262 * Get a SSID of Enroller
264 * @return a SSID of enroller
266 std::string getSsid()
268 if(m_rep.hasAttribute(OC_RSRVD_ES_SSID))
269 return m_rep.getValue<std::string>(OC_RSRVD_ES_SSID);
270 return std::string("");
274 * Get a password of Enroller
276 * @return a password of enroller
278 std::string getPassword()
280 if(m_rep.hasAttribute(OC_RSRVD_ES_CRED))
281 return m_rep.getValue<std::string>(OC_RSRVD_ES_CRED);
282 return std::string("");
286 * Get an auth type of Enroller
288 * @return an auth type of enroller
292 WIFI_AUTHTYPE getAuthType()
294 if(m_rep.hasAttribute(OC_RSRVD_ES_AUTHTYPE))
295 return static_cast<WIFI_AUTHTYPE>(m_rep.getValue<int>(OC_RSRVD_ES_AUTHTYPE));
300 * Get an encryption type of Enroller
302 * @return an encryption type of enroller
306 WIFI_ENCTYPE getEncType()
308 if(m_rep.hasAttribute(OC_RSRVD_ES_ENCTYPE))
309 return static_cast<WIFI_ENCTYPE>(m_rep.getValue<int>(OC_RSRVD_ES_ENCTYPE));
314 * Get a language to be set. A language is expressed in IETF language tag
317 * @return a language to be set
319 std::string getLanguage()
321 if(m_rep.hasAttribute(OC_RSRVD_ES_LANGUAGE))
322 return m_rep.getValue<std::string>(OC_RSRVD_ES_LANGUAGE);
323 return std::string("");
327 * Get a country to be set. A country is expressed in ISO Country Code
328 * (ISO 3166-1 Alpha-2)
330 * @return a country to be set
332 std::string getCountry()
334 if(m_rep.hasAttribute(OC_RSRVD_ES_COUNTRY))
335 return m_rep.getValue<std::string>(OC_RSRVD_ES_COUNTRY);
336 return std::string("");
340 * Get OCRepresentation object
342 * @return OCRepresentation object
344 const OCRepresentation &toOCRepresentation() const
350 OCRepresentation m_rep;
354 * @brief Provisioning state in cloud server property provisioning.
358 ES_CLOUD_PROVISIONING_ERROR = -1, /**< An error in cloud provisioning happens **/
359 ES_CLOUD_PROVISIONING_SUCCESS, /**< Cloud provisioning is successfully done **/
360 ES_CLOUD_ENROLLEE_FOUND, /**< An enrollee is found in a given network **/
361 ES_CLOUD_ENROLLEE_NOT_FOUND /**< NO enrollee is found in a given network **/
365 * Security Provisioning Status
367 class SecProvisioningStatus
370 SecProvisioningStatus(string deviceUUID, ESResult result) :
371 m_devUUID(deviceUUID), m_result(result)
375 const string getDeviceUUID()
380 ESResult getESResult()
390 * @breif This provide a set of getter APIs from received response for getConfiguration().
391 * Received information includes a device name, WiFi supported mode, and frequency.
392 * Additionally, you can know if Enrollee can be access to cloud server with this
400 * The expected OCRepresentation is one for collection resource and has several child
401 * OCRepresentation object corresponding to WiFi, DevConf, and CloudServer resource's
404 EnrolleeConf(const OCRepresentation& rep)
408 std::vector<OCRepresentation> children = rep.getChildren();
410 for(auto child = children.begin(); child != children.end(); ++child)
412 if(child->getUri().find(OC_RSRVD_ES_URI_WIFI) != std::string::npos)
416 else if(child->getUri().find(OC_RSRVD_ES_URI_DEVCONF) != std::string::npos)
418 m_DevConfRep = *child;
420 else if(child->getUri().find(OC_RSRVD_ES_URI_CLOUDSERVER) != std::string::npos)
428 * Get a device name of Enrollee. It is Device's human-friendly name like device model
431 * @return a device name of Enrollee
433 std::string getDeviceName()
435 if(m_DevConfRep.hasAttribute(OC_RSRVD_ES_DEVNAME))
436 return m_DevConfRep.getValue<std::string>(OC_RSRVD_ES_DEVNAME);
437 return std::string("");
441 * Get a set of WiFi supported modes of Enrollee
443 * @return a set of WiFi supported modes of Enrollee
447 vector<WIFI_MODE> getWiFiModes()
449 vector<WIFI_MODE> modes;
452 if(m_WiFiRep.hasAttribute(OC_RSRVD_ES_SUPPORTEDWIFIMODE))
454 for(auto it : m_WiFiRep.getValue
455 <std::vector<int>>(OC_RSRVD_ES_SUPPORTEDWIFIMODE))
457 modes.push_back(static_cast<WIFI_MODE>(it));
464 * Get a WiFi supported frequency of Enrollee
466 * @return a WiFi supported frequency of Enrollee
470 WIFI_FREQ getWiFiFreq()
472 if(m_WiFiRep.hasAttribute(OC_RSRVD_ES_SUPPORTEDWIFIFREQ))
473 return static_cast<WIFI_FREQ>(
474 m_WiFiRep.getValue<int>(OC_RSRVD_ES_SUPPORTEDWIFIFREQ));
475 return WIFI_FREQ_NONE;
479 * Get an accessibility to cloud server of an Enrollee
481 * @return an accessibility to cloud server of an Enrollee
483 bool isCloudAccessible()
485 if(m_CloudRep.getUri().find(OC_RSRVD_ES_URI_CLOUDSERVER) != std::string::npos)
493 * Get OCRepresentation object
495 * @return OCRepresentation object
497 const OCRepresentation& getProvResRep()
503 OCRepresentation m_ProvRep, m_WiFiRep, m_DevConfRep, m_CloudRep;
507 * Status object for getStatus API. This object is given to application
508 * when a response for GET request to provisioning resource at Enrollee is arrived.
509 * It returns a result of the API and requested data delivered in the response which includes
510 * a provisioning status and last error code stored in Enrollee.
512 * @see EnrolleeStatus
514 class GetEnrolleeStatus
517 GetEnrolleeStatus(ESResult result, const EnrolleeStatus& status) :
518 m_result(result), m_enrolleeStatus(status)
522 ESResult getESResult()
527 const EnrolleeStatus& getEnrolleeStatus()
529 return m_enrolleeStatus;
534 EnrolleeStatus m_enrolleeStatus;
538 * Status object for getConfiguration API. This object is given to application
539 * when a response for GET request to provisioning resource at Enrollee is arrived.
540 * It returns a result of the API and requested data delivered in the response which includes
541 * WiFi configuration and device configuration stored in Enrollee.
545 class GetConfigurationStatus
548 GetConfigurationStatus(ESResult result, const EnrolleeConf& conf) :
549 m_result(result), m_enrolleeConf(conf)
553 ESResult getESResult()
558 const EnrolleeConf& getEnrolleeConf()
560 return m_enrolleeConf;
565 EnrolleeConf m_enrolleeConf;
569 * Status object for provisionDeviceProperties API. This object is given to application
570 * when a response for GET request to provisioning resource at Enrollee is arrived.
571 * It returns a result of the request.
573 class DevicePropProvisioningStatus
576 DevicePropProvisioningStatus(ESResult result) :
581 ESResult getESResult()
592 * Status object for provisionCloudProperties API. This object is given to application
593 * when a response for GET request to provisioning resource at Enrollee is arrived.
594 * It returns a result of the request and status of this provisioning. The status provides
595 * an information if the enrollee is found in a given network and the provisioning is
598 class CloudPropProvisioningStatus
601 CloudPropProvisioningStatus(ESResult result, ESCloudProvState state) :
602 m_result(result), m_esCloudState(state)
606 ESResult getESResult()
611 ESCloudProvState getESCloudState()
613 return m_esCloudState;
618 ESCloudProvState m_esCloudState;
622 * Callback function definition for providing Enrollee status
624 typedef function< void(shared_ptr< GetEnrolleeStatus >) > GetStatusCb;
627 * Callback function definition for providing Enrollee configuration status
629 typedef function< void(shared_ptr< GetConfigurationStatus >) > GetConfigurationStatusCb;
632 * Callback function definition for providing Enrollee device property provisioning status
634 typedef function< void(shared_ptr< DevicePropProvisioningStatus >) > DevicePropProvStatusCb;
637 * Callback function definition for providing Enrollee cloud property provisioning status
639 typedef function< void(shared_ptr< CloudPropProvisioningStatus >) > CloudPropProvStatusCb;
642 * Callback function definition for providing Enrollee security provisioning status
644 typedef function< void(shared_ptr<SecProvisioningStatus>) > SecurityProvStatusCb;
647 * Callback definition to be invoked when the security stack expects a pin from application
649 typedef function< void(string&) > SecurityPinCb;
652 * Callback definition to be invoked when the stack expects a db path
654 typedef function< void(string&) > SecProvisioningDbPathCb;
658 #endif //WITH_ARDUINO
660 #endif //ES_COMMON_RICH_H_