In the driver, there are two methods that must be implemented in order to handle config elements:
static std::string ButtonDevice::getElementType();When the configuration changes, the JCCL Configuration Manager asks every registered configuration handler for their respective configuration element types. If the type matches the type of the newly received configuration element, then the handler's config() method is invoked. All device drivers are configuration handlers and thus need to indicate the configuration element type they accept. The type value is returned by this method, and the implementation for our simple driver is the following:
std::string ButtonDevice::getElementType()
{
return std::string("ButtonDevice");
}Note that the string returned matches the token we defined in Example 6.1, “button_device.jdef: Configuration Definition File for Simple Button Device”.
virtual bool gadget::Input::config(jccl::ConfigElementPtr e);When the Configuration Manager detects a configuration change for a given driver, it will pass the new jccl::ConfigElementPtr object as the parameter to this method. For more information about how to use instances of jccl::ConfigElementPtr, refer to the JCCL Programmer's Reference. The following is a simple example for the basic button device we have used thus far:
bool ButtonDevice::config(jccl::ConfigElementPtr e)
{
if ( ! gadget::Digital::config(e) )
{
return false;
}
mPortName = e->getProperty<std::string>("port");
mBaudRate = e->getProperty<int>("baud");
return true;
}