g_doneCB = true;
}
-static void syncDeviceCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
+static void resetDeviceCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError)
{
- if(!hasError)
- {
- OIC_LOG_V(INFO, TAG, "Sync Device SUCCEEDED - ctx: %s", (char*) ctx);
- }
- else
- {
- OIC_LOG_V(ERROR, TAG, "Sync Device FAILED - ctx: %s", (char*) ctx);
- printResultList((const OCProvisionResult_t*) arr, nOfRes);
- }
+ OC_UNUSED(ctx);
+ OIC_LOG_V(INFO, TAG, "Reset Device SUCCEEDED");
g_doneCB = true;
}
return 0;
}
- // select device for removing it
- int dev_num = 0;
+ OCProvisionDev_t *dev = NULL;
+
for ( ; ; )
{
- printf(" > Enter Device Number, for Resetting Device: ");
- for (int ret = 0; 1 != ret; )
- {
- ret = scanf("%d", &dev_num);
- for ( ; 0x20 <= getchar() ; ); // for removing overflow garbages
- // '0x20 <= code' is character region
- }
- if (0 < dev_num && g_own_cnt >= dev_num)
- {
+ printf("************************************************************\n");
+ printf("Reset device candidate list:\n");
+ g_unown_cnt = printDevList(g_own_list);
+ if(0 == g_unown_cnt)
+ {
+ break;
+ }
+
+ printf("Select number device from list\nor: -1 - escape\n");
+ int c = 0;
+
+ if (!scanf("%d",&c))
+ {
+ continue;
+ }
+
+ if(0 == c && NULL != dev)
+ {
+ break;
+ }
+
+ if(-1 == c)
+ {
+ return 0;
+ }
+
+ if(c > g_own_cnt)
+ {
+ continue;
+ }
+
+ dev = g_own_list;
+ for(int lst_cnt = 1; dev && lst_cnt != c; lst_cnt++, dev = dev->next);
break;
- }
- printf(" Entered Wrong Number. Please Enter Again\n");
+
}
g_doneCB = false;
printf(" Resetting Selected Owned Device..\n");
- OCStackResult rst = OCResetDevice((void *) g_ctx, DISCOVERY_TIMEOUT,
- getDevInst((const OCProvisionDev_t *) g_own_list, dev_num), syncDeviceCB);
+ OCStackResult rst = SRPResetDevice(dev, resetDeviceCB);
+
if (OC_STACK_OK != rst)
{
OIC_LOG_V(ERROR, TAG, "OCResetDevice API error: %d", rst);
if (waitCallbackRet()) // input |g_doneCB| flag implicitly
{
- OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error");
+ OIC_LOG_V(ERROR, TAG, "%s: callback error", __func__);
return -1;
}