Overview   API Reference  

devices/util.hpp

00001 #if !defined(__DEVICES_UTIL_HPP__)
00002 #define __DEVICES_UTIL_HPP__
00003 
00004 //
00005 // local includes
00006 //
00007 #include "devices/common.hpp"
00008 
00013 template <typename DescriptorT, typename OptionT>
00014 inline OptionT get_descriptor_option(config_node &device_node, const string &name,
00015                                      OptionT default_value=OptionT())
00016 {
00017     while (const config_node *node=device_node.remove_child(name)) {
00018         if (node->is_string()) {
00019             if (const DescriptorT *descriptor=DescriptorT::get(node->string))
00020                 default_value=descriptor->code;
00021             else
00022                 node->warn_wrong_value();
00023         }
00024         else if (node->is_number()) default_value=node->number;
00025         else node->warn_wrong_type();
00026 
00027         delete node;
00028     }
00029 
00030     return default_value;
00031 }
00032 
00037 inline uint32_t class_option(config_node &device_node, const string &name,
00038                              uint32_t default_value=pci_config_header16::class_code::ANY_DEVICE)
00039 {
00040     return get_descriptor_option<pci_class_descriptor>(device_node, name, default_value);
00041 }
00042 
00043 #endif
00044 
00045 // ***** end of source ***** //
00046 

L4vmm Reference Manual, written by Mario Schwalbe  © 2006-2008