// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainRef
190050
func (c *Domain) Ref() error {
	var err C.virError
	ret := C.virDomainRefWrapper(c.ptr, &err)
	if ret == -1 {
		return makeError(&err)
	}
	return nil
}
668420
func ParseReferenceParam(paramStr string, info SearchParamInfo) *ReferenceParam {
	if info.Postfix != "" {
		typ := findReferencedType("", info)
		q := Query{Resource: typ, Query: info.Postfix + "=" + paramStr}
		return &ReferenceParam{info, ChainedQueryReference{Type: typ, ChainedQuery: q}}
	} else {
		ref := unescape(paramStr)
		re := regexp.MustCompile("\\/?(([^\\/]+)\\/)?([^\\/]+)$")
		if m := re.FindStringSubmatch(ref); m != nil {
			typ := findReferencedType(m[2], info)
			if u, e := url.Parse(ref); e == nil && u.IsAbs() {
				return &ReferenceParam{info, ExternalReference{Type: typ, URL: ref}}
			} else {
				return &ReferenceParam{info, LocalReference{Type: typ, ID: m[3]}}
			}
		}
	}
	return &ReferenceParam{info, nil}
}
198052
func (d *Domain) Save(destFile string) error {
	cPath := C.CString(destFile)
	defer C.free(unsafe.Pointer(cPath))
	var err C.virError
	result := C.virDomainSaveWrapper(d.ptr, cPath, &err)
	if result == -1 {
		return makeError(&err)
	}
	return nil
}
1269488
func (d *Domain) GetAutostart() (bool, error) {
	var out C.int
	var err C.virError
	result := C.virDomainGetAutostartWrapper(d.ptr, (*C.int)(unsafe.Pointer(&out)), &err)
	if result == -1 {
		return false, makeError(&err)
	}
	switch out {
	case 1:
		return true, nil
	default:
		return false, nil
	}
}
488036
func (_class VBDClass) GetVM(sessionID SessionRef, self VBDRef) (_retval VMRef, _err error) {
	_method := "VBD.get_VM"
	_sessionIDArg, _err := convertSessionRefToXen(fmt.Sprintf("%s(%s)", _method, "session_id"), sessionID)
	if _err != nil {
		return
	}
	_selfArg, _err := convertVBDRefToXen(fmt.Sprintf("%s(%s)", _method, "self"), self)
	if _err != nil {
		return
	}
	_result, _err := _class.client.APICall(_method, _sessionIDArg, _selfArg)
	if _err != nil {
		return
	}
	_retval, _err = convertVMRefToGo(_method + " -> ", _result.Value)
	return
}
1364508
func (d *Domain) Reset(flags uint32) error {
	var err C.virError
	ret := C.virDomainResetWrapper(d.ptr, C.uint(flags), &err)
	if ret == -1 {
		return makeError(&err)
	}

	return nil
}
1023179
func ParseRef(s string) (Ref, error) {
	var id Ref
	if s == "" {
		return id, errors.Wrapf(ErrBlankImageID, "parsing %q", s)
	}
	if strings.HasPrefix(s, "/") || strings.HasSuffix(s, "/") {
		return id, errors.Wrapf(ErrMalformedImageID, "parsing %q", s)
	}

	elements := strings.Split(s, "/")
	switch len(elements) {
	case 0: // NB strings.Split will never return []
		return id, errors.Wrapf(ErrMalformedImageID, "parsing %q", s)
	case 1: // no slashes, e.g., "alpine:1.5"; treat as library image
		id.Image = s
	case 2: // may have a domain e.g., "localhost/foo", or not e.g., "weaveworks/scope"
		if domainRegexp.MatchString(elements[0]) {
			id.Domain = elements[0]
			id.Image = elements[1]
		} else {
			id.Image = s
		}
	default: // cannot be a library image, so the first element is assumed to be a domain
		id.Domain = elements[0]
		id.Image = strings.Join(elements[1:], "/")
	}

	// Figure out if there's a tag
	imageParts := strings.Split(id.Image, ":")
	switch len(imageParts) {
	case 1:
		break
	case 2:
		if imageParts[0] == "" || imageParts[1] == "" {
			return id, errors.Wrapf(ErrMalformedImageID, "parsing %q", s)
		}
		id.Image = imageParts[0]
		id.Tag = imageParts[1]
	default:
		return id, ErrMalformedImageID
	}

	return id, nil
}
327999
func (w *WebHookPayload) GetRef() string {
	if w == nil || w.Ref == nil {
		return ""
	}
	return *w.Ref
}
1033205
func domainEventIOErrorCallback(c C.virConnectPtr, d C.virDomainPtr,
	srcPath *C.char, devAlias *C.char, action int, opaque int) {

	domain := VirDomain{ptr: d}
	connection := VirConnection{ptr: c}

	eventDetails := DomainIOErrorEvent{
		SrcPath:  C.GoString(srcPath),
		DevAlias: C.GoString(devAlias),
		Action:   action,
	}

	callDomainCallbackId(opaque, &connection, &domain, eventDetails)
}
1328236
func getVolumeFromRef(ref string) (volNamespace string, volName string, err error) {
	refParts := strings.Split(ref, ".")
	switch len(refParts) {
	case 2:
		return refParts[0], refParts[1], nil
	case 3:
		return refParts[1], refParts[2], nil
	}
	return "", "", fmt.Errorf("ref not in format volNamespace.volName or pvName.volNamespace.volName")
}
1125491
func (r *Reference) GetRef() string {
	if r == nil || r.Ref == nil {
		return ""
	}
	return *r.Ref
}
502095
func (p *PushEvent) GetRef() string {
	if p == nil || p.Ref == nil {
		return ""
	}
	return *p.Ref
}
18351
func (c *CreateEvent) GetRef() string {
	if c == nil || c.Ref == nil {
		return ""
	}
	return *c.Ref
}
676000
func (d *Domain) CoreDump(to string, flags DomainCoreDumpFlags) error {
	cto := C.CString(to)
	defer C.free(unsafe.Pointer(cto))

	var err C.virError
	ret := C.virDomainCoreDumpWrapper(d.ptr, cto, C.uint(flags), &err)
	if ret == -1 {
		return makeError(&err)
	}

	return nil
}
194404
func (c Config) DefaultDecisionRef() ast.Ref {
	ref, _ := parsePathToRef(*c.DefaultDecision)
	return ref
}
1007628
func (c *Interface) Ref() error {
	var err C.virError
	ret := C.virInterfaceRefWrapper(c.ptr, &err)
	if ret == -1 {
		return makeError(&err)
	}
	return nil
}
1098541
func (r *RLockedFile) IncLockRef() {
	r.mutex.Lock()
	r.refs++
	r.mutex.Unlock()
}