Documentation/QOMConventions: Difference between revisions

From QEMU
(Document some collected QOM conventions from my KVM Forum 2012 QOM vadis talk)
 
m (Add link to QOM feature page)
Line 1: Line 1:
== QOM Coding Conventions ==
== [[Features/QOM|QOM]] Coding Conventions ==


* DO use TYPE_FOO constants defined in a header
* DO use TYPE_FOO constants defined in a header

Revision as of 14:57, 7 February 2013

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 */