Commit 6389a14a authored by Jihun Ha's avatar Jihun Ha Committed by Uze Choi

Add an callback for EasySetup resource in case of "connect" method

A new property, "connect", is managed in EasySetup resource, which can handle
POST operation. For that, an additional callback gets to be needed for
EasySetup resource.

Change-Id: I34d5ddeb7f9f1469b992099e75bed78ee3450bab
Signed-off-by: default avatarJihun Ha <jihun.ha@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/17067Tested-by: default avatarjenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: default avatarUze Choi <uzchoi@samsung.com>
Tested-by: default avatarUze Choi <uzchoi@samsung.com>
parent e57f4933
......@@ -29,6 +29,15 @@ extern "C"
{
#endif
/**
* @brief Data structure for connect request from Mediator
*/
typedef struct
{
ES_CONNECT_TYPE connect[NUM_CONNECT_TYPE];
int numRequest;
} ESConnectRequest;
/**
* @brief Data structure delivered from mediator, which provides WiFi information
*/
......@@ -95,6 +104,7 @@ typedef struct
*/
typedef struct
{
void (*ConnectRequestCb) (ESConnectRequest *);
void (*WiFiConfProvCb) (ESWiFiConfData *);
void (*DevConfProvCb) (ESDevConfData *);
void (*CoapCloudConfProvCb) (ESCoapCloudConfData *);
......
......@@ -44,6 +44,27 @@ static bool gIsSecured = false;
static ESProvisioningCallbacks gESProvisioningCb;
static ESDeviceProperty gESDeviceProperty;
void ESConnectRequestCallback(ESResult esResult, ESConnectRequest *eventData)
{
OIC_LOG_V(DEBUG, ES_ENROLLEE_TAG, "ESConnectRequestCallback IN");
if(esResult != ES_OK)
{
OIC_LOG_V(ERROR, ES_ENROLLEE_TAG, "ESConnectRequestCallback Error Occured");
return;
}
if(gESProvisioningCb.ConnectRequestCb != NULL)
{
gESProvisioningCb.ConnectRequestCb(eventData);
}
else
{
OIC_LOG_V(ERROR, ES_ENROLLEE_TAG, "ConnectRequestCb is NULL");
return;
}
}
void ESWiFiConfRsrcCallback(ESResult esResult, ESWiFiConfData *eventData)
{
OIC_LOG(INFO, ES_ENROLLEE_TAG, "ESWiFiConfRsrcCallback IN");
......@@ -154,6 +175,13 @@ ESResult ESInitEnrollee(bool isSecured, ESResourceMask resourceMask, ESProvision
}
}
// TODO: if EasySetupProvCb is NULL, we should return an error at this moment.
if(callbacks.ConnectRequestCb != NULL)
{
gESProvisioningCb.ConnectRequestCb = callbacks.ConnectRequestCb;
RegisterConnectRequestEventCallBack(ESConnectRequestCallback);
}
if(CreateEasySetupResources(gIsSecured, resourceMask) != OC_STACK_OK)
{
UnRegisterResourceEventCallBack();
......@@ -166,7 +194,6 @@ ESResult ESInitEnrollee(bool isSecured, ESResourceMask resourceMask, ESProvision
return ES_ERROR;
}
OIC_LOG(INFO, ES_ENROLLEE_TAG, "ESInitEnrollee OUT");
return ES_OK;
}
......
......@@ -57,6 +57,7 @@ void updateCoapCloudConfResource(OCRepPayload* input);
void updateDevConfResource(OCRepPayload* input);
const char *getResult(OCStackResult result);
ESConnectRequestCB gConnectRequestEvtCb = NULL;
ESWiFiConfCB gWifiConfRsrcEvtCb = NULL;
ESCoapCloudConfCB gCoapCloudConfRsrcEvtCb = NULL;
ESDevConfCB gDevConfRsrcEvtCb = NULL;
......@@ -120,6 +121,11 @@ void RegisterDevConfRsrcEventCallBack(ESDevConfCB cb)
gDevConfRsrcEvtCb = cb;
}
void RegisterConnectRequestEventCallBack(ESConnectRequestCB cb)
{
gConnectRequestEvtCb = cb;
}
void UnRegisterResourceEventCallBack()
{
if (gWifiConfRsrcEvtCb)
......@@ -134,12 +140,21 @@ void UnRegisterResourceEventCallBack()
{
gDevConfRsrcEvtCb = NULL;
}
if (gConnectRequestEvtCb)
{
gConnectRequestEvtCb = NULL;
}
}
OCStackResult initEasySetupResource(bool isSecured)
{
g_ESEasySetupResource.status = ES_STATE_INIT;
g_ESEasySetupResource.lastErrCode = ES_ERRCODE_NO_ERROR;
for( int i = 0 ; i < NUM_CONNECT_TYPE ; ++i )
{
g_ESEasySetupResource.connectRequest[i] = ES_CONNECT_NONE;
}
g_ESEasySetupResource.numRequest = 0;
OCStackResult res = OC_STACK_ERROR;
if (isSecured)
......@@ -281,6 +296,46 @@ void updateEasySetupResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* in
{
OIC_LOG_V(DEBUG, ES_RH_TAG, "g_ESEasySetupResource.status %d", g_ESEasySetupResource.status);
int64_t *connect_req = NULL;
size_t dimensions[MAX_REP_ARRAY_DEPTH] = { 0 };
if (OCRepPayloadGetIntArray(input, OC_RSRVD_ES_CONNECT, &connect_req, dimensions))
{
ESConnectRequest* connectRequest = (ESConnectRequest*)OICMalloc(sizeof(ESConnectRequest));
int cntRequest = 0;
for (int i = 0 ; i < NUM_CONNECT_TYPE ; ++i)
{
g_ESEasySetupResource.connectRequest[i] = ES_CONNECT_NONE;
connectRequest->connect[i] = ES_CONNECT_NONE;
if(i < dimensions[0] &&
(connect_req[i] == ES_CONNECT_WIFI || connect_req[i] == ES_CONNECT_COAPCLOUD))
{
g_ESEasySetupResource.connectRequest[cntRequest] = connect_req[i];
connectRequest->connect[cntRequest] = connect_req[i];
OIC_LOG_V(DEBUG, ES_RH_TAG, "g_ESEasySetupResource.connectType[%d] : %d",
cntRequest, g_ESEasySetupResource.connectRequest[cntRequest]);
cntRequest++;
}
}
connectRequest->numRequest = cntRequest;
g_ESEasySetupResource.numRequest = cntRequest;
if(g_ESEasySetupResource.connectRequest[0] != ES_CONNECT_NONE)
{
OIC_LOG(DEBUG, ES_RH_TAG, "Send ConnectRequest Callback To ES");
// TODO : Need to check appropriateness of gWiFiData
if(gConnectRequestEvtCb != NULL)
{
gConnectRequestEvtCb(ES_OK, connectRequest);
}
else
{
OIC_LOG(ERROR, ES_RH_TAG, "gConnectRequestEvtCb is NULL");
}
}
}
if(ehRequest->query)
{
if(CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_BATCH))
......@@ -942,6 +997,14 @@ OCRepPayload* constructResponseOfEasySetup(OCEntityHandlerRequest *ehRequest)
OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_PROVSTATUS, g_ESEasySetupResource.status);
OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_LAST_ERRORCODE, g_ESEasySetupResource.lastErrCode);
size_t dimensions[MAX_REP_ARRAY_DEPTH] = {g_ESEasySetupResource.numRequest , 0, 0};
int64_t *connectRequest = (int64_t *)OICMalloc(g_ESEasySetupResource.numRequest * sizeof(int64_t));
for(int i = 0 ; i < g_ESEasySetupResource.numRequest ; ++i)
{
connectRequest[i] = g_ESEasySetupResource.connectRequest[i];
}
OCRepPayloadSetIntArray(payload, OC_RSRVD_ES_CONNECT, (int64_t *)connectRequest, dimensions);
if(gWriteUserdataCb)
{
gWriteUserdataCb(payload, OC_RSRVD_ES_RES_TYPE_EASYSETUP);
......@@ -998,6 +1061,13 @@ OCRepPayload* constructResponseOfEasySetup(OCEntityHandlerRequest *ehRequest)
OCRepPayloadSetPropInt(repPayload, OC_RSRVD_ES_PROVSTATUS, g_ESEasySetupResource.status);
OCRepPayloadSetPropInt(repPayload, OC_RSRVD_ES_LAST_ERRORCODE, g_ESEasySetupResource.lastErrCode);
size_t dimensions[MAX_REP_ARRAY_DEPTH] = {g_ESEasySetupResource.numRequest , 0, 0};
int64_t *connectRequest = (int64_t *)OICMalloc(g_ESEasySetupResource.numRequest * sizeof(int64_t));
for(int i = 0 ; i < g_ESEasySetupResource.numRequest ; ++i)
{
connectRequest[i] = g_ESEasySetupResource.connectRequest[i];
}
OCRepPayloadSetIntArray(repPayload, OC_RSRVD_ES_CONNECT, (int64_t *)connectRequest, dimensions);
if(gWriteUserdataCb)
{
......
......@@ -34,6 +34,7 @@
extern "C" {
#endif
typedef void (*ESConnectRequestCB) (ESResult, ESConnectRequest *);
typedef void (*ESWiFiConfCB) (ESResult, ESWiFiConfData *);
typedef void (*ESCoapCloudConfCB) (ESResult, ESCoapCloudConfData *);
typedef void (*ESDevConfCB) (ESResult, ESDevConfData *);
......@@ -47,6 +48,8 @@ typedef struct
OCResourceHandle handle;
ProvStatus status; // provisiong status
ESErrorCode lastErrCode;
ES_CONNECT_TYPE connectRequest[NUM_CONNECT_TYPE];
int numRequest;
} EasySetupResource;
typedef struct
......
......@@ -39,6 +39,7 @@ extern "C"
#define OIC_STRING_MAX_VALUE 64
#define MAX_WEBLINKLEN 3
#define NUM_WIFIMODE 5
#define NUM_CONNECT_TYPE 3
/**
* Attributes used to form a proper easysetup conforming JSON message.
......@@ -143,8 +144,9 @@ typedef enum
*/
typedef enum
{
ES_CONNECT_WIFI = 0x01, /**< WiFi Conf resource **/
ES_CONNECT_COAPCLOUD = 0x02 /**< Coap Cloud Conf resource **/
ES_CONNECT_NONE = 0, /**< Init value **/
ES_CONNECT_WIFI = 1, /**< WiFi Conf resource **/
ES_CONNECT_COAPCLOUD = 2 /**< Coap Cloud Conf resource **/
} ES_CONNECT_TYPE;
/**
......
......@@ -67,6 +67,24 @@ void PrintMenu()
printf("============\n");
}
void ConnectRequestCbInApp(ESConnectRequest *connectRequest)
{
printf("ConnectRequestCbInApp IN\n");
if(connectRequest == NULL)
{
printf("connectRequest is NULL\n");
return ;
}
for(int i = 0 ; i < connectRequest->numRequest ; ++i)
{
printf("connect : %d\n", connectRequest->connect[i]);
}
printf("ConnectRequestCbInApp OUT\n");
}
void WiFiConfProvCbInApp(ESWiFiConfData *eventData)
{
printf("WiFiConfProvCbInApp IN\n");
......@@ -126,6 +144,7 @@ void CoapCloudConfProvCbInApp(ESCoapCloudConfData *eventData)
}
ESProvisioningCallbacks gCallbacks = {
.ConnectRequestCb = &ConnectRequestCbInApp,
.WiFiConfProvCb = &WiFiConfProvCbInApp,
.DevConfProvCb = &DevConfProvCbInApp,
.CoapCloudConfProvCb = &CoapCloudConfProvCbInApp
......
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