Documentation/QOMConventions

From QEMU
Revision as of 14:57, 7 February 2013 by AF (talk | contribs) (Add link to QOM feature page)

QOM Coding Conventions

  • DO use TYPE_FOO constants defined in a header
  • DO use verbose macro names
  • DO use names-separated-by-dashes
  • DON'T duplicate literal string type names
#define TYPE_EXAMPLE "example"
.name = TYPE_EXAMPLE,
object_new(TYPE_EXAMPLE)
qdev_create(NULL, TYPE_EXAMPLE)
  • DO place parent field first
  • DON'T use “busdev” or similar qdev conventions
typedef struct MyState {
    /*< private >*/
    Object parent_obj; /* or PCIDevice parent_obj etc. */
    /*< public >*/

    uint32_t some_register_value;
} MyState;
  • DO use cast macros (based on struct layout)
  • DON'T rely on DO_UPCAST() (field names)
  • DO use per-type variable declarations
  • Avoid using cast macros other than OBJECT() inline
void do_something_with(MyDeviceState *s) {
    PCIDevice *pci = PCI_DEVICE(s);

    pci->field = foo; /* not s->pci.field or PCI(s)->field */