OCStackResult OCSecureResource::removeDevice(unsigned short waitTimeForOwnedDeviceDiscovery, ResultCallBack resultCallback) { if(!resultCallback) { oclog() << "Result calback can't be null"; return OC_STACK_INVALID_PARAM; } OCStackResult result; auto cLock = m_csdkLock.lock(); if(cLock) { ProvisionContext* context = new ProvisionContext(resultCallback); std::lock_guard<std::recursive_mutex> lock(*cLock); result = OCRemoveDevice(static_cast<void*>(context), waitTimeForOwnedDeviceDiscovery, devPtr, &OCSecureResource::callbackWrapper); } else { oclog() <<"Mutex not found"; result = OC_STACK_ERROR; } return result; }
static int removeDevice(void) { // check |own_list| for removing device if(!g_own_list || 1>g_own_cnt) { printf(" > Owned Device List, to Remove Device, is Empty\n"); printf(" > Please Register Unowned Devices first, with [20] Menu\n"); return 0; // normal case } // select device for removing it int dev_num = 0; for( ; ; ) { printf(" > Enter Device Number, for Removing 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) { break; } printf(" Entered Wrong Number. Please Enter Again\n"); } // call |OCRemoveDevice| API actually // calling this API with callback actually acts like blocking // for error checking, the return value saved and printed g_doneCB = false; printf(" Removing Selected Owned Device..\n"); OCStackResult rst = OCRemoveDevice((void*) g_ctx, DISCOVERY_TIMEOUT, getDevInst((const OCProvisionDev_t*) g_own_list, dev_num), removeDeviceCB); if(OC_STACK_OK != rst) { OIC_LOG_V(ERROR, TAG, "OCRemoveDevice API error: %d", rst); return -1; } if(waitCallbackRet()) // input |g_doneCB| flag implicitly { OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error"); return -1; } // display the removed result printf(" > Removed Selected Owned Device\n"); printf(" > Please Discover Owned Devices for the Registered Result, with [10|12] Menu\n"); return 0; }
TEST(OCRemoveDeviceTest, ZeroWaitTime) { unsigned short waitTime = 0; OCProvisionDev_t dev1; EXPECT_EQ(OC_STACK_INVALID_PARAM, OCRemoveDevice(NULL, waitTime, &dev1, NULL)); }
TEST(OCRemoveDeviceTest, NullResultCallback) { unsigned short waitTime = 10; OCProvisionDev_t dev1; EXPECT_EQ(OC_STACK_INVALID_PARAM, OCRemoveDevice(NULL, waitTime, &dev1, NULL)); }
TEST(OCRemoveDeviceTest, NullTargetDevice) { unsigned short waitTime = 10 ; EXPECT_EQ(OC_STACK_INVALID_PARAM, OCRemoveDevice(NULL, waitTime, NULL, provisioningCB)); }