Sample code for Network Registration
//--------------------------------------------------------------------------------------------------/*** Test: Register mode.* This test doesn't work in roaming.!!** le_mrc_SetAutomaticRegisterMode() API test* le_mrc_SetManualRegisterMode() API test* le_mrc_GetRegisterMode() API test**///--------------------------------------------------------------------------------------------------static void Testle_mrc_RegisterMode(void){le_result_t res;int cmpRes;char mccStr[LE_MRC_MNC_BYTES] = {0};char mncStr[LE_MRC_MNC_BYTES] = {0};bool isManualOrigin, isManual;// Get the home PLMN to compare results.mncHomeStr, LE_MRC_MNC_BYTES);LE_INFO("Home PLMN is mcc.%s mnc.%s", mccHomeStr, mncHomeStr);res = le_mrc_GetRegisterMode(&isManualOrigin,mccStr, LE_MRC_MCC_BYTES, mncStr, LE_MRC_MNC_BYTES);LE_INFO("le_mrc_GetRegisterMode Manual(%c), mcc.%s mnc.%s",(isManualOrigin ? 'Y' : 'N'),mccStr, mncStr);res = le_mrc_SetAutomaticRegisterMode();sleep(5);memset(mccStr,0,LE_MRC_MCC_BYTES);memset(mncStr,0,LE_MRC_MNC_BYTES);LE_ASSERT(isManual == false);LE_INFO("le_mrc_GetRegisterMode Manual(%c), mcc.%s mnc.%s",(isManualOrigin ? 'Y' : 'N'),mccStr, mncStr);res = le_mrc_SetManualRegisterMode(mccHomeStr, mncHomeStr);LE_INFO("le_mrc_SetManualRegisterMode %s,%s return %d",mccHomeStr, mncHomeStr, res);sleep(5);memset(mccStr,0,LE_MRC_MCC_BYTES);memset(mncStr,0,LE_MRC_MNC_BYTES);LE_ASSERT(isManual == true);cmpRes = strcmp(mccHomeStr, mccStr);LE_WARN_IF(cmpRes, "Doesn't match mccHomeStr (%s) mccStr (%s)",mccHomeStr, mccStr)LE_ASSERT(cmpRes == 0);cmpRes = strcmp(mncHomeStr, mncStr);LE_WARN_IF(cmpRes, "Doesn't match mncHomeStr (%s) mncStr (%s)",mncHomeStr, mncStr)LE_ASSERT(cmpRes == 0);LE_INFO("le_mrc_GetRegisterMode Manual(Y), mcc.%s mnc.%s", mccStr, mncStr);res = le_mrc_SetAutomaticRegisterMode();sleep(5);memset(mccStr,0,LE_MRC_MCC_BYTES);memset(mncStr,0,LE_MRC_MNC_BYTES);LE_ASSERT(isManual == false);LE_INFO("le_mrc_GetRegisterMode Manual(N)");}//--------------------------------------------------------------------------------------------------/*** Test: Manual selection call back function.**///--------------------------------------------------------------------------------------------------static void MyManualSelectionHandler(le_result_t result,void* contextPtr){LE_INFO("le_mrc_SetManualRegisterModeAsync return %d", result);if (result == LE_OK ){le_sem_Post(ThreadSemaphore);}else{LE_ERROR("Failed");}}//--------------------------------------------------------------------------------------------------/*** Thread for test Register mode asynchronous .** Test API: le_mrc_SetManualRegisterModeAsync() API test*///--------------------------------------------------------------------------------------------------static void* MyRegisterModeAsyncThread(void* context ///< Context){LE_INFO("le_mrc_SetManualRegisterModeAsync mcc.%s mnc.%s",mccHomeStr, mncHomeStr);le_mrc_SetManualRegisterModeAsync(mccHomeStr, mncHomeStr, MyManualSelectionHandler, NULL);return NULL;}//--------------------------------------------------------------------------------------------------/*** Test: Register mode asynchronous.* This test doesn't work in roaming.!!** le_mrc_SetAutomaticRegisterMode() API test*///--------------------------------------------------------------------------------------------------static void Testle_mrc_RegisterModeAsync(void){char mccStr[LE_MRC_MNC_BYTES] = {0};char mncStr[LE_MRC_MNC_BYTES] = {0};bool isManual;int cmpRes;le_result_t res;le_clk_Time_t time;time.sec = 180;time.usec = 0;res = le_mrc_SetAutomaticRegisterMode();sleep(5);// Get the home PLMN to compare results.mncHomeStr, LE_MRC_MNC_BYTES);LE_INFO("Home PLMN is mcc.%s mnc.%s", mccHomeStr, mncHomeStr);// Init the semaphore for asynchronous callbackThreadSemaphore = le_sem_Create("HandlerSem",0);RegistrationThreadRef = le_thread_Create("CallBack", MyRegisterModeAsyncThread, NULL);le_thread_Start(RegistrationThreadRef);// Wait for complete asynchronous registrationres = le_sem_WaitWithTimeOut(ThreadSemaphore, time);le_thread_Cancel(RegistrationThreadRef);le_sem_Delete(ThreadSemaphore);sleep(SLEEP_5S);memset(mccStr,0,LE_MRC_MCC_BYTES);memset(mncStr,0,LE_MRC_MNC_BYTES);LE_ASSERT(isManual == true);cmpRes = strcmp(mccHomeStr, mccStr);LE_WARN_IF(cmpRes, "Doesn't match mccHomeStr (%s) mccStr (%s)",mccHomeStr, mccStr)LE_ASSERT(cmpRes == 0);cmpRes = strcmp(mncHomeStr, mncStr);LE_WARN_IF(cmpRes, "Doesn't match mncHomeStr (%s) mncStr (%s)",mncHomeStr, mncStr)LE_ASSERT(cmpRes == 0);LE_INFO("le_mrc_GetRegisterMode %c, mcc.%s mnc.%s",(isManual ? 'Y':'N'), mccStr, mncStr);sleep(SLEEP_5S);res = le_mrc_SetAutomaticRegisterMode();sleep(SLEEP_5S);}