This sample application demonstrates how to turn modem radio on or off.
1. Get the PhoneFactory and PhoneManager instances
auto &phoneFactory = PhoneFactory::getInstance();
auto phoneManager = phoneFactory.getPhoneManager();
2. Check if telephony subsystem is ready
bool subSystemsStatus = phoneManager->isSubsystemReady();
2.1 If telephony subsystem is not ready, wait for it to be ready
If subsystem is not ready, wait unconditionally.
if (!subSystemsStatus) {
std::future<bool> f = phoneManager->onSubsystemReady();
subSystemsStatus = f.get();
}
3. Instantiate Phone
auto phone = phoneManager->getPhone();
4. Implement IPhoneListener interface to receive service state change notifications
class MyPhoneListener : public telux::tel::IPhoneListener {
public:
void onRadioStateChanged(int phoneId, telux::tel::RadioState radiostate) {
}
~MyPhoneListener() {
}
}
4.1 Instantiate MyPhoneListener
auto myPhoneListener = std::make_shared<MyPhoneListener>();
5. Register for phone info updates
phoneManager->registerListener(myPhoneListener);
6. Implement ICommandResponseCallback to receive the status of setRadioPower API call
class MyPhoneCommandResponseCallback : public ICommandResponseCallback {
public:
MyPhoneCommandResponseCallback() {
}
void commandResponse(ErrorCode error) override;
};
7. Instantiate MyPhoneCommandResponseCallback
auto myPhoneCommandCb = std::make_shared<MyPhoneCommandResponseCallback>();
8. Set the radio power ON/OFF
phone->setRadioPower(true, myPhoneCommandCb);
9. Command response callback is invoked with error code indicating SUCCESS or FAILURE of the operation
MyPhoneCommandResponseCallback::commandResponse(ErrorCode error) {
if(error == ErrorCode::SUCCESS) {
std::cout << "Set Radio Power On request is successful ";
} else {
std::cout << "Set Radio Power On request failed with error " << static_cast<int>(error);
}
}