Commit d944861f authored by sy01.youn's avatar sy01.youn Committed by Madan Lanka

[Enrollee] Implement ESSetState(), ESSetErrorCode() API & fix ESTerminateEnrollee() API

1. ESSetState(), ESSetErrorCode() API is added in easysetup.c

2. ESTerminate() API logic is changed in resourcehandler.c

3. Variable name of ErrorCode is changed. (ESLastErrCode -> ESErrorCode)


Change-Id: I3be46d75924bff137171b06f102ea74c3634beef
Signed-off-by: default avatarsy01.youn <sy01.youn@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/9143Tested-by: default avatarjenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: default avatarJihun Ha <jihun.ha@samsung.com>
Reviewed-by: default avatarMadan Lanka <lanka.madan@samsung.com>
parent dbe5deab
......@@ -73,6 +73,24 @@ ESResult ESInitEnrollee(bool isSecured, ESResourceMask resourceMask, ESProvision
*/
ESResult ESSetDeviceProperty(ESDeviceProperty *deviceProperty);
/**
* This function Sets Enrollee's State.
*
* @param esState Contains current enrollee's state.
* @return ::ES_OK on success, some other value upon failure.
*/
ESResult ESSetState(ESEnrolleeState esState);
/**
* This function Sets Enrollee's Error Code.
*
* @param esErrCode Contains enrollee's error code.
* @return ::ES_OK on success, some other value upon failure.
*/
ESResult ESSetErrorCode(ESErrorCode esErrCode);
/**
* This function performs termination of Provisioning and Network resources.
* Also terminates the IoTivity core stack.
......
......@@ -178,7 +178,13 @@ ESResult ESInitEnrollee(bool isSecured, ESResourceMask resourceMask, ESProvision
if(CreateEasySetupResources(gIsSecured, resourceMask) != OC_STACK_OK)
{
// TODO : Error Handling
UnRegisterResourceEventCallBack();
if (DeleteEasySetupResources() != OC_STACK_OK)
{
OIC_LOG(ERROR, ES_ENROLLEE_TAG, "Deleting prov resource error!!");
}
return ES_ERROR;
}
......@@ -193,6 +199,7 @@ ESResult ESSetDeviceProperty(ESDeviceProperty *deviceProperty)
if(SetDeviceProperty(deviceProperty) != OC_STACK_OK)
{
OIC_LOG(ERROR, ES_ENROLLEE_TAG, "ESSetDeviceProperty Error");
return ES_ERROR;
}
......@@ -209,13 +216,57 @@ ESResult ESSetDeviceProperty(ESDeviceProperty *deviceProperty)
OICStrcpy((gESDeviceProperty.DevConf).deviceName, MAX_DEVICELEN, (deviceProperty->DevConf).deviceName);
OIC_LOG_V(INFO, ES_ENROLLEE_TAG, "Device Name : %s", (gESDeviceProperty.DevConf).deviceName);
OIC_LOG(INFO, ES_ENROLLEE_TAG, "ESSetDeviceProperty OUT");
return ES_OK;
}
ESResult ESSetState(ESEnrolleeState esState)
{
OIC_LOG(INFO, ES_ENROLLEE_TAG, "ESSetState IN");
if(esState <= 0 || esState >= 6)
{
OIC_LOG_V(ERROR, ES_ENROLLEE_TAG, "Invalid ESEnrolleeState : %d", esState);
return ES_ERROR;
}
if(SetEnrolleeState(esState) != OC_STACK_OK)
{
OIC_LOG(ERROR, ES_ENROLLEE_TAG, "ESSetState Error");
return ES_ERROR;
}
OIC_LOG(INFO, ES_ENROLLEE_TAG, "ESSetState OUT");
return ES_OK;
}
ESResult ESSetErrorCode(ESErrorCode esErrCode)
{
OIC_LOG(INFO, ES_ENROLLEE_TAG, "ESSetErrorCode IN");
if(esErrCode <= 0 || esErrCode >= 7)
{
if(esErrCode != 999)
{
OIC_LOG_V(ERROR, ES_ENROLLEE_TAG, "Invalid ESErrorCode : %d", esErrCode);
return ES_ERROR;
}
}
if(SetEnrolleeErrCode(esErrCode) != OC_STACK_OK)
{
OIC_LOG(ERROR, ES_ENROLLEE_TAG, "ESSetErrorCode Error");
return ES_ERROR;
}
OIC_LOG(INFO, ES_ENROLLEE_TAG, "ESSetErrorCode OUT");
return ES_OK;
}
ESResult ESTerminateEnrollee()
{
OIC_LOG(INFO, ES_ENROLLEE_TAG, "ESTerminateEnrollee IN");
UnRegisterResourceEventCallBack();
//Delete Prov resource
......
......@@ -521,18 +521,14 @@ OCStackResult CreateEasySetupResources(bool isSecured, ESResourceMask resourceMa
res = initWiFiResource(isSecured);
if(res != OC_STACK_OK)
{
// TODO: destroy logic will be added
OIC_LOG_V(ERROR, ES_RH_TAG, "initWiFiResource result: %s", getResult(res));
return res;
}
res = OCBindResource(gProvResource.handle, gWiFiResource.handle);
if(res != OC_STACK_OK)
{
// TODO : Error Handling
OIC_LOG_V(ERROR, ES_RH_TAG, "Bind WiFiResource result: %s", getResult(res));
return res;
}
......@@ -544,18 +540,14 @@ OCStackResult CreateEasySetupResources(bool isSecured, ESResourceMask resourceMa
res = initCloudServerResource(isSecured);
if(res != OC_STACK_OK)
{
// TODO: destroy logic will be added
OIC_LOG_V(ERROR, ES_RH_TAG, "initCloudResource result: %s", getResult(res));
return res;
}
res = OCBindResource(gProvResource.handle, gCloudResource.handle);
if(res != OC_STACK_OK)
{
// TODO : Error Handling
OIC_LOG_V(ERROR, ES_RH_TAG, "Bind CloudResource result: %s", getResult(res));
return res;
}
}
......@@ -566,18 +558,14 @@ OCStackResult CreateEasySetupResources(bool isSecured, ESResourceMask resourceMa
res = initDevConfResource(isSecured);
if(res != OC_STACK_OK)
{
// TODO: destroy logic will be added
OIC_LOG_V(ERROR, ES_RH_TAG, "initDevConf result: %s", getResult(res));
return res;
}
res = OCBindResource(gProvResource.handle, gDevConfResource.handle);
if(res != OC_STACK_OK)
{
// TODO : Error Handling
OIC_LOG_V(ERROR, ES_RH_TAG, "Bind DevConfResource result: %s", getResult(res));
return res;
}
}
......@@ -585,12 +573,13 @@ OCStackResult CreateEasySetupResources(bool isSecured, ESResourceMask resourceMa
if(maskFlag == false)
{
// TODO: destroy logic will be added
OIC_LOG_V(ERROR, ES_RH_TAG, "Invalid ResourceMask");
return OC_STACK_ERROR;
}
OIC_LOG_V(INFO, ES_RH_TAG, "Created all resources with result: %s", getResult(res));
return res;
}
......@@ -607,25 +596,26 @@ OCStackResult DeleteProvisioningResource()
OCStackResult DeleteEasySetupResources()
{
OCStackResult res = OCDeleteResource(gProvResource.handle);
OCStackResult res = OCDeleteResource(gWiFiResource.handle);
if (res != OC_STACK_OK)
{
OIC_LOG_V(INFO, ES_RH_TAG, "Deleting Prov resource error with result: %s", getResult(res));
OIC_LOG_V(ERROR, ES_RH_TAG, "Deleting WiFi resource error with result: %s", getResult(res));
}
res = OCDeleteResource(gWiFiResource.handle);
res = OCDeleteResource(gCloudResource.handle);
if (res != OC_STACK_OK)
{
OIC_LOG_V(INFO, ES_RH_TAG, "Deleting WiFi resource error with result: %s", getResult(res));
OIC_LOG_V(ERROR, ES_RH_TAG, "Deleting CloudServer resource error with result: %s", getResult(res));
}
res = OCDeleteResource(gCloudResource.handle);
res = OCDeleteResource(gDevConfResource.handle);
if (res != OC_STACK_OK)
{
OIC_LOG_V(INFO, ES_RH_TAG, "Deleting CloudServer resource error with result: %s", getResult(res));
OIC_LOG_V(ERROR, ES_RH_TAG, "Deleting DevConf resource error with result: %s", getResult(res));
}
res = OCDeleteResource(gDevConfResource.handle);
res = OCDeleteResource(gProvResource.handle);
if (res != OC_STACK_OK)
{
OIC_LOG_V(INFO, ES_RH_TAG, "Deleting DevConf resource error with result: %s", getResult(res));
OIC_LOG_V(ERROR, ES_RH_TAG, "Deleting Prov resource error with result: %s", getResult(res));
}
return res;
......@@ -852,9 +842,30 @@ OCStackResult SetDeviceProperty(ESDeviceProperty *deviceProperty)
OIC_LOG_V(INFO, ES_RH_TAG, "Device Name : %s", gDevConfResource.devName);
OIC_LOG(INFO, ES_RH_TAG, "SetDeviceProperty OUT");
return OC_EH_OK;
return OC_STACK_OK;
}
OCStackResult SetEnrolleeState(ESEnrolleeState esState)
{
OIC_LOG(INFO, ES_RH_TAG, "SetEnrolleeState IN");
gProvResource.status = esState;
OIC_LOG_V(INFO, ES_RH_TAG, "Enrollee Status : %d", gProvResource.status);
OIC_LOG(INFO, ES_RH_TAG, "SetEnrolleeState OUT");
return OC_STACK_OK;
}
OCStackResult SetEnrolleeErrCode(ESErrorCode esErrCode)
{
OIC_LOG(INFO, ES_RH_TAG, "SetEnrolleeErrCode IN");
gProvResource.lastErrCode = esErrCode;
OIC_LOG_V(INFO, ES_RH_TAG, "Enrollee ErrorCode : %d", gProvResource.lastErrCode);
OIC_LOG(INFO, ES_RH_TAG, "SetEnrolleeErrCode OUT");
return OC_STACK_OK;
}
const char *getResult(OCStackResult result)
{
switch (result)
......
......@@ -43,7 +43,7 @@ typedef struct PROVRESOURCE
OCResourceHandle handle;
ProvStatus status; // provisiong status
bool trigger; // Trigger network connection, 0 : Init value, 1 : Connected to the target network.
ESLastErrCode lastErrCode;
ESErrorCode lastErrCode;
char errorMessage[MAX_ERRMSGLEN];
char ocfWebLinks[MAX_WEBLINKLEN];
} ProvResource;
......@@ -81,7 +81,8 @@ OCStackResult CreateEasySetupResources(bool isSecured, ESResourceMask resourceMa
OCStackResult DeleteEasySetupResources();
OCStackResult SetDeviceProperty(ESDeviceProperty *deviceProperty);
OCStackResult SetEnrolleeState(ESEnrolleeState esState);
OCStackResult SetEnrolleeErrCode(ESErrorCode esErrCode);
void GetTargetNetworkInfoFromProvResource(char *, char *);
void RegisterWifiRsrcEventCallBack(ESWiFiCB);
......
......@@ -225,7 +225,7 @@ typedef enum
/**
* Error Code that given WiFi's SSID is not found
*/
ES_ERRCODE_SSID_NOTFOUND = 1,
ES_ERRCODE_SSID_NOT_FOUND = 1,
/**
* Error Code that given WiFi's Password is wrong
......@@ -235,7 +235,7 @@ typedef enum
/**
* Error Code that IP address is not allocated
*/
ES_ERRCODE_IP_NOTALLOCATED,
ES_ERRCODE_IP_NOT_ALLOCATED,
/**
* Error Code that there is no Internet connection
......@@ -256,7 +256,7 @@ typedef enum
* No Error Occured
*/
ES_ERRCODE_NONE = 999
} ESLastErrCode;
} ESErrorCode;
typedef struct
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment